Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ def docs(
scan_code = [],
code_targets = [],
test_sources = [],
testlink_source = "xml",
known_good = None,
metamodel = None,
bundles = [],
Expand All @@ -218,6 +219,12 @@ def docs(
expand to their files.
test_sources: Optional list of repo-relative directory paths which will be used to filter testcases for documentation generation.
When empty (default), all testcases found in `bazel-testlogs` will be used.
testlink_source: Where test links come from. "xml" (default) scans
`bazel-testlogs/**/test.xml`, "lobster" reads the `*.lobster`
activity pools emitted by lobster-gtest, "none" disables test
links. Note that "lobster" carries no failure messages and
reports skipped tests as passed, and that `test_sources` has
no effect in that mode.
known_good: Optional label to a "known good" JSON file for source links.
metamodel: Optional label to a metamodel.yaml file. When set, the extension loads this
file instead of the default metamodel shipped with score_metamodel.
Expand Down Expand Up @@ -328,6 +335,7 @@ def docs(
"SOURCE_DIRECTORY": source_dir,
"PACKAGE_DIR": native.package_name(),
"TEST_SOURCES": str(test_sources),
"TESTLINK_SOURCE": testlink_source,
"DATA": str(data),
"EXTERNAL_NEEDS_FILES": str(external_needs),
# `bazel run` starts from a runfiles tree, so this logical path is
Expand Down
21 changes: 21 additions & 0 deletions docs/reference/bazel_macros.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,27 @@ Minimal example (root ``BUILD``)
Explicit source files or filegroups to scan. Use ``code_targets`` for
implementation targets; it follows their dependencies automatically.

- ``testlink_source`` (string, optional, default ``"xml"``)
Selects where the ``score_source_code_linker`` takes test links from.

``"xml"``
Scan ``bazel-testlogs/**/test.xml``. Requires the tests to have been run
via ``bazel test``; a ``cc_test`` that is only consumed as a dependency of
``unit()``/``component()``/``dependable_element()`` does not produce such a
file.

``"lobster"``
Read the ``*.lobster`` activity pools that ``lobster-gtest`` emits below
``bazel-bin``. These are produced by every build of the corresponding
traceability target, so no separate test run is required. Two limitations
apply: ``lobster-gtest`` discards the ``<failure>`` message, so failed
tests carry no result text, and it reports skipped tests as passed.
``test_sources`` has no effect in this mode.

``"none"``
Do not create testcase needs at all. Source code links
(``req-Id:`` annotations) are unaffected and keep working.

- ``external_needs`` (list of bazel labels)
External ``:needs_json_file`` targets from other modules/repositories
for referencing their needs.
Expand Down
1 change: 1 addition & 0 deletions src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ filegroup(
"//src/extensions/score_metamodel:all_sources",
"//src/extensions/score_mounts:all_sources",
"//src/extensions/score_source_code_linker:all_sources",
"//src/extensions/score_lobster_report:all_sources",
"//src/extensions/score_sphinx_bundle:all_sources",
"//src/extensions/score_sync_toml:all_sources",
"//src/extensions/score_metrics:all_sources",
Expand Down
31 changes: 31 additions & 0 deletions src/extensions/score_lobster_report/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# *******************************************************************************
# Copyright (c) 2026 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************
load("@aspect_rules_py//py:defs.bzl", "py_library")
load("@docs_as_code_hub_env//:requirements.bzl", "all_requirements")

filegroup(
name = "all_sources",
srcs = glob(["*.py"]),
visibility = ["//visibility:public"],
)

py_library(
name = "score_lobster_report",
srcs = [":all_sources"],
imports = ["."],
visibility = ["//visibility:public"],
deps = all_requirements + [
"@score_docs_as_code//src/helper_lib",
"@score_docs_as_code//src/extensions/score_source_code_linker",
],
)
46 changes: 46 additions & 0 deletions src/extensions/score_lobster_report/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# *******************************************************************************
# Copyright (c) 2026 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************
"""
Renders a pre-built Lobster traceability report (JSON, as produced by the
rules_score ``component()``/``dependable_element()`` Bazel macros) as a table
directly inside a Sphinx page, via the ``.. lobster-traceability-report::``
directive.

Unlike ``score_source_code_linker`` (which turns ``bazel-testlogs/**/test.xml``
into sphinx-needs at build time), this extension reads a fixed, already-built
JSON file straight off disk when the directive runs. That keeps the Bazel
target that actually produces the JSON (e.g. a ``component()``/
``dependable_element()`` instance, which is ``testonly`` because it depends on
``cc_test`` targets) out of the (non-testonly) ``docs()`` Bazel dependency
graph entirely - the docs build never needs a Bazel-level dependency on it,
only the file to exist on disk, exactly like the bazel-testlogs scan does for
test results.
"""

from sphinx.application import Sphinx

from src.extensions.score_lobster_report.directive import (
LobsterTraceabilityReportDirective,
)


def setup(app: Sphinx) -> dict[str, object]:
app.add_directive(
"lobster-traceability-report", LobsterTraceabilityReportDirective
)

return {
"version": "1.0.0",
"parallel_read_safe": True,
"parallel_write_safe": True,
}
Loading
Loading