From 80e5e7aea6649dea95f6259ca17d6e26cfc4f798 Mon Sep 17 00:00:00 2001 From: Nerivec <62446222+Nerivec@users.noreply.github.com> Date: Wed, 30 Oct 2024 21:58:26 +0100 Subject: [PATCH] Improve subprocess run logging (#88) * Log SLC output. * Update from feedback. * Fix. * Update feedback. --- tools/build_project.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tools/build_project.py b/tools/build_project.py index 424919dd..64216933 100755 --- a/tools/build_project.py +++ b/tools/build_project.py @@ -168,6 +168,18 @@ def load_toolchains(paths: list[pathlib.Path]) -> dict[pathlib.Path, str]: return toolchains +def subprocess_run_verbose(command: list[str], prefix: str) -> None: + with subprocess.Popen( + command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT + ) as proc: + for line in proc.stdout: + LOGGER.info("[%s] %r", prefix, line.decode("utf-8").strip()) + + if proc.returncode != 0: + LOGGER.error("[%s] Error: %s", prefix, proc.returncode) + sys.exit(1) + + def main(): parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter @@ -387,10 +399,10 @@ def main(): f.write(result.stdout) # Next, generate a chip-specific project from the modified base project - print(f"Generating project for {manifest['device']}") + LOGGER.info(f"Generating project for {manifest['device']}") # fmt: off - subprocess.run( + subprocess_run_verbose( SLC + [ "generate", @@ -403,7 +415,7 @@ def main(): "--sdk", sdk, "--output-type", args.build_system, ], - check=True, + "slc generate" ) # fmt: on @@ -543,7 +555,7 @@ def main(): makefile.write_text(makefile_contents) # fmt: off - subprocess.run( + subprocess_run_verbose( [ "make", "-C", args.build_dir, @@ -553,7 +565,7 @@ def main(): f"POST_BUILD_EXE={args.postbuild}", "VERBOSE=1", ], - check=True, + "make" ) # fmt: on