From aa6de2b3c5204bfa69f68b75a7884ae987f2ff89 Mon Sep 17 00:00:00 2001 From: rmaddikery Date: Thu, 29 Oct 2026 15:40:44 +0100 Subject: [PATCH] extend examples with a feature-flag-selected variant - showcases how an integrator provided feature flag selects the respective variant that works seamlessly with the dependable_element. --- .../examples/some_other_library/BUILD | 21 +++++++++++++++++-- .../examples/some_other_library/MODULE.bazel | 1 + .../variants/variant_1/BUILD | 19 +++++++++++++++++ .../variants/variant_2/BUILD | 19 +++++++++++++++++ 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 bazel/rules/rules_score/examples/some_other_library/variants/variant_1/BUILD create mode 100644 bazel/rules/rules_score/examples/some_other_library/variants/variant_2/BUILD diff --git a/bazel/rules/rules_score/examples/some_other_library/BUILD b/bazel/rules/rules_score/examples/some_other_library/BUILD index 11ee04d7..7f72ebed 100644 --- a/bazel/rules/rules_score/examples/some_other_library/BUILD +++ b/bazel/rules/rules_score/examples/some_other_library/BUILD @@ -11,6 +11,7 @@ # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* +load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") load( "@score_tooling//bazel/rules/rules_score:rules_score.bzl", "architectural_design", @@ -67,6 +68,22 @@ dependability_analysis( safety_analysis = [":other_library_safety_analysis"], ) +# Selects the implementation variant; consumers pass --@some_other_library//:use_variant_2=true. +bool_flag( + name = "use_variant_2", + build_setting_default = False, +) + +config_setting( + name = "is_variant_2", + flag_values = {":use_variant_2": "True"}, +) + +_VARIANT = select({ + ":is_variant_2": ["//variants/variant_2:variant"], + "//conditions:default": ["//variants/variant_1:variant"], +}) + unit( name = "abc", scope = ["//:__pkg__"], @@ -74,7 +91,7 @@ unit( unit_design = [], implementation = [ ":some_other_library", - ], + ] + _VARIANT, ) component( @@ -102,5 +119,5 @@ cc_library( name = "some_other_library", srcs = [], visibility = ["//visibility:public"], - deps = [], + deps = _VARIANT, ) diff --git a/bazel/rules/rules_score/examples/some_other_library/MODULE.bazel b/bazel/rules/rules_score/examples/some_other_library/MODULE.bazel index 9682075d..891249bf 100644 --- a/bazel/rules/rules_score/examples/some_other_library/MODULE.bazel +++ b/bazel/rules/rules_score/examples/some_other_library/MODULE.bazel @@ -34,4 +34,5 @@ llvm = use_extension( llvm.toolchain(llvm_version = "19.1.7") use_repo(llvm, "llvm_toolchain", "llvm_toolchain_llvm") +bazel_dep(name = "bazel_skylib", version = "1.8.2") bazel_dep(name = "trlc", version = "3.1.1") diff --git a/bazel/rules/rules_score/examples/some_other_library/variants/variant_1/BUILD b/bazel/rules/rules_score/examples/some_other_library/variants/variant_1/BUILD new file mode 100644 index 00000000..e98a62ac --- /dev/null +++ b/bazel/rules/rules_score/examples/some_other_library/variants/variant_1/BUILD @@ -0,0 +1,19 @@ +# ******************************************************************************* +# 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 +# ******************************************************************************* + +# Default variant of other_seooc, selected when //:use_variant_2 is off. +cc_library( + name = "variant", + srcs = [], + visibility = ["//visibility:public"], +) diff --git a/bazel/rules/rules_score/examples/some_other_library/variants/variant_2/BUILD b/bazel/rules/rules_score/examples/some_other_library/variants/variant_2/BUILD new file mode 100644 index 00000000..af1c4c1e --- /dev/null +++ b/bazel/rules/rules_score/examples/some_other_library/variants/variant_2/BUILD @@ -0,0 +1,19 @@ +# ******************************************************************************* +# 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 +# ******************************************************************************* + +# Alternative variant of other_seooc, selected when //:use_variant_2 is on. +cc_library( + name = "variant", + srcs = [], + visibility = ["//visibility:public"], +)