1414"""
1515Component Requirements build rules for S-CORE projects.
1616
17- This module provides macros and rules for defining component requirements
18- following S-CORE process guidelines. Component requirements are derived from
19- feature requirements and define the specific requirements for a software component.
17+ Component requirements are derived from feature requirements and define the
18+ specific requirements for a software component.
2019"""
2120
22- load ("//bazel/rules/rules_score:providers.bzl" , "ComponentRequirementsInfo" , "SphinxSourcesInfo" )
23-
24- # ComponentRequirementsInfo and FeatureRequirementsInfo are re-exported from providers.bzl for backward compatibility.
25-
26- # ============================================================================
27- # Private Rule Implementation
28- # ============================================================================
29-
30- def _component_requirements_impl (ctx ):
31- """Implementation for component_requirements rule.
32-
33- Collects component requirements source files and links them to their
34- parent feature requirements through providers.
35-
36- Args:
37- ctx: Rule context
38-
39- Returns:
40- List of providers including DefaultInfo and ComponentRequirementsInfo
41- """
42- srcs = depset (ctx .files .srcs )
43-
44- # Collect feature requirements providers
45- feature_reqs = []
46-
47- # Collect transitive sphinx sources from feature requirements
48- transitive = [srcs ]
49-
50- return [
51- DefaultInfo (files = srcs ),
52- ComponentRequirementsInfo (
53- srcs = srcs ,
54- name = ctx .label .name ,
55- ),
56- SphinxSourcesInfo (
57- srcs = srcs ,
58- deps = depset (transitive = transitive ),
59- ancillary = depset (),
60- ),
61- ]
62-
63- # ============================================================================
64- # Rule Definition
65- # ============================================================================
66-
67- _component_requirements = rule (
68- implementation = _component_requirements_impl ,
69- doc = "Collects component requirements documents with traceability to feature requirements" ,
70- attrs = {
71- "srcs" : attr .label_list (
72- allow_files = [".rst" , ".md" , ".trlc" ],
73- mandatory = True ,
74- doc = "Source files containing component requirements specifications" ,
75- ),
76- },
77- )
21+ load ("@trlc//:trlc.bzl" , "trlc_requirements_test" )
22+ load ("//bazel/rules/rules_score/private:requirements.bzl" , "score_requirements_rule" )
7823
7924# ============================================================================
8025# Public Macro
@@ -83,35 +28,58 @@ _component_requirements = rule(
8328def component_requirements (
8429 name ,
8530 srcs ,
31+ deps = [],
32+ spec = Label ("//bazel/rules/rules_score/trlc/config:score_requirements_model" ),
33+ ref_package = "" ,
8634 visibility = None ):
8735 """Define component requirements following S-CORE process guidelines.
8836
89- Component requirements are derived from feature requirements and define
90- the specific functional and safety requirements for a software component.
91- They establish traceability from high-level features to component-level
92- specifications.
37+ Creates a target providing ComponentRequirementsInfo, TrlcProviderInfo,
38+ and SphinxSourcesInfo, plus a validation test target ``<name>_test``.
39+
40+ Because this target emits TrlcProviderInfo, downstream targets can
41+ reference it directly in their ``deps`` without any intermediate
42+ trlc_requirements wrapper.
9343
9444 Args:
95- name: The name of the component requirements target. Used as the base
96- name for all generated targets.
97- srcs: List of labels to .rst, .md, or .trlc files containing the
98- component requirements specifications as defined in the S-CORE
99- process.
45+ name: The name of the target.
46+ srcs: List of .trlc source files containing CompReq records as defined
47+ in the S-CORE requirements model.
48+ deps: Optional list of requirement targets (e.g. assumed_system_requirements,
49+ feature_requirements) whose TRLC records are needed for cross-reference
50+ parsing. These targets must provide TrlcProviderInfo.
51+ spec: Optional TRLC specification target providing RSL type definitions.
52+ Defaults to the S-CORE requirements model
53+ (``@score_tooling//bazel/rules/rules_score/trlc/config:score_requirements_model``).
54+ Override this when using a custom requirements model.
10055 visibility: Bazel visibility specification for the generated targets.
10156
10257 Generated Targets:
103- <name>: Main component requirements target providing ComponentRequirementsInfo
58+ <name>: Main target providing ComponentRequirementsInfo, TrlcProviderInfo,
59+ and SphinxSourcesInfo.
60+ <name>_test: TRLC validation test (runs ``trlc --verify``).
10461
10562 Example:
10663 ```starlark
10764 component_requirements(
108- name = "my_component_requirements",
109- srcs = ["component_requirements.rst"],
65+ name = "comp_req",
66+ srcs = ["component_requirements.trlc"],
67+ deps = [":asr", ":feat_req"],
11068 )
11169 ```
11270 """
113- _component_requirements (
71+ score_requirements_rule (
11472 name = name ,
11573 srcs = srcs ,
74+ deps = deps ,
75+ req_kind = "component" ,
76+ lobster_config = Label ("//bazel/rules/rules_score/lobster/config:component_requirement" ),
77+ spec = spec ,
78+ ref_package = ref_package ,
79+ visibility = visibility ,
80+ )
81+ trlc_requirements_test (
82+ name = name + "_test" ,
83+ reqs = [":" + name ],
11684 visibility = visibility ,
11785 )
0 commit comments