Skip to content

Commit

Permalink
Use absolute path with "-fsanitize-ignorelist" (#2911)
Browse files Browse the repository at this point in the history
Also generalize `_pwd_flags`. Flags can use both, " " and "=" as
argument separators.
  • Loading branch information
vitalybuka authored Oct 2, 2024
1 parent 5c8f791 commit 9594fa7
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions cargo/private/cargo_build_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def get_cc_compile_args_and_env(cc_toolchain, feature_configuration):
)
return cc_c_args, cc_cxx_args, cc_env

def _pwd_flags_sysroot(args):
def _pwd_flags(args):
"""Prefix execroot-relative paths of known arguments with ${pwd}.
Args:
Expand All @@ -144,38 +144,33 @@ def _pwd_flags_sysroot(args):
list: The modified argument list.
"""
res = []
for arg in args:
s, opt, path = arg.partition("--sysroot=")
if s == "" and not paths.is_absolute(path):
res.append("{}${{pwd}}/{}".format(opt, path))
else:
res.append(arg)
return res
fix_next_arg = False

def _pwd_flags_isystem(args):
"""Prefix execroot-relative paths of known arguments with ${pwd}.
flags = ["-fsanitize-ignorelist", "-isystem", "--sysroot"]

Args:
args (list): List of tool arguments.
def split_flag(flag):
if flag in flags:
return (flag, None)
for flag in flags:
s, opt, path = arg.partition(flag + "=")
if s == "":
return (opt, path)
return (None, None)

Returns:
list: The modified argument list.
"""
res = []
fix_next_arg = False
for arg in args:
if fix_next_arg and not paths.is_absolute(arg):
res.append("${{pwd}}/{}".format(arg))
fix_next_arg = False
else:
res.append(arg)

fix_next_arg = arg == "-isystem"
opt, path = split_flag(arg)
if opt and path:
res.append("{}${{pwd}}/{}".format(opt, path))
else:
fix_next_arg = (opt != None)
res.append(arg)

return res

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

def _feature_enabled(ctx, feature_name, default = False):
"""Check if a feature is enabled.
Expand Down

0 comments on commit 9594fa7

Please sign in to comment.