Skip to content

Commit

Permalink
Update from feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerivec committed Oct 29, 2024
1 parent 1b3eed6 commit ab326a6
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions tools/build_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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"
Expand Down Expand Up @@ -536,7 +535,7 @@ def main():
makefile.write_text(makefile_contents)

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

Expand Down

0 comments on commit ab326a6

Please sign in to comment.