Skip to content
Merged
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
6 changes: 3 additions & 3 deletions cargo/private/cargo_build_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ def _prefix_pwd_to_flag(args, flag_variations):
res = []
prefix_next_arg = False
for arg in args:
# When expecting a path argument and we see -Xclang, skip over it and
# When expecting a path argument, skip Clang forwarding tokens and
# map the next argument instead.
# ex: -Xclang -internal-isystem -Xclang path
# to: -Xclang -internal-isystem -Xclang ${pwd}/path
if prefix_next_arg and arg == "-Xclang":
if prefix_next_arg and arg in ("-Xclang", "-Xpreprocessor"):
res.append(arg)
continue

Expand Down Expand Up @@ -217,7 +217,7 @@ def _pwd_flags_fsanitize_ignorelist(args):

def _pwd_flags_isystem(args):
"""Prefix execroot-relative paths in -isystem-like arguments with ${pwd}."""
return _prefix_pwd_to_flag(args, ["-isystem", "-isystem-after", "-internal-isystem", "-cxx-isystem", "-stdlib++-isystem", "/imsvc"])
return _prefix_pwd_to_flag(args, ["-isystem", "-isystem-after", "-internal-isystem", "-internal-externc-isystem", "-cxx-isystem", "-stdlib++-isystem", "/imsvc"])

def _pwd_flags_L(args):
"""Prefix execroot-relative paths in -L arguments with ${pwd}."""
Expand Down
3 changes: 3 additions & 0 deletions cargo/tests/cargo_build_script/cc_args_and_env/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ load(
"direct_libs_absolute_test",
"direct_libs_as_flag_operand_test",
"direct_libs_relative_test",
"forwarded_header_paths_test",
"fsanitize_ignorelist_absolute_test",
"fsanitize_ignorelist_relative_test",
"imacros_absolute_test",
Expand Down Expand Up @@ -91,3 +92,5 @@ direct_libs_relative_test(name = "direct_libs_relative_test")
direct_libs_absolute_test(name = "direct_libs_absolute_test")

direct_libs_as_flag_operand_test(name = "direct_libs_as_flag_operand_test")

forwarded_header_paths_test(name = "forwarded_header_paths_test")
Original file line number Diff line number Diff line change
Expand Up @@ -771,3 +771,26 @@ def direct_libs_as_flag_operand_test(name):
target_under_test = "%s/cargo_build_script" % name,
expected_cflags = ["-imacros", "${pwd}/test/relative/libfoo.a", "-B", "${pwd}/test/relative/obj.o"],
)

def forwarded_header_paths_test(name):
"""Tests path rewriting through Clang forwarding options.

Args:
name: Prefix for the generated analysis tests.
"""
for forwarding in ["-Xclang", "-Xpreprocessor"]:
for category in ["-internal-isystem", "-internal-externc-isystem"]:
for kind, path, expected in [
("relative", "test/relative/include", "${pwd}/test/relative/include"),
("absolute", "/test/absolute/include", "/test/absolute/include"),
]:
case = name + forwarding + category + "_" + kind
cargo_build_script_with_extra_cc_compile_flags(
name = case + "/cargo_build_script",
extra_cc_compile_flags = [forwarding, category, forwarding, path, "-DKEEP=1"],
)
cc_args_and_env_analysis_test(
name = case,
target_under_test = case + "/cargo_build_script",
expected_cflags = [forwarding, category, forwarding, expected, "-DKEEP=1"],
)
Loading