Skip to content

Commit 19ea50b

Browse files
committed
TST: Try testing rpath with non-FHS library dir
Let's see if I got the syntax right. Next step will be hooking the temporary /tmp/libxx_z.so file handling into pytest's tempfile handling.
1 parent 7b693ab commit 19ea50b

File tree

1 file changed

+37
-10
lines changed

1 file changed

+37
-10
lines changed

distutils/tests/test_build_ext.py

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import contextlib
2+
import glob
23
import importlib
34
import os
45
import platform
@@ -94,19 +95,32 @@ class TestBuildExt(TempdirManager):
9495
def build_ext(self, *args, **kwargs):
9596
return build_ext(*args, **kwargs)
9697

97-
def test_build_ext(self):
98+
@pytest.mark.parametrize("copy_so", [False, True])
99+
def test_build_ext(self, copy_so):
98100
missing_compiler_executable()
99101
copy_xxmodule_c(self.tmp_dir)
100102
xx_c = os.path.join(self.tmp_dir, 'xxmodule.c')
101103
xx_ext = Extension('xx', [xx_c])
102104
if sys.platform != "win32":
103-
xx_ext = Extension(
104-
'xx',
105-
[xx_c],
106-
library_dirs=['/usr/lib'],
107-
libraries=['z'],
108-
runtime_library_dirs=['/usr/lib'],
109-
)
105+
if not copy_so:
106+
xx_ext = Extension(
107+
'xx',
108+
[xx_c],
109+
library_dirs=['/usr/lib'],
110+
libraries=['z'],
111+
runtime_library_dirs=['/usr/lib'],
112+
)
113+
elif sys.platform == 'linux':
114+
libz_so = glob.glob('/usr/lib*/libz.so*')
115+
shutil.copyfile(libz_so[0], '/tmp/libxx_z.so')
116+
117+
xx_ext = Extension(
118+
'xx',
119+
[xx_c],
120+
library_dirs=['/tmp'],
121+
libraries=['xx_z'],
122+
runtime_library_dirs=['/tmp'],
123+
)
110124
dist = Distribution({'name': 'xx', 'ext_modules': [xx_ext]})
111125
dist.package_dir = self.tmp_dir
112126
cmd = self.build_ext(dist)
@@ -125,10 +139,13 @@ def test_build_ext(self):
125139
sys.stdout = old_stdout
126140

127141
with safe_extension_import('xx', self.tmp_dir):
128-
self._test_xx()
142+
self._test_xx(copy_so)
143+
144+
if sys.platform == 'linux' and copy_so:
145+
os.unlink('/tmp/libxx_z.so')
129146

130147
@staticmethod
131-
def _test_xx():
148+
def _test_xx(copy_so):
132149
import xx
133150

134151
for attr in ('error', 'foo', 'new', 'roj'):
@@ -142,6 +159,16 @@ def _test_xx():
142159
assert xx.__doc__ == doc
143160
assert isinstance(xx.Null(), xx.Null)
144161
assert isinstance(xx.Str(), xx.Str)
162+
163+
if sys.platform == 'linux':
164+
so_headers = subprocess.check_output(["readelf", "-d", xx.__file__], universal_newlines=True)
165+
if not copy_so:
166+
# Linked against a library in /usr/lib{,64}
167+
assert 'RPATH' not in so_headers and 'RUNPATH' not in so_headers
168+
else:
169+
# Linked against a library in /tmp
170+
assert 'RPATH' in so_headers or 'RUNPATH' in so_headers
171+
# The import is the real test here
145172

146173
def test_solaris_enable_shared(self):
147174
dist = Distribution({'name': 'xx'})

0 commit comments

Comments
 (0)