Skip to content

Commit

Permalink
Improve subprocess run logging (NabuCasa#88)
Browse files Browse the repository at this point in the history
* Log SLC output.

* Update from feedback.

* Fix.

* Update feedback.
  • Loading branch information
Nerivec authored and darkxst committed Nov 24, 2024
1 parent 3f8c126 commit 80e5e7a
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions tools/build_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -403,7 +415,7 @@ def main():
"--sdk", sdk,
"--output-type", args.build_system,
],
check=True,
"slc generate"
)
# fmt: on

Expand Down Expand Up @@ -543,7 +555,7 @@ def main():
makefile.write_text(makefile_contents)

# fmt: off
subprocess.run(
subprocess_run_verbose(
[
"make",
"-C", args.build_dir,
Expand All @@ -553,7 +565,7 @@ def main():
f"POST_BUILD_EXE={args.postbuild}",
"VERBOSE=1",
],
check=True,
"make"
)
# fmt: on

Expand Down

0 comments on commit 80e5e7a

Please sign in to comment.