Skip to content

Commit

Permalink
Merge pull request #120 from HexDecimal/fix-119
Browse files Browse the repository at this point in the history
MRG: Don't follow libraries which won't be copied.

Combines `lib_flit_func` and `copy_flit_func` behavior into one function.
This makes sure that a file which won't be copied will not have its dependencies analyzed.

Fixes #119
  • Loading branch information
matthew-brett authored Sep 17, 2021
2 parents df13bef + c681e19 commit e4be05b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
4 changes: 4 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ Releases

First release that requires Python 3.

* Fixed issue where Delocate would attempt to modify the install names of a
non-copied library which dynamically links to a copied library.
[#120](https://github.com/matthew-brett/delocate/pull/120)

* 0.9.0 (Saturday July 17th 2021)

Refactoring, updating and `arm64` (M1) support.
Expand Down
11 changes: 8 additions & 3 deletions delocate/delocating.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ def delocate_path(
Default is callable rejecting only libraries beginning with
``/usr/lib`` or ``/System``. None means copy all libraries. This will
usually end up copying large parts of the system run-time.
Libraries which won't be copied will not be inspected for dependencies.
executable_path : None or str, optional
If not None, an alternative path to use for resolving
`@executable_path`.
Expand Down Expand Up @@ -410,23 +411,27 @@ def delocate_path(
raise TypeError('lib_filt_func string can only be "dylibs-only"')
if lib_filt_func is None:
lib_filt_func = (lambda _: True)
if copy_filt_func is None:
copy_filt_func = (lambda _: True)
if not exists(lib_path):
os.makedirs(lib_path)
# Do not inspect dependencies of libraries that will not be copied.
filt_func = (lambda path: lib_filt_func(path) and copy_filt_func(path))

lib_dict = {} # type: Dict[Text, Dict[Text, Text]]
missing_libs = False
for library_path in walk_directory(
tree_path, lib_filt_func, executable_path=executable_path
tree_path, filt_func, executable_path=executable_path
):
for depending_path, install_name in get_dependencies(
library_path,
executable_path=executable_path,
filt_func=lib_filt_func,
filt_func=filt_func,
):
if depending_path is None:
missing_libs = True
continue
if copy_filt_func and not copy_filt_func(depending_path):
if not filt_func(depending_path):
continue
lib_dict.setdefault(depending_path, {})
lib_dict[depending_path][library_path] = install_name
Expand Down
31 changes: 23 additions & 8 deletions delocate/tests/test_wheelies.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,9 @@ def func(fn):

assert_equal(delocate_wheel('test.whl', lib_filt_func=func), {})
# Default - looks in every file
shutil.copyfile('test.whl', 'test2.whl') # for following test
dep_mod = pjoin('fakepkg1', 'subpkg', 'module.other')
assert_equal(delocate_wheel('test.whl'),
{realpath(stray_lib): {dep_mod: stray_lib}})
# With func that does find the module

def func(fn):
return fn.endswith('.other')

assert_equal(delocate_wheel('test2.whl', lib_filt_func=func),
{realpath(stray_lib): {dep_mod: stray_lib}})


def _thin_lib(stray_lib, arch):
Expand Down Expand Up @@ -322,3 +314,26 @@ def test_fix_rpath():
with InWheel('tmp.whl'):
check_call(['codesign', '--verify',
'fakepkg/.dylibs/libextfunc_rpath.dylib'])

# Now test filters with recursive dependencies.
def ignore_libextfunc(path: str) -> bool:
"""Ignore libextfunc which will also ignore its dependency and
include no files.
"""
return "libextfunc_rpath.dylib" not in path

assert delocate_wheel(
RPATH_WHEEL, 'tmp.whl', lib_filt_func=ignore_libextfunc) == {}

def ignore_libextfunc2(path: str) -> bool:
"""Ignore libextfunc2. libextfunc will still be bundled."""
return "libextfunc2_rpath.dylib" not in path

# Only the direct dependencies of module2.abi3.so
stray_libs_only_direct = {
realpath('libs/libextfunc_rpath.dylib'): {dep_mod: dep_path},
}

assert delocate_wheel(
RPATH_WHEEL, 'tmp.whl', lib_filt_func=ignore_libextfunc2
) == stray_libs_only_direct

0 comments on commit e4be05b

Please sign in to comment.