Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion cc/toolchains/actions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,13 @@ cc_action_type(
def _cc_action_type_set_impl(ctx):
if not ctx.attr.actions and not ctx.attr.allow_empty:
fail("Each cc_action_type_set must contain at least one action type.")
actions = collect_action_types(ctx.attr.actions)
if ctx.attr.excludes:
excludes = {a[ActionTypeInfo]: True for a in ctx.attr.excludes}
actions = depset([a for a in actions.to_list() if a not in excludes])
return [ActionTypeSetInfo(
label = ctx.label,
actions = collect_action_types(ctx.attr.actions),
actions = actions,
)]

cc_action_type_set = rule(
Expand Down Expand Up @@ -95,6 +99,10 @@ cc_action_type_set(
mandatory = True,
doc = "A list of cc_action_type or cc_action_type_set",
),
"excludes": attr.label_list(
providers = [ActionTypeInfo],
doc = "A list of cc_action_type to exclude from the action set. Applied after accumulating all actions.",
),
"allow_empty": attr.bool(default = False),
},
provides = [ActionTypeSetInfo],
Expand Down
42 changes: 19 additions & 23 deletions cc/toolchains/actions/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -233,51 +233,47 @@ cc_action_type_set(
)

cc_action_type_set(
name = "cpp_compile_without_header_parsing",
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think we had a use for this one so I replaced it with the one that is used and includes more actions

name = "cpp_compile_actions",
actions = [
":linkstamp_compile",
":clif_match",
":cpp_compile",
":cpp_module_compile",
":cpp_header_parsing",
":cpp_module_codegen",
":clif_match",
":cpp_module_compile",
":linkstamp_compile",
":lto_backend",
":objcpp_compile",
],
)

cc_action_type_set(
name = "cpp_compile_actions",
name = "compile_actions",
actions = [
":cpp_compile_without_header_parsing",
":cpp_header_parsing",
":lto_backend",
":cpp_compile_actions",
":c_compile_actions",
":assembly_actions",
":objc_compile",
],
)

# This matches `compile_actions` with `lto_backend` omitted, because
# `lto_backend` actions do not instantiate the full set of build variables.
cc_action_type_set(
name = "source_compile_actions",
actions = [
":compile_actions_without_header_parsing",
":cpp_header_parsing",
":compile_actions",
],
excludes = [
# `lto_backend` actions do not instantiate the full set of build variables.
":lto_backend",
],
)

cc_action_type_set(
name = "compile_actions_without_header_parsing",
Comment thread
keith marked this conversation as resolved.
actions = [
":cpp_compile_without_header_parsing",
":c_compile_actions",
":assembly_actions",
":objc_compile",
":compile_actions",
],
)

cc_action_type_set(
name = "compile_actions",
actions = [
":source_compile_actions",
":lto_backend",
excludes = [
":cpp_header_parsing",
],
)

Expand Down
15 changes: 13 additions & 2 deletions cc/toolchains/args/compiler_input_flags/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,29 @@ load("//cc/toolchains:feature.bzl", "cc_feature")

cc_feature(
name = "feature",
args = [":flags"],
args = [
":flags",
":header_parsing_args",
],
overrides = "//cc/toolchains/features/legacy:compiler_input_flags",
visibility = ["//visibility:public"],
)

cc_args(
name = "flags",
actions = ["//cc/toolchains/actions:compile_actions"],
actions = ["//cc/toolchains/actions:compile_actions_without_header_parsing"],
args = [
"-c",
"{source_file}",
],
format = {"source_file": "//cc/toolchains/variables:source_file"},
requires_not_none = "//cc/toolchains/variables:source_file",
)

cc_args(
name = "header_parsing_args",
actions = ["//cc/toolchains/actions:cpp_header_parsing"],
args = ["{source_file}"],
format = {"source_file": "//cc/toolchains/variables:source_file"},
requires_not_none = "//cc/toolchains/variables:source_file",
)
3 changes: 2 additions & 1 deletion docs/toolchain_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ cc_action_type(
<pre>
load("@rules_cc//cc/toolchains/impl:documented_api.bzl", "cc_action_type_set")

cc_action_type_set(<a href="#cc_action_type_set-name">name</a>, <a href="#cc_action_type_set-actions">actions</a>, <a href="#cc_action_type_set-allow_empty">allow_empty</a>)
cc_action_type_set(<a href="#cc_action_type_set-name">name</a>, <a href="#cc_action_type_set-actions">actions</a>, <a href="#cc_action_type_set-allow_empty">allow_empty</a>, <a href="#cc_action_type_set-excludes">excludes</a>)
</pre>

Represents a set of actions.
Expand Down Expand Up @@ -80,6 +80,7 @@ cc_action_type_set(
| <a id="cc_action_type_set-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="cc_action_type_set-actions"></a>actions | A list of cc_action_type or cc_action_type_set | <a href="https://bazel.build/concepts/labels">List of labels</a> | required | |
| <a id="cc_action_type_set-allow_empty"></a>allow_empty | - | Boolean | optional | `False` |
| <a id="cc_action_type_set-excludes"></a>excludes | A list of cc_action_type to exclude from the action set. Applied after accumulating all actions. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |


<a id="cc_args_list"></a>
Expand Down
6 changes: 0 additions & 6 deletions tests/rule_based_toolchain/action_type_sets/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ action_type_set_diff_test(
expected = "//tests/rule_based_toolchain/action_type_sets:goldens/c_compile_actions.txt",
)

action_type_set_diff_test(
name = "cpp_compile_without_header_parsing_test",
action_type_set = "//cc/toolchains/actions:cpp_compile_without_header_parsing",
expected = "//tests/rule_based_toolchain/action_type_sets:goldens/cpp_compile_without_header_parsing.txt",
)

action_type_set_diff_test(
name = "cpp_compile_actions_test",
action_type_set = "//cc/toolchains/actions:cpp_compile_actions",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ c++-module-compile
c-compile
clif-match
linkstamp-compile
lto-backend
objc++-compile
objc-compile
preprocess-assemble

This file was deleted.

25 changes: 25 additions & 0 deletions tests/rule_based_toolchain/actions/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,31 @@ util.helper_target(
visibility = ["//tests/rule_based_toolchain:__subpackages__"],
)

util.helper_target(
cc_action_type_set,
name = "all_compile_except_c",
actions = [
":c_compile",
":cpp_compile",
],
excludes = [
":c_compile",
],
visibility = ["//tests/rule_based_toolchain:__subpackages__"],
)

util.helper_target(
cc_action_type_set,
name = "all_compile_except_c_nested",
actions = [
":all_compile",
],
excludes = [
":c_compile",
],
visibility = ["//tests/rule_based_toolchain:__subpackages__"],
)

analysis_test_suite(
name = "test_suite",
targets = TARGETS,
Expand Down
12 changes: 12 additions & 0 deletions tests/rule_based_toolchain/actions/actions_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,24 @@ def _test_action_types_impl(env, targets):
targets.cpp_compile.label,
])

def _test_action_type_set_excludes_impl(env, targets):
env.expect.that_target(targets.all_compile_except_c).provider(ActionTypeSetInfo) \
.actions().contains_exactly([targets.cpp_compile.label])

def _test_action_type_set_excludes_nested_impl(env, targets):
env.expect.that_target(targets.all_compile_except_c_nested).provider(ActionTypeSetInfo) \
.actions().contains_exactly([targets.cpp_compile.label])

TARGETS = [
":c_compile",
":cpp_compile",
":all_compile",
":all_compile_except_c",
":all_compile_except_c_nested",
]

TESTS = {
"actions_test": _test_action_types_impl,
"action_type_set_excludes_test": _test_action_type_set_excludes_impl,
"action_type_set_excludes_nested_test": _test_action_type_set_excludes_nested_impl,
}