Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace autogen DIF code by bazel rules #25775

Merged
merged 9 commits into from
Jan 16, 2025
4 changes: 0 additions & 4 deletions ci/scripts/check-generated.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ gen_and_check_clean \
"secded primitive code" \
util/design/secded_gen.py --no_fpv || bad=1

gen_and_check_clean \
"DIFs" \
util/make_new_dif.py --mode=regen --only=autogen || bad=1

gen_and_check_clean "MUBI package" util/design/gen-mubi.py || bad=1

gen_and_check_clean "HW block summary" util/gen_doc_hw_summary_table.py || bad=1
Expand Down
81 changes: 81 additions & 0 deletions rules/autogen.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,87 @@ opentitan_ip_rust_header = rule(
} | stamp_attr(-1, "//rules:stamp_flag"),
)

def _opentitan_autogen_dif_gen(ctx):
outputs = []
outdir = "{}/{}".format(ctx.bin_dir.path, ctx.label.package)
top = ctx.attr.top[OpenTitanTopInfo]

# Fail if the requested IP is not in the top
if ctx.attr.ip not in top.ip_hjson:
fail("Cannot generate DIF: top {} does not contain IP {}".format(top.name, ctx.attr.ip))
ip_hjson = top.ip_hjson[ctx.attr.ip]

groups = {}
for group, files in ctx.attr.output_groups.items():
deps = []
for file in files:
deps.append(ctx.actions.declare_file(file))
outputs.extend(deps)
groups[group] = depset(deps)

inputs = [ip_hjson]

arguments = [
"--ipcfg",
ip_hjson.path,
"--outdir",
outdir,
]

ctx.actions.run(
outputs = outputs,
inputs = inputs,
arguments = arguments,
executable = ctx.executable._autogen_dif,
)

return [
DefaultInfo(files = depset(outputs)),
OutputGroupInfo(**groups),
]

opentitan_autogen_dif_gen = rule(
implementation = _opentitan_autogen_dif_gen,
doc = "Generate the DIFs file for an IP",
attrs = {
"top": attr.label(mandatory = True, providers = [OpenTitanTopInfo], doc = "Opentitan top description"),
"ip": attr.string(mandatory = True, doc = "Name of the IP for which to generate the DIF"),
"output_groups": attr.string_list_dict(
allow_empty = True,
doc = """
Mappings from output group names to lists of paths contained in
that group.
""",
),
"_autogen_dif": attr.label(
default = "//util:autogen_dif",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nt: autogen_dif is a misnomer since there is nothing "auto" about invoking a tool to generate something. "gen_dif" is better, but I know "autogen" is unfortunately pervasive in our project.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tool is invoked by bazel which I guess is why it was called autogen to start with. But generally I agree that gen would be better.

executable = True,
cfg = "exec",
),
},
)

# See opentitan_autogen_dif_gen for documentation of parameters.
def opentitan_autogen_dif(name, top, ip, target_compatible_with = []):
opentitan_autogen_dif_gen(
name = "{}_gen".format(name),
top = top,
ip = ip,
output_groups = {
"hdr": ["dif_{}_autogen.h".format(ip)],
"src": ["dif_{}_autogen.c".format(ip)],
"unittest": ["dif_{}_autogen_unittest.cc".format(ip)],
},
target_compatible_with = target_compatible_with,
)

for grp in ["hdr", "src", "unittest"]:
native.filegroup(
name = "{}_{}".format(name, grp),
srcs = [":{}_gen".format(name)],
output_group = grp,
)

def _chip_info_src(ctx):
stamp_args = []
stamp_files = []
Expand Down
Loading
Loading