Skip to content

Commit a23bd17

Browse files
committed
Increase logging for external commands
The `external_commands.run()` function now logs all environment variables. Before it only logged extra environment variables defined in a plugin. The logs were missing information about global environment variables, e.g. env vars defined in a build container. These additional env vars influence a build, too. The run log file now contains the command, env vars, and current working directory, too. Signed-off-by: Christian Heimes <cheimes@redhat.com>
1 parent f4cb469 commit a23bd17

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/fromager/external_commands.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,16 @@ def run(
7070
*cmd,
7171
]
7272

73-
logger.debug(
74-
"running: %s %s in %s",
75-
" ".join(f"{k}={shlex.quote(v)}" for k, v in extra_environ.items()),
76-
" ".join(shlex.quote(str(s)) for s in cmd),
77-
cwd or ".",
78-
)
73+
cmd_str = " ".join(shlex.quote(str(s)) for s in cmd)
74+
env_str = " ".join(f"{k}={shlex.quote(v)}" for k, v in sorted(env.items()))
75+
cwd_str = cwd or os.path.abspath(os.getcwd())
76+
77+
logger.debug("running: %s %s in %s", cmd_str, env_str, cwd_str)
7978
if log_filename:
8079
with open(log_filename, "w") as log_file:
80+
print(f"cmd: {cmd_str}", file=log_file)
81+
print(f"env: {env_str}", file=log_file)
82+
print(f"cwd: {cwd_str}", file=log_file)
8183
completed = subprocess.run(
8284
cmd,
8385
cwd=cwd,

0 commit comments

Comments
 (0)