Documentation generation#
Introduction#
As described in the Overview of technologies chapter, Eclipse S-CORE uses the Sphinx and sphinx-needs toolchain to generate documentation from rst files. Elements of the Eclipse S-CORE metamodel, e.g. requirements, architecture elements and test cases, are represented as sphinx-needs objects.
The integration of Sphinx, sphinx-needs, and the Eclipse S-CORE-specific extensions is implemented in the repository:
The docs-as-code how-to documentation describes in detail how documentation is created and built. Here, we focus on a simple example.
Defining a Bazel Documentation Target#
To generate HTML documentation from .rst files, S-CORE provides the docs Bazel macro.
In the top-level BUILD file of your module,
you find a call of this macro. Without the bundles explained below, it looks like this:
1load("@score_docs_as_code//:docs.bzl", "docs")
2
3docs(
4 external_needs = [
5 "@score_process_description//:needs_json",
6 ],
7 project = "Module Template Project",
8 project_url = "https://eclipse-score.github.io/module_template/",
9 source_dir = "docs",
10)
The most important parameters are:
source_dir: the directory that is given to Sphinx as source directory. Sphinx does not rely on Bazel dependencies to decide which files are included, but on its own toctree mechanism, starting fromindex.rst.projectandproject_url: the name and the published URL of your documentation. With both set, no ownconf.pyis needed; all S-CORE Sphinx extensions and the metamodel checks are configured by docs-as-code. Replace the template values by the name and URL of your module.external_needs: documentation of other modules whose sphinx-needs objects you want to reference, e.g. the process description, whose guidelines and work products the documents of the template reference. The template still uses the label@score_process_description//:needs_json; docs-as-code accepts it, but recommends the public:docstarget of the module instead, e.g."@score_process_description//:docs". The module must also be declared withbazel_depinMODULE.bazel. See Reference Other Modules for details.bundles: further documentation bundles which are mounted into your documentation, e.g. the documentation of each component inscore/<component_name>. The template mounts//score/component_example:docsand//examples:docsthis way, see Component documentation below.
The index.rst file in source_dir
is the main entry point for your documentation. In the template, it is structured as follows:
Folder in |
Content |
|---|---|
|
Information about the template itself, e.g. the folder structure; remove it in your module |
|
Feature architecture, safety and security analysis and planning of the features implemented by the module |
|
Module documents, e.g. user, safety and security manuals, safety and security management, release note |
|
Mount point of the component documentation |
|
Module verification report |
|
Release notes of the module versions |
The documents implement the work products of the
S-CORE process description. Each document declares the
work product it realizes, e.g. :realizes: wp__requirements_comp, and contains .. attention:: boxes which
describe how to adapt it to your module.
Component documentation#
The documentation of a component is located next to its code, in score/component_example/docs:
File / folder |
Content |
|---|---|
|
Component request: purpose of the component and the |
|
Component requirements and assumptions of use, and the inspection checklist |
|
Component architecture and the inspection checklist |
|
Detailed design with static and dynamic PlantUML diagrams, and the implementation inspection checklist |
|
FMEA, DFA, component classification and assumptions of use from the safety and security analysis |
The component BUILD file turns this folder into a documentation bundle:
1load("@score_docs_as_code//:docs.bzl", "docs_bundle")
2
3docs_bundle(
4 name = "docs",
5 code_targets = [
6 ":component_example",
7 ],
8 primary_need_id = "comp__mod_temp_component_name_template",
9 source_dir = "docs",
10 visibility = ["//visibility:public"],
11)
source_diris the folder with the rst files of the component.code_targetslists the Bazel targets whose source files are scanned for links to requirements, see Linking requirements, code and tests below.primary_need_idis the need which represents the component, here thecompneed fromindex.rst.
The top-level docs macro mounts the bundle with "mount_at": "components/component_example", so the component
documentation appears under Components in the generated documentation.
Building documentation#
The docs macro creates the following targets:
Command |
Purpose |
|---|---|
|
Builds the HTML documentation into the |
|
Checks the documentation, incl. the metamodel and traceability checks, without creating HTML |
|
Checks all external links |
|
Starts a local server which rebuilds the documentation on every change |
|
Creates the virtual environment |
The first execution of a Bazel command may take longer, because Bazel needs to download toolchains and dependencies. Subsequent runs will be much faster.
$ bazel run //:docs
...
reading sources... [100%] index
...
Needs successfully exported
build succeeded.
The HTML pages are in _build.
After a successful build, open _build/index.html in a web browser.
When working on the documentation, it is helpful to see the current status directly in the web browser. Use the live preview for this:
$ bazel run //:live_preview
...
build succeeded.
[sphinx-autobuild] Serving on http://127.0.0.1:8000
[sphinx-autobuild] Waiting to detect changes...
A local server is started on http://127.0.0.1:8000. Open it in your web browser to view the current version of the documentation. The live preview:
rebuilds automatically
updates on every file change
stays active until you stop the Bazel process (Ctrl+C).
The published documentation of the module template shows what the result looks like.
Linking requirements, code and tests#
The documentation does not only contain the rst files: docs-as-code also scans the source code and reads the results of the Bazel tests, and links both to the requirements. This makes the traceability from requirements to code and tests visible in the generated documentation. In the template, the chain looks like this:
Requirement: the component requirement is defined in requirements/requirements.rst:
.. comp_req:: Some Title :id: comp_req__mod_temp_component_name__some_title :reqtype: Functional :security: YES :safety: ASIL_B :derived_from: feat_req__example_feature__example_req :status: valid :version: 1 :satisfied_by: comp__mod_temp_component_name_template The component shall return the greeting "Hello, <name>!" for a given name through make_hello_message.
Code: the implementation references the requirement in a comment starting with
req-traceability:(orreq-Id:):// req-traceability: comp_req__mod_temp_component_name__some_title std::string make_hello_message(const std::string& name) {
The files of the
code_targetsof thedocs_bundleare scanned for these comments. The requirement gets the attributesource_code_linkwith a link to the file and line on GitHub.Test: the component integration test declares the requirement it verifies with
RecordProperty("PartiallyVerifies", ...), together withTestType,DerivationTechniqueandDescription, see build and test. GoogleTest writes these properties intotest.xml. The documentation build reads alltest.xmlfiles inbazel-testlogs/, creates a test case need for each test and links it to the requirement.
Test results only appear in the documentation if the tests were executed before the documentation build:
bazel test --config=score-linux-x86_64 //score/...
bazel run //:docs
The live preview does not show test results. Which requirement types a test may verify depends on its test level, see the software verification plan. The docs-as-code how-tos Link Source Code to Requirements and Link Tests to Requirements describe the details, e.g. for Python and Rust tests.