From ab326a688cde225a5534025b6dff7f3238cf62f2 Mon Sep 17 00:00:00 2001 From: Nerivec <62446222+Nerivec@users.noreply.github.com> Date: Tue, 29 Oct 2024 17:57:51 +0100 Subject: [PATCH] Update from feedback. --- tools/build_project.py | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/tools/build_project.py b/tools/build_project.py index 00dd5c7c..f7b5d60a 100755 --- a/tools/build_project.py +++ b/tools/build_project.py @@ -30,11 +30,6 @@ yaml = YAML(typ="safe") -def log_subprocess_output(pipe, prefix: str = "subprocess"): - for line in iter(pipe.readline, b""): - LOGGER.info("[%s] %r", prefix, line) - - def evaulate_f_string(f_string: str, variables: dict[str, typing.Any]) -> str: """ Evaluates an `f`-string with the given locals. @@ -174,6 +169,20 @@ def load_toolchains(paths: list[pathlib.Path]) -> dict[pathlib.Path, str]: return toolchains +def subprocess_run_verbose(command: list[str], prefix: str) -> None: + result = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + + with result.stdout: + for line in iter(result.stdout, b""): + LOGGER.info("[%s] %r", prefix, line.decode("utf-8").strip()) + + result_returncode = result.wait() + + if result_returncode != 0: + LOGGER.error("[%s] Error: %s", prefix, result_returncode) + sys.exit(1) + + def main(): parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter @@ -379,7 +388,7 @@ def main(): LOGGER.info(f"Generating project for {manifest['device']}") # fmt: off - slc_result = subprocess.Popen( + subprocess_run_verbose( SLC + [ "generate", @@ -392,20 +401,10 @@ def main(): "--sdk", sdk, "--output-type", args.build_system, ], - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT + "slc generate" ) # fmt: on - with slc_result.stdout: - log_subprocess_output(slc_result.stdout, "SLC generate") - - slc_result_returncode = slc_result.wait() - - if slc_result_returncode != 0: - LOGGER.error("[SLC generate] Error: %s", slc_result_returncode) - sys.exit(1) - # Make sure all extensions are valid for sdk_extension in base_project.get("sdk_extension", []): expected_dir = sdk / f"extension/{sdk_extension['id']}_extension" @@ -536,7 +535,7 @@ def main(): makefile.write_text(makefile_contents) # fmt: off - subprocess.run( + subprocess_run_verbose( [ "make", "-C", args.build_dir, @@ -546,7 +545,7 @@ def main(): f"POST_BUILD_EXE={args.postbuild}", "VERBOSE=1", ], - check=True, + "make" ) # fmt: on