f4pga/flows/common.sub: print stdout on error optionally (#642)

This commit is contained in:
Krzysztof Boroński 2022-09-30 19:56:41 +02:00 committed by Unai Martinez-Corral
parent 54802ec0e3
commit b30f113151
1 changed files with 6 additions and 2 deletions

View File

@ -133,14 +133,17 @@ class SubprocessException(Exception):
return_code: int return_code: int
def sub(*args, env=None, cwd=None): def sub(*args, env=None, cwd=None, print_stdout_on_fail=False):
""" """
Execute subroutine. Execute subroutine.
""" """
out = run(args, capture_output=True, env=env, cwd=cwd) out = run(args, capture_output=True, env=env, cwd=cwd)
if out.returncode != 0: if out.returncode != 0:
print(f"[ERROR]: {args[0]} non-zero return code.\n" f"stderr:\n{out.stderr.decode()}\n\n") print(f"[ERROR]: {args[0]} non-zero return code.\n")
if print_stdout_on_fail:
print(f"stdout:\n{out.stdout.decode()}\n\n")
print(f"stderr:\n{out.stderr.decode()}\n\n")
exit(out.returncode) exit(out.returncode)
return out.stdout return out.stdout
@ -179,6 +182,7 @@ def vpr(mode: str, vprargs: VprArgs, cwd=None):
+ vprargs.optional + vprargs.optional
), ),
cwd=cwd, cwd=cwd,
print_stdout_on_fail=True,
) )