Skip to content

Commit 822e77f

Browse files
committed
assumptions_of_use: render TRLC sources to RST via trlc_rst
Instead of passing raw TRLC source files into SphinxSourcesInfo, run each source through the trlc_rst renderer (same tool used by requirements.bzl) to produce a proper .rst file for inclusion in the Sphinx documentation build.
1 parent a8f1eaa commit 822e77f

1 file changed

Lines changed: 31 additions & 4 deletions

File tree

bazel/rules/rules_score/private/assumptions_of_use.bzl

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,27 @@ def _assumptions_of_use_impl(ctx):
3939
Returns:
4040
List of providers including DefaultInfo and AssumptionsOfUseInfo
4141
"""
42-
srcs = depset(ctx.files.srcs)
42+
43+
# Render each TRLC source to RST for Sphinx
44+
rendered_files = []
45+
for src in ctx.attr.srcs:
46+
trlc_provider = src[TrlcProviderInfo]
47+
rendered_file = ctx.actions.declare_file("{}_{}.rst".format(ctx.attr.name, src.label.name))
48+
args = ctx.actions.args()
49+
args.add("--output", rendered_file.path)
50+
args.add("--input-dir", ".")
51+
args.add("--title", ctx.label.name.replace("_", " ").title())
52+
args.add("--source-files")
53+
args.add_all(trlc_provider.reqs)
54+
ctx.actions.run(
55+
inputs = src[DefaultInfo].files,
56+
outputs = [rendered_file],
57+
arguments = [args],
58+
executable = ctx.executable._renderer,
59+
)
60+
rendered_files.append(rendered_file)
61+
62+
all_srcs = depset(rendered_files)
4363

4464
# Collect requirements providers and lobster files
4565
reqs = []
@@ -55,20 +75,21 @@ def _assumptions_of_use_impl(ctx):
5575
lobster_files.append(info.srcs)
5676

5777
# Collect transitive sphinx sources from requirements
58-
transitive = [srcs]
78+
transitive = [all_srcs]
5979
for req in ctx.attr.requirements:
6080
if SphinxSourcesInfo in req:
6181
transitive.append(req[SphinxSourcesInfo].deps)
6282

6383
return [
64-
DefaultInfo(files = srcs),
84+
DefaultInfo(files = all_srcs),
6585
AssumptionsOfUseInfo(
6686
srcs = depset(transitive = lobster_files),
6787
name = ctx.label.name,
6888
),
6989
SphinxSourcesInfo(
70-
srcs = srcs,
90+
srcs = all_srcs,
7191
deps = depset(transitive = transitive),
92+
ancillary = depset(),
7293
),
7394
]
7495

@@ -90,6 +111,12 @@ _assumptions_of_use = rule(
90111
mandatory = False,
91112
doc = "List of feature or component requirements targets that these Assumptions of Use trace to",
92113
),
114+
"_renderer": attr.label(
115+
default = Label("@trlc//tools/trlc_rst:trlc_rst"),
116+
executable = True,
117+
allow_files = True,
118+
cfg = "exec",
119+
),
93120
},
94121
)
95122

0 commit comments

Comments
 (0)