Skip to content

Commit 7bd475a

Browse files
committed
[rules score] clean up deps in sphinx build
1 parent 5212cef commit 7bd475a

10 files changed

Lines changed: 31 additions & 44 deletions

bazel/rules/rules_score/private/architectural_design.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ def _architectural_design_impl(ctx):
174174
SphinxSourcesInfo(
175175
srcs = sphinx_srcs,
176176
deps = sphinx_srcs,
177-
ancillary = depset(),
178177
),
179178
]
180179

bazel/rules/rules_score/private/assumptions_of_use.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ def _assumptions_of_use_impl(ctx):
8989
SphinxSourcesInfo(
9090
srcs = all_srcs,
9191
deps = depset(transitive = transitive),
92-
ancillary = depset(),
9392
),
9493
]
9594

bazel/rules/rules_score/private/component.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ def _component_impl(ctx):
207207
SphinxSourcesInfo(
208208
srcs = req_sphinx_depset,
209209
deps = sphinx_depset,
210-
ancillary = depset(),
211210
),
212211
]
213212

bazel/rules/rules_score/private/dependability_analysis.bzl

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,21 @@ load("//bazel/rules/rules_score/private:lobster_config.bzl", "format_lobster_sou
3030
# Private Helpers
3131
# ============================================================================
3232

33-
def _collect_analysis_providers(sa, rst_srcs_list, rst_deps_list, rst_ancillary_list, lobster_files):
33+
def _collect_analysis_providers(sa, rst_srcs_list, rst_deps_list, lobster_files):
3434
"""Collect analysis providers from a single sub-analysis target.
3535
3636
Updates the provided lists/dicts in-place.
3737
3838
Args:
39-
sa: A sub-analysis target (fmea or security).
40-
rst_srcs_list: List of depsets to extend with SphinxSourcesInfo.srcs.
41-
rst_deps_list: List of depsets to extend with SphinxSourcesInfo.deps.
42-
rst_ancillary_list: List of depsets to extend with SphinxSourcesInfo.ancillary.
43-
lobster_files: Dict to update with AnalysisInfo.lobster_files
44-
(canonical name → File).
39+
sa: A sub-analysis target (fmea or security).
40+
rst_srcs_list: List of depsets to extend with SphinxSourcesInfo.srcs.
41+
rst_deps_list: List of depsets to extend with SphinxSourcesInfo.deps.
42+
lobster_files: Dict to update with AnalysisInfo.lobster_files
43+
(canonical name → File).
4544
"""
4645
if SphinxSourcesInfo in sa:
4746
rst_srcs_list.append(sa[SphinxSourcesInfo].srcs)
4847
rst_deps_list.append(sa[SphinxSourcesInfo].deps)
49-
rst_ancillary_list.append(sa[SphinxSourcesInfo].ancillary)
5048
if AnalysisInfo in sa:
5149
lobster_files.update(sa[AnalysisInfo].lobster_files)
5250

@@ -76,7 +74,6 @@ def _dependability_analysis_impl(ctx):
7674

7775
rst_srcs_transitive = [dfa_rst_files]
7876
rst_deps_transitive = [dfa_rst_files]
79-
rst_ancillary_transitive = []
8077
lobster_files = {} # canonical name → File, merged from all sub-analyses
8178

8279
# -------------------------------------------------------------------------
@@ -85,15 +82,15 @@ def _dependability_analysis_impl(ctx):
8582
fmea_output_files = []
8683
for sa in ctx.attr.fmea:
8784
fmea_output_files.append(sa[DefaultInfo].files)
88-
_collect_analysis_providers(sa, rst_srcs_transitive, rst_deps_transitive, rst_ancillary_transitive, lobster_files)
85+
_collect_analysis_providers(sa, rst_srcs_transitive, rst_deps_transitive, lobster_files)
8986

9087
# -------------------------------------------------------------------------
9188
# Collect from security_analysis targets
9289
# -------------------------------------------------------------------------
9390
security_output_files = []
9491
for sa in ctx.attr.security_analysis:
9592
security_output_files.append(sa[DefaultInfo].files)
96-
_collect_analysis_providers(sa, rst_srcs_transitive, rst_deps_transitive, rst_ancillary_transitive, lobster_files)
93+
_collect_analysis_providers(sa, rst_srcs_transitive, rst_deps_transitive, lobster_files)
9794

9895
# Architectural design sphinx deps (optional)
9996
if ctx.attr.arch_design and SphinxSourcesInfo in ctx.attr.arch_design:
@@ -185,7 +182,6 @@ def _dependability_analysis_impl(ctx):
185182
SphinxSourcesInfo(
186183
srcs = all_rst_srcs,
187184
deps = all_rst_deps,
188-
ancillary = depset(transitive = rst_ancillary_transitive),
189185
),
190186
]
191187

bazel/rules/rules_score/private/dependable_element.bzl

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ _INTEGRITY_LEVEL_RANK = {level: rank for rank, level in enumerate(_INTEGRITY_LEV
121121
# ============================================================================
122122

123123
def _get_sphinx_files(target):
124-
return target[SphinxSourcesInfo].srcs.to_list()
124+
return target[SphinxSourcesInfo].deps.to_list()
125125

126126
def _filter_doc_files(files):
127127
"""Filter files to only include documentation files.
@@ -249,13 +249,17 @@ def _process_artifact_files(ctx, artifact_name, label):
249249
output_files = []
250250
index_refs = []
251251

252-
# Get and filter files
252+
# deps contains all files to symlink (own srcs + transitive children);
253+
# srcs are the toctree entries for this rule only.
253254
all_files = _get_sphinx_files(label)
254255
doc_files = _filter_doc_files(all_files)
255256

256257
if not doc_files:
257258
return (output_files, index_refs)
258259

260+
# Build a lookup of srcs paths so we know which files are toctree entries.
261+
srcs_paths = {f.path: True for f in label[SphinxSourcesInfo].srcs.to_list()}
262+
259263
# Find common directory to preserve hierarchy
260264
common_dir = _find_common_directory(doc_files)
261265

@@ -273,28 +277,13 @@ def _process_artifact_files(ctx, artifact_name, label):
273277
)
274278
output_files.append(output_file)
275279

276-
# Add to index if it's a document file
277-
if _is_document_file(artifact_file):
280+
# Add to toctree index only for files directly owned by this rule.
281+
if _is_document_file(artifact_file) and artifact_file.path in srcs_paths:
278282
doc_ref = (artifact_name + "/" + relative_path) \
279283
.replace(".rst", "") \
280284
.replace(".md", "")
281285
index_refs.append(doc_ref)
282286

283-
# Symlink ancillary files (present for sub-toctrees / .. uml:: resolution,
284-
# but NOT added to the outer toctree index).
285-
if SphinxSourcesInfo in label:
286-
for anc_file in label[SphinxSourcesInfo].ancillary.to_list():
287-
if anc_file.extension not in ["rst", "md", "puml", "plantuml", "png", "svg", "inc", "json"]:
288-
continue
289-
relative_path = _compute_relative_path(anc_file, _find_common_directory([anc_file]))
290-
output_file = _create_artifact_symlink(
291-
ctx,
292-
artifact_name,
293-
anc_file,
294-
relative_path,
295-
)
296-
output_files.append(output_file)
297-
298287
return (output_files, index_refs)
299288

300289
def _process_artifact_type(ctx, artifact_name):

bazel/rules/rules_score/private/fmea.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,13 @@ def _fmea_impl(ctx):
281281
for f in root_cause_lobster_files:
282282
lobster_files["root_causes.lobster"] = f
283283

284-
# detail_rsts are ancillary: they must be present next to fmea.rst for the
285-
# sub-toctree to resolve, but they are NOT top-level toctree entries.
284+
# detail_rsts are NOT top-level toctree entries (they live in sub-toctrees
285+
# within fmea.rst), but they must be present in the Sphinx tree. They go
286+
# into deps so dependable_element symlinks them alongside toctree files.
286287
toctree_files = [f for f in output_files if f not in detail_rsts]
287288
all_sphinx_srcs = depset(toctree_files)
288289

289-
sphinx_deps = [all_sphinx_srcs]
290+
sphinx_deps = [all_sphinx_srcs, depset(detail_rsts)]
290291
if ctx.attr.arch_design and SphinxSourcesInfo in ctx.attr.arch_design:
291292
sphinx_deps.append(ctx.attr.arch_design[SphinxSourcesInfo].deps)
292293

@@ -301,7 +302,6 @@ def _fmea_impl(ctx):
301302
SphinxSourcesInfo(
302303
srcs = all_sphinx_srcs,
303304
deps = depset(transitive = sphinx_deps),
304-
ancillary = depset(detail_rsts),
305305
),
306306
]
307307

bazel/rules/rules_score/private/requirements.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ def _requirements_impl(ctx):
123123
SphinxSourcesInfo(
124124
srcs = sphinx_srcs,
125125
deps = depset(transitive = transitive_sphinx),
126-
ancillary = depset(),
127126
),
128127
]
129128

bazel/rules/rules_score/private/unit.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ def _unit_impl(ctx):
9696
SphinxSourcesInfo(
9797
srcs = all_files,
9898
deps = depset(transitive = [all_files] + sphinx_design_deps),
99-
ancillary = depset(),
10099
),
101100
]
102101

bazel/rules/rules_score/private/unit_design.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ def _unit_design_impl(ctx):
9595
SphinxSourcesInfo(
9696
srcs = all_source_files,
9797
deps = all_source_files,
98-
ancillary = depset(),
9998
),
10099
]
101100

bazel/rules/rules_score/providers.bzl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,19 @@ SphinxSourcesInfo = provider(
4949
builds, including reStructuredText, Markdown, PlantUML diagrams, and
5050
image files. Rules that produce documentation artifacts should provide
5151
this to enable integration with sphinx_module and dependable_element.
52+
53+
Semantics:
54+
srcs — Files directly owned/generated by this rule. Only these are
55+
used as top-level toctree entries by dependable_element.
56+
For leaf rules (no children), srcs == deps.
57+
deps — All files needed in the Sphinx tree: own srcs plus all
58+
transitive files from children. dependable_element symlinks
59+
everything in deps into the output tree. Parent/container
60+
rules bubble up children's deps into their own deps field.
5261
""",
5362
fields = {
54-
"srcs": "Depset of direct source files for Sphinx documentation (.rst, .md, .puml, .plantuml, .svg, .png, etc.)",
55-
"deps": "Depset of transitive Sphinx source files collected from all direct and transitive dependencies.",
56-
"ancillary": "Depset of files that must be physically present in the Sphinx tree (e.g. for sub-toctrees or .. uml:: directives) but are NOT top-level toctree entries.",
63+
"srcs": "Depset of files directly owned by this rule (.rst, .md, .puml, etc.). Used by dependable_element as toctree entries.",
64+
"deps": "Depset of all files needed in the Sphinx tree — own srcs plus transitive deps from all children. For leaf rules, equals srcs.",
5765
},
5866
)
5967

0 commit comments

Comments
 (0)