Skip to content

Commit 5a0d0d9

Browse files
committed
delocate/tools.py (_delete_rpaths, _remove_absolute_rpaths): Delete unique rpaths in one install_name_tool call, loop until done
1 parent 8321952 commit 5a0d0d9

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

delocate/tools.py

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -753,19 +753,25 @@ def _delete_rpaths(
753753
filename : str
754754
filename of library
755755
rpaths : Iterable[str]
756-
rpaths to delete
756+
rpaths to delete, must not contain duplicates
757757
ad_hoc_sign : {True, False}, optional
758-
If True, sign file with ad-hoc signature
758+
If True, sign file with ad-hoc signature if any change was made
759759
"""
760-
for rpath in rpaths:
760+
delete_rpath_args = []
761+
for rpath in _unique_everseen(rpaths):
761762
logger.info("Sanitize: Deleting rpath %r from %r", rpath, filename)
762763
# We can run these as one command to install_name_tool if there are
763764
# no duplicates. When there are duplicates, we need to delete them
764-
# separately.
765-
_run(
766-
["install_name_tool", "-delete_rpath", rpath, filename],
767-
check=True,
768-
)
765+
# separately. This must be done by the caller.
766+
delete_rpath_args.extend(["-delete_rpath", rpath])
767+
768+
if not delete_rpath_args:
769+
return
770+
771+
_run(
772+
["install_name_tool"] + delete_rpath_args + [filename],
773+
check=True,
774+
)
769775
if ad_hoc_sign:
770776
replace_signature(filename, "-")
771777

@@ -808,17 +814,24 @@ def _remove_absolute_rpaths(filename: str, ad_hoc_sign: bool = True) -> None:
808814
filename : str
809815
filename of library
810816
ad_hoc_sign : {True, False}, optional
811-
If True, sign file with ad-hoc signature
817+
If True, sign file with ad-hoc signature if any change was made
812818
"""
813-
_delete_rpaths(
814-
filename,
815-
(
816-
rpath
817-
for rpath in itertools.chain(*_get_rpaths(filename).values())
818-
if not _is_rpath_sanitary(rpath)
819-
),
820-
ad_hoc_sign,
821-
)
819+
any_change = False
820+
while rpaths := [
821+
rpath
822+
for rpath in _unique_everseen(
823+
itertools.chain(*_get_rpaths(filename).values()),
824+
)
825+
if not _is_rpath_sanitary(rpath)
826+
]:
827+
_delete_rpaths(
828+
filename,
829+
rpaths,
830+
ad_hoc_sign=False,
831+
)
832+
any_change = True
833+
if any_change and ad_hoc_sign:
834+
replace_signature(filename, "-")
822835

823836

824837
def zip2dir(

0 commit comments

Comments
 (0)