Skip to content

Commit 33a384b

Browse files
committed
[rules score] fix tests
- execute Rules Score Tests from Test Module in CI - Fix Test Module dependencies - Fix Failing Tests - Make it possible to inject own LLVM Toolchain for LibClang
1 parent b1d1a01 commit 33a384b

18 files changed

Lines changed: 271 additions & 213 deletions

File tree

.bazelignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@
1313

1414
python_basics/integration_tests
1515
starpls/integration_tests
16+
# Should be run from its own directory (separate Module)
17+
bazel/rules/rules_score/test

.bazelrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ common --registry=https://bcr.bazel.build
77

88
common --extra_toolchains=@score_gcc_x86_64_toolchain//:x86_64-linux
99

10+
# libclang toolchain for the C/C++ parser used by the score rules. Registered
11+
# only for score_tooling's own build (its LLVM is a dev dependency); integrating
12+
# repositories register their own libclang toolchain instead.
13+
common --extra_toolchains=//cpp/libclang:score_tooling_libclang_toolchain
14+
1015
build --java_language_version=17
1116
build --tool_java_language_version=17
1217
build --java_runtime_version=remotejdk_17

.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.3.1
1+
8.5.1

.github/workflows/tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ jobs:
4141
bazel test //coverage/tests:all
4242
- name: Run rules_score tests
4343
run: |
44-
bazel test //bazel/rules/rules_score/...
44+
cd bazel/rules/rules_score/test
45+
bazel test //...
4546
- name: Run Plantuml Tooling clippy
4647
run: |
4748
bazel build //plantuml/... --config=clippy

bazel/rules/rules_score/private/sphinx_module.bzl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -414,12 +414,6 @@ def sphinx_module(
414414
extension will not be available).
415415
visibility: Bazel visibility
416416
"""
417-
if graphviz == None:
418-
graphviz = select({
419-
"//bazel/rules/rules_score:linux_x86_64": "@graphviz_deb//:all",
420-
"//conditions:default": None,
421-
})
422-
423417
_score_needs(
424418
name = name + "_needs",
425419
srcs = srcs,

bazel/rules/rules_score/private/unit.bzl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ load("@rules_cc//cc:find_cc_toolchain.bzl", "use_cc_toolchain")
2525
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
2626
load("@rules_rust//rust:defs.bzl", "rust_common")
2727
load("//bazel/rules/rules_score:providers.bzl", "CcDependencyInfo", "CertifiedScope", "SphinxSourcesInfo", "UnitDesignInfo", "UnitInfo")
28-
load("//cpp/libclang:cpp_parser.bzl", "cpp_parser_action_internal_attrs", "cpp_parser_target_aspects", "has_cpp_parser_inputs", "run_cpp_parser_action")
28+
load("//cpp/libclang:cpp_parser.bzl", "cpp_parser_action_internal_attrs", "cpp_parser_action_toolchains", "cpp_parser_target_aspects", "has_cpp_parser_inputs", "run_cpp_parser_action")
2929
load(":cc_dependency_aspect.bzl", "cc_dependencies_aspect")
3030

3131
def _run_implementation_cpp_parser(ctx, impl, output_prefix):
@@ -34,9 +34,6 @@ def _run_implementation_cpp_parser(ctx, impl, output_prefix):
3434
target = impl,
3535
output_prefix = output_prefix,
3636
tool = ctx.attr._tool,
37-
libclang = ctx.file._libclang,
38-
llvm_cxx_builtin_include = ctx.attr._llvm_cxx_builtin_include,
39-
llvm_extra_config_site = ctx.attr._llvm_extra_config_site,
4037
log_level = ctx.attr._log_level[BuildSettingInfo].value,
4138
)
4239

@@ -167,7 +164,7 @@ _unit = rule(
167164
doc = "Defines a software unit with design, implementation, and tests for S-CORE process compliance",
168165
subrules = [subrule_gtest_report],
169166
attrs = _unit_attrs,
170-
toolchains = use_cc_toolchain(),
167+
toolchains = cpp_parser_action_toolchains() + use_cc_toolchain(),
171168
fragments = ["cpp"],
172169
)
173170

bazel/rules/rules_score/private/verbosity.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
4444
# Merge into a rule's attrs dict with ``**VERBOSITY_ATTR``.
4545
VERBOSITY_ATTR = {
4646
"_verbosity": attr.label(
47-
default = Label("//bazel/rules/rules_score:verbosity"),
47+
default = Label("@score_tooling//bazel/rules/rules_score:verbosity"),
4848
doc = "Verbosity level build setting (warn/info/debug).",
4949
),
5050
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.3.1
1+
8.5.1

bazel/rules/rules_score/test/BUILD

Lines changed: 64 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
load("@aspect_rules_py//py:defs.bzl", "py_binary")
2+
13
# *******************************************************************************
24
# Copyright (c) 2025 Contributors to the Eclipse Foundation
35
#
@@ -26,6 +28,8 @@ load(
2628
"unit",
2729
"unit_design",
2830
)
31+
load("@score_tooling//bazel/rules/rules_score:sphinx_toolchain.bzl", "sphinx_toolchain")
32+
load("@score_tooling//cpp/libclang:libclang_toolchain.bzl", "libclang_toolchain")
2933
load("@trlc//:trlc.bzl", "trlc_requirements", "trlc_requirements_test")
3034
load(
3135
":html_generation_test.bzl",
@@ -93,6 +97,56 @@ load(
9397

9498
package(default_visibility = ["//visibility:public"])
9599

100+
# ============================================================================
101+
# Sphinx Toolchain — uses score_docs_as_code so score_metamodel is importable
102+
# ============================================================================
103+
104+
exports_files(["template/conf.template.py"])
105+
106+
py_binary(
107+
name = "score_build",
108+
srcs = ["@score_tooling//bazel/rules/rules_score:src/sphinx_wrapper.py"],
109+
main = "@score_tooling//bazel/rules/rules_score:src/sphinx_wrapper.py",
110+
package_collisions = "warning",
111+
visibility = ["//visibility:public"],
112+
deps = [
113+
"@score_docs_as_code//src:plantuml_for_python",
114+
"@score_docs_as_code//src/extensions/score_sphinx_bundle",
115+
"@score_tooling//bazel/rules/rules_score:bazel_sphinx_needs",
116+
"@score_tooling//bazel/rules/rules_score:sphinx_module_ext",
117+
],
118+
)
119+
120+
sphinx_toolchain(
121+
name = "score_sphinx_toolchain",
122+
conf_template = "//:template/conf.template.py",
123+
html_merge_tool = "@score_tooling//bazel/rules/rules_score:sphinx_html_merge",
124+
sphinx = ":score_build",
125+
)
126+
127+
toolchain(
128+
name = "score_toolchain",
129+
toolchain = ":score_sphinx_toolchain",
130+
toolchain_type = "@score_tooling//bazel/rules/rules_score:toolchain_type",
131+
)
132+
133+
# ============================================================================
134+
# libclang Toolchain — this integrating repo supplies its own libclang/C++
135+
# toolchain for the score libclang-based C/C++ parser.
136+
# ============================================================================
137+
libclang_toolchain(
138+
name = "test_libclang",
139+
cxx_builtin_include = "@llvm_toolchain_llvm//:cxx_builtin_include",
140+
extra_config_site = "@llvm_toolchain_llvm//:extra_config_site",
141+
libclang = "@llvm_toolchain_llvm//:lib/libclang.so",
142+
)
143+
144+
toolchain(
145+
name = "test_libclang_toolchain",
146+
toolchain = ":test_libclang",
147+
toolchain_type = "@score_tooling//cpp/libclang:libclang_toolchain_type",
148+
)
149+
96150
# ============================================================================
97151
# Test Fixtures - Module Definitions
98152
# ============================================================================
@@ -126,15 +180,6 @@ sphinx_module(
126180
],
127181
)
128182

129-
# Test 2: Graphviz Rendering
130-
# Tests hermetic graphviz support via sphinx.ext.graphviz directive
131-
sphinx_module(
132-
name = "graphviz_test_lib",
133-
srcs = glob(["fixtures/graphviz_test/*.rst"]),
134-
index = "fixtures/graphviz_test/index.rst",
135-
sphinx = "@score_tooling//bazel/rules/rules_score:score_build",
136-
)
137-
138183
# Test 3: SEooC (Safety Element out of Context) Module
139184
# Tests the score_component macro with S-CORE process artifacts
140185

@@ -283,7 +328,7 @@ unit_design(
283328
unit(
284329
name = "test_unit",
285330
testonly = True,
286-
scope = ["//bazel/rules/rules_score/test:mock_lib1"],
331+
scope = ["//:mock_lib1"],
287332
tests = [":test_unit_tests"],
288333
unit_design = [":test_unit_design"],
289334
implementation = [
@@ -709,26 +754,11 @@ aous_rst_sphinx_test(
709754
requirements_rst_test_suite(name = "requirements_rst_tests")
710755

711756
# ============================================================================
712-
# Image srcs Tests
757+
# Image srcs Tests (defined in sub-package to avoid workspace-root edge case)
713758
# ============================================================================
714-
715-
# Fixture: feature_requirements with image_srcs
716-
feature_requirements(
717-
name = "feat_req_with_image",
718-
srcs = ["fixtures/seooc_test/feature_requirements.trlc"],
719-
image_srcs = [
720-
"fixtures/image_srcs/diagrams/arch.svg",
721-
"fixtures/image_srcs/diagrams/arch.png",
722-
],
723-
deps = [":asr_trlc"],
724-
)
725-
726-
image_srcs_sphinx_sources_test(
727-
name = "image_srcs_sphinx_sources_test",
728-
target_under_test = ":feat_req_with_image",
729-
)
730-
731-
requirements_image_test_suite(name = "requirements_image_tests")
759+
# feat_req_with_image and image_srcs_sphinx_sources_test live in
760+
# //fixtures/image_srcs so that ctx.label.package is non-empty and
761+
# subrule_trlc_image_stage can strip the prefix correctly.
732762

733763
# ============================================================================
734764
# Combined Test Suite
@@ -745,7 +775,7 @@ requirements_image_test_suite(name = "requirements_image_tests")
745775
trlc_requirements(
746776
name = "safety_measures_fixtures",
747777
srcs = ["fixtures/seooc_test/safety_measures_fixtures.trlc"],
748-
spec = ["//bazel/rules/rules_score/trlc/config:score_requirements_model"],
778+
spec = ["@score_tooling//bazel/rules/rules_score/trlc/config:score_requirements_model"],
749779
)
750780

751781
trlc_requirements_test(
@@ -757,22 +787,22 @@ py_test(
757787
name = "test_safety_analysis_tools",
758788
size = "small",
759789
srcs = ["test_safety_analysis_tools.py"],
760-
deps = ["//bazel/rules/rules_score:safety_analysis_tools"],
790+
deps = ["@score_tooling//bazel/rules/rules_score:safety_analysis_tools"],
761791
)
762792

763793
py_test(
764794
name = "test_aou_forwarding_to_lobster",
765795
size = "small",
766796
srcs = ["test_aou_forwarding_to_lobster.py"],
767-
deps = ["//bazel/rules/rules_score:aou_forwarding_to_lobster"],
797+
deps = ["@score_tooling//bazel/rules/rules_score:aou_forwarding_to_lobster"],
768798
)
769799

770800
py_test(
771801
name = "test_rst_to_trlc",
772802
size = "small",
773803
srcs = ["rst_to_trlc_test.py"],
774804
main = "rst_to_trlc_test.py",
775-
deps = ["//bazel/rules/rules_score:rst_to_trlc_lib"],
805+
deps = ["@score_tooling//bazel/rules/rules_score:rst_to_trlc_lib"],
776806
)
777807

778808
py_test(
@@ -787,27 +817,18 @@ py_test(
787817
deps = ["@trlc//tools/trlc_rst:trlc_rst_lib"],
788818
)
789819

790-
py_test(
791-
name = "test_graphviz_rendering",
792-
size = "small",
793-
srcs = ["graphviz_render_test.py"],
794-
data = [":graphviz_test_lib"],
795-
main = "graphviz_render_test.py",
796-
)
797-
798820
# Combined test suite for all tests
799821
test_suite(
800822
name = "all_tests",
801823
tests = [
802-
":requirements_image_tests",
803824
":requirements_rst_tests",
804825
":seooc_tests",
805826
":sphinx_module_tests",
806827
":test_aou_forwarding_to_lobster",
807-
":test_graphviz_rendering",
808828
":test_rst_to_trlc",
809829
":test_safety_analysis_tools",
810830
":test_trlc_rst_image_rendering",
811831
":unit_component_tests",
832+
"//fixtures/image_srcs:requirements_image_tests",
812833
],
813834
)

bazel/rules/rules_score/test/MODULE.bazel

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ pip.parse(
5555
use_repo(pip, "pip_tooling_test")
5656

5757
bazel_dep(name = "score_docs_as_code", version = "3.0.1", dev_dependency = True)
58+
59+
bazel_dep(name = "googletest", version = "1.17.0.bcr.2")
5860
# bazel_dep(name = "score_platform", version = "0.5.0")
5961
# bazel_dep(name = "score_process", version = "1.3.2")
6062

@@ -68,16 +70,40 @@ register_toolchains(
6870
"//:score_toolchain",
6971
)
7072

73+
###############################################################################
74+
# LLVM Toolchain (provides libclang for the score libclang toolchain below)
75+
#
76+
# As an integrating repository, this module supplies its own libclang/C++
77+
# toolchain instead of relying on score_tooling's (score_tooling declares LLVM
78+
# only as a dev dependency and does not register a libclang toolchain for
79+
# consumers).
80+
###############################################################################
81+
bazel_dep(name = "toolchains_llvm", version = "1.6.0")
82+
83+
llvm = use_extension(
84+
"@toolchains_llvm//toolchain/extensions:llvm.bzl",
85+
"llvm",
86+
)
87+
llvm.toolchain(
88+
cxx_standard = {"": "c++17"},
89+
llvm_version = "19.1.7",
90+
)
91+
use_repo(llvm, "llvm_toolchain", "llvm_toolchain_llvm")
92+
93+
register_toolchains(
94+
"//:test_libclang_toolchain",
95+
)
96+
7197
bazel_dep(name = "trlc", version = "0.0.0")
7298
git_override(
7399
module_name = "trlc",
74-
commit = "7f06d0396fd0e5f02b657d25700775af5113b7e0",
100+
commit = "c4c531b9d667085daa09dfc1590edacc314bfda4",
75101
remote = "https://github.com/bmw-software-engineering/trlc.git",
76102
)
77103

78104
bazel_dep(name = "lobster", version = "0.0.0")
79105
git_override(
80106
module_name = "lobster",
81-
commit = "56881461f9d3fde2918d1731aa5937aaf64cd67c",
107+
commit = "2792e2daee2cf524fdc7b1545fd3537791ebc36c",
82108
remote = "https://github.com/bmw-software-engineering/lobster.git",
83109
)

0 commit comments

Comments
 (0)