Skip to content

Commit 0dc0099

Browse files
Improve logging for the yosys toolchain
1 parent 17428a7 commit 0dc0099

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

tools/yosys.bzl

+8
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,19 @@ def yosys_vhdl_synth(ctx):
7373
cmd.add(yosys_gen)
7474
cmd.add("--input", in_json_file)
7575
cmd.add("--output", yosys_py.as_output())
76+
7677

7778
ctx.actions.run(cmd, category="yosys_synth_gen")
7879

80+
yosys_synth_log = ctx.actions.declare_output("synth.log")
81+
yosys_ghdl_warns = ctx.actions.declare_output("ghdl_stderr.log")
7982
yosys_synth_cmd = cmd_args(hidden=[in_json_file, maps])
8083
yosys_synth_cmd.add(ctx.attrs._python[PythonToolchainInfo].interpreter)
8184
yosys_synth_cmd.add(yosys_py)
8285
yosys_synth_cmd.add("--output", yosys_json.as_output())
86+
yosys_synth_cmd.add("--log", yosys_synth_log.as_output())
87+
yosys_synth_cmd.add("--ghdl_stderr", yosys_ghdl_warns.as_output())
88+
8389

8490
ctx.actions.run(yosys_synth_cmd, category="yosys_run")
8591
providers.append(DefaultInfo(default_output=yosys_json))
@@ -92,13 +98,15 @@ def ice40_nextpnr(ctx, yoys_providers):
9298
yosys_json = yoys_providers[0].default_outputs[0]
9399

94100
asc = ctx.actions.declare_output("{}.asc".format(ctx.attrs.name))
101+
next_pnr_log = ctx.actions.declare_output("nextpnr.log")
95102
cmd = cmd_args()
96103
cmd.add(ctx.attrs._nextpnr_ice40[RunInfo])
97104
cmd.add(next_pnr_family_flags(ctx.attrs.family))
98105
cmd.add("--package", ctx.attrs.package)
99106
cmd.add("--pcf", ctx.attrs.pinmap)
100107
cmd.add("--json", yosys_json)
101108
cmd.add("--asc", asc.as_output())
109+
cmd.add("--log", next_pnr_log.as_output())
102110

103111
ctx.actions.run(cmd, category="next_pnr")
104112

tools/yosys_gen/templates/synth_py.jinja2

+17-3
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,40 @@
33
# Generated run.py from buck2
44
import subprocess
55
import argparse
6+
import sys
67

78
parser = argparse.ArgumentParser()
8-
parser.add_argument("--output", dest="output", help="Explicit output python")
9+
parser.add_argument("--output", dest="output", help="Explicit output yosys json")
10+
parser.add_argument("--log", dest="log", help="Explicit output yosys log")
11+
parser.add_argument("--ghdl_stderr", dest="ghdl_stderr", help="Explicit output ghdl stderr")
912

1013
args = parser.parse_args()
1114
files_str = (
1215
{% for source in project.sources %}
1316
{% set suffix = source.path.suffix %}
1417
{% if suffix in [".vhd"] %}
15-
"{{source.path.absolute().as_posix()}}"
18+
"{{source.path.absolute().as_posix()}} "
1619
{% endif %}
1720
{% endfor %}
1821
)
1922

2023
cmd = [
2124
"yosys",
25+
"-l",
26+
f"{args.log}",
2227
"-m",
2328
"ghdl",
2429
"-p",
2530
f'ghdl --std=08 {files_str} -e {{project.top_entity_name}}; {{project.synth_family}} -json {args.output}',
2631
]
2732

28-
a = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=False)
33+
#a = subprocess.run(cmd, stdout=subprocess.PIPE, check=False)
34+
yosys = subprocess.run(
35+
cmd,
36+
encoding="utf-8",
37+
check=True,
38+
capture_output=True)
39+
40+
with open(args.ghdl_stderr, "w") as f:
41+
f.write(yosys.stderr)
42+
sys.stderr.write(yosys.stderr)

0 commit comments

Comments
 (0)