diff --git a/cc/toolchains/args.bzl b/cc/toolchains/args.bzl index a852292f5..95cdf5217 100644 --- a/cc/toolchains/args.bzl +++ b/cc/toolchains/args.bzl @@ -67,7 +67,7 @@ def _cc_args_impl(ctx): ) files = nested.files else: - files = collect_files(ctx.attr.data + ctx.attr.allowlist_include_directories) + files = collect_files(ctx.attr.data) requires = collect_provider(ctx.attr.requires_any_of, FeatureConstraintInfo) @@ -262,6 +262,9 @@ def cc_args( your toolchain and you've ensured that the toolchain is compiling with the `-no-canonical-prefixes` and/or `-fno-canonical-system-headers` arguments. + These files are not automatically passed to each action. If they + need to be, add them to 'data' as well. + This can help work around errors like: `the source file 'main.c' includes the following non-builtin files with absolute paths (if these are builtin files, make sure these paths are in your toolchain)`. diff --git a/cc/toolchains/impl/nested_args.bzl b/cc/toolchains/impl/nested_args.bzl index fa17d790e..e59711d5a 100644 --- a/cc/toolchains/impl/nested_args.bzl +++ b/cc/toolchains/impl/nested_args.bzl @@ -99,7 +99,7 @@ def nested_args_provider_from_ctx(ctx, maybe_used_vars = []): args = ctx.attr.args, format = ctx.attr.format, nested = collect_provider(ctx.attr.nested, NestedArgsInfo), - files = collect_files(ctx.attr.data + getattr(ctx.attr, "allowlist_include_directories", [])), + files = collect_files(ctx.attr.data), iterate_over = ctx.attr.iterate_over, requires_not_none = _var(ctx.attr.requires_not_none), requires_none = _var(ctx.attr.requires_none), diff --git a/cc/toolchains/tool.bzl b/cc/toolchains/tool.bzl index ee0a49bc5..51ba7c31b 100644 --- a/cc/toolchains/tool.bzl +++ b/cc/toolchains/tool.bzl @@ -30,7 +30,7 @@ def _cc_tool_impl(ctx): else: fail("Expected cc_tool's src attribute to be either an executable or a single file") - runfiles = collect_data(ctx, ctx.attr.data + [ctx.attr.src] + ctx.attr.allowlist_include_directories) + runfiles = collect_data(ctx, ctx.attr.data + [ctx.attr.src]) tool = ToolInfo( label = ctx.label, exe = exe, @@ -93,6 +93,9 @@ As a rule of thumb, only use this if Bazel is complaining about absolute paths i toolchain and you've ensured that the toolchain is compiling with the `-no-canonical-prefixes` and/or `-fno-canonical-system-headers` arguments. +These files are not automatically passed to each action. If they need to be, +add them to 'data' as well. + This can help work around errors like: `the source file 'main.c' includes the following non-builtin files with absolute paths (if these are builtin files, make sure these paths are in your toolchain)`. diff --git a/tests/rule_based_toolchain/args/BUILD b/tests/rule_based_toolchain/args/BUILD index dd72250df..7f47073c4 100644 --- a/tests/rule_based_toolchain/args/BUILD +++ b/tests/rule_based_toolchain/args/BUILD @@ -63,6 +63,15 @@ util.helper_target( args = ["--secret-builtin-include-dir"], ) +util.helper_target( + cc_args, + name = "with_dir_and_data", + actions = ["//tests/rule_based_toolchain/actions:all_compile"], + allowlist_include_directories = ["//tests/rule_based_toolchain/testdata:directory"], + args = ["--secret-builtin-include-dir"], + data = ["//tests/rule_based_toolchain/testdata:directory"], +) + util.helper_target( cc_args, name = "good_env_format", diff --git a/tests/rule_based_toolchain/args/args_test.bzl b/tests/rule_based_toolchain/args/args_test.bzl index 619c7ba89..2adc82b0b 100644 --- a/tests/rule_based_toolchain/args/args_test.bzl +++ b/tests/rule_based_toolchain/args/args_test.bzl @@ -152,11 +152,21 @@ def _env_only_requires_test(env, targets): def _with_dir_test(env, targets): with_dir = env.expect.that_target(targets.with_dir).provider(ArgsInfo) with_dir.allowlist_include_directories().contains_exactly([_TOOL_DIRECTORY]) - with_dir.files().contains_at_least(_SIMPLE_FILES) + with_dir.files().contains_exactly([]) c_compile = env.expect.that_target(targets.with_dir).provider(ArgsListInfo).by_action().get( targets.c_compile[ActionTypeInfo], ) + c_compile.files().contains_exactly([]) + +def _with_dir_and_data_test(env, targets): + with_dir = env.expect.that_target(targets.with_dir_and_data).provider(ArgsInfo) + with_dir.allowlist_include_directories().contains_exactly([_TOOL_DIRECTORY]) + with_dir.files().contains_at_least(_SIMPLE_FILES) + + c_compile = env.expect.that_target(targets.with_dir_and_data).provider(ArgsListInfo).by_action().get( + targets.c_compile[ActionTypeInfo], + ) c_compile.files().contains_at_least(_SIMPLE_FILES) TARGETS = [ @@ -165,6 +175,7 @@ TARGETS = [ ":env_only", ":env_only_requires", ":with_dir", + ":with_dir_and_data", ":iterate_over_optional", ":good_env_format", ":good_env_format_optional", @@ -349,6 +360,7 @@ TESTS = { "env_only_test": _env_only_test, "env_only_requires_test": _env_only_requires_test, "with_dir_test": _with_dir_test, + "with_dir_and_data_test": _with_dir_and_data_test, "good_env_format_test": _good_env_format_test, "good_env_format_optional_test": _good_env_format_optional_test, } diff --git a/tests/rule_based_toolchain/args_list/BUILD b/tests/rule_based_toolchain/args_list/BUILD index 64f0fbbbf..f0bc4a6ee 100644 --- a/tests/rule_based_toolchain/args_list/BUILD +++ b/tests/rule_based_toolchain/args_list/BUILD @@ -48,6 +48,7 @@ util.helper_target( actions = ["//tests/rule_based_toolchain/actions:c_compile"], allowlist_include_directories = ["//tests/rule_based_toolchain/testdata:subdirectory_1"], args = ["dir1"], + data = ["//tests/rule_based_toolchain/testdata:subdirectory_1"], visibility = ["//tests/rule_based_toolchain:__subpackages__"], ) @@ -57,6 +58,7 @@ util.helper_target( actions = ["//tests/rule_based_toolchain/actions:cpp_compile"], allowlist_include_directories = ["//tests/rule_based_toolchain/testdata:subdirectory_2"], args = ["dir2"], + data = ["//tests/rule_based_toolchain/testdata:subdirectory_2"], visibility = ["//tests/rule_based_toolchain:__subpackages__"], ) diff --git a/tests/rule_based_toolchain/features/BUILD b/tests/rule_based_toolchain/features/BUILD index c98231871..e43da9d32 100644 --- a/tests/rule_based_toolchain/features/BUILD +++ b/tests/rule_based_toolchain/features/BUILD @@ -115,6 +115,7 @@ util.helper_target( actions = ["//tests/rule_based_toolchain/actions:c_compile"], allowlist_include_directories = ["//tests/rule_based_toolchain/testdata:subdirectory_1"], args = ["--include-builtin-dirs"], + data = ["//tests/rule_based_toolchain/testdata:subdirectory_1"], ) util.helper_target( diff --git a/tests/rule_based_toolchain/tool/BUILD b/tests/rule_based_toolchain/tool/BUILD index daa617aab..8b1c07303 100644 --- a/tests/rule_based_toolchain/tool/BUILD +++ b/tests/rule_based_toolchain/tool/BUILD @@ -21,6 +21,7 @@ cc_tool( name = "tool_with_allowlist_include_directories", src = "//tests/rule_based_toolchain/testdata:bin_wrapper.sh", allowlist_include_directories = ["//tests/rule_based_toolchain/testdata:directory"], + data = ["//tests/rule_based_toolchain/testdata:directory"], visibility = ["//tests/rule_based_toolchain:__subpackages__"], ) diff --git a/tests/rule_based_toolchain/toolchain_config/BUILD b/tests/rule_based_toolchain/toolchain_config/BUILD index 08b5f8380..7bf8d3b43 100644 --- a/tests/rule_based_toolchain/toolchain_config/BUILD +++ b/tests/rule_based_toolchain/toolchain_config/BUILD @@ -32,7 +32,10 @@ util.helper_target( actions = ["//tests/rule_based_toolchain/actions:c_compile"], allowlist_include_directories = ["//tests/rule_based_toolchain/testdata:subdirectory_1"], args = ["c_compile_args"], - data = ["//tests/rule_based_toolchain/testdata:file1"], + data = [ + "//tests/rule_based_toolchain/testdata:file1", + "//tests/rule_based_toolchain/testdata:subdirectory_1", + ], ) util.helper_target( @@ -48,6 +51,7 @@ cc_tool( src = "//tests/rule_based_toolchain/testdata:bin_wrapper", allowlist_include_directories = ["//tests/rule_based_toolchain/testdata:subdirectory_3"], capabilities = ["//cc/toolchains/capabilities:supports_pic"], + data = ["//tests/rule_based_toolchain/testdata:subdirectory_3"], ) cc_sysroot( @@ -94,7 +98,10 @@ util.helper_target( actions = ["//tests/rule_based_toolchain/actions:all_compile"], allowlist_include_directories = ["//tests/rule_based_toolchain/testdata:subdirectory_2"], args = ["compile_args"], - data = ["//tests/rule_based_toolchain/testdata:file2"], + data = [ + "//tests/rule_based_toolchain/testdata:file2", + "//tests/rule_based_toolchain/testdata:subdirectory_2", + ], ) util.helper_target(