@@ -38,6 +38,21 @@ def step_timeout(timeout):
3838 return timeout + 10 * 60
3939
4040
41+ def get_j_opts (worker , default = None ):
42+ """Get option(s) for parallel make: ["-jN"]
43+
44+ Rerurns an one-element list or an empty one if default is None and no
45+ parallelism is specified. This avoids branches when adding the option:
46+
47+ command = [cmd, *get_j_opts(worker), ...]
48+ """
49+ if worker .parallel_tests is None :
50+ if default is None :
51+ return []
52+ return [f"-j{ default } " ]
53+ return [f"-j{ worker .parallel_tests } " ]
54+
55+
4156class BaseBuild (factory .BuildFactory ):
4257 factory_tags = []
4358 test_timeout = TEST_TIMEOUT
@@ -67,18 +82,18 @@ class UnixBuild(BaseBuild):
6782 configureFlags = ["--with-pydebug" ]
6883 compile_environ = {}
6984 interpreterFlags = ""
70- testFlags = ["-j2" ]
85+ testFlags = []
7186 makeTarget = "all"
7287 test_environ = {}
7388 build_out_of_tree = False
7489
75- def setup (self , parallel , branch , test_with_PTY = False , ** kwargs ):
90+ def setup (self , branch , worker , test_with_PTY = False , ** kwargs ):
7691 out_of_tree_dir = "build_oot"
7792
7893 # Adjust the timeout for this worker
79- self .test_timeout *= kwargs . get ( " timeout_factor" , 1 )
94+ self .test_timeout *= worker . timeout_factor
8095
81- exclude_test_resources = kwargs . get ( " exclude_test_resources" , [])
96+ exclude_test_resources = worker . exclude_test_resources
8297
8398 # In 3.10, test_asyncio wasn't split out, and refleaks tests
8499 # need more time.
@@ -106,15 +121,10 @@ def setup(self, parallel, branch, test_with_PTY=False, **kwargs):
106121 self .addStep (
107122 Configure (command = configure_cmd , ** oot_kwargs )
108123 )
109- compile = ["make" , self .makeTarget ]
110- testopts = list ( self .testFlags )
124+ compile = ["make" , * get_j_opts ( worker ), self .makeTarget ]
125+ testopts = [ * self .testFlags , * get_j_opts ( worker , 2 )]
111126 if not has_option ("-R" , self .testFlags ):
112127 testopts .extend (("--junit-xml" , JUNIT_FILENAME ))
113- if parallel :
114- compile = ["make" , parallel , self .makeTarget ]
115- testopts .append (parallel )
116- if not has_option ("-j" , testopts ):
117- testopts .append ("-j2" )
118128 # Add excluded test resources
119129 if exclude_test_resources :
120130 u_loc = None
@@ -165,9 +175,9 @@ class UnixPerfBuild(UnixBuild):
165175
166176
167177class UnixTraceRefsBuild (UnixBuild ):
168- def setup (self , parallel , branch , test_with_PTY = False , ** kwargs ):
178+ def setup (self , branch , worker , test_with_PTY = False , ** kwargs ):
169179 self .configureFlags = ["--with-pydebug" , "--with-trace-refs" ]
170- return super ().setup (parallel , branch , test_with_PTY = test_with_PTY , ** kwargs )
180+ return super ().setup (branch , worker , test_with_PTY = test_with_PTY , ** kwargs )
171181
172182
173183class UnixRefleakBuild (UnixBuild ):
@@ -198,12 +208,12 @@ class UnixInstalledBuild(BaseBuild):
198208 buildersuffix = ".installed"
199209 configureFlags = []
200210 interpreterFlags = ["-Wdefault" , "-bb" , "-E" ]
201- defaultTestOpts = ["-rwW" , "-uall" , "-j2" ]
211+ defaultTestOpts = ["-rwW" , "-uall" ]
202212 makeTarget = "all"
203213 installTarget = "install"
204214 factory_tags = ["installed" ]
205215
206- def setup (self , parallel , branch , test_with_PTY = False , ** kwargs ):
216+ def setup (self , branch , worker , test_with_PTY = False , ** kwargs ):
207217 if branch == MAIN_BRANCH_NAME :
208218 branch = MAIN_BRANCH_VERSION
209219 elif branch == "custom" :
@@ -216,14 +226,14 @@ def setup(self, parallel, branch, test_with_PTY=False, **kwargs):
216226 )
217227 )
218228
219- compile = [ "make" , self . makeTarget ]
220- install = ["make" , self .installTarget ]
221- testopts = list ( self .defaultTestOpts )
222- testopts . append ( f"--timeout= { self . test_timeout } " )
223- if parallel :
224- compile = [ "make" , parallel , self .makeTarget ]
225- install = [ "make" , parallel , self . installTarget ]
226- testopts . append ( parallel )
229+ j_opts = get_j_opts ( worker )
230+ compile = ["make" , * j_opts , self .makeTarget ]
231+ install = [ "make" , * j_opts , self .installTarget ]
232+ testopts = [
233+ * self . defaultTestOpts ,
234+ f"--timeout= { self .test_timeout } " ,
235+ * get_j_opts ( worker , 2 ),
236+ ]
227237
228238 test = [installed_python ,
229239 * self .interpreterFlags ,
@@ -274,7 +284,7 @@ class UnixBuildWithoutDocStrings(UnixBuild):
274284class UnixBigmemBuild (UnixBuild ):
275285 buildersuffix = ".bigmem"
276286 testFlags = [
277- "-M60g" , "-j8" , "- uall,extralargefile" ,
287+ "-M60g" , "-uall,extralargefile" ,
278288 "--prioritize=test_bigmem,test_lzma,test_bz2,test_re,test_array"
279289 ]
280290 test_timeout = TEST_TIMEOUT * 5
@@ -596,18 +606,24 @@ class BaseWindowsBuild(BaseBuild):
596606 clean_command = [r"Tools\buildbot\clean.bat" ]
597607 python_command = [r"python.bat" ]
598608 buildFlags = ["-p" , "Win32" ]
599- testFlags = ["-p" , "Win32" , "-j2" ]
609+ testFlags = ["-p" , "Win32" ]
600610 cleanFlags = []
601611 factory_tags = ["win32" ]
602612
603- def setup (self , parallel , branch , ** kwargs ):
613+ def setup (self , branch , worker , ** kwargs ):
604614 build_command = self .build_command + self .buildFlags
605- test_command = [* self .test_command , * self .testFlags ]
615+ test_command = [
616+ * self .test_command ,
617+ * self .testFlags ,
618+ * get_j_opts (worker , 2 ),
619+ ]
606620 if not has_option ("-R" , self .testFlags ):
607621 test_command .extend ((r"--junit-xml" , JUNIT_FILENAME ))
608- clean_command = self .clean_command + self .cleanFlags
609- if parallel :
610- test_command .append (parallel )
622+ clean_command = [
623+ * self .clean_command ,
624+ * self .cleanFlags ,
625+ * get_j_opts (worker ),
626+ ]
611627 self .addStep (Compile (command = build_command ))
612628 self .addStep (PythonInfo (
613629 command = self .python_command + ["-m" , "test.pythoninfo" ],
@@ -628,19 +644,19 @@ class WindowsBuild(BaseWindowsBuild):
628644
629645class WindowsRefleakBuild (BaseWindowsBuild ):
630646 buildersuffix = ".x32.refleak"
631- testFlags = ["-j2" , "- R" , "3:3" , "-u-cpu" ]
647+ testFlags = ["-R" , "3:3" , "-u-cpu" ]
632648 test_timeout = REFLEAK_TIMEOUT
633649 factory_tags = ["win32" , "refleak" ]
634650
635651
636652class SlowWindowsBuild (WindowsBuild ):
637653 test_timeout = TEST_TIMEOUT * 2
638- testFlags = ["-j2" , "- u-cpu" , "-u-largefile" ]
654+ testFlags = ["-u-cpu" , "-u-largefile" ]
639655
640656
641657class Windows64Build (BaseWindowsBuild ):
642658 buildFlags = ["-p" , "x64" ]
643- testFlags = ["-p" , "x64" , "-j2" ]
659+ testFlags = ["-p" , "x64" ]
644660 cleanFlags = ["-p" , "x64" ]
645661 factory_tags = ["win64" ]
646662
@@ -707,7 +723,7 @@ class Windows64PGONoGilTailcallBuild(Windows64PGONoGilBuild):
707723
708724class WindowsARM64Build (BaseWindowsBuild ):
709725 buildFlags = ["-p" , "ARM64" ]
710- testFlags = ["-p" , "ARM64" , "-j2" ]
726+ testFlags = ["-p" , "ARM64" ]
711727 cleanFlags = ["-p" , "ARM64" ]
712728 factory_tags = ["win-arm64" ]
713729
@@ -731,7 +747,7 @@ class UnixCrossBuild(UnixBuild):
731747 host_make_cmd = ["make" ]
732748 can_execute_python = True
733749
734- def setup (self , parallel , branch , test_with_PTY = False , ** kwargs ):
750+ def setup (self , branch , worker , test_with_PTY = False , ** kwargs ):
735751 assert self .host is not None , "Must set self.host on cross builds"
736752
737753 out_of_tree_dir = "build_oot"
@@ -778,10 +794,7 @@ def setup(self, parallel, branch, test_with_PTY=False, **kwargs):
778794 workdir = oot_build_path
779795 )
780796 )
781- if parallel :
782- compile = ["make" , parallel ]
783- else :
784- compile = ["make" ]
797+ compile = ["make" , * get_j_opts (worker )]
785798
786799 self .addStep (
787800 Compile (
@@ -809,13 +822,9 @@ def setup(self, parallel, branch, test_with_PTY=False, **kwargs):
809822 )
810823 )
811824
812- testopts = list ( self .testFlags )
825+ testopts = [ * self .testFlags , * get_j_opts ( worker , 2 )]
813826 if not has_option ("-R" , self .testFlags ):
814827 testopts .extend ((" --junit-xml" , JUNIT_FILENAME ))
815- if parallel :
816- testopts .append (parallel )
817- if not has_option ("-j" , self .testFlags ):
818- testopts .append ("-j2" )
819828
820829 test = [
821830 "make" ,
@@ -825,10 +834,7 @@ def setup(self, parallel, branch, test_with_PTY=False, **kwargs):
825834 f"TESTTIMEOUT={ self .test_timeout } " ,
826835 ]
827836
828- if parallel :
829- compile = self .host_make_cmd + [parallel , self .makeTarget ]
830- else :
831- compile = self .host_make_cmd + [self .makeTarget ]
837+ compile = [* self .host_make_cmd , * get_j_opts (worker ), * self .makeTarget ]
832838 self .addStep (
833839 Compile (
834840 name = "Compile host Python" ,
@@ -884,7 +890,7 @@ class Wasm32WasiCrossBuild(UnixCrossBuild):
884890 host = "wasm32-unknown-wasi"
885891 host_configure_cmd = ["../../Tools/wasm/wasi-env" , "../../configure" ]
886892
887- def setup (self , parallel , branch , test_with_PTY = False , ** kwargs ):
893+ def setup (self , branch , worker , test_with_PTY = False , ** kwargs ):
888894 self .addStep (
889895 SetPropertyFromCommand (
890896 name = "Find config.site-wasm32-wasi" ,
@@ -907,7 +913,7 @@ def setup(self, parallel, branch, test_with_PTY=False, **kwargs):
907913 )
908914 )
909915 self .compile_environ ["WASI_SDK_PATH" ] = "/opt/wasi-sdk-21.0"
910- super ().setup (parallel , branch , test_with_PTY = test_with_PTY , ** kwargs )
916+ super ().setup (branch , worker , test_with_PTY = test_with_PTY , ** kwargs )
911917
912918
913919class _Wasm32WasiPreview1Build (UnixBuild ):
@@ -922,7 +928,7 @@ def __init__(self, source, *, extra_tags=[], **kwargs):
922928 self .buildersuffix += self .append_suffix
923929 super ().__init__ (source , extra_tags = extra_tags , ** kwargs )
924930
925- def setup (self , parallel , branch , test_with_PTY = False , ** kwargs ):
931+ def setup (self , branch , worker , test_with_PTY = False , ** kwargs ):
926932 wasi_py = "Tools/wasm/wasi.py"
927933 host_triple = "wasm32-wasip1"
928934 host_path = f"build/cross-build/{ host_triple } "
@@ -965,13 +971,9 @@ def setup(self, parallel, branch, test_with_PTY=False, **kwargs):
965971 ))
966972
967973 # Copied from UnixBuild.
968- testopts = list ( self .testFlags )
974+ testopts = [ * self .testFlags , * get_j_opts ( worker , 2 )]
969975 if not has_option ("-R" , self .testFlags ):
970976 testopts .extend (("--junit-xml" , JUNIT_FILENAME ))
971- if parallel :
972- testopts .append (parallel )
973- if not has_option ("-j" , testopts ):
974- testopts .append ("-j2" )
975977 test = [
976978 "make" ,
977979 "buildbottest" ,
@@ -1045,12 +1047,14 @@ def __init__(self, source, **kwargs):
10451047
10461048 super ().__init__ (source , ** kwargs )
10471049
1048- def py313_setup (self , parallel , branch , test_with_PTY = False , ** kwargs ):
1050+ def py313_setup (self , branch , worker , test_with_PTY = False , ** kwargs ):
10491051 out_of_tree_dir = "build_oot"
10501052 oot_dir_path = os .path .join ("build" , out_of_tree_dir )
10511053 oot_build_path = os .path .join (oot_dir_path , "build" )
10521054 oot_host_path = os .path .join (oot_dir_path , "host" )
10531055
1056+ j_opts = get_j_opts (worker )
1057+
10541058 # Create out of tree directory for "build", the platform we are
10551059 # currently running on
10561060 self .addStep (
@@ -1080,10 +1084,7 @@ def py313_setup(self, parallel, branch, test_with_PTY=False, **kwargs):
10801084 workdir = oot_build_path ,
10811085 )
10821086 )
1083- if parallel :
1084- compile = ["make" , parallel ]
1085- else :
1086- compile = ["make" ]
1087+ compile = ["make" , * j_opts ]
10871088
10881089 self .addStep (
10891090 Compile (
@@ -1141,12 +1142,8 @@ def py313_setup(self, parallel, branch, test_with_PTY=False, **kwargs):
11411142 )
11421143 )
11431144
1144- if parallel :
1145- compile = ["make" , parallel , self .makeTarget ]
1146- install = ["make" , parallel , "install" ]
1147- else :
1148- compile = ["make" , self .makeTarget ]
1149- install = ["make" , "install" ]
1145+ compile = ["make" , * j_opts , self .makeTarget ]
1146+ install = ["make" , * j_opts , "install" ]
11501147
11511148 self .addStep (
11521149 Compile (
@@ -1187,7 +1184,7 @@ def py313_setup(self, parallel, branch, test_with_PTY=False, **kwargs):
11871184 )
11881185 )
11891186
1190- def current_setup (self , parallel , branch , test_with_PTY = False , ** kwargs ):
1187+ def current_setup (self , branch , worker , test_with_PTY = False , ** kwargs ):
11911188 build_environ = {
11921189 "CACHE_DIR" : "/Users/buildbot/downloads" ,
11931190 }
@@ -1237,7 +1234,7 @@ def current_setup(self, parallel, branch, test_with_PTY=False, **kwargs):
12371234 ),
12381235 ])
12391236
1240- def setup (self , parallel , branch , test_with_PTY = False , ** kwargs ):
1237+ def setup (self , branch , * args , ** kwargs ):
12411238 # Builds on Python 3.13 use a direct set of calls to make. Python 3.14
12421239 # introduced a simpler XCframework build script; Python 3.15 moved that
12431240 # script to the Platforms folder.
@@ -1248,9 +1245,9 @@ def setup(self, parallel, branch, test_with_PTY=False, **kwargs):
12481245 # The symlink approach will fail for Python 3.13 *PR* builds, because
12491246 # there's no way to identify the base branch for a PR.
12501247 if branch == "3.13" :
1251- self .py313_setup (parallel , branch , test_with_PTY = test_with_PTY , ** kwargs )
1248+ self .py313_setup (branch , * args , ** kwargs )
12521249 else :
1253- self .current_setup (parallel , branch , test_with_PTY = test_with_PTY , ** kwargs )
1250+ self .current_setup (branch , * args , ** kwargs )
12541251
12551252
12561253class IOSARM64SimulatorBuild (_IOSSimulatorBuild ):
@@ -1336,16 +1333,14 @@ class ValgrindBuild(UnixBuild):
13361333 factory_tags = ["valgrind" ]
13371334 test_timeout = TEST_TIMEOUT * 5
13381335
1339- def setup (self , parallel , branch , ** kwargs ):
1336+ def setup (self , branch , worker , ** kwargs ):
13401337 self .addStep (
13411338 Configure (
13421339 command = ["./configure" , "--prefix" , "$(PWD)/target" ] + self .configureFlags
13431340 )
13441341 )
13451342
1346- compile = ["make" , self .makeTarget ]
1347- if parallel :
1348- compile = ["make" , parallel , self .makeTarget ]
1343+ compile = ["make" , * get_j_opts (worker ), self .makeTarget ]
13491344
13501345 self .addStep (Compile (command = compile , env = self .compile_environ ))
13511346
0 commit comments