Implement provides in rule based toolchain.

BEGIN_PUBLIC
Implement provides in rule based toolchain.
END_PUBLIC

PiperOrigin-RevId: 619082926
Change-Id: I938640981bd10f0e3d41402d211672a45264df1a
This commit is contained in:
Googler 2024-03-25 23:43:33 -07:00 committed by Copybara-Service
parent 61def7a42c
commit 991cdf09a9
3 changed files with 46 additions and 7 deletions

View File

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

View File

@ -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")
@ -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(

View File

@ -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):
@ -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