mirror of
https://github.com/espressif/esp-idf
synced 2025-03-09 09:09:10 -04:00
fix(tools): allow to save stdout and stderr if the exec command fails
Currently, if a command run by the exec command returns an error code, its stdout and stderr are not saved. It could be beneficial to store at least the stderr if requested. Additionally, avoid creating output files when there is no content and also store the stderr of the failed command to diag.log. Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
This commit is contained in:
parent
e5ee4207c6
commit
88c099d756
@ -1,4 +1,4 @@
|
||||
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
import atexit
|
||||
import difflib
|
||||
@ -583,9 +583,10 @@ def cmd_exec(args: Dict, step: Dict, recipe: Dict) -> None:
|
||||
|
||||
if p.returncode:
|
||||
warn(f'Exec command "{cmd}" failed with exit code {p.returncode}')
|
||||
return
|
||||
if p.stderr:
|
||||
dbg(f'stderr: "{p.stderr}"')
|
||||
|
||||
if stdout:
|
||||
if stdout and p.stdout:
|
||||
try:
|
||||
stdout_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with open(stdout_path, 'a' if append else 'w') as f:
|
||||
@ -593,7 +594,7 @@ def cmd_exec(args: Dict, step: Dict, recipe: Dict) -> None:
|
||||
except Exception:
|
||||
warn(f'Cannot write exec command "{cmd}" stdout to "{stdout}"')
|
||||
|
||||
if stderr:
|
||||
if stderr and p.stderr:
|
||||
try:
|
||||
stderr_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with open(stderr_path, 'a' if append else 'w') as f:
|
||||
|
Loading…
x
Reference in New Issue
Block a user