@@ -350,7 +350,8 @@ def setupArgumentsParser():
350
350
351
351
parser .add_argument ('--parallel' , action = 'store_true' )
352
352
parser .add_argument ('--no-parallel' , action = 'store_false' , dest = 'parallel' )
353
- parser .set_defaults (parallel = True )
353
+ parser .add_argument ('--no-rerun-in-env' , action = 'store_false' , dest = 'rerun_in_env' )
354
+ parser .set_defaults (parallel = True , rerun_in_env = True )
354
355
355
356
args = parser .parse_args ()
356
357
@@ -495,6 +496,26 @@ def main():
495
496
level = logging .INFO ,
496
497
format = '%(asctime)s %(name)s %(levelname)-7s %(message)s'
497
498
)
499
+
500
+ # The scripts executed by this generally MUST be within a bootstrapped environment because
501
+ # we need:
502
+ # - zap-cli in PATH
503
+ # - scripts/codegen.py uses click (can be in current pyenv, but guaranteed in bootstrap)
504
+ # - formatting is using bootstrapped clang-format
505
+ # Figure out if bootstrapped. For now assume `PW_ROOT` is such a marker in the environment
506
+ if "PW_ROOT" not in os .environ :
507
+ logging .error ("Script MUST be run in a bootstrapped environment." )
508
+
509
+ # using the `--no-rerun-in-env` to avoid recursive infinite calls
510
+ if '--no-rerun-in-env' not in sys .argv :
511
+ import shlex
512
+ logging .info ("Will re-try running in a build environment...." )
513
+
514
+ what_to_run = sys .argv + ['--no-rerun-in-env' ]
515
+ launcher = os .path .join (CHIP_ROOT_DIR , 'scripts' , 'run_in_build_env.sh' )
516
+ os .execv (launcher , [launcher , shlex .join (what_to_run )])
517
+ sys .exit (1 )
518
+
498
519
checkPythonVersion ()
499
520
os .chdir (CHIP_ROOT_DIR )
500
521
args = setupArgumentsParser ()
0 commit comments