Skip to content

Commit

Permalink
Fix deleting duplicated rpaths
Browse files Browse the repository at this point in the history
  • Loading branch information
isuruf committed Mar 21, 2024
1 parent 43ad6b3 commit 378949d
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions delocate/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,24 @@ def add_rpath(filename: str, newpath: str, ad_hoc_sign: bool = True) -> None:
replace_signature(filename, "-")


@ensure_writable
def delete_rpath(filename: str, existing_path: str, ad_hoc_sign: bool = True) -> None:
"""Remove rpath `newpath` from library `filename`.
Parameters
----------
filename : str
filename of library
existing_path : str
rpath to delete
ad_hoc_sign : {True, False}, optional
If True, sign file with ad-hoc signature
"""
_run(["install_name_tool", "-delete_rpath", existing_path, filename], check=True)
if ad_hoc_sign:
replace_signature(filename, "-")


_SANITARY_RPATH = re.compile(r"^@loader_path/|^@executable_path/")
"""Matches rpaths which are considered sanitary."""

Expand Down Expand Up @@ -858,16 +876,13 @@ def _remove_absolute_rpaths(filename: str, ad_hoc_sign: bool = True) -> None:
ad_hoc_sign : {True, False}, optional
If True, sign file with ad-hoc signature
"""
commands = [] # install_name_tool commands
for rpath in get_rpaths(filename):
if not _is_rpath_sanitary(rpath):
commands += ["-delete_rpath", rpath]
logger.info("Sanitize: Deleting rpath %r from %r", rpath, filename)
if not commands:
return
_run(["install_name_tool", filename, *commands], check=True)
if ad_hoc_sign:
replace_signature(filename, "-")
# We can run these as one command to install_name_tool if there are
# no duplicates. When there are duplicates, we need to delete them
# separately.
delete_rpath(filename, rpath, ad_hoc_sign)


def zip2dir(
Expand Down

0 comments on commit 378949d

Please sign in to comment.