21
21
import sys
22
22
import subprocess
23
23
import logging
24
+ import multiprocessing
25
+
24
26
from dataclasses import dataclass
25
27
26
28
CHIP_ROOT_DIR = os .path .realpath (
@@ -113,6 +115,11 @@ def setupArgumentsParser():
113
115
help = "Don't do any generation, just log what targets would be generated (default: False)" )
114
116
parser .add_argument ('--run-bootstrap' , default = None , action = 'store_true' ,
115
117
help = 'Automatically run ZAP bootstrap. By default the bootstrap is not triggered' )
118
+
119
+ parser .add_argument ('--parallel' , action = 'store_true' )
120
+ parser .add_argument ('--no-parallel' , action = 'store_false' , dest = 'parallel' )
121
+ parser .set_defaults (parallel = True )
122
+
116
123
return parser .parse_args ()
117
124
118
125
@@ -253,6 +260,14 @@ def getTargets(type, test_target):
253
260
return targets
254
261
255
262
263
+ def _ParallelGenerateOne (target ):
264
+ """
265
+ Helper method to be passed to multiprocessing parallel generation of
266
+ items.
267
+ """
268
+ target .generate ()
269
+
270
+
256
271
def main ():
257
272
logging .basicConfig (
258
273
level = logging .INFO ,
@@ -269,8 +284,15 @@ def main():
269
284
if args .run_bootstrap :
270
285
subprocess .check_call (os .path .join (CHIP_ROOT_DIR , "scripts/tools/zap/zap_bootstrap.sh" ), shell = True )
271
286
272
- for target in targets :
273
- target .generate ()
287
+ if args .parallel :
288
+ # Ensure each zap run is independent
289
+ os .environ ['ZAP_TEMPSTATE' ] = '1'
290
+ with multiprocessing .Pool () as pool :
291
+ for _ in pool .imap_unordered (_ParallelGenerateOne , targets ):
292
+ pass
293
+ else :
294
+ for target in targets :
295
+ target .generate ()
274
296
275
297
276
298
if __name__ == '__main__' :
0 commit comments