Skip to content

Commit 4c88104

Browse files
gh-84461: Use HOSTRUNNER to run regression tests (GH-93694)
Co-authored-by: Brett Cannon <brett@python.org> (cherry picked from commit dc5e02b) Co-authored-by: Christian Heimes <christian@python.org>
1 parent 54fe3d5 commit 4c88104

File tree

4 files changed

+55
-6
lines changed

4 files changed

+55
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
``run_tests.py`` now handles cross compiling env vars correctly and pass
2+
``HOSTRUNNER`` to regression tests.

Tools/scripts/run_tests.py

+42-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
"""
99

1010
import os
11+
import shlex
1112
import sys
13+
import sysconfig
1214
import test.support
1315

1416

@@ -19,15 +21,37 @@ def is_multiprocess_flag(arg):
1921
def is_resource_use_flag(arg):
2022
return arg.startswith('-u') or arg.startswith('--use')
2123

24+
def is_python_flag(arg):
25+
return arg.startswith('-p') or arg.startswith('--python')
26+
2227

2328
def main(regrtest_args):
2429
args = [sys.executable,
2530
'-u', # Unbuffered stdout and stderr
2631
'-W', 'default', # Warnings set to 'default'
2732
'-bb', # Warnings about bytes/bytearray
28-
'-E', # Ignore environment variables
2933
]
3034

35+
cross_compile = '_PYTHON_HOST_PLATFORM' in os.environ
36+
if (hostrunner := os.environ.get("_PYTHON_HOSTRUNNER")) is None:
37+
hostrunner = sysconfig.get_config_var("HOSTRUNNER")
38+
if cross_compile:
39+
# emulate -E, but keep PYTHONPATH + cross compile env vars, so
40+
# test executable can load correct sysconfigdata file.
41+
keep = {
42+
'_PYTHON_PROJECT_BASE',
43+
'_PYTHON_HOST_PLATFORM',
44+
'_PYTHON_SYSCONFIGDATA_NAME',
45+
'PYTHONPATH'
46+
}
47+
environ = {
48+
name: value for name, value in os.environ.items()
49+
if not name.startswith(('PYTHON', '_PYTHON')) or name in keep
50+
}
51+
else:
52+
environ = os.environ.copy()
53+
args.append("-E")
54+
3155
# Allow user-specified interpreter options to override our defaults.
3256
args.extend(test.support.args_from_interpreter_flags())
3357

@@ -38,16 +62,30 @@ def main(regrtest_args):
3862
if sys.platform == 'win32':
3963
args.append('-n') # Silence alerts under Windows
4064
if not any(is_multiprocess_flag(arg) for arg in regrtest_args):
41-
args.extend(['-j', '0']) # Use all CPU cores
65+
if cross_compile and hostrunner:
66+
# For now use only one core for cross-compiled builds;
67+
# hostrunner can be expensive.
68+
args.extend(['-j', '1'])
69+
else:
70+
args.extend(['-j', '0']) # Use all CPU cores
4271
if not any(is_resource_use_flag(arg) for arg in regrtest_args):
4372
args.extend(['-u', 'all,-largefile,-audio,-gui'])
73+
74+
if cross_compile and hostrunner:
75+
# If HOSTRUNNER is set and -p/--python option is not given, then
76+
# use hostrunner to execute python binary for tests.
77+
if not any(is_python_flag(arg) for arg in regrtest_args):
78+
buildpython = sysconfig.get_config_var("BUILDPYTHON")
79+
args.extend(["--python", f"{hostrunner} {buildpython}"])
80+
4481
args.extend(regrtest_args)
45-
print(' '.join(args))
82+
83+
print(shlex.join(args))
4684
if sys.platform == 'win32':
4785
from subprocess import call
4886
sys.exit(call(args))
4987
else:
50-
os.execv(sys.executable, args)
88+
os.execve(sys.executable, args, environ)
5189

5290

5391
if __name__ == '__main__':

configure

+5-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

+6-1
Original file line numberDiff line numberDiff line change
@@ -1492,13 +1492,18 @@ then
14921492
dnl TODO: support other WASI runtimes
14931493
dnl wasmtime starts the proces with "/" as CWD. For OOT builds add the
14941494
dnl directory containing _sysconfigdata to PYTHONPATH.
1495-
[WASI/*], [HOSTRUNNER='wasmtime run --env PYTHONPATH=$$(realpath --relative-to $(abs_srcdir) $(abs_builddir))/$$(cat pybuilddir.txt) --mapdir /::$(srcdir) --'],
1495+
[WASI/*], [HOSTRUNNER='wasmtime run --env PYTHONPATH=/$(shell realpath --relative-to $(abs_srcdir) $(abs_builddir))/$(shell cat pybuilddir.txt) --mapdir /::$(srcdir) --'],
14961496
[HOSTRUNNER='']
14971497
)
14981498
fi
14991499
AC_SUBST([HOSTRUNNER])
15001500
AC_MSG_RESULT([$HOSTRUNNER])
15011501

1502+
if test -n "$HOSTRUNNER"; then
1503+
dnl Pass hostrunner variable as env var in order to expand shell expressions.
1504+
PYTHON_FOR_BUILD="_PYTHON_HOSTRUNNER='$HOSTRUNNER' $PYTHON_FOR_BUILD"
1505+
fi
1506+
15021507
AC_MSG_RESULT($LDLIBRARY)
15031508

15041509
# LIBRARY_DEPS, LINK_PYTHON_OBJS and LINK_PYTHON_DEPS variable

0 commit comments

Comments
 (0)