Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore computation of include directories #10623

Merged

Conversation

alalazo
Copy link
Member

@alalazo alalazo commented Feb 15, 2019

This PR restores the computation of the include directories that was remove as part of the hotfix in #10604 It also adds the following modifications:

davydden
davydden previously approved these changes Feb 15, 2019
lib/spack/llnl/util/filesystem.py Show resolved Hide resolved
@davydden
Copy link
Member

@alalazo FYI https://github.blog/2019-02-14-introducing-draft-pull-requests/ 😄

@alalazo alalazo force-pushed the fixes/restore_computation_of_include_dirs branch from f428656 to 7e6e43c Compare February 16, 2019 20:17
@alalazo alalazo force-pushed the fixes/restore_computation_of_include_dirs branch from 09de4a0 to 93b1e87 Compare February 18, 2019 10:44
@alalazo alalazo added headers and removed WIP labels Feb 18, 2019
@alalazo
Copy link
Member Author

alalazo commented Feb 18, 2019

@davydden Can you please double check this PR works for the cases reported in #10601 and #10603 also on MacOS?

Copy link
Member

@davydden davydden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davydden Can you please double check this PR works for the cases reported in #10601 and #10603 also on MacOS?

I will try it today evening, on the conference the whole week.

@davydden
Copy link
Member

@alalazo

Can you please double check this PR works for the cases reported in #10601 and #10603 also on MacOS?

I can confirm that both cmake and expat (as a dependency) builds fine with this PR on macOS. I think it's ready to be merged, @scheibelp ping.

@scheibelp
Copy link
Member

I think libxml2 is a case where this may be problematic: it defines headers in <prefix>/include/libxml2/, and at least some dependents appear to import from this directly (rather than as #include <libxml2/foo.h>). My inclination is that there needs to be a separate object/function for handling each of the following behaviors:

  • Finding all headers and their directories
  • Reporting the include directories that dependents should use

That being said, if dependents are split on how to refer to headers in libxml2 (e.g. some of them refer to foo.h and some to libxml2/foo.h) then there wouldn't be a libxml2-"centric" solution: the dependents themselves would have to choose how to refer to it.

See:

@davydden
Copy link
Member

davydden commented Feb 19, 2019

@scheibelp

it defines headers in <prefix>/include/libxml2/, and at least some dependents appear to import from this directly (rather than as #include <libxml2/foo.h>).

that's too bad. But I don't think such issues should hold this PR. I would be inclined to consider them anomalies that one can discuss how to handle or maybe convince downstream package authors to do "proper" includes (i.e. #include <foo/utilities.h is safe way compared to #include <utilities.h> as there could be a number of utilities.h provided by various packages. Frankly I don't understand why would anyone want to import headers that way...)

@alalazo
Copy link
Member Author

alalazo commented Feb 20, 2019

@scheibelp Despite not being a recommended best practice, are you aware of packages that are using libxml2 with include directives like:

#include "libxml2/foo.h"

? It seems that libxml2's web-page advises to use what xml2-config --cflags returns and as far as I can see this always include:

-I<prefix>/include/libxml2

If that's the case we can allow setting the HeaderList.directories property and add a custom headers to libxml2. This will solve the current problem and we can then discuss a more extensive refactoring that involves a splitting of responsibilities in another issue.

@scheibelp
Copy link
Member

Despite not being a recommended best practice, are you aware of packages that are using libxml2 with include directives like:
#include "libxml2/foo.h"

No - in fact I think that's the issue (i.e. the fact that libxml2 wants users to build with -I<libxml2-prefix>/include/libxml2 is in conflict with this PR). Right now I think it would be the intent of this PR that for libxml2, .headers.directories would report <libxml2-prefix>/include (vs. <libxml2-prefix>/include/libxml2).

If that's true, .headers.directories would be insufficient for specifying -I entries for dependents of libxml2. My goals are:

  • sensible defaults for .headers.directories (which I think this achieves)
  • allow packages to provide some method to specify -I entries to dependents

Right now, I don't think this PR handles the second goal; that wouldn't be a deal breaker, but I also don't see a clear path forward for handling the second goal.

I wanted to check: do you think dependents should be responsible for calling pkgconfig to retrieve the appropriate -I entries, and that Spack should only be responsible for reporting the "root" include directory?

@alalazo
Copy link
Member Author

alalazo commented Feb 20, 2019

do you think dependents should be responsible for calling pkgconfig to retrieve the appropriate -I entries, and that Spack should only be responsible for reporting the "root" include directory?

No, I don't think so. My idea for now would be that libxml2 and other similar packages should override headers and be able to do the following:

@property
def headers(self):
    # Compute the HeaderList in some way
    hl = ...
    hl.directories = [self.spec.prefix.include.libxml2]
    return hl

I was asking the question above because having a few dependencies that use -I<prefix>/include and others that do -I<prefix>/include/libxml2 would complicate things a bit and require a solution similar to what we do for libs (give comma separated query parameters after the spec name when getting items).

I also think that separating concerns might make sense, but that requires more extensive modifications - at least a refactoring of HeaderList and the addition of a new ForwardQueryToPackage descriptor in Spec - that's why I am proposing to save it for later in case.

@alalazo
Copy link
Member Author

alalazo commented Feb 20, 2019

Updated description at the top

@scheibelp
Copy link
Member

So to be clear (not that we have documented it anywhere) HeaderList.directories used to be a shorthand to refer to the directories where the header files are stored. That API has now changed to be: the directories that dependents should reference with -I. I think it would be worthwhile to document that in HeaderList

@alalazo
Copy link
Member Author

alalazo commented Feb 21, 2019

@scheibelp With 7c2e5c9 and 74852c4 we now have:

$ spack-python
Spack version 0.12.1
Python 2.7.15rc1, Linux x86_64
>>> import spack.spec
>>> s = spack.spec.Spec('hwloc')
>>> s.concretize()
>>> s['libxml2'].headers.directories
['/home/mculpo/PycharmProjects/spack/opt/spack/linux-ubuntu18.04-x86_64/gcc-8.2.0/libxml2-2.9.8-imjssszfoiodyeesuf5xpm5da5cl25vs/include/libxml2']
>>> s['libxml2'].headers.cpp_flags
'-I/home/mculpo/PycharmProjects/spack/opt/spack/linux-ubuntu18.04-x86_64/gcc-8.2.0/libxml2-2.9.8-imjssszfoiodyeesuf5xpm5da5cl25vs/include/libxml2'

Would that be enough?

@alalazo
Copy link
Member Author

alalazo commented Feb 21, 2019

@michaelkuhn I thought you might be interested too in the latest commits that involve libxml2

Copy link
Member

@scheibelp scheibelp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a couple requests regarding names, and a minor request about simplifying some logic.

Also I'd like to make it slightly easier for users to override Package.headers (the comment in libxml2).

lib/spack/llnl/util/filesystem.py Outdated Show resolved Hide resolved
lib/spack/spack/test/conftest.py Outdated Show resolved Hide resolved
var/spack/repos/builtin/packages/libxml2/package.py Outdated Show resolved Hide resolved
lib/spack/spack/test/llnl/util/filesystem.py Outdated Show resolved Hide resolved
@alalazo
Copy link
Member Author

alalazo commented Feb 22, 2019

@scheibelp The comments should have been addressed. Let me know if there are other things to be fixed.

Copy link
Member

@scheibelp scheibelp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a couple updates to requests.

lib/spack/llnl/util/filesystem.py Outdated Show resolved Hide resolved
lib/spack/spack/test/conftest.py Outdated Show resolved Hide resolved
HeaderList now overrides the 'directories' property in a way that is
conforming to common C and C++ best practices.
@alalazo alalazo force-pushed the fixes/restore_computation_of_include_dirs branch from 987f0e3 to 1926d9e Compare February 23, 2019 06:34
@alalazo
Copy link
Member Author

alalazo commented Feb 23, 2019

@scheibelp Done

@alalazo alalazo mentioned this pull request Feb 25, 2019
@scheibelp scheibelp merged commit 42386db into spack:develop Feb 26, 2019
@scheibelp
Copy link
Member

Thanks!

@alalazo alalazo deleted the fixes/restore_computation_of_include_dirs branch February 26, 2019 18:45
scheibelp added a commit that referenced this pull request Mar 4, 2019
Fixes #10769 

This updates the .headers property to include header subdirectories
for Python and Eigen (as is recommended by these packages).

#10623 updated the default behavior of .headers.directories to
exclude subdirectories (since this can cause clashes with system
headers). This broke some packages which depended on the old behavior
of .headers.directories: for example if you had
<package-prefix>/include/subdir/ex1.h, .headers.directories would
include <package-prefix>/include/subdir.
michaelkuhn added a commit to michaelkuhn/spack that referenced this pull request Mar 5, 2019
This is likely caused by spack#10623. An alternative approach for the
netcdf-fortran problem would be to extend the list of suffixes
considered in `find_headers`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants