1
0
Fork 0
mirror of https://git.sr.ht/~kivikakk/niar synced 2024-12-22 06:52:24 +00:00

Compare commits

...

2 commits

Author SHA1 Message Date
Asherah Connor 944321f5d9 cmdrunner: report exit statuses. 2024-09-27 17:44:19 +10:00
Asherah Connor 6a0c97d1f5 cxxrtl: less traceback. 2024-09-27 17:32:55 +10:00
2 changed files with 27 additions and 9 deletions

View file

@ -5,7 +5,7 @@ import subprocess
from .logging import logger
__all__ = ["CompilationUnit", "CommandRunner"]
__all__ = ["CompilationUnit", "CommandRunner", "CommandFailedError"]
class CompilationUnit:
@ -76,6 +76,8 @@ class CompilationUnit:
with open(inf, "rb") as f:
r[str(inf)] = f.read()
return r
class CommandRunner:
cus: list[CompilationUnit]
@ -121,14 +123,16 @@ class CommandRunner:
failed = []
for cu, proc in runnables:
if proc is not None and proc.wait() != 0:
failed.append(cu)
if proc is not None:
status = proc.wait()
if status != 0:
failed.append((cu, status))
if failed:
logger.error("the following process(es) failed:")
for cu in failed:
logger.error(f" {formatted(cu)}")
raise RuntimeError(f"failed {step} step")
for (cu, status) in failed:
logger.error(f" {formatted(cu)} (status={status})")
raise CommandFailedError(f"failed {step} step")
for cu, _ in runnables:
cu.mark_up_to_date()
@ -144,6 +148,10 @@ class CommandRunner:
logger.info(f"{action} {formatted(cu)}")
class CommandFailedError(RuntimeError):
pass
def formatted(cu):
if inspect.isfunction(cu.cmd):
return cu.cmd.__name__

View file

@ -12,7 +12,7 @@ from amaranth._toolchain.yosys import find_yosys
from amaranth.back import rtlil
from .build import construct_top
from .cmdrunner import CommandRunner
from .cmdrunner import CommandRunner, CommandFailedError
from .logging import logtime, logger
from .project import Project
@ -251,7 +251,11 @@ def main(np: Project, args):
infs=cc_o_paths + list(np.path("cxxrtl").glob("**/*.zig")),
outf=outf,
chdir="cxxrtl")
cr.run()
try:
cr.run()
except CommandFailedError:
logger.log(logging.INFO, "aborting on CommandFailedError")
return
shutil.copy(outf, exe_o_path)
else:
cmd = [
@ -266,7 +270,11 @@ def main(np: Project, args):
cr.add_process(cmd,
infs=cc_o_paths,
outf=exe_o_path)
cr.run()
try:
cr.run()
except CommandFailedError:
logger.log(logging.INFO, "aborting on CommandFailedError")
return
if not args.compile:
cmd = [exe_o_path]
@ -278,6 +286,8 @@ def main(np: Project, args):
except KeyboardInterrupt:
print(file=sys.stderr)
logger.log(logging.INFO, "aborting on KeyboardInterrupt")
except CommandFailedError:
logger.log(logging.INFO, "aborting on CommandFailedError")
def _make_yosys_relative(path):