2024-02-20 23:53:42 +00:00
|
|
|
# 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.
|
|
|
|
"""Test subjects for cc_toolchain_info providers."""
|
|
|
|
|
2024-02-21 14:24:05 +00:00
|
|
|
load("@bazel_skylib//lib:structs.bzl", "structs")
|
|
|
|
load("@rules_testing//lib:truth.bzl", _subjects = "subjects")
|
2024-02-20 23:53:42 +00:00
|
|
|
load(
|
|
|
|
"//cc/toolchains:cc_toolchain_info.bzl",
|
2024-02-26 21:58:02 +00:00
|
|
|
"ActionTypeConfigInfo",
|
|
|
|
"ActionTypeConfigSetInfo",
|
2024-02-20 23:53:42 +00:00
|
|
|
"ActionTypeInfo",
|
|
|
|
"ActionTypeSetInfo",
|
2024-02-21 01:58:00 +00:00
|
|
|
"AddArgsInfo",
|
|
|
|
"ArgsInfo",
|
2024-02-23 21:54:01 +00:00
|
|
|
"ArgsListInfo",
|
2024-02-20 23:53:42 +00:00
|
|
|
"FeatureConstraintInfo",
|
|
|
|
"FeatureInfo",
|
|
|
|
"FeatureSetInfo",
|
|
|
|
"MutuallyExclusiveCategoryInfo",
|
|
|
|
"ToolInfo",
|
|
|
|
)
|
|
|
|
load(":generate_factory.bzl", "ProviderDepset", "ProviderSequence", "generate_factory")
|
2024-02-23 21:54:01 +00:00
|
|
|
load(":generics.bzl", "dict_key_subject", "optional_subject", "result_subject", "struct_subject", _result_fn_wrapper = "result_fn_wrapper")
|
2024-02-20 23:53:42 +00:00
|
|
|
|
2024-02-21 14:24:05 +00:00
|
|
|
visibility("//tests/rule_based_toolchain/...")
|
2024-02-20 23:53:42 +00:00
|
|
|
|
2024-02-22 11:05:41 +00:00
|
|
|
# The default runfiles subject uses path instead of short_path.
|
|
|
|
# This makes it rather awkward for copybara.
|
|
|
|
runfiles_subject = lambda value, meta: _subjects.depset_file(value.files, meta = meta)
|
|
|
|
|
2024-02-20 23:53:42 +00:00
|
|
|
# buildifier: disable=name-conventions
|
|
|
|
_ActionTypeFactory = generate_factory(
|
|
|
|
ActionTypeInfo,
|
|
|
|
"ActionTypeInfo",
|
|
|
|
dict(
|
2024-02-21 14:24:05 +00:00
|
|
|
name = _subjects.str,
|
2024-02-20 23:53:42 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
# buildifier: disable=name-conventions
|
|
|
|
_ActionTypeSetFactory = generate_factory(
|
|
|
|
ActionTypeSetInfo,
|
|
|
|
"ActionTypeInfo",
|
|
|
|
dict(
|
|
|
|
actions = ProviderDepset(_ActionTypeFactory),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
# buildifier: disable=name-conventions
|
|
|
|
_MutuallyExclusiveCategoryFactory = generate_factory(
|
|
|
|
MutuallyExclusiveCategoryInfo,
|
|
|
|
"MutuallyExclusiveCategoryInfo",
|
2024-02-21 14:24:05 +00:00
|
|
|
dict(name = _subjects.str),
|
2024-02-20 23:53:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
_FEATURE_FLAGS = dict(
|
2024-02-21 14:24:05 +00:00
|
|
|
name = _subjects.str,
|
|
|
|
enabled = _subjects.bool,
|
2024-02-23 21:54:01 +00:00
|
|
|
args = None,
|
2024-02-20 23:53:42 +00:00
|
|
|
implies = None,
|
|
|
|
requires_any_of = None,
|
2024-02-23 21:54:01 +00:00
|
|
|
mutually_exclusive = ProviderSequence(_MutuallyExclusiveCategoryFactory),
|
2024-02-27 12:44:55 +00:00
|
|
|
overridable = _subjects.bool,
|
|
|
|
external = _subjects.bool,
|
2024-02-20 23:53:42 +00:00
|
|
|
overrides = None,
|
|
|
|
)
|
|
|
|
|
|
|
|
# Break the dependency loop.
|
|
|
|
# buildifier: disable=name-conventions
|
|
|
|
_FakeFeatureFactory = generate_factory(
|
|
|
|
FeatureInfo,
|
|
|
|
"FeatureInfo",
|
|
|
|
_FEATURE_FLAGS,
|
|
|
|
)
|
|
|
|
|
|
|
|
# buildifier: disable=name-conventions
|
|
|
|
_FeatureSetFactory = generate_factory(
|
|
|
|
FeatureSetInfo,
|
|
|
|
"FeatureSetInfo",
|
|
|
|
dict(features = _FakeFeatureFactory),
|
|
|
|
)
|
|
|
|
|
|
|
|
# buildifier: disable=name-conventions
|
|
|
|
_FeatureConstraintFactory = generate_factory(
|
|
|
|
FeatureConstraintInfo,
|
|
|
|
"FeatureConstraintInfo",
|
|
|
|
dict(
|
|
|
|
all_of = ProviderDepset(_FakeFeatureFactory),
|
|
|
|
none_of = ProviderDepset(_FakeFeatureFactory),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
# buildifier: disable=name-conventions
|
2024-02-21 01:58:00 +00:00
|
|
|
_AddArgsFactory = generate_factory(
|
|
|
|
AddArgsInfo,
|
|
|
|
"AddArgsInfo",
|
2024-02-20 23:53:42 +00:00
|
|
|
dict(
|
2024-02-21 14:24:05 +00:00
|
|
|
args = _subjects.collection,
|
|
|
|
files = _subjects.depset_file,
|
2024-02-20 23:53:42 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
# buildifier: disable=name-conventions
|
2024-02-21 01:58:00 +00:00
|
|
|
_ArgsFactory = generate_factory(
|
|
|
|
ArgsInfo,
|
|
|
|
"ArgsInfo",
|
2024-02-20 23:53:42 +00:00
|
|
|
dict(
|
|
|
|
actions = ProviderDepset(_ActionTypeFactory),
|
2024-02-21 01:58:00 +00:00
|
|
|
args = ProviderSequence(_AddArgsFactory),
|
2024-02-21 14:24:05 +00:00
|
|
|
env = _subjects.dict,
|
|
|
|
files = _subjects.depset_file,
|
2024-02-20 23:53:42 +00:00
|
|
|
requires_any_of = ProviderSequence(_FeatureConstraintFactory),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2024-02-23 21:54:01 +00:00
|
|
|
# buildifier: disable=name-conventions
|
|
|
|
_ArgsListFactory = generate_factory(
|
|
|
|
ArgsListInfo,
|
|
|
|
"ArgsListInfo",
|
|
|
|
dict(
|
|
|
|
args = ProviderSequence(_ArgsFactory),
|
|
|
|
by_action = lambda values, *, meta: dict_key_subject(struct_subject(
|
|
|
|
args = _subjects.collection,
|
|
|
|
files = _subjects.depset_file,
|
|
|
|
))({value.action: value for value in values}, meta = meta),
|
|
|
|
files = _subjects.depset_file,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2024-02-20 23:53:42 +00:00
|
|
|
# buildifier: disable=name-conventions
|
|
|
|
_FeatureFactory = generate_factory(
|
|
|
|
FeatureInfo,
|
|
|
|
"FeatureInfo",
|
|
|
|
_FEATURE_FLAGS | dict(
|
2024-02-23 21:54:01 +00:00
|
|
|
# Use .factory so it's not inlined.
|
|
|
|
args = _ArgsListFactory.factory,
|
2024-02-20 23:53:42 +00:00
|
|
|
implies = ProviderDepset(_FakeFeatureFactory),
|
|
|
|
requires_any_of = ProviderSequence(_FeatureSetFactory),
|
2024-02-27 12:44:55 +00:00
|
|
|
overrides = optional_subject(_FakeFeatureFactory.factory),
|
2024-02-20 23:53:42 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
# buildifier: disable=name-conventions
|
|
|
|
_ToolFactory = generate_factory(
|
|
|
|
ToolInfo,
|
|
|
|
"ToolInfo",
|
|
|
|
dict(
|
2024-02-21 14:24:05 +00:00
|
|
|
exe = _subjects.file,
|
2024-02-22 11:05:41 +00:00
|
|
|
runfiles = runfiles_subject,
|
2024-02-20 23:53:42 +00:00
|
|
|
requires_any_of = ProviderSequence(_FeatureConstraintFactory),
|
2024-02-21 14:24:05 +00:00
|
|
|
execution_requirements = _subjects.collection,
|
2024-02-20 23:53:42 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
# buildifier: disable=name-conventions
|
2024-02-26 21:58:02 +00:00
|
|
|
_ActionTypeConfigFactory = generate_factory(
|
|
|
|
ActionTypeConfigInfo,
|
|
|
|
"ActionTypeConfigInfo",
|
2024-02-20 23:53:42 +00:00
|
|
|
dict(
|
2024-02-26 21:58:02 +00:00
|
|
|
action_type = _ActionTypeFactory,
|
2024-02-20 23:53:42 +00:00
|
|
|
tools = ProviderSequence(_ToolFactory),
|
2024-02-23 21:54:01 +00:00
|
|
|
args = ProviderSequence(_ArgsFactory),
|
2024-02-20 23:53:42 +00:00
|
|
|
implies = ProviderDepset(_FeatureFactory),
|
2024-02-26 21:58:02 +00:00
|
|
|
files = runfiles_subject,
|
2024-02-20 23:53:42 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
# buildifier: disable=name-conventions
|
2024-02-26 21:58:02 +00:00
|
|
|
_ActionTypeConfigSetFactory = generate_factory(
|
|
|
|
ActionTypeConfigSetInfo,
|
|
|
|
"ActionTypeConfigSetInfo",
|
|
|
|
dict(
|
|
|
|
configs = dict_key_subject(_ActionTypeConfigFactory.factory),
|
|
|
|
),
|
2024-02-20 23:53:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
FACTORIES = [
|
|
|
|
_ActionTypeFactory,
|
|
|
|
_ActionTypeSetFactory,
|
2024-02-21 01:58:00 +00:00
|
|
|
_AddArgsFactory,
|
|
|
|
_ArgsFactory,
|
2024-02-23 21:54:01 +00:00
|
|
|
_ArgsListFactory,
|
2024-02-20 23:53:42 +00:00
|
|
|
_MutuallyExclusiveCategoryFactory,
|
|
|
|
_FeatureFactory,
|
|
|
|
_FeatureConstraintFactory,
|
|
|
|
_FeatureSetFactory,
|
|
|
|
_ToolFactory,
|
2024-02-26 21:58:02 +00:00
|
|
|
_ActionTypeConfigSetFactory,
|
2024-02-20 23:53:42 +00:00
|
|
|
]
|
2024-02-21 14:24:05 +00:00
|
|
|
|
|
|
|
result_fn_wrapper = _result_fn_wrapper
|
|
|
|
|
|
|
|
subjects = struct(
|
|
|
|
**(structs.to_dict(_subjects) | dict(
|
|
|
|
result = result_subject,
|
|
|
|
optional = optional_subject,
|
|
|
|
struct = struct_subject,
|
2024-02-22 11:05:41 +00:00
|
|
|
runfiles = runfiles_subject,
|
2024-02-23 21:54:01 +00:00
|
|
|
dict_key = dict_key_subject,
|
2024-02-21 14:24:05 +00:00
|
|
|
) | {factory.name: factory.factory for factory in FACTORIES})
|
|
|
|
)
|