Skip to content

Commit 166ef4c

Browse files
committed
Use in run tests
1 parent e05da9b commit 166ef4c

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

mypyc/test/librt_cache.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ def get_librt_path(experimental: bool = True) -> str:
186186
with open(setup_py, "w") as f:
187187
f.write(_generate_setup_py(build_dir, experimental))
188188

189-
# Build
189+
# Build (parallel builds don't work well because multiple extensions
190+
# share the same runtime C files, causing race conditions)
190191
result = subprocess.run(
191192
[sys.executable, setup_py, "build_ext", "--inplace"],
192193
cwd=build_dir,

mypyc/test/test_run.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from mypyc.options import CompilerOptions
2828
from mypyc.test.config import test_data_prefix
2929
from mypyc.test.test_serialization import check_serialization_roundtrip
30+
from mypyc.test.librt_cache import get_librt_path
3031
from mypyc.test.testutil import (
3132
ICODE_GEN_BUILTINS,
3233
TESTUTIL_PATH,
@@ -289,6 +290,7 @@ def run_case_step(self, testcase: DataDrivenTestCase, incremental_step: int) ->
289290

290291
setup_file = os.path.abspath(os.path.join(WORKDIR, "setup.py"))
291292
# We pass the C file information to the build script via setup.py unfortunately
293+
# Note: install_librt is always False since we use cached librt from librt_cache
292294
with open(setup_file, "w", encoding="utf-8") as f:
293295
f.write(
294296
setup_format.format(
@@ -297,16 +299,15 @@ def run_case_step(self, testcase: DataDrivenTestCase, incremental_step: int) ->
297299
(cfiles, deps),
298300
self.multi_file,
299301
opt_level,
300-
librt,
302+
False, # install_librt - use cached version instead
301303
experimental_features,
302304
)
303305
)
304306

305307
if librt:
306-
# This hack forces Python to prefer the local "installation".
307-
os.makedirs("librt", exist_ok=True)
308-
with open(os.path.join("librt", "__init__.py"), "a"):
309-
pass
308+
# Use cached pre-built librt instead of rebuilding for each test
309+
cached_librt = get_librt_path(experimental_features)
310+
shutil.copytree(os.path.join(cached_librt, "librt"), "librt")
310311

311312
if not run_setup(setup_file, ["build_ext", "--inplace"]):
312313
if testcase.config.getoption("--mypyc-showc"):

0 commit comments

Comments
 (0)