From 280d3ad603b35b12f1cb8a25582fa4f0ccd63ef3 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 25 Jun 2024 11:23:00 -0700 Subject: [PATCH] Allow creation of sentinel features in rule-based toolchains BEGIN_PUBLIC Makes the `args` attribute of `cc_feature` optional so that users may declare sentinel features that do not have any inherent arguments. END_PUBLIC PiperOrigin-RevId: 646545838 Change-Id: I470a496aec951608f21cc8ea693387c5b551c8a9 --- cc/toolchains/feature.bzl | 1 - tests/rule_based_toolchain/features/BUILD | 7 +++++++ tests/rule_based_toolchain/features/features_test.bzl | 8 ++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cc/toolchains/feature.bzl b/cc/toolchains/feature.bzl index c81a756..312f184 100644 --- a/cc/toolchains/feature.bzl +++ b/cc/toolchains/feature.bzl @@ -125,7 +125,6 @@ Example: doc = """Whether or not this feature is enabled by default.""", ), "args": attr.label_list( - mandatory = True, doc = """Args that, when expanded, implement this feature.""", providers = [ArgsListInfo], ), diff --git a/tests/rule_based_toolchain/features/BUILD b/tests/rule_based_toolchain/features/BUILD index cc3c0c7..a8bfb54 100644 --- a/tests/rule_based_toolchain/features/BUILD +++ b/tests/rule_based_toolchain/features/BUILD @@ -109,6 +109,13 @@ util.helper_target( overrides = ":builtin_feature", ) +util.helper_target( + cc_feature, + name = "sentinel_feature", + enabled = True, + feature_name = "sentinel_feature_name", +) + analysis_test_suite( name = "test_suite", targets = TARGETS, diff --git a/tests/rule_based_toolchain/features/features_test.bzl b/tests/rule_based_toolchain/features/features_test.bzl index 2345cd7..ee18a07 100644 --- a/tests/rule_based_toolchain/features/features_test.bzl +++ b/tests/rule_based_toolchain/features/features_test.bzl @@ -37,6 +37,12 @@ visibility("private") _C_COMPILE_FILE = "tests/rule_based_toolchain/testdata/file1" +def _sentinel_feature_test(env, targets): + sentinel_feature = env.expect.that_target(targets.sentinel_feature).provider(FeatureInfo) + sentinel_feature.name().equals("sentinel_feature_name") + sentinel_feature.args().args().contains_exactly([]) + sentinel_feature.enabled().equals(True) + def _simple_feature_test(env, targets): simple = env.expect.that_target(targets.simple).provider(FeatureInfo) simple.name().equals("feature_name") @@ -154,6 +160,7 @@ TARGETS = [ ":mutual_exclusion_feature", ":overrides", ":requires", + ":sentinel_feature", ":simple", ":simple2", ":transitive_constraint", @@ -161,6 +168,7 @@ TARGETS = [ # @unsorted-dict-items TESTS = { + "sentinel_feature_test": _sentinel_feature_test, "simple_feature_test": _simple_feature_test, "feature_collects_requirements_test": _feature_collects_requirements_test, "feature_collects_implies_test": _feature_collects_implies_test,