1
1
import contextlib
2
+ import glob
2
3
import importlib
3
4
import os
4
5
import platform
@@ -94,19 +95,32 @@ class TestBuildExt(TempdirManager):
94
95
def build_ext (self , * args , ** kwargs ):
95
96
return build_ext (* args , ** kwargs )
96
97
97
- def test_build_ext (self ):
98
+ @pytest .mark .parametrize ("copy_so" , [False , True ])
99
+ def test_build_ext (self , copy_so ):
98
100
missing_compiler_executable ()
99
101
copy_xxmodule_c (self .tmp_dir )
100
102
xx_c = os .path .join (self .tmp_dir , 'xxmodule.c' )
101
103
xx_ext = Extension ('xx' , [xx_c ])
102
104
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
+ )
110
124
dist = Distribution ({'name' : 'xx' , 'ext_modules' : [xx_ext ]})
111
125
dist .package_dir = self .tmp_dir
112
126
cmd = self .build_ext (dist )
@@ -125,10 +139,13 @@ def test_build_ext(self):
125
139
sys .stdout = old_stdout
126
140
127
141
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' )
129
146
130
147
@staticmethod
131
- def _test_xx ():
148
+ def _test_xx (copy_so ):
132
149
import xx
133
150
134
151
for attr in ('error' , 'foo' , 'new' , 'roj' ):
@@ -142,6 +159,16 @@ def _test_xx():
142
159
assert xx .__doc__ == doc
143
160
assert isinstance (xx .Null (), xx .Null )
144
161
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
145
172
146
173
def test_solaris_enable_shared (self ):
147
174
dist = Distribution ({'name' : 'xx' })
0 commit comments