From 9594fa70b5b6f556a7b4f57ca0ac7c48149bf280 Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Wed, 2 Oct 2024 04:01:55 -0700 Subject: [PATCH] Use absolute path with "-fsanitize-ignorelist" (#2911) Also generalize `_pwd_flags`. Flags can use both, " " and "=" as argument separators. --- cargo/private/cargo_build_script.bzl | 41 ++++++++++++---------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/cargo/private/cargo_build_script.bzl b/cargo/private/cargo_build_script.bzl index f1e1654672..7d54360d64 100644 --- a/cargo/private/cargo_build_script.bzl +++ b/cargo/private/cargo_build_script.bzl @@ -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: @@ -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.