Skip to content

Commit b98d44c

Browse files
hoe-jocastler
authored andcommitted
[rules score] add lobster rst report
1 parent 8b8b524 commit b98d44c

10 files changed

Lines changed: 1420 additions & 1 deletion

File tree

bazel/rules/rules_score/private/dependable_element.bzl

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,22 @@ def _dependable_element_index_impl(ctx):
790790
# Generate submodule links for the index page
791791
deps_links = _process_deps(ctx)
792792

793+
# The traceability report is generated into {label.name}/traceability_report/,
794+
# which is a sibling of index.rst inside the same {label.name}/ srcdir that
795+
# Sphinx uses (srcdir = parent of --index_file). The toctree therefore
796+
# references it as "traceability_report/index" with no "../" traversal.
797+
# A lightweight provider-presence check mirrors the condition in the lobster
798+
# block below; when no lobster inputs exist the substitution is empty so
799+
# Sphinx does not complain about a missing document.
800+
_has_feature_reqs = any([
801+
FeatureRequirementsInfo in r or AssumedSystemRequirementsInfo in r
802+
for r in ctx.attr.requirements
803+
])
804+
_has_comp_reqs = any([ComponentInfo in c for c in ctx.attr.components])
805+
traceability_report = (
806+
"traceability_report/index" if _has_feature_reqs and _has_comp_reqs else ""
807+
)
808+
793809
# Render the index.rst using the template
794810
title = ctx.attr.module_name
795811
underline = "=" * len(title)
@@ -808,6 +824,7 @@ def _dependable_element_index_impl(ctx):
808824
"{dependability_analysis}": "\n ".join(artifacts_by_type["dependability_analysis"]),
809825
"{checklists}": "\n ".join(artifacts_by_type["checklists"]),
810826
"{submodules}": deps_links,
827+
"{traceability_report}": traceability_report,
811828
},
812829
)
813830

@@ -980,6 +997,7 @@ def _dependable_element_index_impl(ctx):
980997

981998
lobster_report_file = None
982999
lobster_html_report = None
1000+
lobster_rst_dir = None
9831001
lobster_files = []
9841002
if feat_req_list and comp_req_list:
9851003
lobster_config = ctx.actions.declare_file(ctx.label.name + "/de_traceability_config")
@@ -1002,7 +1020,28 @@ def _dependable_element_index_impl(ctx):
10021020
lobster_report_file = subrule_lobster_report(all_lobster_inputs, lobster_config)
10031021
lobster_html_report = subrule_lobster_html_report(lobster_report_file)
10041022

1005-
lobster_files = [lobster_config, lobster_report_file, lobster_html_report]
1023+
# Generate multi-page RST report inside the index subdirectory so that
1024+
# Sphinx (which uses {label.name}/index.rst's parent as srcdir) can
1025+
# resolve the toctree entry "traceability_report/index" without ../.
1026+
lobster_rst_dir = ctx.actions.declare_directory(
1027+
ctx.label.name + "/traceability_report",
1028+
)
1029+
package = ctx.label.package
1030+
package_depth = len(package.split("/")) if package else 0
1031+
source_root = "/".join([".." for _ in range(package_depth + 2)]) + "/"
1032+
rst_args = ctx.actions.args()
1033+
rst_args.add(lobster_report_file.path)
1034+
rst_args.add_all(["--out-dir", lobster_rst_dir.path])
1035+
rst_args.add_all(["--source-root", source_root])
1036+
ctx.actions.run(
1037+
executable = ctx.executable._lobster_rst_report,
1038+
inputs = [lobster_report_file],
1039+
outputs = [lobster_rst_dir],
1040+
arguments = [rst_args],
1041+
progress_message = "lobster-rst-report (pages) {}".format(ctx.label.name),
1042+
)
1043+
1044+
lobster_files = [lobster_config, lobster_report_file, lobster_html_report, lobster_rst_dir]
10061045
output_files.extend(lobster_files)
10071046

10081047
return [
@@ -1016,6 +1055,7 @@ def _dependable_element_index_impl(ctx):
10161055
DependableElementLobsterInfo(
10171056
lobster_report = lobster_report_file,
10181057
lobster_html_report = lobster_html_report,
1058+
lobster_rst_dir = lobster_rst_dir,
10191059
),
10201060
OutputGroupInfo(debug = depset([validation_log])),
10211061
]
@@ -1093,6 +1133,12 @@ _dependable_element_index = rule(
10931133
allow_single_file = True,
10941134
doc = "Lobster config template for dependable element traceability.",
10951135
),
1136+
"_lobster_rst_report": attr.label(
1137+
default = Label("//tools/lobster_rst_report:lobster-rst-report"),
1138+
executable = True,
1139+
cfg = "exec",
1140+
doc = "Lobster RST report tool for generating the multi-page Sphinx traceability report.",
1141+
),
10961142
},
10971143
**VERBOSITY_ATTR
10981144
),

bazel/rules/rules_score/providers.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ DependableElementLobsterInfo = provider(
205205
fields = {
206206
"lobster_report": "The lobster report JSON File object, or None when no traceability data is available.",
207207
"lobster_html_report": "The lobster HTML report File object, or None when no traceability data is available.",
208+
"lobster_rst_dir": "The lobster multi-page RST report TreeArtifact (directory), or None when no traceability data is available.",
208209
},
209210
)
210211

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ Components
6161
{components}
6262

6363

64+
Traceability
65+
------------
66+
67+
.. toctree::
68+
:maxdepth: 1
69+
70+
{traceability_report}
71+
72+
6473
Checklists
6574
----------
6675

tools/lobster_rst_report/BUILD

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2026 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
14+
load("@rules_python//python:defs.bzl", "py_binary", "py_library")
15+
16+
py_library(
17+
name = "lobster_rst_report_lib",
18+
srcs = [
19+
"__init__.py",
20+
"_helpers.py",
21+
"_renderers.py",
22+
"graphviz_utils.py",
23+
"rst_report.py",
24+
],
25+
imports = [".."],
26+
deps = ["@lobster//lobster/common"],
27+
)
28+
29+
py_binary(
30+
name = "lobster-rst-report",
31+
srcs = ["lobster-rst-report.py"],
32+
visibility = ["//visibility:public"],
33+
deps = [":lobster_rst_report_lib"],
34+
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2026 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************

0 commit comments

Comments
 (0)