@@ -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 ),
0 commit comments