Skip to content

Commit e3b4f65

Browse files
authored
[module api] Initial version (#95)
* [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 * [Module API] Introduce build per module Incorporated first feedback. Introduced a modular sphinx-build. * Fix integration tests * Added artefact specific rules * Add functionality to filter sphinx output * switched from print to logger * Add fmea as attribute for dependability * Bugfix for relative references * Fixed formating issues * Add links to submodule to index * refactoring acc. to naming convention. Parameter renaming * Renamed to rules_score * Updated documentation * Removed backward compatible parameter * Remove feature_requirements from ComponentRequirementsInfo
1 parent fe54d6a commit e3b4f65

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+5693
-6
lines changed

.bazelrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
common --registry=https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/
22
common --registry=https://bcr.bazel.build
3+
4+
build --java_language_version=17
5+
build --tool_java_language_version=17
6+
build --java_runtime_version=remotejdk_17
7+
build --tool_java_runtime_version=remotejdk_17

MODULE.bazel

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ bazel_dep(name = "rules_java", version = "8.15.1")
2828
bazel_dep(name = "rules_rust", version = "0.61.0")
2929
bazel_dep(name = "rules_multitool", version = "1.9.0")
3030
bazel_dep(name = "score_rust_policies", version = "0.0.2")
31-
32-
bazel_dep(name = "bazel_skylib", version = "1.7.1", dev_dependency = True)
33-
31+
bazel_dep(name = "bazel_skylib", version = "1.7.1")
3432
bazel_dep(name = "buildifier_prebuilt", version = "8.2.0.2")
3533

3634
###############################################################################
@@ -95,3 +93,13 @@ multitool.hub(
9593
lockfile = "tools/yamlfmt.lock.json",
9694
)
9795
use_repo(multitool, "yamlfmt_hub")
96+
97+
bazel_dep(name = "score_docs_as_code", version = "2.2.0")
98+
git_override(
99+
module_name = "score_docs_as_code",
100+
commit = "718388bd5e0f10debd97a131d238ad4d758ddd1e",
101+
remote = "https://github.com/eclipse-score/docs-as-code.git",
102+
)
103+
104+
bazel_dep(name = "score_platform", version = "0.5.0")
105+
bazel_dep(name = "score_process", version = "1.3.2")

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,15 @@ bazel run //:rust_coverage -- --min-line-coverage 80
5858

5959
## Upgrading from separate MODULES
6060

61-
If you are still using separate module imports and want to upgrade to the new version.
61+
If you are still using separate module imports and want to upgrade to the new version.
6262
Here are two examples to showcase how to do this.
6363

6464
```
6565
load("@score_python_basics//:defs.bzl", "score_py_pytest") => load("@score_tooling//:defs.bzl", "score_py_pytest")
6666
load("@score_cr_checker//:cr_checker.bzl", "copyright_checker") => load("@score_tooling//:defs.bzl", "copyright_checker")
6767
```
68-
All things inside of 'tooling' can now be imported from `@score_tooling//:defs.bzl`.
68+
69+
All things inside of 'tooling' can now be imported from `@score_tooling//:defs.bzl`.
6970
The available import targets are:
7071

7172
- score_virtualenv
@@ -78,6 +79,7 @@ The available import targets are:
7879
- rust_coverage_report
7980

8081
## Format the tooling repository
81-
```bash
82+
83+
```bash
8284
bazel run //:format.fix
8385
```

bazel/rules/rules_score/BUILD

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
load(
2+
"//bazel/rules/rules_score:rules_score.bzl",
3+
"sphinx_module",
4+
)
5+
6+
exports_files([
7+
"templates/conf.template.py",
8+
"templates/seooc_index.template.rst",
9+
])
10+
11+
# HTML merge tool
12+
py_binary(
13+
name = "sphinx_html_merge",
14+
srcs = ["src/sphinx_html_merge.py"],
15+
main = "src/sphinx_html_merge.py",
16+
visibility = ["//visibility:public"],
17+
)
18+
19+
# Sphinx build binary with all required dependencies
20+
py_binary(
21+
name = "score_build",
22+
srcs = ["src/sphinx_wrapper.py"],
23+
data = [],
24+
env = {
25+
"SOURCE_DIRECTORY": "",
26+
"DATA": "",
27+
"ACTION": "check",
28+
},
29+
main = "src/sphinx_wrapper.py",
30+
visibility = ["//visibility:public"],
31+
deps = [
32+
"@score_docs_as_code//src:plantuml_for_python",
33+
"@score_docs_as_code//src/extensions/score_sphinx_bundle",
34+
],
35+
)
36+
37+
sphinx_module(
38+
name = "rules_score_doc",
39+
srcs = glob(
40+
[
41+
"docs/**/*.rst",
42+
"docs/**/*.puml",
43+
],
44+
allow_empty = True,
45+
),
46+
index = "docs/index.rst",
47+
visibility = ["//visibility:public"],
48+
deps = [
49+
"@score_process//:score_process_module",
50+
],
51+
)
Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
SCORE Rules for Bazel
2+
=====================
3+
4+
This package provides Bazel build rules for defining and building SCORE documentation modules with integrated Sphinx-based HTML generation.
5+
6+
.. contents:: Table of Contents
7+
:depth: 2
8+
:local:
9+
10+
11+
Overview
12+
--------
13+
14+
The ``rules_score`` package provides Bazel rules for structuring and documenting safety-critical software following S-CORE process guidelines:
15+
16+
**Documentation Rule:**
17+
18+
- ``sphinx_module``: Generic rule for building Sphinx HTML documentation with dependency support
19+
20+
**Artifact Rules:**
21+
22+
- ``feature_requirements``: High-level feature specifications
23+
- ``component_requirements``: Component-level requirements
24+
- ``assumptions_of_use``: Safety-relevant operating conditions
25+
- ``architectural_design``: Software architecture documentation
26+
- ``safety_analysis``: Detailed safety analysis (FMEA, FTA)
27+
- ``dependability_analysis``: Comprehensive safety analysis results
28+
29+
**Structural Rules:**
30+
31+
- ``unit``: Smallest testable software element (design + implementation + tests)
32+
- ``component``: Collection of units providing specific functionality
33+
- ``dependable_element``: Complete Safety Element out of Context (SEooC) with full documentation
34+
35+
All rules support cross-module dependencies for automatic sphinx-needs integration and HTML merging.
36+
37+
38+
sphinx_module
39+
-------------
40+
41+
Builds Sphinx-based HTML documentation from RST source files with support for dependencies and cross-referencing.
42+
43+
.. code-block:: python
44+
45+
sphinx_module(
46+
name = "my_docs",
47+
srcs = glob(["docs/**/*.rst"]),
48+
index = "docs/index.rst",
49+
deps = ["@external_module//:docs"],
50+
)
51+
52+
**Key Parameters:**
53+
54+
- ``srcs``: RST/MD source files
55+
- ``index``: Main index.rst file
56+
- ``deps``: Other sphinx_module or dependable_element targets for cross-referencing
57+
- ``sphinx``: Sphinx build binary (default: ``//bazel/rules/rules_score:score_build``)
58+
59+
**Output:** ``<name>/html/`` with merged dependency documentation
60+
61+
62+
Artifact Rules
63+
--------------
64+
65+
Artifact rules define S-CORE process work products. All provide ``SphinxSourcesInfo`` for documentation generation.
66+
67+
**feature_requirements**
68+
69+
.. code-block:: python
70+
71+
feature_requirements(
72+
name = "features",
73+
srcs = ["docs/features.rst"],
74+
)
75+
76+
**component_requirements**
77+
78+
.. code-block:: python
79+
80+
component_requirements(
81+
name = "requirements",
82+
srcs = ["docs/requirements.rst"],
83+
feature_requirement = [":features"],
84+
)
85+
86+
**assumptions_of_use**
87+
88+
.. code-block:: python
89+
90+
assumptions_of_use(
91+
name = "aous",
92+
srcs = ["docs/assumptions.rst"],
93+
)
94+
95+
**architectural_design**
96+
97+
.. code-block:: python
98+
99+
architectural_design(
100+
name = "architecture",
101+
static = ["docs/static_arch.rst"],
102+
dynamic = ["docs/dynamic_arch.rst"],
103+
)
104+
105+
**safety_analysis**
106+
107+
.. code-block:: python
108+
109+
safety_analysis(
110+
name = "safety",
111+
controlmeasures = ["docs/controls.rst"],
112+
failuremodes = ["docs/failures.rst"],
113+
fta = ["docs/fta.rst"],
114+
arch_design = ":architecture",
115+
)
116+
117+
**dependability_analysis**
118+
119+
.. code-block:: python
120+
121+
dependability_analysis(
122+
name = "analysis",
123+
arch_design = ":architecture",
124+
dfa = ["docs/dfa.rst"],
125+
safety_analysis = [":safety"],
126+
)
127+
128+
129+
Structural Rules
130+
----------------
131+
132+
**unit**
133+
134+
Define the smallest testable software element.
135+
136+
.. code-block:: python
137+
138+
unit(
139+
name = "my_unit",
140+
unit_design = [":architecture"],
141+
implementation = ["//src:lib"],
142+
tests = ["//tests:unit_test"],
143+
)
144+
145+
**component**
146+
147+
Define a collection of units.
148+
149+
.. code-block:: python
150+
151+
component(
152+
name = "my_component",
153+
component_requirements = [":requirements"],
154+
units = [":my_unit"],
155+
implementation = ["//src:binary"],
156+
tests = ["//tests:integration_test"],
157+
)
158+
159+
**dependable_element**
160+
161+
Define a complete SEooC with automatic documentation generation.
162+
163+
.. code-block:: python
164+
165+
dependable_element(
166+
name = "my_seooc",
167+
description = "My safety-critical component",
168+
assumptions_of_use = [":aous"],
169+
requirements = [":requirements"],
170+
architectural_design = [":architecture"],
171+
dependability_analysis = [":analysis"],
172+
components = [":my_component"],
173+
tests = ["//tests:system_test"],
174+
deps = ["@platform//:platform_module"],
175+
)
176+
177+
**Generated Targets:**
178+
179+
- ``<name>``: Sphinx module with HTML documentation
180+
- ``<name>_needs``: Sphinx-needs JSON for cross-referencing
181+
- ``<name>_index``: Generated index.rst with artifact structure
182+
183+
184+
Dependency Management
185+
---------------------
186+
187+
Use ``deps`` for cross-module references. HTML is automatically merged:
188+
189+
.. code-block:: text
190+
191+
<name>/html/
192+
├── index.html # Main documentation
193+
├── _static/
194+
├── dependency1/ # Merged dependency
195+
└── dependency2/
196+
197+
198+
Complete Example
199+
----------------
200+
201+
.. code-block:: python
202+
203+
load("//bazel/rules/rules_score:rules_score.bzl",
204+
"architectural_design", "assumptions_of_use",
205+
"component", "component_requirements",
206+
"dependability_analysis", "dependable_element",
207+
"feature_requirements", "safety_analysis", "unit")
208+
209+
# Artifacts
210+
feature_requirements(name = "features", srcs = ["docs/features.rst"])
211+
component_requirements(name = "reqs", srcs = ["docs/reqs.rst"],
212+
feature_requirement = [":features"])
213+
assumptions_of_use(name = "aous", srcs = ["docs/aous.rst"])
214+
architectural_design(name = "arch", static = ["docs/arch.rst"],
215+
dynamic = ["docs/dynamic.rst"])
216+
safety_analysis(name = "safety", arch_design = ":arch")
217+
dependability_analysis(name = "analysis", arch_design = ":arch",
218+
dfa = ["docs/dfa.rst"],
219+
safety_analysis = [":safety"])
220+
221+
# Implementation
222+
cc_library(name = "kvs_lib", srcs = ["kvs.cpp"], hdrs = ["kvs.h"])
223+
cc_test(name = "kvs_test", srcs = ["kvs_test.cpp"], deps = [":kvs_lib"])
224+
225+
# Structure
226+
unit(name = "kvs_unit", unit_design = [":arch"],
227+
implementation = [":kvs_lib"], tests = [":kvs_test"])
228+
component(name = "kvs_component", requirements = [":reqs"],
229+
units = [":kvs_unit"], implementation = [":kvs_lib"], tests = [])
230+
231+
# SEooC
232+
dependable_element(
233+
name = "persistency_kvs",
234+
description = "Key-Value Store for persistent data storage",
235+
assumptions_of_use = [":aous"],
236+
requirements = [":reqs"],
237+
architectural_design = [":arch"],
238+
dependability_analysis = [":analysis"],
239+
components = [":kvs_component"],
240+
tests = [],
241+
deps = ["@score_process//:score_process_module"],
242+
)
243+
244+
Build:
245+
246+
.. code-block:: bash
247+
248+
bazel build //:persistency_kvs
249+
# Output: bazel-bin/persistency_kvs/html/
250+
251+
Reference Implementation
252+
------------------------
253+
254+
See complete examples in the test BUILD file:
255+
256+
.. literalinclude:: ../test/BUILD
257+
:language: python
258+
:caption: test/BUILD

bazel/rules/rules_score/private/BUILD

Whitespace-only changes.

0 commit comments

Comments
 (0)