From 1b3eed61d0281778604705ebe3e28cfc4c4c8d6d Mon Sep 17 00:00:00 2001 From: Nerivec <62446222+Nerivec@users.noreply.github.com> Date: Tue, 29 Oct 2024 17:22:06 +0100 Subject: [PATCH 1/4] Log SLC output. --- tools/build_project.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/tools/build_project.py b/tools/build_project.py index ec8c865f..00dd5c7c 100755 --- a/tools/build_project.py +++ b/tools/build_project.py @@ -30,6 +30,11 @@ 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. @@ -371,10 +376,10 @@ def main(): yaml.dump(manifest["gbl"], f) # 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( + slc_result = subprocess.Popen( SLC + [ "generate", @@ -387,10 +392,20 @@ def main(): "--sdk", sdk, "--output-type", args.build_system, ], - check=True, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT ) # 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" 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 2/4] 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 From 5f26b02a0f3061474a4b37511e4cfd5a94daafba Mon Sep 17 00:00:00 2001 From: Nerivec <62446222+Nerivec@users.noreply.github.com> Date: Tue, 29 Oct 2024 18:01:43 +0100 Subject: [PATCH 3/4] Fix. --- tools/build_project.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/build_project.py b/tools/build_project.py index f7b5d60a..5bf81cbf 100755 --- a/tools/build_project.py +++ b/tools/build_project.py @@ -173,7 +173,7 @@ 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""): + for line in iter(result.stdout.readline, b""): LOGGER.info("[%s] %r", prefix, line.decode("utf-8").strip()) result_returncode = result.wait() From ca4089626e9434cf07a3fdf5de99934488bccd08 Mon Sep 17 00:00:00 2001 From: Nerivec <62446222+Nerivec@users.noreply.github.com> Date: Tue, 29 Oct 2024 18:09:49 +0100 Subject: [PATCH 4/4] Update feedback. --- tools/build_project.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tools/build_project.py b/tools/build_project.py index 5bf81cbf..385766c1 100755 --- a/tools/build_project.py +++ b/tools/build_project.py @@ -170,16 +170,14 @@ def load_toolchains(paths: list[pathlib.Path]) -> dict[pathlib.Path, str]: 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.readline, b""): + 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()) - result_returncode = result.wait() - - if result_returncode != 0: - LOGGER.error("[%s] Error: %s", prefix, result_returncode) + if proc.returncode != 0: + LOGGER.error("[%s] Error: %s", prefix, proc.returncode) sys.exit(1)