Skip to content

Commit

Permalink
Implement provides in rule based toolchain.
Browse files Browse the repository at this point in the history
BEGIN_PUBLIC
Implement provides in rule based toolchain.
END_PUBLIC

PiperOrigin-RevId: 619082926
Change-Id: I938640981bd10f0e3d41402d211672a45264df1a
  • Loading branch information
Googler authored and copybara-github committed Mar 26, 2024
1 parent 61def7a commit 991cdf0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
29 changes: 29 additions & 0 deletions cc/toolchains/mutually_exclusive_category.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2024 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Rule for mutually exclusive categories in the rule based toolchain."""

load(":cc_toolchain_info.bzl", "MutuallyExclusiveCategoryInfo")

def _cc_mutually_exclusive_category_impl(ctx):
return [MutuallyExclusiveCategoryInfo(
label = ctx.label,
name = str(ctx.label),
)]

cc_mutually_exclusive_category = rule(
implementation = _cc_mutually_exclusive_category_impl,
doc = "A category of features, for which only one can be enabled",
attrs = {},
provides = [MutuallyExclusiveCategoryInfo],
)
10 changes: 9 additions & 1 deletion tests/rule_based_toolchain/features/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ load("//cc/toolchains:args.bzl", "cc_args")
load("//cc/toolchains:feature.bzl", "cc_feature")
load("//cc/toolchains:feature_constraint.bzl", "cc_feature_constraint")
load("//cc/toolchains:feature_set.bzl", "cc_feature_set")
load("//cc/toolchains:mutually_exclusive_category.bzl", "cc_mutually_exclusive_category")
load("//cc/toolchains/impl:external_feature.bzl", "cc_external_feature")
load("//tests/rule_based_toolchain:analysis_test_suite.bzl", "analysis_test_suite")
load(":features_test.bzl", "TARGETS", "TESTS")
Expand Down Expand Up @@ -59,13 +60,20 @@ util.helper_target(
implies = [":simple"],
)

cc_mutually_exclusive_category(
name = "category",
)

util.helper_target(
cc_feature,
name = "mutual_exclusion_feature",
args = [":c_compile"],
enabled = True,
feature_name = "mutual_exclusion",
mutually_exclusive = [":simple"],
mutually_exclusive = [
":simple",
":category",
],
)

util.helper_target(
Expand Down
14 changes: 8 additions & 6 deletions tests/rule_based_toolchain/features/features_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def _feature_collects_mutual_exclusion_test(env, targets):
FeatureInfo,
).mutually_exclusive().contains_exactly([
targets.simple.label,
targets.category.label,
])

def _feature_set_collects_features_test(env, targets):
Expand Down Expand Up @@ -144,17 +145,18 @@ def _feature_can_be_overridden_test(env, targets):
overrides.overrides().some().label().equals(targets.builtin_feature.label)

TARGETS = [
":builtin_feature",
":c_compile",
":simple",
":simple2",
":category",
":direct_constraint",
":feature_set",
":requires",
":implies",
":mutual_exclusion_feature",
":direct_constraint",
":transitive_constraint",
":builtin_feature",
":overrides",
":requires",
":simple",
":simple2",
":transitive_constraint",
]

# @unsorted-dict-items
Expand Down

0 comments on commit 991cdf0

Please sign in to comment.