Use absolute path with "-fsanitize-ignorelist" (#2911)
Also generalize `_pwd_flags`. Flags can use both, " " and "=" as
argument separators.
diff --git a/cargo/private/cargo_build_script.bzl b/cargo/private/cargo_build_script.bzl
index f1e1654..7d54360 100644
--- a/cargo/private/cargo_build_script.bzl
+++ b/cargo/private/cargo_build_script.bzl
@@ -134,25 +134,7 @@
)
return cc_c_args, cc_cxx_args, cc_env
-def _pwd_flags_sysroot(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("--sysroot=")
- if s == "" and not paths.is_absolute(path):
- res.append("{}${{pwd}}/{}".format(opt, path))
- else:
- res.append(arg)
- return res
-
-def _pwd_flags_isystem(args):
+def _pwd_flags(args):
"""Prefix execroot-relative paths of known arguments with ${pwd}.
Args:
@@ -163,19 +145,32 @@
"""
res = []
fix_next_arg = False
+
+ flags = ["-fsanitize-ignorelist", "-isystem", "--sysroot"]
+
+ 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)
+
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.