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
5 changes: 4 additions & 1 deletion cc/toolchains/args.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)`.
Expand Down
2 changes: 1 addition & 1 deletion cc/toolchains/impl/nested_args.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
5 changes: 4 additions & 1 deletion cc/toolchains/tool.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)`.
Expand Down
9 changes: 9 additions & 0 deletions tests/rule_based_toolchain/args/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 13 additions & 1 deletion tests/rule_based_toolchain/args/args_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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",
Expand Down Expand Up @@ -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,
}
2 changes: 2 additions & 0 deletions tests/rule_based_toolchain/args_list/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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__"],
)

Expand All @@ -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__"],
)

Expand Down
1 change: 1 addition & 0 deletions tests/rule_based_toolchain/features/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions tests/rule_based_toolchain/tool/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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__"],
)

Expand Down
11 changes: 9 additions & 2 deletions tests/rule_based_toolchain/toolchain_config/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down