cargo_build_script: Add regression test for revert #2925 (#2936)

#2931 added tests for _pwd_flags, however 
the test as-is passes with #2911 and #2922,
which still caused problems and reverted.
Here I introduce a test case for likely
unfixed in reverted #2925.

The test needs strictter check for cflags. As-ls
`flag in cflags` is a just substring search and
very weak test for abs path.

For #2917
This commit is contained in:
Vitaly Buka 2024-10-17 10:49:20 -07:00 committed by GitHub
parent 63fa643067
commit 0c6bcc8a63
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 3 deletions

View File

@ -5,6 +5,7 @@ load(
"isystem_absolute_test",
"isystem_relative_test",
"sysroot_absolute_test",
"sysroot_next_absolute_test",
"sysroot_relative_test",
)
@ -12,6 +13,8 @@ sysroot_relative_test(name = "sysroot_relative_test")
sysroot_absolute_test(name = "sysroot_absolute_test")
sysroot_next_absolute_test(name = "sysroot_next_absolute_test")
isystem_relative_test(name = "isystem_relative_test")
isystem_absolute_test(name = "isystem_absolute_test")

View File

@ -83,7 +83,7 @@ def _cc_args_and_env_analysis_test_impl(ctx):
env = analysistest.begin(ctx)
tut = analysistest.target_under_test(env)
cargo_action = tut[DepActionsInfo].actions[0]
cflags = cargo_action.env["CFLAGS"]
cflags = cargo_action.env["CFLAGS"].split(" ")
for flag in ctx.attr.expected_cflags:
asserts.true(
env,
@ -173,6 +173,17 @@ def sysroot_absolute_test(name):
expected_cflags = ["--sysroot=/test/absolute/sysroot"],
)
def sysroot_next_absolute_test(name):
cargo_build_script_with_extra_cc_compile_flags(
name = "%s/cargo_build_script" % name,
extra_cc_compile_flags = ["--sysroot=/test/absolute/sysroot", "test/relative/another"],
)
cc_args_and_env_analysis_test(
name = name,
target_under_test = "%s/cargo_build_script" % name,
expected_cflags = ["--sysroot=/test/absolute/sysroot", "test/relative/another"],
)
def isystem_relative_test(name):
cargo_build_script_with_extra_cc_compile_flags(
name = "%s/cargo_build_script" % name,
@ -181,7 +192,7 @@ def isystem_relative_test(name):
cc_args_and_env_analysis_test(
name = name,
target_under_test = "%s/cargo_build_script" % name,
expected_cflags = ["-isystem ${pwd}/test/relative/path"],
expected_cflags = ["-isystem", "${pwd}/test/relative/path"],
)
def isystem_absolute_test(name):
@ -192,7 +203,7 @@ def isystem_absolute_test(name):
cc_args_and_env_analysis_test(
name = name,
target_under_test = "%s/cargo_build_script" % name,
expected_cflags = ["-isystem /test/absolute/path"],
expected_cflags = ["-isystem", "/test/absolute/path"],
)
def fsanitize_ignorelist_relative_test(name):