matthew-brett / delocate

Find and copy needed dynamic libraries into python wheels
BSD 2-Clause "Simplified" License
262 stars 59 forks source link

Avoid duplication when library has soft links and been used in the same wheels. #134

Closed sighingnow closed 2 years ago

sighingnow commented 2 years ago

Resolves issue #133.

I have managed to reproduce the issue by the following minimal case:

We have:

  liba.dylib
  links/liba.dylib, a soft link to liba.dylib

and

  libb.dylib, depends on liba.dylib via `@rpath/liba.dylib`
  links/libb.dylib, depends on links/liba.dylib and been found via `DYLD_LIBRARY_PATH`

During resolving dependencies, the first is found via resolving from @rpath by resolve_dynamic_paths, and the later is resolved from DYLD_LIBRARY_PATH by search_environment_for_lib, where the soft link path is returned, thus the conflicit happens.

For more details, see the minimal reproduce case in test_tree_libs_from_directory_with_links, and we have verified the patch in our real-world wheels that triggerred #133 before.

sighingnow commented 2 years ago

This pull request generates copied files in the test case rather than put it into tests/data to avoid affecting other test cases.

codecov-commenter commented 2 years ago

Codecov Report

Merging #134 (43bd372) into master (9c2c6a4) will not change coverage. The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #134   +/-   ##
=======================================
  Coverage   95.28%   95.28%           
=======================================
  Files          13       13           
  Lines        1018     1018           
=======================================
  Hits          970      970           
  Misses         48       48           
Impacted Files Coverage Δ
delocate/libsana.py 97.64% <100.00%> (ø)

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 9c2c6a4...43bd372. Read the comment docs.

sighingnow commented 2 years ago

The fix itself looks good.

You should add a note for this fix in the changelog.

I'd accept the test if it was at least using a try..finally block when working with os.environ.

I have applied the suggested change.

sighingnow commented 2 years ago

Hi @HexDecimal could we get this one merge? and it it is possible, could we have a new release on pypi to include this fix?

Thanks!

HexDecimal commented 2 years ago

@matthew-brett, would you look at the test in case I've missed anything obvious? Or should I merge PR's without your input?

I can make a bug fix release immediately once this is merged.

matthew-brett commented 2 years ago

Thanks both. Yes, will have a look at this tomorrow morning, but @HexDecimal - feel free to merge without me if I'm being slow, or a merge needs doing.

sighingnow commented 2 years ago

Thanks for this - just a few suggestions.

Thanks for reviewing, all comments have been addressed.

sighingnow commented 2 years ago

Lint error fixed.

matthew-brett commented 2 years ago

Thanks very much @sighingnow for the PR, and @HexDecimal for the review.

HexDecimal commented 2 years ago

You're welcome. I've also released a version with this fix.

sighingnow commented 2 years ago

You're welcome. I've also released a version with this fix.

Thanks a lot.