diff --git a/cc/toolchains/actions.bzl b/cc/toolchains/actions.bzl index 84dc83796..9a8928e5b 100644 --- a/cc/toolchains/actions.bzl +++ b/cc/toolchains/actions.bzl @@ -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( @@ -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], diff --git a/cc/toolchains/actions/BUILD b/cc/toolchains/actions/BUILD index 3f73f21ed..cbfd95043 100644 --- a/cc/toolchains/actions/BUILD +++ b/cc/toolchains/actions/BUILD @@ -233,51 +233,47 @@ cc_action_type_set( ) cc_action_type_set( - name = "cpp_compile_without_header_parsing", + 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", 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", ], ) diff --git a/cc/toolchains/args/compiler_input_flags/BUILD b/cc/toolchains/args/compiler_input_flags/BUILD index 592f1e748..1cca4c929 100644 --- a/cc/toolchains/args/compiler_input_flags/BUILD +++ b/cc/toolchains/args/compiler_input_flags/BUILD @@ -3,14 +3,17 @@ 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}", @@ -18,3 +21,11 @@ cc_args( 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", +) diff --git a/docs/toolchain_api.md b/docs/toolchain_api.md index 1e0f5c798..85866aaea 100755 --- a/docs/toolchain_api.md +++ b/docs/toolchain_api.md @@ -51,7 +51,7 @@ cc_action_type(
 load("@rules_cc//cc/toolchains/impl:documented_api.bzl", "cc_action_type_set")
 
-cc_action_type_set(name, actions, allow_empty)
+cc_action_type_set(name, actions, allow_empty, excludes)
 
Represents a set of actions. @@ -80,6 +80,7 @@ cc_action_type_set( | name | A unique name for this target. | Name | required | | | actions | A list of cc_action_type or cc_action_type_set | List of labels | required | | | allow_empty | - | Boolean | optional | `False` | +| excludes | A list of cc_action_type to exclude from the action set. Applied after accumulating all actions. | List of labels | optional | `[]` | diff --git a/tests/rule_based_toolchain/action_type_sets/BUILD b/tests/rule_based_toolchain/action_type_sets/BUILD index 8cdde7d2f..c4053972a 100644 --- a/tests/rule_based_toolchain/action_type_sets/BUILD +++ b/tests/rule_based_toolchain/action_type_sets/BUILD @@ -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", diff --git a/tests/rule_based_toolchain/action_type_sets/goldens/compile_actions_without_header_parsing.txt b/tests/rule_based_toolchain/action_type_sets/goldens/compile_actions_without_header_parsing.txt index 5e5c26f44..4037fe262 100644 --- a/tests/rule_based_toolchain/action_type_sets/goldens/compile_actions_without_header_parsing.txt +++ b/tests/rule_based_toolchain/action_type_sets/goldens/compile_actions_without_header_parsing.txt @@ -5,6 +5,7 @@ c++-module-compile c-compile clif-match linkstamp-compile +lto-backend objc++-compile objc-compile preprocess-assemble diff --git a/tests/rule_based_toolchain/action_type_sets/goldens/cpp_compile_without_header_parsing.txt b/tests/rule_based_toolchain/action_type_sets/goldens/cpp_compile_without_header_parsing.txt deleted file mode 100644 index ba8a18f45..000000000 --- a/tests/rule_based_toolchain/action_type_sets/goldens/cpp_compile_without_header_parsing.txt +++ /dev/null @@ -1,6 +0,0 @@ -c++-compile -c++-module-codegen -c++-module-compile -clif-match -linkstamp-compile -objc++-compile diff --git a/tests/rule_based_toolchain/actions/BUILD b/tests/rule_based_toolchain/actions/BUILD index 4e45f7ec7..20ca7c283 100644 --- a/tests/rule_based_toolchain/actions/BUILD +++ b/tests/rule_based_toolchain/actions/BUILD @@ -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, diff --git a/tests/rule_based_toolchain/actions/actions_test.bzl b/tests/rule_based_toolchain/actions/actions_test.bzl index 284ed9aea..1f677a6ac 100644 --- a/tests/rule_based_toolchain/actions/actions_test.bzl +++ b/tests/rule_based_toolchain/actions/actions_test.bzl @@ -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, }