Skip to content

Commit

Permalink
Allow creation of sentinel features in rule-based toolchains
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Googler authored and copybara-github committed Jun 25, 2024
1 parent 9ff1d1b commit 280d3ad
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 0 additions & 1 deletion cc/toolchains/feature.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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],
),
Expand Down
7 changes: 7 additions & 0 deletions tests/rule_based_toolchain/features/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions tests/rule_based_toolchain/features/features_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -154,13 +160,15 @@ TARGETS = [
":mutual_exclusion_feature",
":overrides",
":requires",
":sentinel_feature",
":simple",
":simple2",
":transitive_constraint",
]

# @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,
Expand Down

0 comments on commit 280d3ad

Please sign in to comment.