Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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)],

Check warning on line 65 in mesonpy/_rpath.py

View check run for this annotation

Codecov / codecov/patch

mesonpy/_rpath.py#L63-L65

Added lines #L63 - L65 were not covered by tests
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

Check warning on line 72 in mesonpy/_rpath.py

View check run for this annotation

Codecov / codecov/patch

mesonpy/_rpath.py#L67-L72

Added lines #L67 - L72 were not covered by tests

def _set_rpath(filepath: Path, rpath: Iterable[str]) -> None:
subprocess.run(['/usr/bin/elfedit', '-e', 'dyn:rpath ' + ':'.join(rpath), os.fspath(filepath)], check=True)

Check warning on line 75 in mesonpy/_rpath.py

View check run for this annotation

Codecov / codecov/patch

mesonpy/_rpath.py#L74-L75

Added lines #L74 - L75 were not covered by tests

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)

Check warning on line 85 in mesonpy/_rpath.py

View check run for this annotation

Codecov / codecov/patch

mesonpy/_rpath.py#L77-L85

Added lines #L77 - L85 were not covered by tests

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
Loading