Skip to content

Commit 6a0c97d

Browse files
committed
cxxrtl: less traceback.
1 parent 5623460 commit 6a0c97d

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

niar/cmdrunner.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from .logging import logger
77

8-
__all__ = ["CompilationUnit", "CommandRunner"]
8+
__all__ = ["CompilationUnit", "CommandRunner", "CommandFailedError"]
99

1010

1111
class CompilationUnit:
@@ -76,6 +76,8 @@ def process_infs(self):
7676
with open(inf, "rb") as f:
7777
r[str(inf)] = f.read()
7878
return r
79+
80+
7981
class CommandRunner:
8082
cus: list[CompilationUnit]
8183

@@ -128,7 +130,7 @@ def run_cus(self, cus, step):
128130
logger.error("the following process(es) failed:")
129131
for cu in failed:
130132
logger.error(f" {formatted(cu)}")
131-
raise RuntimeError(f"failed {step} step")
133+
raise CommandFailedError(f"failed {step} step")
132134

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

146148

149+
class CommandFailedError(RuntimeError):
150+
pass
151+
152+
147153
def formatted(cu):
148154
if inspect.isfunction(cu.cmd):
149155
return cu.cmd.__name__

niar/cxxrtl.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from amaranth.back import rtlil
1313

1414
from .build import construct_top
15-
from .cmdrunner import CommandRunner
15+
from .cmdrunner import CommandRunner, CommandFailedError
1616
from .logging import logtime, logger
1717
from .project import Project
1818

@@ -251,7 +251,11 @@ def rtlil_to_cc():
251251
infs=cc_o_paths + list(np.path("cxxrtl").glob("**/*.zig")),
252252
outf=outf,
253253
chdir="cxxrtl")
254-
cr.run()
254+
try:
255+
cr.run()
256+
except CommandFailedError:
257+
logger.log(logging.INFO, "aborting on CommandFailedError")
258+
return
255259
shutil.copy(outf, exe_o_path)
256260
else:
257261
cmd = [
@@ -266,7 +270,11 @@ def rtlil_to_cc():
266270
cr.add_process(cmd,
267271
infs=cc_o_paths,
268272
outf=exe_o_path)
269-
cr.run()
273+
try:
274+
cr.run()
275+
except CommandFailedError:
276+
logger.log(logging.INFO, "aborting on CommandFailedError")
277+
return
270278

271279
if not args.compile:
272280
cmd = [exe_o_path]

0 commit comments

Comments
 (0)