From 8abf9fb8e2023a797c30ce940f58af71fbb0ce6d Mon Sep 17 00:00:00 2001 From: Min RK Date: Thu, 22 Aug 2024 10:19:43 +0200 Subject: [PATCH 1/3] sanitize rpaths by default --- delocate/cmd/common.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/delocate/cmd/common.py b/delocate/cmd/common.py index f4533516..7db713e7 100644 --- a/delocate/cmd/common.py +++ b/delocate/cmd/common.py @@ -70,8 +70,15 @@ delocate_parser.add_argument( "--sanitize-rpaths", action="store_true", - help="Remove absolute and relative rpaths from binaries", + help="Remove absolute and relative rpaths from binaries (default)", ) +delocate_parser.add_argument( + "--no-sanitize-rpaths", + action="store_false", + dest="sanitize_rpaths", + help="Don't remove absolute and relative rpaths from binaries", +) +delocate_parser.set_defaults(sanitize_rpaths=True) def verbosity_config(args: Namespace) -> None: From d32ecbfdc6bfcf188495b8a4e720aa1d3308be5b Mon Sep 17 00:00:00 2001 From: Min RK Date: Tue, 27 Aug 2024 16:36:21 +0200 Subject: [PATCH 2/3] changelog for sanitize-rpaths --- Changelog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Changelog.md b/Changelog.md index 2831c1d5..ca7c860c 100644 --- a/Changelog.md +++ b/Changelog.md @@ -18,6 +18,8 @@ rules on making a good Changelog. ### Changed +- Sanitize rpaths (`--sanitize-rpaths`) is now the default behavior. + Opt out with new `--no-sanitize-rpaths` [#223](https://github.com/matthew-brett/delocate/pull/223) - Improved error message for when a MacOS target version is not met. [#211](https://github.com/matthew-brett/delocate/issues/211) - `delocate-fuse` is no longer available and will throw an error when invoked. From 37f0bbba1399bb68a675d92e72064f82f871cc00 Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 28 Aug 2024 07:48:58 +0200 Subject: [PATCH 3/3] test sanitize_rpaths toggles --- delocate/cmd/common.py | 2 +- delocate/tests/test_scripts.py | 33 +++++++++++++++++++++++++++------ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/delocate/cmd/common.py b/delocate/cmd/common.py index 7db713e7..9811f559 100644 --- a/delocate/cmd/common.py +++ b/delocate/cmd/common.py @@ -70,6 +70,7 @@ delocate_parser.add_argument( "--sanitize-rpaths", action="store_true", + default=True, help="Remove absolute and relative rpaths from binaries (default)", ) delocate_parser.add_argument( @@ -78,7 +79,6 @@ dest="sanitize_rpaths", help="Don't remove absolute and relative rpaths from binaries", ) -delocate_parser.set_defaults(sanitize_rpaths=True) def verbosity_config(args: Namespace) -> None: diff --git a/delocate/tests/test_scripts.py b/delocate/tests/test_scripts.py index bd3a3ddd..1874a4ff 100644 --- a/delocate/tests/test_scripts.py +++ b/delocate/tests/test_scripts.py @@ -21,6 +21,7 @@ import pytest from pytest_console_scripts import ScriptRunner +from ..cmd.common import delocate_parser from ..tmpdirs import InGivenDirectory, InTemporaryDirectory from ..tools import dir2zip, get_rpaths, set_install_name, zip2dir from ..wheeltools import InWheel @@ -615,10 +616,22 @@ def test_fix_wheel_with_excluded_dylibs( _check_wheel(test2_name, ".dylibs") +def test_sanitize_rpaths_flag() -> None: + args = delocate_parser.parse_args([]) + assert args.sanitize_rpaths + args = delocate_parser.parse_args(["--sanitize-rpaths"]) + assert args.sanitize_rpaths + args = delocate_parser.parse_args(["--no-sanitize-rpaths"]) + assert not args.sanitize_rpaths + + @pytest.mark.xfail( # type: ignore[misc] sys.platform != "darwin", reason="Needs macOS linkage." ) -def test_sanitize_command(tmp_path: Path, script_runner: ScriptRunner) -> None: +@pytest.mark.parametrize("sanitize_rpaths", [True, False]) +def test_sanitize_command( + tmp_path: Path, script_runner: ScriptRunner, sanitize_rpaths: bool +) -> None: unpack_dir = tmp_path / "unpack" zip2dir(RPATH_WHEEL, unpack_dir) assert "libs/" in set( @@ -630,18 +643,26 @@ def test_sanitize_command(tmp_path: Path, script_runner: ScriptRunner) -> None: libs_path.mkdir() shutil.copy(DATA_PATH / "libextfunc_rpath.dylib", libs_path) shutil.copy(DATA_PATH / "libextfunc2_rpath.dylib", libs_path) + cmd = ["delocate-wheel", "-vv"] + if not sanitize_rpaths: + cmd.append("--no-sanitize-rpaths") result = script_runner.run( - ["delocate-wheel", "-vv", "--sanitize-rpaths", rpath_wheel], + cmd + [rpath_wheel], check=True, cwd=tmp_path, ) - assert "Sanitize: Deleting rpath 'libs/' from" in result.stderr + if sanitize_rpaths: + assert "Sanitize: Deleting rpath 'libs/' from" in result.stderr + else: + assert "Deleting rpath" not in result.stderr unpack_dir = tmp_path / "unpack" zip2dir(rpath_wheel, unpack_dir) - assert "libs/" not in set( - get_rpaths(str(unpack_dir / "fakepkg/subpkg/module2.abi3.so")) - ) + rpaths = set(get_rpaths(str(unpack_dir / "fakepkg/subpkg/module2.abi3.so"))) + if sanitize_rpaths: + assert "libs/" not in rpaths + else: + assert "libs/" in rpaths @pytest.mark.xfail( # type: ignore[misc]