Skip to content

Commit ebaa142

Browse files
marc-hbkv2019i
authored andcommitted
xtensa-build-zephyr.py: log ALL "evil" environment differences
This is a typical example of why environment variables are (a sometimes necessary) evil: imagine you're trying to reproduce exactly the `west build` command run by xtensa-build-zephyr.py when building with the `xt-xcc` toolchain. So you would typically look at the logs, feel lucky that it shows the extra environment variables used and copy them: ``` XTENSA_TOOLCHAIN_PATH=/srv/home/jenkins/xcc/install/tools TOOLCHAIN_VER=RG-2017.8-linux XTENSA_SYSTEM=/home/jenkins/xcc/install/builds/RG-2017.8-linux/cavs... In dir: workspace/sof; running: west build ... ``` Except this won't work because there's one variable currently missing: `ZEPHYR_TOOLCHAIN_VARIANT`! Of course there could be more in the future. Fix this by leveraging the recent os.environ.copy() added by commit 8aab183 ("xtensa-build-zephyr: fix DEFAULT_TOOLCHAIN_VARIANT spill on next platf") compare it to the current os.environ and show the difference in a totally generic, non-hardcoded way. Signed-off-by: Marc Herbert <marc.herbert@intel.com>
1 parent 5da0812 commit ebaa142

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

scripts/xtensa-build-zephyr.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,15 @@ def execute_command(*run_args, **run_kwargs):
270270
cwd = run_kwargs.get('cwd')
271271
print_cwd = f"In dir: {cwd}" if cwd else f"in current dir: {os.getcwd()}"
272272
print_args = shlex.join(command_args)
273-
print(f"{print_cwd}; running command: {print_args}", flush=True)
273+
output = f"{print_cwd}; running command:\n {print_args}"
274+
env_arg = run_kwargs.get('env')
275+
env_change = set(env_arg.items()) - set(os.environ.items()) if env_arg else None
276+
if env_change:
277+
output += "\n... with extra/modified environment:"
278+
for k_v in env_change:
279+
output += f"\n{k_v[0]}={k_v[1]}"
280+
print(output, flush=True)
281+
274282

275283
if run_kwargs.get('check') is None:
276284
run_kwargs['check'] = True
@@ -568,8 +576,6 @@ def build_platforms():
568576
TOOLCHAIN_VER = platform_dict["XTENSA_TOOLS_VERSION"]
569577
XTENSA_CORE = platform_dict["XTENSA_CORE"]
570578
platf_build_environ["TOOLCHAIN_VER"] = TOOLCHAIN_VER
571-
print(f"XTENSA_TOOLCHAIN_PATH={XTENSA_TOOLCHAIN_PATH}")
572-
print(f"TOOLCHAIN_VER={TOOLCHAIN_VER}")
573579

574580
# Set variables expected by xcc toolchain. CMake cannot set (evil) build-time
575581
# environment variables at configure time:
@@ -578,7 +584,6 @@ def build_platforms():
578584
TOOLCHAIN_VER).absolute())
579585
XTENSA_SYSTEM = str(pathlib.Path(XTENSA_BUILDS_DIR, XTENSA_CORE, "config").absolute())
580586
platf_build_environ["XTENSA_SYSTEM"] = XTENSA_SYSTEM
581-
print(f"XTENSA_SYSTEM={XTENSA_SYSTEM}")
582587

583588
platform_build_dir_name = f"build-{platform}"
584589

0 commit comments

Comments
 (0)