Skip to content

Commit 335ac46

Browse files
committed
fmea: replace inline diagram embeds with per-diagram RST toctree pages
Instead of rendering all FTA diagrams inline with '.. uml::' in a single 'Root Causes' section, generate one RST wrapper page per preprocessed diagram using make_puml_rst_wrappers() and reference them via a toctree.
1 parent ace6510 commit 335ac46

2 files changed

Lines changed: 43 additions & 11 deletions

File tree

bazel/rules/rules_score/private/fmea.bzl

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ by the ``dependability_analysis`` rule which wraps this one.
4343

4444
load("@trlc//:trlc.bzl", "TrlcProviderInfo")
4545
load("//bazel/rules/rules_score:providers.bzl", "AnalysisInfo", "ArchitecturalDesignInfo", "SphinxSourcesInfo")
46+
load("//bazel/rules/rules_score/private:puml_utils.bzl", "make_puml_rst_wrappers")
4647
load("//bazel/rules/rules_score/private:verbosity.bzl", "VERBOSITY_ATTR", "get_log_level")
4748

4849
# ============================================================================
@@ -58,7 +59,7 @@ def _process_root_causes(ctx):
5859
``ctx.executable._safety_analysis_tools``.
5960
6061
Returns:
61-
Tuple ``(preprocessed_diagrams, [root_causes_lobster], rst_section_text)``.
62+
Tuple ``(preprocessed_diagrams, detail_rsts, [root_causes_lobster], rst_section_text)``.
6263
All lists are empty and the section text is ``""`` when there are no
6364
PlantUML root-cause inputs.
6465
"""
@@ -68,7 +69,7 @@ def _process_root_causes(ctx):
6869
if f.extension in ("puml", "plantuml")
6970
]
7071
if not puml_inputs:
71-
return [], [], ""
72+
return [], [], [], ""
7273

7374
# Declare one preprocessed output per input diagram (same directory).
7475
preprocessed_diagrams = [
@@ -95,13 +96,34 @@ def _process_root_causes(ctx):
9596
progress_message = "Processing root cause FTA diagrams for %s" % ctx.label.name,
9697
)
9798

98-
# Build the RST fragment that fmea.rst embeds.
99-
diagrams_rst = "\n\n".join(
100-
[".. uml:: " + diagram.basename for diagram in preprocessed_diagrams],
99+
# Generate one detail RST per preprocessed FTA diagram via the shared
100+
# puml_diagram template. The "fta_" prefix is stripped from the stem so
101+
# the page is titled e.g. "Server Not Listening" instead of
102+
# "Fta Server Not Listening".
103+
detail_rsts = make_puml_rst_wrappers(
104+
ctx,
105+
preprocessed_diagrams,
106+
ctx.label.name,
107+
ctx.file._puml_rst_template,
108+
strip_prefix = "fta_",
109+
filename_prefix = "detail_",
101110
)
102-
root_causes_rst_section = "Root Causes\n-----------\n\n{}".format(diagrams_rst)
103111

104-
return preprocessed_diagrams, [root_causes_lobster], root_causes_rst_section
112+
# Build toctree entries directly from the declared RST wrapper filenames so
113+
# the toctree is always consistent with what make_puml_rst_wrappers produces,
114+
# regardless of any prefix convention on the input files.
115+
toctree_entries = [
116+
" " + rst.basename[:-4] # strip ".rst"
117+
for rst in detail_rsts
118+
]
119+
120+
root_causes_rst_section = (
121+
"Root Cause Analysis\n-------------------\n\n" +
122+
".. toctree::\n :maxdepth: 1\n\n" +
123+
"\n".join(toctree_entries) + "\n"
124+
)
125+
126+
return preprocessed_diagrams, detail_rsts, [root_causes_lobster], root_causes_rst_section
105127

106128
# ============================================================================
107129
# Private Helpers
@@ -150,8 +172,9 @@ def _fmea_impl(ctx):
150172
# -------------------------------------------------------------------------
151173
# 0. Process root causes (FTA diagrams) if provided
152174
# -------------------------------------------------------------------------
153-
preprocessed_diagrams, root_cause_lobster_files, root_causes_rst_section = _process_root_causes(ctx)
175+
preprocessed_diagrams, detail_rsts, root_cause_lobster_files, root_causes_rst_section = _process_root_causes(ctx)
154176
output_files.extend(preprocessed_diagrams)
177+
output_files.extend(detail_rsts)
155178

156179
# -------------------------------------------------------------------------
157180
# 1. Render failure modes: TRLC -> .inc via trlc_rst
@@ -272,7 +295,10 @@ def _fmea_impl(ctx):
272295
for f in root_cause_lobster_files:
273296
lobster_files["root_causes.lobster"] = f
274297

275-
all_sphinx_srcs = depset(output_files)
298+
# detail_rsts are ancillary: they must be present next to fmea.rst for the
299+
# sub-toctree to resolve, but they are NOT top-level toctree entries.
300+
toctree_files = [f for f in output_files if f not in detail_rsts]
301+
all_sphinx_srcs = depset(toctree_files)
276302

277303
sphinx_deps = [all_sphinx_srcs]
278304
if ctx.attr.arch_design and SphinxSourcesInfo in ctx.attr.arch_design:
@@ -289,6 +315,7 @@ def _fmea_impl(ctx):
289315
SphinxSourcesInfo(
290316
srcs = all_sphinx_srcs,
291317
deps = depset(transitive = sphinx_deps),
318+
ancillary = depset(detail_rsts),
292319
),
293320
]
294321

@@ -364,6 +391,11 @@ _fmea = rule(
364391
allow_single_file = True,
365392
doc = "RST template for the FMEA page.",
366393
),
394+
"_puml_rst_template": attr.label(
395+
default = Label("//bazel/rules/rules_score:templates/puml_diagram.template.rst"),
396+
allow_single_file = True,
397+
doc = "RST template for PlantUML diagram wrapper pages.",
398+
),
367399
},
368400
**VERBOSITY_ATTR
369401
),

bazel/rules/rules_score/templates/fmea.template.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717

1818
{failure_modes_section}
1919

20-
{control_measures_section}
21-
2220
{root_causes_section}
21+
22+
{control_measures_section}

0 commit comments

Comments
 (0)