8
8
"""
9
9
10
10
import os
11
+ import shlex
11
12
import sys
13
+ import sysconfig
12
14
import test .support
13
15
14
16
@@ -19,15 +21,37 @@ def is_multiprocess_flag(arg):
19
21
def is_resource_use_flag (arg ):
20
22
return arg .startswith ('-u' ) or arg .startswith ('--use' )
21
23
24
+ def is_python_flag (arg ):
25
+ return arg .startswith ('-p' ) or arg .startswith ('--python' )
26
+
22
27
23
28
def main (regrtest_args ):
24
29
args = [sys .executable ,
25
30
'-u' , # Unbuffered stdout and stderr
26
31
'-W' , 'default' , # Warnings set to 'default'
27
32
'-bb' , # Warnings about bytes/bytearray
28
- '-E' , # Ignore environment variables
29
33
]
30
34
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
+
31
55
# Allow user-specified interpreter options to override our defaults.
32
56
args .extend (test .support .args_from_interpreter_flags ())
33
57
@@ -38,16 +62,30 @@ def main(regrtest_args):
38
62
if sys .platform == 'win32' :
39
63
args .append ('-n' ) # Silence alerts under Windows
40
64
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
42
71
if not any (is_resource_use_flag (arg ) for arg in regrtest_args ):
43
72
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
+
44
81
args .extend (regrtest_args )
45
- print (' ' .join (args ))
82
+
83
+ print (shlex .join (args ))
46
84
if sys .platform == 'win32' :
47
85
from subprocess import call
48
86
sys .exit (call (args ))
49
87
else :
50
- os .execv (sys .executable , args )
88
+ os .execve (sys .executable , args , environ )
51
89
52
90
53
91
if __name__ == '__main__' :
0 commit comments