Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo_build_script: De-duplicate _pwd_flags implementation #2956

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 18 additions & 41 deletions cargo/private/cargo_build_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,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 @@ -163,56 +163,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 and not paths.is_absolute(path):
res.append("{}${{pwd}}/{}".format(opt, path))
else:
fix_next_arg = (opt and path == None)
res.append(arg)

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_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
Loading