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

resolve loader_path #100

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion delocate/delocating.py
Expand Up @@ -199,7 +199,7 @@ def _copy_required(lib_path, copy_filt_func, copied_libs):
``dependings_dict`` entry for ``copied_libs['/sys/libB.dylib']``
"""
# Paths will be prepended with `lib_path`
lib_dict = tree_libs(lib_path)
lib_dict = tree_libs(lib_path, original_paths=list(copied_libs.keys()))
isuruf marked this conversation as resolved.
Show resolved Hide resolved
# Map library paths after copy ('copied') to path before copy ('orig')
rp_lp = realpath(lib_path)
copied2orig = dict((pjoin(rp_lp, basename(c)), c) for c in copied_libs)
Expand Down
15 changes: 13 additions & 2 deletions delocate/libsana.py
Expand Up @@ -13,7 +13,7 @@
from .tmpdirs import TemporaryDirectory


def tree_libs(start_path, filt_func=None):
def tree_libs(start_path, filt_func=None, original_paths=[]):
isuruf marked this conversation as resolved.
Show resolved Hide resolved
""" Return analysis of library dependencies within `start_path`

Parameters
Expand All @@ -24,6 +24,8 @@ def tree_libs(start_path, filt_func=None):
If None, inspect all files for library dependencies. If callable,
accepts filename as argument, returns True if we should inspect the
file, False otherwise.
original_paths: list
A list of the original paths of the libraries copied to ``start_path``.

Returns
-------
Expand Down Expand Up @@ -56,7 +58,16 @@ def tree_libs(start_path, filt_func=None):
depending_libpath = realpath(pjoin(dirpath, base))
if filt_func is not None and not filt_func(depending_libpath):
continue
rpaths = get_rpaths(depending_libpath)

depending_libpath_orig = depending_libpath
Copy link
Owner

Choose a reason for hiding this comment

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

Comments would help here.

for orig_path in original_paths:
if os.path.basename(orig_path) == base and \
os.path.isabs(orig_path):
depending_libpath_orig = orig_path
break

rpaths = get_rpaths(depending_libpath_orig)

search_paths = rpaths + env_var_paths
for install_name in get_install_names(depending_libpath):
# If the library starts with '@rpath' we'll try and resolve it
Expand Down
5 changes: 5 additions & 0 deletions delocate/tests/test_install_names.py
Expand Up @@ -141,6 +141,11 @@ def test_add_rpath():
assert_equal(get_rpaths(libfoo), ('/a/path',))
add_rpath(libfoo, '/another/path')
assert_equal(get_rpaths(libfoo), ('/a/path', '/another/path'))
add_rpath(libfoo, '@loader_path')
assert_equal(get_rpaths(libfoo), ('/a/path', '/another/path', tmpdir))
add_rpath(libfoo, '@loader_path/lib')
Copy link
Owner

Choose a reason for hiding this comment

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

Is this now testing the original path manipulation?

assert_equal(get_rpaths(libfoo), ('/a/path', '/another/path', tmpdir,
pjoin(tmpdir, 'lib')))


def _copy_libs(lib_files, out_path):
Expand Down
7 changes: 6 additions & 1 deletion delocate/tools.py
Expand Up @@ -324,7 +324,12 @@ def get_rpaths(filename):
continue
cmdsize, path = lines[line_no:line_no+2]
assert cmdsize.startswith('cmdsize ')
paths.append(RPATH_RE.match(path).groups()[0])
path = (RPATH_RE.match(path).groups()[0])
if path.startswith("@loader_path/"):
path = os.path.join(os.path.dirname(filename), path[13:])
elif path == "@loader_path":
path = os.path.dirname(filename)
paths.append(path)
line_no += 2
return tuple(paths)

Expand Down