Skip to content

Commit

Permalink
cargo_build_script: Add support for -fsanitize-ignorelist=
Browse files Browse the repository at this point in the history
This is trivial copy/paste implementation, to
minimize regression probability.

Previously it was combined with refactoring, but
introduced regression and was reverted bazelbuild#2911.

This time I split refactoring into follow up PR.
  • Loading branch information
vitalybuka committed Oct 16, 2024
1 parent ded96a9 commit 7e6942e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
20 changes: 19 additions & 1 deletion cargo/private/cargo_build_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,26 @@ def _pwd_flags_isystem(args):

return res

def _pwd_flags_fsanitize_ignorelist(args):
"""Prefix execroot-relative paths of known arguments with ${pwd}.
Args:
args (list): List of tool arguments.
Returns:
list: The modified argument list.
"""
res = []
for arg in args:
s, opt, path = arg.partition("-fsanitize-ignorelist=")
if s == "" and not paths.is_absolute(path):
res.append("{}${{pwd}}/{}".format(opt, path))
else:
res.append(arg)
return res

def _pwd_flags(args):
return _pwd_flags_isystem(_pwd_flags_sysroot(args))
return _pwd_flags_fsanitize_ignorelist(_pwd_flags_isystem(_pwd_flags_sysroot(args)))

def _feature_enabled(ctx, feature_name, default = False):
"""Check if a feature is enabled.
Expand Down
6 changes: 6 additions & 0 deletions test/cargo_build_script/cc_args_and_env/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ load(
"isystem_relative_test",
"sysroot_absolute_test",
"sysroot_relative_test",
"fsanitize_ignorelist_absolute_test",
"fsanitize_ignorelist_relative_test",
)

sysroot_relative_test(name = "sysroot_relative_test")
Expand All @@ -13,3 +15,7 @@ sysroot_absolute_test(name = "sysroot_absolute_test")
isystem_relative_test(name = "isystem_relative_test")

isystem_absolute_test(name = "isystem_absolute_test")

fsanitize_ignorelist_absolute_test(name = "fsanitize_ignorelist_absolute_test")

fsanitize_ignorelist_relative_test(name = "fsanitize_ignorelist_relative_test")
22 changes: 22 additions & 0 deletions test/cargo_build_script/cc_args_and_env/cc_args_and_env_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,25 @@ def isystem_absolute_test(name):
target_under_test = "%s/cargo_build_script" % name,
expected_cflags = ["-isystem /test/absolute/path"],
)

def fsanitize_ignorelist_relative_test(name):
cargo_build_script_with_extra_cc_compile_flags(
name = "%s/cargo_build_script" % name,
extra_cc_compile_flags = ["-fsanitize-ignorelist=test/relative/path"],
)
cc_args_and_env_analysis_test(
name = name,
target_under_test = "%s/cargo_build_script" % name,
expected_cflags = ["-fsanitize-ignorelist=${pwd}/test/relative/path"],
)

def fsanitize_ignorelist_absolute_test(name):
cargo_build_script_with_extra_cc_compile_flags(
name = "%s/cargo_build_script" % name,
extra_cc_compile_flags = ["-fsanitize-ignorelist=/test/absolute/path"],
)
cc_args_and_env_analysis_test(
name = name,
target_under_test = "%s/cargo_build_script" % name,
expected_cflags = ["-fsanitize-ignorelist=/test/absolute/path"],
)

0 comments on commit 7e6942e

Please sign in to comment.