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

Relax restrictions on detecting boost dependency #7909

Merged
merged 3 commits into from
Aug 4, 2021
Merged

Relax restrictions on detecting boost dependency #7909

merged 3 commits into from
Aug 4, 2021

Conversation

kjmeagher
Copy link
Contributor

This does two things:

  • allows the .so files to be symlinks
  • searches lib and lib64 in BOOST_ROOT even if it finds lib
    directories from the compiler

The first condition is needed for the homebrew on macs because certian
boost modules are provided by seperate packages and are put together in
a directory with symlinks to the .so files. The both conditions are
needed for high performace computing environments where dependencies are
often provided in nonstandard directories with symlinks

Copy link
Member

@mensinda mensinda 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 nothing against these changes in principle, but the implementation needs some work.

Also, a test case would be nice.

Comment on lines 579 to 546
if system_dirs:
return system_dirs

Copy link
Member

Choose a reason for hiding this comment

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

Removing this effectively makes the above code where system_dirs useless, which might break existing setups.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed it to use both the system_dirs and the hard-coded lib directories

@@ -652,7 +649,7 @@ def filter_libraries(self, libs: T.List[BoostLibraryFile], lib_vers: str) -> T.L
def detect_libraries(self, libdir: Path) -> T.List[BoostLibraryFile]:
libs = [] # type: T.List[BoostLibraryFile]
for i in libdir.iterdir():
if not i.is_file() or i.is_symlink():
Copy link
Member

Choose a reason for hiding this comment

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

Symlinks were excluded on purpose to avoid duplicate libraries in the detection logic and because symlinks usually remove information. Please either ensure that all symlinks are resolved or that "real" paths of a library are always preferred.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed it to resolve all the symlinks and use set() to remove duplicates

Copy link
Member

Choose a reason for hiding this comment

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

Why not make libs into a set from the very beginning?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No good reason. I changed it to use a set from the begining

@lgtm-com
Copy link

lgtm-com bot commented Oct 28, 2020

This pull request introduces 1 alert when merging 4305227 into 42d6b37 - view on LGTM.com

new alerts:

  • 1 for Unused local variable

@deepbluev7
Copy link
Contributor

deepbluev7 commented Nov 5, 2020

The symlink thing was something that confused me for quite a while. I used cget to build boost, which by default symlinks all libraries into a directory. This means there are only symlinked libraries in the lib folder. I worked around this for now, but this PR would have saved me quite a bit of time. I do agree though, that non-symlinked libraries should be preferred. Thank you for working on this!

@kjmeagher kjmeagher marked this pull request as draft July 14, 2021 14:38
@lgtm-com
Copy link

lgtm-com bot commented Jul 14, 2021

This pull request introduces 1 alert when merging afe2acc into 762c073 - view on LGTM.com

new alerts:

  • 1 for Unused local variable

@codecov
Copy link

codecov bot commented Jul 14, 2021

Codecov Report

Merging #7909 (19d10fe) into master (7dee480) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7909      +/-   ##
==========================================
- Coverage   66.43%   66.43%   -0.01%     
==========================================
  Files         374      374              
  Lines       84329    84325       -4     
  Branches    17557    17555       -2     
==========================================
- Hits        56026    56019       -7     
+ Misses      23383    23379       -4     
- Partials     4920     4927       +7     
Impacted Files Coverage Δ
mesonbuild/dependencies/boost.py 83.61% <100.00%> (+0.56%) ⬆️
mesonbuild/scripts/vcstagger.py 87.50% <0.00%> (-4.17%) ⬇️
mesonbuild/dependencies/ui.py 69.75% <0.00%> (-2.47%) ⬇️
mesonbuild/dependencies/dev.py 69.54% <0.00%> (-1.15%) ⬇️
mesonbuild/dependencies/base.py 84.21% <0.00%> (-0.59%) ⬇️
dependencies/boost.py 82.26% <0.00%> (+0.98%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7dee480...19d10fe. Read the comment docs.

This does two things:
* allows the library files to be symlinks
* searches `lib` and `lib64` in `BOOST_ROOT` even if it finds lib
  directories from the compiler

The first condition is needed for the homebrew on macOS because boost and boost
python are provided in seperate packages and are put together in /usr/local/lib
with symlinks to the library files. The both conditions are needed for high
performace computing environments where dependencies are often provided in
nonstandard directories with symlinks

A test case was added which looks for boost libraries in seperate directories
which have been symlinked to BOOST_ROOT/lib
@kjmeagher kjmeagher marked this pull request as ready for review July 15, 2021 15:58
Copy link
Member

@mensinda mensinda left a comment

Choose a reason for hiding this comment

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

I just got one more issue, but then this is good to go.

@@ -561,7 +557,7 @@ def detect_lib_dirs(self, root: Path) -> T.List[Path]:
# Filter out paths that don't match the target arch to avoid finding
# the wrong libraries. See https://github.com/mesonbuild/meson/issues/7110
if not self.arch:
return dirs + subdirs
return system_dirs + dirs + subdirs
Copy link
Member

Choose a reason for hiding this comment

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

system_dirs should also be returned here in an elif branch since they would be ignored otherwise and should not be subject to the filtering logic below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After reading #7110 I think I might be going about this wrong let me try a different approach

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I re-wrote it to work explicitly what I was trying to do. Now when searching BOOST_ROOT it won't use the system_dirs, but when looking in other directories like /usr/local it will

continue
if not any([i.name.startswith(x) for x in ['libboost_', 'boost_']]):
continue

libs += [BoostLibraryFile(i)]
return [x for x in libs if x.is_boost()] # Filter out no boost libraries
libs.add(i.resolve())
Copy link
Member

Choose a reason for hiding this comment

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

When I suggested making it into a set from the beginning, I was kind of assuming the logical next step is to consolidate this. You no longer need multiple complex filtering passes, so...

Suggested change
libs.add(i.resolve())
libs.add(BoostLibraryFile(i.resolve()))

And then you don't need to assign blibs and make the return line refer to a different variable. This would help reduce the size of the diff... :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made the requested change

This boolean parameter is added to check_and_set_roots() and detect_lib_dirs()
when true it will first search the compiler library directories before checking
the standard lib directories. This is set to false when using BOOST_ROOT and
set to true when useing other system directories like /usr/local

Also simplify using a set to remove duplicate lib files

Also remove the part where you search the Cellar in homebrew, this is
unnescessary now that symlinks can be followed it should find boost
when searching /usr/local so no need to search the Cellar
Comment on lines -682 to -686
# Homebrew
brew_boost = Path('/usr/local/Cellar/boost')
if brew_boost.is_dir():
tmp += [x for x in brew_boost.iterdir()]

Copy link
Member

Choose a reason for hiding this comment

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

What is the reason behind removing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On homebrew systems, boost should be detected in /usr/local/lib instead of the cellar. Looking in the cellar made sense before when the logic couldn't follow symlinks. But since this patch adds support for following symlinks, it now finds boost in /usr/local/lib like it should. In addition, event if it somehow got to checking the cellar it wouldn't find boost_python because it is in a different homebrew formula.

kjmeagher added a commit to icecube/nuflux that referenced this pull request Jul 19, 2021
This currently uses my fork of meson but it should be changed to
the official repo when my PR is accepted. See mesonbuild/meson#7909
@mensinda mensinda merged commit 3c3fa0a into mesonbuild:master Aug 4, 2021
jpakkane pushed a commit that referenced this pull request Aug 18, 2021
Previously the meson test case would only test boost-python on linux.
With the #7909 it is now possible to use boost-python on macOS/homebrew.
This enables the boost-python test on both linux and macOS.
It also uses python.extension_module() instead of shared_library to make the
python extension module.
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.

4 participants