Skip to content

Commit d0d165a

Browse files
committed
Run cpyext test build from its build directory
1 parent db8635b commit d0d165a

File tree

1 file changed

+27
-19
lines changed
  • graalpython/com.oracle.graal.python.test/src/tests/cpyext

1 file changed

+27
-19
lines changed

graalpython/com.oracle.graal.python.test/src/tests/cpyext/__init__.py

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@
3636
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3737
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3838
# SOFTWARE.
39-
4039
from importlib import invalidate_caches
4140

4241
import gc
4342
import os
43+
import shutil
4444
import sys
4545
import unittest
4646
from copy import deepcopy
@@ -109,18 +109,18 @@ def ccompile(self, name, check_duplicate_name=True):
109109
m.update(block)
110110
cur_checksum = m.hexdigest()
111111

112-
install_dir = DIR / 'build' / name
112+
build_dir = DIR / 'build' / name
113113

114114
# see if there is already a checksum file
115-
checksum_file = install_dir / f'{name}{EXT_SUFFIX}.sha256'
115+
checksum_file = build_dir / f'{name}{EXT_SUFFIX}.sha256'
116116
available_checksum = ""
117117
if checksum_file.exists():
118118
# read checksum file
119119
with open(checksum_file, "r") as f:
120120
available_checksum = f.readline()
121121

122122
# note, the suffix is already a string like '.so'
123-
lib_file = install_dir / f'{name}{EXT_SUFFIX}'
123+
lib_file = build_dir / f'{name}{EXT_SUFFIX}'
124124

125125
if check_duplicate_name and available_checksum != cur_checksum and name in compiled_registry:
126126
raise RuntimeError(f"\n\nModule with name '{name}' was already compiled, but with different source code. "
@@ -134,20 +134,28 @@ def ccompile(self, name, check_duplicate_name=True):
134134
# Note: It could be that the C source file's checksum didn't change but someone
135135
# manually deleted the shared library file.
136136
if available_checksum != cur_checksum or not lib_file.exists():
137-
module = Extension(name, sources=[str(source_file)])
138-
args = [
139-
'--verbose' if sys.flags.verbose else '--quiet',
140-
'build', f'--build-base={install_dir}',
141-
'install_lib', '-f', f'--install-dir={install_dir}',
142-
]
143-
setup(
144-
script_name='setup',
145-
script_args=args,
146-
name=name,
147-
version='1.0',
148-
description='',
149-
ext_modules=[module]
150-
)
137+
os.makedirs(build_dir, exist_ok=True)
138+
# MSVC linker doesn't like absolute paths in some parameters, so just run from the build dir
139+
old_cwd = os.getcwd()
140+
os.chdir(build_dir)
141+
try:
142+
shutil.copy(source_file, '.')
143+
module = Extension(name, sources=[source_file.name])
144+
args = [
145+
'--verbose' if sys.flags.verbose else '--quiet',
146+
'build',
147+
'install_lib', '-f', '--install-dir=.',
148+
]
149+
setup(
150+
script_name='setup',
151+
script_args=args,
152+
name=name,
153+
version='1.0',
154+
description='',
155+
ext_modules=[module]
156+
)
157+
finally:
158+
os.chdir(old_cwd)
151159

152160
# write new checksum
153161
with open(checksum_file, "w") as f:
@@ -163,7 +171,7 @@ def ccompile(self, name, check_duplicate_name=True):
163171
if GRAALPYTHON:
164172
file_not_empty(lib_file)
165173

166-
return str(install_dir)
174+
return str(build_dir)
167175

168176

169177
def file_not_empty(path):

0 commit comments

Comments
 (0)