https://github.com/mesonbuild/meson-python/pull/702 --- meson_python-0.17.1/mesonpy/_rpath.py.orig +++ meson_python-0.17.1/mesonpy/_rpath.py @@ -58,6 +58,31 @@ if path.startswith('@loader_path/'): _replace_rpath(filepath, path, '@loader_path/' + libs_relative_path) +elif sys.platform == 'sunos5': + + def _get_rpath(filepath: Path) -> List[str]: + rpath = [] + r = subprocess.run(['/usr/bin/elfedit', '-r', '-e', 'dyn:rpath', os.fspath(filepath)], capture_output=True, check=True, text=True) + for line in [x.split() for x in r.stdout.split('\n')]: + if len(line) >= 4 and line[1] in ['RPATH', 'RUNPATH']: + for path in line[3].split(':'): + if not path in rpath: + rpath.append(path) + return rpath + + def _set_rpath(filepath: Path, rpath: Iterable[str]) -> None: + subprocess.run(['/usr/bin/elfedit', '-e', 'dyn:rpath ' + ':'.join(rpath), os.fspath(filepath)], check=True) + + def fix_rpath(filepath: Path, libs_relative_path: str) -> None: + old_rpath = _get_rpath(filepath) + new_rpath = [] + for path in old_rpath: + if path.startswith('$ORIGIN/'): + path = '$ORIGIN/' + libs_relative_path + new_rpath.append(path) + if new_rpath != old_rpath: + _set_rpath(filepath, new_rpath) + else: def fix_rpath(filepath: Path, libs_relative_path: str) -> None: --- meson_python-0.17.1/tests/test_wheel.py.orig +++ meson_python-0.17.1/tests/test_wheel.py @@ -140,7 +140,7 @@ assert artifact.read('license_file-1.0.0.dist-info/LICENSE.custom').rstrip() == b'Hello!' -@pytest.mark.skipif(sys.platform not in {'linux', 'darwin'}, reason='Not supported on this platform') +@pytest.mark.skipif(sys.platform not in {'linux', 'darwin', 'sunos5'}, reason='Not supported on this platform') def test_contents(package_library, wheel_library): artifact = wheel.wheelfile.WheelFile(wheel_library) @@ -154,19 +154,19 @@ } -@pytest.mark.skipif(sys.platform not in {'linux', 'darwin'}, reason='Not supported on this platform') +@pytest.mark.skipif(sys.platform not in {'linux', 'darwin', 'sunos5'}, reason='Not supported on this platform') def test_local_lib(venv, wheel_link_against_local_lib): venv.pip('install', wheel_link_against_local_lib) output = venv.python('-c', 'import example; print(example.example_sum(1, 2))') assert int(output) == 3 -@pytest.mark.skipif(sys.platform not in {'linux', 'darwin'}, reason='Not supported on this platform') +@pytest.mark.skipif(sys.platform not in {'linux', 'darwin', 'sunos5'}, reason='Not supported on this platform') def test_rpath(wheel_link_against_local_lib, tmp_path): artifact = wheel.wheelfile.WheelFile(wheel_link_against_local_lib) artifact.extractall(tmp_path) - origin = {'linux': '$ORIGIN', 'darwin': '@loader_path'}[sys.platform] + origin = {'linux': '$ORIGIN', 'darwin': '@loader_path', 'sunos5': '$ORIGIN'}[sys.platform] expected = {f'{origin}/.link_against_local_lib.mesonpy.libs', 'custom-rpath',} rpath = set(mesonpy._rpath._get_rpath(tmp_path / f'example{EXT_SUFFIX}')) @@ -175,19 +175,19 @@ assert rpath >= expected -@pytest.mark.skipif(sys.platform not in {'linux', 'darwin'}, reason='Not supported on this platform') +@pytest.mark.skipif(sys.platform not in {'linux', 'darwin', 'sunos5'}, reason='Not supported on this platform') def test_uneeded_rpath(wheel_purelib_and_platlib, tmp_path): artifact = wheel.wheelfile.WheelFile(wheel_purelib_and_platlib) artifact.extractall(tmp_path) - origin = {'linux': '$ORIGIN', 'darwin': '@loader_path'}[sys.platform] + origin = {'linux': '$ORIGIN', 'darwin': '@loader_path', 'sunos5': '$ORIGIN'}[sys.platform] rpath = mesonpy._rpath._get_rpath(tmp_path / f'plat{EXT_SUFFIX}') for path in rpath: assert origin not in path -@pytest.mark.skipif(sys.platform not in {'linux', 'darwin'}, reason='Not supported on this platform') +@pytest.mark.skipif(sys.platform not in {'linux', 'darwin', 'sunos5'}, reason='Not supported on this platform') def test_executable_bit(wheel_executable_bit): artifact = wheel.wheelfile.WheelFile(wheel_executable_bit)