Skip to content

Commit

Permalink
sanitize rpaths by default (#223)
Browse files Browse the repository at this point in the history
* sanitize rpaths by default

* changelog for sanitize-rpaths

* test sanitize_rpaths toggles
  • Loading branch information
minrk authored Aug 29, 2024
1 parent de38e09 commit a21c657
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 8 additions & 1 deletion delocate/cmd/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@
delocate_parser.add_argument(
"--sanitize-rpaths",
action="store_true",
help="Remove absolute and relative rpaths from binaries",
default=True,
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",
)


Expand Down
33 changes: 27 additions & 6 deletions delocate/tests/test_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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]
Expand Down

0 comments on commit a21c657

Please sign in to comment.