Skip to content

Commit bf4edc4

Browse files
authored
make zap_regen_all auto-trigger a buildenv bootstrap/activate when run if not already activated (#34284)
* Auto-use run_in_build_env for zap_regen_all * Restyle * Remove some debug logging * Fix linter
1 parent 717b248 commit bf4edc4

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

scripts/tools/zap_regen_all.py

+22-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ def setupArgumentsParser():
350350

351351
parser.add_argument('--parallel', action='store_true')
352352
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)
354355

355356
args = parser.parse_args()
356357

@@ -495,6 +496,26 @@ def main():
495496
level=logging.INFO,
496497
format='%(asctime)s %(name)s %(levelname)-7s %(message)s'
497498
)
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+
498519
checkPythonVersion()
499520
os.chdir(CHIP_ROOT_DIR)
500521
args = setupArgumentsParser()

0 commit comments

Comments
 (0)