-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement cc_action_type_config. Rename it from cc_action_config, to make it clear that we are not configuring an action, but rather configuring a type of action. END_PUBLIC PiperOrigin-RevId: 610518142 Change-Id: Ic10755952ee786d30a3a5564aa09a8dc16499f3a
- Loading branch information
1 parent
0d68da5
commit c5493f9
Showing
11 changed files
with
368 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
# 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:args_utils.bzl", "get_action_type") | ||
load( | ||
"//cc/toolchains/impl:collect.bzl", | ||
"collect_action_types", | ||
"collect_args_lists", | ||
"collect_features", | ||
"collect_files", | ||
"collect_tools", | ||
) | ||
load( | ||
":cc_toolchain_info.bzl", | ||
"ActionTypeConfigInfo", | ||
"ActionTypeConfigSetInfo", | ||
"ActionTypeSetInfo", | ||
"ArgsListInfo", | ||
"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) | ||
args_list = collect_args_lists(ctx.attr.args, ctx.label) | ||
files = collect_files(ctx.attr.additional_files) | ||
|
||
configs = {} | ||
for action_type in collect_action_types(ctx.attr.action_types).to_list(): | ||
for_action = get_action_type(args_list, action_type) | ||
configs[action_type] = ActionTypeConfigInfo( | ||
label = ctx.label, | ||
action_type = action_type, | ||
tools = tools, | ||
args = for_action.args, | ||
implies = implies, | ||
files = ctx.runfiles( | ||
transitive_files = depset(transitive = [files, for_action.files]), | ||
).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. | ||
""", | ||
), | ||
"args": attr.label_list( | ||
providers = [ArgsListInfo], | ||
doc = """Labels that point to `cc_arg`s / `cc_arg_list`s that are | ||
unconditionally bound to the specified actions. | ||
""", | ||
), | ||
"implies": attr.label_list( | ||
providers = [FeatureSetInfo], | ||
doc = "Features that should be enabled when this action is used.", | ||
), | ||
"additional_files": attr.label_list( | ||
allow_files = True, | ||
doc = """Files required for this action type. | ||
For example, the c-compile action type might add the C standard library header | ||
files from the sysroot. | ||
""", | ||
), | ||
}, | ||
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"], | ||
) | ||
""", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# 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. | ||
""".""" | ||
|
||
def get_action_type(args_list, action_type): | ||
"""Returns the corresponding entry in ArgsListInfo.by_action. | ||
Args: | ||
args_list: (ArgsListInfo) The args list to look through | ||
action_type: (ActionTypeInfo) The action type to look up. | ||
Returns: | ||
The information corresponding to this action type. | ||
""" | ||
for args in args_list.by_action: | ||
if args.action == action_type: | ||
return args | ||
|
||
return struct(action = action_type, args = tuple(), files = depset([])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
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"], | ||
additional_files = [ | ||
"//tests/rule_based_toolchain/testdata:multiple2", | ||
], | ||
args = ["//tests/rule_based_toolchain/args_list"], | ||
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, | ||
) |
Oops, something went wrong.