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
This commit is contained in:
Googler 2024-06-25 11:23:00 -07:00 committed by Copybara-Service
parent 9ff1d1b6fd
commit 280d3ad603
3 changed files with 15 additions and 1 deletions

View File

@ -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],
),

View File

@ -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,

View File

@ -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,