Skip to content

Commit

Permalink
cxxrtl: less traceback.
Browse files Browse the repository at this point in the history
  • Loading branch information
kivikakk committed Sep 27, 2024
1 parent 5623460 commit 6a0c97d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
10 changes: 8 additions & 2 deletions niar/cmdrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from .logging import logger

__all__ = ["CompilationUnit", "CommandRunner"]
__all__ = ["CompilationUnit", "CommandRunner", "CommandFailedError"]


class CompilationUnit:
Expand Down Expand Up @@ -76,6 +76,8 @@ def process_infs(self):
with open(inf, "rb") as f:
r[str(inf)] = f.read()
return r


class CommandRunner:
cus: list[CompilationUnit]

Expand Down Expand Up @@ -128,7 +130,7 @@ def run_cus(self, cus, step):
logger.error("the following process(es) failed:")
for cu in failed:
logger.error(f" {formatted(cu)}")
raise RuntimeError(f"failed {step} step")
raise CommandFailedError(f"failed {step} step")

for cu, _ in runnables:
cu.mark_up_to_date()
Expand All @@ -144,6 +146,10 @@ def report(self, cu, *, skip=False):
logger.info(f"{action} {formatted(cu)}")


class CommandFailedError(RuntimeError):
pass


def formatted(cu):
if inspect.isfunction(cu.cmd):
return cu.cmd.__name__
Expand Down
14 changes: 11 additions & 3 deletions niar/cxxrtl.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
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

Expand Down Expand Up @@ -251,7 +251,11 @@ def rtlil_to_cc():
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 = [
Expand All @@ -266,7 +270,11 @@ def rtlil_to_cc():
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]
Expand Down

0 comments on commit 6a0c97d

Please sign in to comment.