Skip to content

Commit 9088c76

Browse files
committed
[module api] Initial version
This commit introduces the initial implementation of the score_module Bazel rules for handling SEOOC (Safety Element Out Of Context) modules. Key additions: - Core rules in score_module.bzl and private/seooc.bzl - Test infrastructure with fixtures covering architecture design, assumptions of use, component requirements, and safety analysis
1 parent f484bc2 commit 9088c76

17 files changed

Lines changed: 1527 additions & 1 deletion

bazel/rules/score_module/BUILD

Whitespace-only changes.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2024 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+
# Configuration file for the Sphinx documentation builder.
15+
#
16+
# For the full list of built-in configuration values, see the documentation:
17+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
18+
19+
20+
# -- Project information -----------------------------------------------------
21+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
22+
23+
project = "SCORE MODULE API"
24+
project_url = "https://eclipse-score.github.io/module_template/"
25+
project_prefix = "MODULE_TEMPLATE_"
26+
author = "S-CORE"
27+
version = "0.1"
28+
29+
# -- General configuration ---------------------------------------------------
30+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
31+
32+
33+
extensions = [
34+
"sphinx_design",
35+
"sphinx_needs",
36+
"sphinxcontrib.plantuml",
37+
"score_plantuml",
38+
"score_metamodel",
39+
"score_draw_uml_funcs",
40+
"score_source_code_linker",
41+
"score_layout",
42+
]
43+
44+
exclude_patterns = [
45+
"bazel-*",
46+
".venv_docs",
47+
]
48+
49+
templates_path = ["templates"]
50+
51+
# Enable numref
52+
numfig = True
Lines changed: 333 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,333 @@
1+
SCORE Module Bazel Rules
2+
=========================
3+
4+
This directory contains Bazel rules for defining and building SCORE safety modules following ISO 26262 SEooC (Safety Element out of Context) standards.
5+
6+
.. contents:: Table of Contents
7+
:depth: 2
8+
:local:
9+
10+
11+
Overview
12+
--------
13+
14+
The ``score_module`` package provides Bazel build rules to structure,
15+
validate, and document safety-critical software modules. These rules
16+
integrate with Sphinx documentation generation to produce comprehensive
17+
safety documentation.
18+
19+
.. uml::
20+
21+
@startuml
22+
[SEooC] as SEooC
23+
[bazel module] as bzlmod
24+
Artifact "Assumptions of Use" as AoU
25+
Artifact "(Assumed) Component Requirements" as CR <<document>>
26+
Artifact "Architecture Design" as AD <<document>>
27+
Artifact "Safety Analysis" as SA <<document>>
28+
Card "Implementation" as Impl <<target>>
29+
Card "Testsuite" as Test <<target>>
30+
31+
32+
33+
bzlmod "1" *-- "*" SEooC : contains
34+
SEooC ..> SEooC : depends on
35+
SEooC "1" *-- "1" AoU : has
36+
SEooC "1" *-- "1" CR : has
37+
SEooC "1" *-- "1" AD : has
38+
SEooC "1" *-- "1" Impl : has
39+
SEooC "1" *-- "1" Test : has
40+
SEooC "1" *-- "1" SA : has
41+
42+
note right of bzlmod
43+
A score_module can contain
44+
one or more Safety Elements
45+
out of Context (SEooC)
46+
end note
47+
48+
@enduml
49+
50+
51+
52+
53+
54+
Rules and Macros
55+
----------------
56+
57+
safety_element_out_of_context
58+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
59+
60+
**File:** ``score_module.bzl``
61+
62+
**Purpose:** Main macro for defining a Safety Element out of Context
63+
(SEooC) module with integrated documentation generation following ISO 26262
64+
standards.
65+
66+
**Usage:**
67+
68+
.. code-block:: python
69+
70+
safety_element_out_of_context(
71+
name = "my_module",
72+
assumptions_of_use = ":assumptions",
73+
component_requirements = ":requirements",
74+
architectural_design = ":architecture",
75+
safety_analysis = ":safety_analysis",
76+
implementations = [":my_lib", ":my_component"],
77+
tests = [":my_lib_test", ":my_integration_test"],
78+
visibility = ["//visibility:public"]
79+
)
80+
81+
**Parameters:**
82+
83+
- ``name``: The name of the safety element module. Used as the base name
84+
for all generated targets.
85+
- ``assumptions_of_use``: Label to a ``.rst`` or ``.md`` file containing the
86+
Assumptions of Use, which define the safety-relevant operating conditions
87+
and constraints for the SEooC as required by ISO 26262-10 clause 5.4.4.
88+
- ``component_requirements``: Label to a ``.rst`` or ``.md`` file containing
89+
the component requirements specification, defining functional and safety
90+
requirements as required by ISO 26262-3 clause 7.
91+
- ``architectural_design``: Label to a ``.rst`` or ``.md`` file containing
92+
the architectural design specification, describing the software architecture
93+
and design decisions as required by ISO 26262-6 clause 7.
94+
- ``safety_analysis``: Label to a ``.rst`` or ``.md`` file containing the
95+
safety analysis, including FMEA, FMEDA, FTA, or other safety analysis
96+
results as required by ISO 26262-9 clause 8. Documents hazard analysis and
97+
safety measures.
98+
- ``implementations``: List of labels to Bazel targets representing the actual
99+
software implementation (cc_library, cc_binary, etc.) that realizes the
100+
component requirements. This is the source code that implements the safety
101+
functions as required by ISO 26262-6 clause 8.
102+
- ``tests``: List of labels to Bazel test targets (cc_test, py_test, etc.)
103+
that verify the implementation against requirements. Includes unit tests and
104+
integration tests as required by ISO 26262-6 clause 9 for software unit
105+
verification.
106+
- ``visibility``: Bazel visibility specification for the generated SEooC
107+
target. Controls which other packages can depend on this safety element.
108+
109+
**Generated Targets:**
110+
111+
This macro creates multiple targets automatically:
112+
113+
1. ``<name>_index``: Generates index.rst and conf.py files for the module
114+
documentation
115+
2. ``<name>_seooc_index_lib``: Sphinx documentation library for the
116+
generated index
117+
3. ``<name>``: The main SEooC target that aggregates all documentation
118+
4. ``<name>.html``: Convenience target to build HTML documentation
119+
120+
**Implementation Details:**
121+
122+
The macro orchestrates several internal rules to:
123+
124+
- Generate a documentation index with a structured table of contents
125+
- Organize documentation files under ``docs/safety_elements/<module_name>/``
126+
- Integrate assumptions of use and component requirements into a unified documentation structure
127+
- Provide Sphinx-compatible output for HTML generation
128+
129+
Private Rules
130+
-------------
131+
132+
seooc
133+
~~~~~
134+
135+
**File:** ``private/seooc.bzl``
136+
137+
**Purpose:** Internal rule that aggregates safety documentation artifacts
138+
into a Sphinx-compatible structure.
139+
140+
**Implementation:** ``_seooc_build_impl``
141+
142+
**Functionality:**
143+
144+
- Collects documentation from ``assumptions_of_use`` and
145+
``component_requirements`` dependencies
146+
- Reorganizes file paths to place artifacts under
147+
``docs/safety_elements/<module_name>/``
148+
- Merges the generated index with artifact documentation
149+
- Returns a ``SphinxDocsLibraryInfo`` provider for downstream consumption
150+
151+
**Attributes:**
152+
153+
- ``assumptions_of_use``: Label to assumptions of use documentation (mandatory)
154+
- ``component_requirements``: Label to component requirements documentation (mandatory)
155+
- ``index``: Label to the generated index file (mandatory)
156+
157+
**Output:**
158+
159+
Returns a ``SphinxDocsLibraryInfo`` provider containing:
160+
161+
- ``transitive``: Depset of documentation file structs with relocated paths
162+
- ``files``: Empty list (files are in transitive dependencies)
163+
164+
seooc_sphinx_environment
165+
~~~~~~~~~~~~~~~~~~~~~~~~
166+
167+
**File:** ``private/seooc_index.bzl``
168+
169+
**Purpose:** Generates the Sphinx environment files (index.rst and conf.py)
170+
for a safety module.
171+
172+
**Implementation:** ``_seooc_sphinx_environment_impl``
173+
174+
**Functionality:**
175+
176+
- Creates a module-specific ``index.rst`` with:
177+
178+
- Module name as header (uppercase with underline)
179+
- Table of contents (toctree) linking to all safety artifacts
180+
- References to assumptions of use and component requirements index files
181+
182+
- Generates a ``conf.py`` configuration file (currently placeholder content)
183+
184+
**Attributes:**
185+
186+
- ``module_name``: String name of the module (used for header generation)
187+
- ``assumptions_of_use``: Label to assumptions documentation
188+
- ``component_requirements``: Label to requirements documentation
189+
190+
**Generated Content Example:**
191+
192+
.. code-block:: rst
193+
194+
MY_MODULE
195+
=========
196+
197+
.. toctree::
198+
:maxdepth: 2
199+
:caption: Contents:
200+
201+
assumptions_of_use/index
202+
component_requirements/index
203+
architectural_design/index
204+
safety_analysis/index
205+
206+
**Output:**
207+
208+
Returns ``DefaultInfo`` with generated ``index.rst`` files.
209+
210+
Documentation Structure
211+
-----------------------
212+
213+
When using these rules, documentation is organized in the Bazel sandbox as
214+
follows::
215+
216+
docs/
217+
└── safety_elements/
218+
└── <module_name>/
219+
├── index.rst (generated)
220+
├── conf.py (generated)
221+
├── assumptions_of_use/
222+
│ └── (user-provided documentation)
223+
├── component_requirements/
224+
│ └── (user-provided documentation)
225+
├── architectural_design/
226+
│ └── (user-provided documentation)
227+
└── safety_analysis/
228+
└── (user-provided documentation)
229+
230+
bazel-bin/
231+
└── <module_name>/
232+
└── _sources/
233+
└── (generated documentation sources)
234+
235+
This structure reflects the file organization created in the Bazel sandbox
236+
during the documentation generation process. The generated ``index.rst`` file
237+
includes a table of contents that references all provided artifacts.
238+
239+
Integration with Sphinx
240+
------------------------
241+
242+
The rules generate ``SphinxDocsLibraryInfo`` providers that are compatible
243+
with ``@rules_python//sphinxdocs``. This enables:
244+
245+
- Automatic discovery of documentation files by Sphinx
246+
- Proper path relocation for modular documentation
247+
- Transitive dependency handling across multiple safety modules
248+
- HTML, PDF, and other Sphinx output formats
249+
250+
Usage Example
251+
-------------
252+
253+
Complete example in a BUILD file:
254+
255+
.. code-block:: python
256+
257+
load("@baselibs//bazel/score_module:score_module.bzl",
258+
"safety_element_out_of_context")
259+
260+
# Documentation artifacts
261+
sphinx_docs_library(
262+
name = "assumptions",
263+
srcs = ["docs/assumptions_of_use.rst"],
264+
)
265+
266+
sphinx_docs_library(
267+
name = "requirements",
268+
srcs = ["docs/component_requirements.rst"],
269+
)
270+
271+
sphinx_docs_library(
272+
name = "architecture",
273+
srcs = ["docs/architectural_design.rst"],
274+
)
275+
276+
sphinx_docs_library(
277+
name = "safety",
278+
srcs = ["docs/safety_analysis.rst"],
279+
)
280+
281+
# Implementation targets
282+
cc_library(
283+
name = "lifecycle_lib",
284+
srcs = ["lifecycle_manager.cpp"],
285+
hdrs = ["lifecycle_manager.h"],
286+
)
287+
288+
# Test targets
289+
cc_test(
290+
name = "lifecycle_test",
291+
srcs = ["lifecycle_manager_test.cpp"],
292+
deps = [":lifecycle_lib"],
293+
)
294+
295+
# Safety Element out of Context
296+
safety_element_out_of_context(
297+
name = "lifecycle_manager_seooc",
298+
assumptions_of_use = ":assumptions",
299+
component_requirements = ":requirements",
300+
architectural_design = ":architecture",
301+
safety_analysis = ":safety",
302+
implementations = [":lifecycle_lib"],
303+
tests = [":lifecycle_test"],
304+
visibility = ["//visibility:public"],
305+
)
306+
307+
Then build the documentation:
308+
309+
.. code-block:: bash
310+
311+
# Build the SEooC target
312+
bazel build //:lifecycle_manager_seooc
313+
314+
# Generate HTML documentation
315+
bazel build //:lifecycle_manager_seooc.html
316+
317+
Dependencies
318+
------------
319+
320+
- ``@rules_python//sphinxdocs``: Sphinx documentation build rules
321+
- ``SphinxDocsLibraryInfo``: Provider for documentation artifacts
322+
323+
Design Rationale
324+
----------------
325+
326+
These rules enforce a structured approach to safety documentation by:
327+
328+
1. **Standardization**: All safety modules follow the same documentation
329+
structure
330+
2. **Traceability**: Build system ensures all required artifacts are present
331+
3. **Modularity**: Documentation can be composed from multiple sources
332+
4. **Automation**: Index generation and path management are automated
333+
5. **Integration**: Seamless integration with existing Sphinx workflows

bazel/rules/score_module/private/BUILD

Whitespace-only changes.

0 commit comments

Comments
 (0)