diff --git a/cc/toolchains/action_type_config.bzl b/cc/toolchains/action_type_config.bzl deleted file mode 100644 index 4752ac2..0000000 --- a/cc/toolchains/action_type_config.bzl +++ /dev/null @@ -1,113 +0,0 @@ -# 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. -"""Implementation of cc_action_type_config.""" - -load( - "//cc/toolchains/impl:collect.bzl", - "collect_action_types", - "collect_features", - "collect_tools", -) -load( - ":cc_toolchain_info.bzl", - "ActionTypeConfigInfo", - "ActionTypeConfigSetInfo", - "ActionTypeSetInfo", - "FeatureSetInfo", -) - -def _cc_action_type_config_impl(ctx): - if not ctx.attr.action_types: - fail("At least one action type is required for cc_action_type_config") - if not ctx.attr.tools: - fail("At least one tool is required for cc_action_type_config") - - tools = tuple(collect_tools(ctx, ctx.attr.tools)) - implies = collect_features(ctx.attr.implies) - - configs = {} - for action_type in collect_action_types(ctx.attr.action_types).to_list(): - configs[action_type] = ActionTypeConfigInfo( - label = ctx.label, - action_type = action_type, - tools = tools, - implies = implies, - files = ctx.runfiles().merge_all([tool.runfiles for tool in tools]), - ) - - return [ActionTypeConfigSetInfo(label = ctx.label, configs = configs)] - -cc_action_type_config = rule( - implementation = _cc_action_type_config_impl, - # @unsorted-dict-items - attrs = { - "action_types": attr.label_list( - providers = [ActionTypeSetInfo], - mandatory = True, - doc = """A list of action names to apply this action to. - -See @toolchain//actions:all for valid options. -""", - ), - "tools": attr.label_list( - mandatory = True, - cfg = "exec", - allow_files = True, - doc = """The tool to use for the specified actions. - -A tool can be a `cc_tool`, or a binary. - -If multiple tools are specified, the first tool that has `with_features` that -satisfy the currently enabled feature set is used. -""", - ), - "implies": attr.label_list( - providers = [FeatureSetInfo], - doc = "Features that should be enabled when this action is used.", - ), - }, - provides = [ActionTypeConfigSetInfo], - doc = """Declares the configuration and selection of `cc_tool` rules. - -Action configs are bound to a toolchain through `action_configs`, and are the -driving mechanism for controlling toolchain tool invocation/behavior. - -Action configs define three key things: - -* Which tools to invoke for a given type of action. -* Tool features and compatibility. -* `cc_args`s that are unconditionally bound to a tool invocation. - -Examples: - - cc_action_config( - name = "ar", - action_types = ["@toolchain//actions:all_ar_actions"], - implies = [ - "@toolchain//features/legacy:archiver_flags", - "@toolchain//features/legacy:linker_param_file", - ], - tools = [":ar_tool"], - ) - - cc_action_config( - name = "clang", - action_types = [ - "@toolchain//actions:all_asm_actions", - "@toolchain//actions:all_c_compiler_actions", - ], - tools = [":clang_tool"], - ) -""", -) diff --git a/cc/toolchains/cc_toolchain_info.bzl b/cc/toolchains/cc_toolchain_info.bzl index d498dc4..36e922b 100644 --- a/cc/toolchains/cc_toolchain_info.bzl +++ b/cc/toolchains/cc_toolchain_info.bzl @@ -164,27 +164,6 @@ ToolConfigInfo = provider( }, ) -ActionTypeConfigInfo = provider( - doc = "Configuration of a Bazel action.", - # @unsorted-dict-items - fields = { - "label": "(Label) The label defining this provider. Place in error messages to simplify debugging", - "action_type": "(ActionTypeInfo) The type of the action", - "tools": "(Sequence[ToolInfo]) The tool applied to the action will be the first tool in the sequence with a feature set that matches the feature configuration", - "implies": "(depset[FeatureInfo]) Set of features implied by this action config", - "files": "(runfiles) The files required to run these actions", - }, -) - -ActionTypeConfigSetInfo = provider( - doc = "A set of action configs", - # @unsorted-dict-items - fields = { - "label": "(Label) The label defining this provider. Place in error messages to simplify debugging", - "configs": "(dict[ActionTypeInfo, ActionTypeConfigInfo]) A set of action configs", - }, -) - ToolchainConfigInfo = provider( doc = "The configuration for a toolchain", # @unsorted-dict-items @@ -192,7 +171,7 @@ ToolchainConfigInfo = provider( "label": "(Label) The label defining this provider. Place in error messages to simplify debugging", "features": "(Sequence[FeatureInfo]) The features available for this toolchain", "enabled_features": "(Sequence[FeatureInfo]) The features That are enabled by default for this toolchain", - "action_type_configs": "(dict[ActionTypeInfo, ActionTypeConfigInfo]) The configuration of action configs for the toolchain.", + "tool_map": "(ToolConfigInfo) A provider mapping toolchain action types to tools.", "args": "(Sequence[ArgsInfo]) A list of arguments to be unconditionally applied to the toolchain.", "files": "(dict[ActionTypeInfo, depset[File]]) Files required for the toolchain, keyed by the action type.", }, diff --git a/cc/toolchains/impl/collect.bzl b/cc/toolchains/impl/collect.bzl index 6dd760a..a1daa23 100644 --- a/cc/toolchains/impl/collect.bzl +++ b/cc/toolchains/impl/collect.bzl @@ -15,7 +15,6 @@ load( "//cc/toolchains:cc_toolchain_info.bzl", - "ActionTypeConfigSetInfo", "ActionTypeSetInfo", "ArgsListInfo", "FeatureSetInfo", @@ -151,22 +150,3 @@ def collect_args_lists(targets, label): for k, v in by_action.items() ]), ) - -def collect_action_type_config_sets(targets, label, fail = fail): - """Collects several `cc_action_type_config` labels together. - - Args: - targets: (List[Target]) A list of targets providing ActionTypeConfigSetInfo - label: The label to apply to the resulting config. - fail: (function) The fail function. Should only be used in tests. - Returns: - A combined ActionTypeConfigSetInfo representing a variety of action - types. - """ - configs = {} - for atcs in collect_provider(targets, ActionTypeConfigSetInfo): - for action_type, config in atcs.configs.items(): - if action_type in configs: - fail("The action type %s is configured by both %s and %s. Each action type may only be configured once." % (action_type.label, config.label, configs[action_type].label)) - configs[action_type] = config - return ActionTypeConfigSetInfo(label = label, configs = configs) diff --git a/cc/toolchains/impl/legacy_converter.bzl b/cc/toolchains/impl/legacy_converter.bzl index 1d74d88..99cc353 100644 --- a/cc/toolchains/impl/legacy_converter.bzl +++ b/cc/toolchains/impl/legacy_converter.bzl @@ -131,15 +131,16 @@ def convert_tool(tool): with_features = [], ) -def _convert_action_type_config(atc): - implies = sorted([ft.name for ft in atc.implies.to_list()]) - - return legacy_action_config( - action_name = atc.action_type.name, - enabled = True, - tools = [convert_tool(tool) for tool in atc.tools], - implies = implies, - ) +def _convert_tool_map(tool_map): + return [ + legacy_action_config( + action_name = action_type.name, + enabled = True, + tools = [convert_tool(tool_map.configs[action_type])], + implies = [], + ) + for action_type in tool_map.configs.keys() + ] def convert_toolchain(toolchain): """Converts a rule-based toolchain into the legacy providers. @@ -165,10 +166,7 @@ def convert_toolchain(toolchain): mutually_exclusive = [], external = False, ))) - action_configs = [ - _convert_action_type_config(atc) - for atc in toolchain.action_type_configs.values() - ] + action_configs = _convert_tool_map(toolchain.tool_map) return struct( features = [ft for ft in features if ft != None], diff --git a/cc/toolchains/impl/toolchain_config.bzl b/cc/toolchains/impl/toolchain_config.bzl index f2d95d1..24af9c0 100644 --- a/cc/toolchains/impl/toolchain_config.bzl +++ b/cc/toolchains/impl/toolchain_config.bzl @@ -17,10 +17,10 @@ load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") load("@bazel_skylib//rules/directory:providers.bzl", "DirectoryInfo") load( "//cc/toolchains:cc_toolchain_info.bzl", - "ActionTypeConfigSetInfo", "ActionTypeSetInfo", "ArgsListInfo", "FeatureSetInfo", + "ToolConfigInfo", "ToolchainConfigInfo", ) load(":collect.bzl", "collect_action_types") @@ -60,7 +60,7 @@ def _cc_toolchain_config_impl(ctx): label = ctx.label, known_features = ctx.attr.known_features + [ctx.attr._builtin_features], enabled_features = ctx.attr.enabled_features, - action_type_configs = ctx.attr.action_type_configs, + tool_map = ctx.attr.tool_map, args = ctx.attr.args, ) @@ -108,7 +108,7 @@ cc_toolchain_config = rule( # @unsorted-dict-items attrs = { # Attributes new to this rule. - "action_type_configs": attr.label_list(providers = [ActionTypeConfigSetInfo]), + "tool_map": attr.label(providers = [ToolConfigInfo], mandatory = True), "args": attr.label_list(providers = [ArgsListInfo]), "known_features": attr.label_list(providers = [FeatureSetInfo]), "enabled_features": attr.label_list(providers = [FeatureSetInfo]), diff --git a/cc/toolchains/impl/toolchain_config_info.bzl b/cc/toolchains/impl/toolchain_config_info.bzl index 61c5dcb..a2c6bf1 100644 --- a/cc/toolchains/impl/toolchain_config_info.bzl +++ b/cc/toolchains/impl/toolchain_config_info.bzl @@ -13,9 +13,9 @@ # limitations under the License. """Helper functions to create and validate a ToolchainConfigInfo.""" -load("//cc/toolchains:cc_toolchain_info.bzl", "ToolchainConfigInfo") +load("//cc/toolchains:cc_toolchain_info.bzl", "ToolConfigInfo", "ToolchainConfigInfo") load(":args_utils.bzl", "get_action_type") -load(":collect.bzl", "collect_action_type_config_sets", "collect_args_lists", "collect_features") +load(":collect.bzl", "collect_args_lists", "collect_features") visibility([ "//cc/toolchains/...", @@ -106,9 +106,6 @@ def _validate_args(self, known_features, fail): fail, ) -def _validate_action_config(self, known_features, fail): - _validate_implies(self, known_features, fail = fail) - def _validate_feature(self, known_features, fail): _validate_requires_any_of_feature_set(self, known_features, fail = fail) for arg in self.args.args: @@ -120,19 +117,17 @@ def _validate_toolchain(self, fail = fail): for feature in self.features: _validate_feature(feature, known_features, fail = fail) - for atc in self.action_type_configs.values(): - _validate_action_config(atc, known_features, fail = fail) for args in self.args: _validate_args(args, known_features, fail = fail) -def _collect_files_for_action_type(atc, features, args): - transitive_files = [atc.files.files, get_action_type(args, atc.action_type).files] +def _collect_files_for_action_type(action_type, tool_map, features, args): + transitive_files = [tool_map[action_type].runfiles.files, get_action_type(args, action_type).files] for ft in features: - transitive_files.append(get_action_type(ft.args, atc.action_type).files) + transitive_files.append(get_action_type(ft.args, action_type).files) return depset(transitive = transitive_files) -def toolchain_config_info(label, known_features = [], enabled_features = [], args = [], action_type_configs = [], fail = fail): +def toolchain_config_info(label, known_features = [], enabled_features = [], args = [], tool_map = None, fail = fail): """Generates and validates a ToolchainConfigInfo from lists of labels. Args: @@ -141,8 +136,7 @@ def toolchain_config_info(label, known_features = [], enabled_features = [], arg enabled_features: (List[Target]) A list of features that are enabled by default. Every enabled feature is implicitly also a known feature. args: (List[Target]) A list of targets providing ArgsListInfo - action_type_configs: (List[Target]) A list of targets providing - ActionTypeConfigSetInfo + tool_map: (Target) A target providing ToolMapInfo. fail: A fail function. Use only during tests. Returns: A validated ToolchainConfigInfo @@ -155,22 +149,25 @@ def toolchain_config_info(label, known_features = [], enabled_features = [], arg features = collect_features(enabled_features + known_features).to_list() enabled_features = collect_features(enabled_features).to_list() + if tool_map == None: + fail("tool_map is required") + + # The `return` here is to support testing, since injecting `fail()` has a + # side-effect of allowing code to continue. + return None # buildifier: disable=unreachable + args = collect_args_lists(args, label = label) - action_type_configs = collect_action_type_config_sets( - action_type_configs, - label = label, - fail = fail, - ).configs + tools = tool_map[ToolConfigInfo].configs files = { - atc.action_type: _collect_files_for_action_type(atc, features, args) - for atc in action_type_configs.values() + action_type: _collect_files_for_action_type(action_type, tools, features, args) + for action_type in tools.keys() } toolchain_config = ToolchainConfigInfo( label = label, features = features, enabled_features = enabled_features, - action_type_configs = action_type_configs, + tool_map = tool_map[ToolConfigInfo], args = args.args, files = files, ) diff --git a/tests/rule_based_toolchain/action_type_config/BUILD b/tests/rule_based_toolchain/action_type_config/BUILD deleted file mode 100644 index 3c44113..0000000 --- a/tests/rule_based_toolchain/action_type_config/BUILD +++ /dev/null @@ -1,38 +0,0 @@ -load("@rules_testing//lib:util.bzl", "util") -load("//cc/toolchains:action_type_config.bzl", "cc_action_type_config") -load("//tests/rule_based_toolchain:analysis_test_suite.bzl", "analysis_test_suite") -load(":action_type_config_test.bzl", "TARGETS", "TESTS") - -util.helper_target( - cc_action_type_config, - name = "file_map", - action_types = ["//tests/rule_based_toolchain/actions:all_compile"], - tools = [ - "//tests/rule_based_toolchain/testdata:bin_wrapper.sh", - "//tests/rule_based_toolchain/tool:wrapped_tool", - ], -) - -util.helper_target( - cc_action_type_config, - name = "c_compile_config", - action_types = ["//tests/rule_based_toolchain/actions:c_compile"], - tools = [ - "//tests/rule_based_toolchain/testdata:bin_wrapper.sh", - ], -) - -util.helper_target( - cc_action_type_config, - name = "cpp_compile_config", - action_types = ["//tests/rule_based_toolchain/actions:cpp_compile"], - tools = [ - "//tests/rule_based_toolchain/testdata:bin_wrapper.sh", - ], -) - -analysis_test_suite( - name = "test_suite", - targets = TARGETS, - tests = TESTS, -) diff --git a/tests/rule_based_toolchain/action_type_config/action_type_config_test.bzl b/tests/rule_based_toolchain/action_type_config/action_type_config_test.bzl deleted file mode 100644 index 3394ee2..0000000 --- a/tests/rule_based_toolchain/action_type_config/action_type_config_test.bzl +++ /dev/null @@ -1,81 +0,0 @@ -# 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. -"""Tests for the action_type_config rule.""" - -load( - "//cc/toolchains:cc_toolchain_info.bzl", - "ActionTypeConfigSetInfo", - "ActionTypeInfo", -) -load("//cc/toolchains/impl:collect.bzl", _collect_action_type_configs = "collect_action_type_config_sets") -load("//tests/rule_based_toolchain:subjects.bzl", "result_fn_wrapper", "subjects") - -visibility("private") - -_TOOL_FILES = [ - "tests/rule_based_toolchain/testdata/bin", - "tests/rule_based_toolchain/testdata/bin_wrapper", - "tests/rule_based_toolchain/testdata/bin_wrapper.sh", -] - -collect_action_type_configs = result_fn_wrapper(_collect_action_type_configs) - -def _files_taken_test(env, targets): - configs = env.expect.that_target(targets.file_map).provider(ActionTypeConfigSetInfo).configs() - c_compile = configs.get(targets.c_compile[ActionTypeInfo]) - c_compile.files().contains_exactly(_TOOL_FILES) - - cpp_compile = configs.get(targets.cpp_compile[ActionTypeInfo]) - cpp_compile.files().contains_exactly(_TOOL_FILES) - -def _merge_distinct_configs_succeeds_test(env, targets): - configs = env.expect.that_value( - collect_action_type_configs( - targets = [targets.c_compile_config, targets.cpp_compile_config], - label = env.ctx.label, - ), - factory = subjects.result(subjects.ActionTypeConfigSetInfo), - ).ok().configs() - configs.get(targets.c_compile[ActionTypeInfo]).label().equals( - targets.c_compile_config.label, - ) - configs.get(targets.cpp_compile[ActionTypeInfo]).label().equals( - targets.cpp_compile_config.label, - ) - -def _merge_overlapping_configs_fails_test(env, targets): - err = env.expect.that_value( - collect_action_type_configs( - targets = [targets.file_map, targets.c_compile_config], - label = env.ctx.label, - ), - factory = subjects.result(subjects.ActionTypeConfigSetInfo), - ).err() - err.contains("//tests/rule_based_toolchain/actions:c_compile is configured by both") - err.contains("//tests/rule_based_toolchain/action_type_config:c_compile_config") - err.contains("//tests/rule_based_toolchain/action_type_config:file_map") - -TARGETS = [ - ":file_map", - ":c_compile_config", - ":cpp_compile_config", - "//tests/rule_based_toolchain/actions:c_compile", - "//tests/rule_based_toolchain/actions:cpp_compile", -] - -TESTS = { - "files_taken_test": _files_taken_test, - "merge_distinct_configs_succeeds_test": _merge_distinct_configs_succeeds_test, - "merge_overlapping_configs_fails_test": _merge_overlapping_configs_fails_test, -} diff --git a/tests/rule_based_toolchain/generics.bzl b/tests/rule_based_toolchain/generics.bzl index c4ec9e8..505b09e 100644 --- a/tests/rule_based_toolchain/generics.bzl +++ b/tests/rule_based_toolchain/generics.bzl @@ -136,5 +136,6 @@ dict_key_subject = lambda factory: lambda value, *, meta: struct( value[key], meta = meta.derive("get({})".format(key)), ), + keys = lambda: subjects.collection(value.keys(), meta = meta.derive("keys()")), contains = lambda key: subjects.bool(key in value, meta = meta.derive("contains({})".format(key))), ) diff --git a/tests/rule_based_toolchain/subjects.bzl b/tests/rule_based_toolchain/subjects.bzl index a02552b..92f6fc8 100644 --- a/tests/rule_based_toolchain/subjects.bzl +++ b/tests/rule_based_toolchain/subjects.bzl @@ -17,8 +17,6 @@ load("@bazel_skylib//lib:structs.bzl", "structs") load("@rules_testing//lib:truth.bzl", _subjects = "subjects") load( "//cc/toolchains:cc_toolchain_info.bzl", - "ActionTypeConfigInfo", - "ActionTypeConfigSetInfo", "ActionTypeInfo", "ActionTypeSetInfo", "ArgsInfo", @@ -193,27 +191,6 @@ _ToolConfigFactory = generate_factory( ), ) -# buildifier: disable=name-conventions -_ActionTypeConfigFactory = generate_factory( - ActionTypeConfigInfo, - "ActionTypeConfigInfo", - dict( - action_type = _ActionTypeFactory, - tools = ProviderSequence(_ToolFactory), - implies = ProviderDepset(_FeatureFactory), - files = runfiles_subject, - ), -) - -# buildifier: disable=name-conventions -_ActionTypeConfigSetFactory = generate_factory( - ActionTypeConfigSetInfo, - "ActionTypeConfigSetInfo", - dict( - configs = dict_key_subject(_ActionTypeConfigFactory.factory), - ), -) - # buildifier: disable=name-conventions _ToolchainConfigFactory = generate_factory( ToolchainConfigInfo, @@ -221,7 +198,7 @@ _ToolchainConfigFactory = generate_factory( dict( features = ProviderDepset(_FeatureFactory), enabled_features = _subjects.collection, - action_type_configs = dict_key_subject(_ActionTypeConfigFactory.factory), + tool_map = optional_subject(_ToolConfigFactory.factory), args = ProviderSequence(_ArgsFactory), files = dict_key_subject(_subjects.depset_file), ), @@ -239,7 +216,6 @@ FACTORIES = [ _FeatureSetFactory, _ToolFactory, _ToolConfigFactory, - _ActionTypeConfigSetFactory, _ToolchainConfigFactory, ] diff --git a/tests/rule_based_toolchain/tool_config/BUILD b/tests/rule_based_toolchain/tool_map/BUILD similarity index 100% rename from tests/rule_based_toolchain/tool_config/BUILD rename to tests/rule_based_toolchain/tool_map/BUILD diff --git a/tests/rule_based_toolchain/tool_config/tool_map_test.bzl b/tests/rule_based_toolchain/tool_map/tool_map_test.bzl similarity index 100% rename from tests/rule_based_toolchain/tool_config/tool_map_test.bzl rename to tests/rule_based_toolchain/tool_map/tool_map_test.bzl diff --git a/tests/rule_based_toolchain/toolchain_config/BUILD b/tests/rule_based_toolchain/toolchain_config/BUILD index 7acb55e..c1199f8 100644 --- a/tests/rule_based_toolchain/toolchain_config/BUILD +++ b/tests/rule_based_toolchain/toolchain_config/BUILD @@ -1,8 +1,8 @@ load("@rules_testing//lib:util.bzl", "util") -load("//cc/toolchains:action_type_config.bzl", "cc_action_type_config") load("//cc/toolchains:args.bzl", "cc_args") load("//cc/toolchains:feature.bzl", "cc_feature") load("//cc/toolchains:feature_set.bzl", "cc_feature_set") +load("//cc/toolchains:tool_map.bzl", "cc_tool_map") load("//cc/toolchains/impl:external_feature.bzl", "cc_external_feature") load("//cc/toolchains/impl:toolchain_config.bzl", "cc_legacy_file_group", "cc_toolchain_config") load("//tests/rule_based_toolchain:analysis_test_suite.bzl", "analysis_test_suite") @@ -43,7 +43,6 @@ util.helper_target( util.helper_target( cc_toolchain_config, name = "collects_files_toolchain_config", - action_type_configs = [":compile_config"], args = [":c_compile_args"], cxx_builtin_include_directories = [ "//tests/rule_based_toolchain/testdata:directory", @@ -52,6 +51,7 @@ util.helper_target( known_features = [":compile_feature"], skip_experimental_flag_validation_for_test = True, sysroot = "//tests/rule_based_toolchain/testdata:directory", + tool_map = ":compile_tool_map", ) util.helper_target( @@ -77,12 +77,11 @@ util.helper_target( ) util.helper_target( - cc_action_type_config, - name = "compile_config", - action_types = ["//tests/rule_based_toolchain/actions:all_compile"], - tools = [ - "//tests/rule_based_toolchain/tool:wrapped_tool", - ], + cc_tool_map, + name = "compile_tool_map", + tools = { + "//tests/rule_based_toolchain/actions:all_compile": "//tests/rule_based_toolchain/tool:wrapped_tool", + }, ) util.helper_target( @@ -93,13 +92,17 @@ util.helper_target( ) util.helper_target( - cc_action_type_config, - name = "c_compile_config", - action_types = ["//tests/rule_based_toolchain/actions:c_compile"], - implies = [":simple_feature"], - tools = [ - "//tests/rule_based_toolchain/tool:wrapped_tool", - ], + cc_tool_map, + name = "c_compile_tool_map", + tools = { + "//tests/rule_based_toolchain/actions:c_compile": "//tests/rule_based_toolchain/tool:wrapped_tool", + }, +) + +util.helper_target( + cc_tool_map, + name = "empty_tool_map", + tools = {}, ) util.helper_target( diff --git a/tests/rule_based_toolchain/toolchain_config/toolchain_config_test.bzl b/tests/rule_based_toolchain/toolchain_config/toolchain_config_test.bzl index 29ab9ab..e2c56be 100644 --- a/tests/rule_based_toolchain/toolchain_config/toolchain_config_test.bzl +++ b/tests/rule_based_toolchain/toolchain_config/toolchain_config_test.bzl @@ -50,13 +50,26 @@ def _expect_that_toolchain(env, expr = None, **kwargs): factory = subjects.result(subjects.ToolchainConfigInfo), ) -def _empty_toolchain_valid_test(env, _targets): - _expect_that_toolchain(env).ok() +def _missing_tool_map_invalid_test(env, _targets): + _expect_that_toolchain( + env, + tool_map = None, + expr = "missing_tool_map", + ).err().contains( + "tool_map is required", + ) + +def _empty_toolchain_valid_test(env, targets): + _expect_that_toolchain( + env, + tool_map = targets.empty_tool_map, # tool_map is always required. + ).ok() def _duplicate_feature_names_invalid_test(env, targets): _expect_that_toolchain( env, known_features = [targets.simple_feature, targets.same_feature_name], + tool_map = targets.empty_tool_map, expr = "duplicate_feature_name", ).err().contains_all_of([ "The feature name simple_feature was defined by", @@ -68,47 +81,22 @@ def _duplicate_feature_names_invalid_test(env, targets): _expect_that_toolchain( env, known_features = [targets.builtin_feature, targets.overrides_feature], + tool_map = targets.empty_tool_map, expr = "override_feature", ).ok() -def _duplicate_action_type_invalid_test(env, targets): - _expect_that_toolchain( - env, - known_features = [targets.simple_feature], - action_type_configs = [targets.compile_config, targets.c_compile_config], - ).err().contains_all_of([ - "The action type %s is configured by" % targets.c_compile.label, - targets.compile_config.label, - targets.c_compile_config.label, - ]) - -def _action_config_implies_missing_feature_invalid_test(env, targets): - _expect_that_toolchain( - env, - known_features = [targets.simple_feature], - action_type_configs = [targets.c_compile_config], - expr = "action_type_config_with_implies", - ).ok() - - _expect_that_toolchain( - env, - known_features = [], - action_type_configs = [targets.c_compile_config], - expr = "action_type_config_missing_implies", - ).err().contains( - "%s implies the feature %s" % (targets.c_compile_config.label, targets.simple_feature.label), - ) - def _feature_config_implies_missing_feature_invalid_test(env, targets): _expect_that_toolchain( env, expr = "feature_with_implies", known_features = [targets.simple_feature, targets.implies_simple_feature], + tool_map = targets.empty_tool_map, ).ok() _expect_that_toolchain( env, known_features = [targets.implies_simple_feature], + tool_map = targets.empty_tool_map, expr = "feature_missing_implies", ).err().contains( "%s implies the feature %s" % (targets.implies_simple_feature.label, targets.simple_feature.label), @@ -118,16 +106,19 @@ def _feature_missing_requirements_invalid_test(env, targets): _expect_that_toolchain( env, known_features = [targets.requires_any_simple_feature, targets.simple_feature], + tool_map = targets.empty_tool_map, expr = "requires_any_simple_has_simple", ).ok() _expect_that_toolchain( env, known_features = [targets.requires_any_simple_feature, targets.simple_feature2], + tool_map = targets.empty_tool_map, expr = "requires_any_simple_has_simple2", ).ok() _expect_that_toolchain( env, known_features = [targets.requires_any_simple_feature], + tool_map = targets.empty_tool_map, expr = "requires_any_simple_has_none", ).err().contains( "It is impossible to enable %s" % targets.requires_any_simple_feature.label, @@ -136,11 +127,13 @@ def _feature_missing_requirements_invalid_test(env, targets): _expect_that_toolchain( env, known_features = [targets.requires_all_simple_feature, targets.simple_feature, targets.simple_feature2], + tool_map = targets.empty_tool_map, expr = "requires_all_simple_has_both", ).ok() _expect_that_toolchain( env, known_features = [targets.requires_all_simple_feature, targets.simple_feature], + tool_map = targets.empty_tool_map, expr = "requires_all_simple_has_simple", ).err().contains( "It is impossible to enable %s" % targets.requires_all_simple_feature.label, @@ -148,6 +141,7 @@ def _feature_missing_requirements_invalid_test(env, targets): _expect_that_toolchain( env, known_features = [targets.requires_all_simple_feature, targets.simple_feature2], + tool_map = targets.empty_tool_map, expr = "requires_all_simple_has_simple2", ).err().contains( "It is impossible to enable %s" % targets.requires_all_simple_feature.label, @@ -158,12 +152,14 @@ def _args_missing_requirements_invalid_test(env, targets): env, args = [targets.requires_all_simple_args], known_features = [targets.simple_feature, targets.simple_feature2], + tool_map = targets.empty_tool_map, expr = "has_both", ).ok() _expect_that_toolchain( env, args = [targets.requires_all_simple_args], known_features = [targets.simple_feature], + tool_map = targets.empty_tool_map, expr = "has_only_one", ).err().contains( "It is impossible to enable %s" % targets.requires_all_simple_args.label, @@ -217,9 +213,9 @@ def _toolchain_collects_files_test(env, targets): ), ]).in_order() - exe = tc.action_type_configs().get( + exe = tc.tool_map().some().configs().get( targets.c_compile[ActionTypeInfo], - ).actual.tools[0].exe + ).actual.exe env.expect.that_collection(legacy.action_configs).contains_exactly([ legacy_action_config( action_name = "c_compile", @@ -238,13 +234,14 @@ TARGETS = [ "//tests/rule_based_toolchain/actions:c_compile", "//tests/rule_based_toolchain/actions:cpp_compile", ":builtin_feature", - ":compile_config", + ":compile_tool_map", ":collects_files_c_compile", ":collects_files_cpp_compile", ":collects_files_toolchain_config", ":compile_feature", ":c_compile_args", - ":c_compile_config", + ":c_compile_tool_map", + ":empty_tool_map", ":implies_simple_feature", ":overrides_feature", ":requires_any_simple_feature", @@ -258,9 +255,8 @@ TARGETS = [ # @unsorted-dict-items TESTS = { "empty_toolchain_valid_test": _empty_toolchain_valid_test, + "missing_tool_map_invalid_test": _missing_tool_map_invalid_test, "duplicate_feature_names_fail_validation_test": _duplicate_feature_names_invalid_test, - "duplicate_action_type_invalid_test": _duplicate_action_type_invalid_test, - "action_config_implies_missing_feature_invalid_test": _action_config_implies_missing_feature_invalid_test, "feature_config_implies_missing_feature_invalid_test": _feature_config_implies_missing_feature_invalid_test, "feature_missing_requirements_invalid_test": _feature_missing_requirements_invalid_test, "args_missing_requirements_invalid_test": _args_missing_requirements_invalid_test,