Skip to content

Commit

Permalink
ENH: sunos5 support for rpath operations
Browse files Browse the repository at this point in the history
  • Loading branch information
mtelka authored and dnicolodi committed Nov 27, 2024
1 parent 856debc commit 91d64d1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
26 changes: 26 additions & 0 deletions mesonpy/_rpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,32 @@ def fix_rpath(filepath: Path, libs_relative_path: str) -> None:
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 path not 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:
Expand Down
14 changes: 7 additions & 7 deletions tests/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_contents_license_file(wheel_license_file):
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)

Expand All @@ -154,19 +154,19 @@ def test_contents(package_library, wheel_library):
}


@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}'))
Expand All @@ -175,19 +175,19 @@ def test_rpath(wheel_link_against_local_lib, tmp_path):
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)

Expand Down

0 comments on commit 91d64d1

Please sign in to comment.