Skip to content

Commit 91d64d1

Browse files
mtelkadnicolodi
authored andcommitted
ENH: sunos5 support for rpath operations
1 parent 856debc commit 91d64d1

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

mesonpy/_rpath.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,32 @@ def fix_rpath(filepath: Path, libs_relative_path: str) -> None:
5858
if path.startswith('@loader_path/'):
5959
_replace_rpath(filepath, path, '@loader_path/' + libs_relative_path)
6060

61+
elif sys.platform == 'sunos5':
62+
63+
def _get_rpath(filepath: Path) -> List[str]:
64+
rpath = []
65+
r = subprocess.run(['/usr/bin/elfedit', '-r', '-e', 'dyn:rpath', os.fspath(filepath)],
66+
capture_output=True, check=True, text=True)
67+
for line in [x.split() for x in r.stdout.split('\n')]:
68+
if len(line) >= 4 and line[1] in ['RPATH', 'RUNPATH']:
69+
for path in line[3].split(':'):
70+
if path not in rpath:
71+
rpath.append(path)
72+
return rpath
73+
74+
def _set_rpath(filepath: Path, rpath: Iterable[str]) -> None:
75+
subprocess.run(['/usr/bin/elfedit', '-e', 'dyn:rpath ' + ':'.join(rpath), os.fspath(filepath)], check=True)
76+
77+
def fix_rpath(filepath: Path, libs_relative_path: str) -> None:
78+
old_rpath = _get_rpath(filepath)
79+
new_rpath = []
80+
for path in old_rpath:
81+
if path.startswith('$ORIGIN/'):
82+
path = '$ORIGIN/' + libs_relative_path
83+
new_rpath.append(path)
84+
if new_rpath != old_rpath:
85+
_set_rpath(filepath, new_rpath)
86+
6187
else:
6288

6389
def fix_rpath(filepath: Path, libs_relative_path: str) -> None:

tests/test_wheel.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def test_contents_license_file(wheel_license_file):
140140
assert artifact.read('license_file-1.0.0.dist-info/LICENSE.custom').rstrip() == b'Hello!'
141141

142142

143-
@pytest.mark.skipif(sys.platform not in {'linux', 'darwin'}, reason='Not supported on this platform')
143+
@pytest.mark.skipif(sys.platform not in {'linux', 'darwin', 'sunos5'}, reason='Not supported on this platform')
144144
def test_contents(package_library, wheel_library):
145145
artifact = wheel.wheelfile.WheelFile(wheel_library)
146146

@@ -154,19 +154,19 @@ def test_contents(package_library, wheel_library):
154154
}
155155

156156

157-
@pytest.mark.skipif(sys.platform not in {'linux', 'darwin'}, reason='Not supported on this platform')
157+
@pytest.mark.skipif(sys.platform not in {'linux', 'darwin', 'sunos5'}, reason='Not supported on this platform')
158158
def test_local_lib(venv, wheel_link_against_local_lib):
159159
venv.pip('install', wheel_link_against_local_lib)
160160
output = venv.python('-c', 'import example; print(example.example_sum(1, 2))')
161161
assert int(output) == 3
162162

163163

164-
@pytest.mark.skipif(sys.platform not in {'linux', 'darwin'}, reason='Not supported on this platform')
164+
@pytest.mark.skipif(sys.platform not in {'linux', 'darwin', 'sunos5'}, reason='Not supported on this platform')
165165
def test_rpath(wheel_link_against_local_lib, tmp_path):
166166
artifact = wheel.wheelfile.WheelFile(wheel_link_against_local_lib)
167167
artifact.extractall(tmp_path)
168168

169-
origin = {'linux': '$ORIGIN', 'darwin': '@loader_path'}[sys.platform]
169+
origin = {'linux': '$ORIGIN', 'darwin': '@loader_path', 'sunos5': '$ORIGIN'}[sys.platform]
170170
expected = {f'{origin}/.link_against_local_lib.mesonpy.libs', 'custom-rpath',}
171171

172172
rpath = set(mesonpy._rpath._get_rpath(tmp_path / f'example{EXT_SUFFIX}'))
@@ -175,19 +175,19 @@ def test_rpath(wheel_link_against_local_lib, tmp_path):
175175
assert rpath >= expected
176176

177177

178-
@pytest.mark.skipif(sys.platform not in {'linux', 'darwin'}, reason='Not supported on this platform')
178+
@pytest.mark.skipif(sys.platform not in {'linux', 'darwin', 'sunos5'}, reason='Not supported on this platform')
179179
def test_uneeded_rpath(wheel_purelib_and_platlib, tmp_path):
180180
artifact = wheel.wheelfile.WheelFile(wheel_purelib_and_platlib)
181181
artifact.extractall(tmp_path)
182182

183-
origin = {'linux': '$ORIGIN', 'darwin': '@loader_path'}[sys.platform]
183+
origin = {'linux': '$ORIGIN', 'darwin': '@loader_path', 'sunos5': '$ORIGIN'}[sys.platform]
184184

185185
rpath = mesonpy._rpath._get_rpath(tmp_path / f'plat{EXT_SUFFIX}')
186186
for path in rpath:
187187
assert origin not in path
188188

189189

190-
@pytest.mark.skipif(sys.platform not in {'linux', 'darwin'}, reason='Not supported on this platform')
190+
@pytest.mark.skipif(sys.platform not in {'linux', 'darwin', 'sunos5'}, reason='Not supported on this platform')
191191
def test_executable_bit(wheel_executable_bit):
192192
artifact = wheel.wheelfile.WheelFile(wheel_executable_bit)
193193

0 commit comments

Comments
 (0)