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

Fix tool path for nmake #1165

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
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
19 changes: 13 additions & 6 deletions foreign_cc/private/make_env_vars.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ def get_make_env_vars(
flags,
user_vars,
deps,
inputs):
vars = _get_make_variables(workspace_name, tools, flags, user_vars)
inputs,
make_commands = []):
vars = _get_make_variables(workspace_name, tools, flags, user_vars, make_commands)
deps_flags = _define_deps_flags(deps, inputs)

# For cross-compilation.
Expand Down Expand Up @@ -94,7 +95,7 @@ _MAKE_TOOLS = {
# missing: cxx_linker_executable
}

def _get_make_variables(workspace_name, tools, flags, user_env_vars):
def _get_make_variables(workspace_name, tools, flags, user_env_vars, make_commands):
vars = {}

for flag in _MAKE_FLAGS:
Expand All @@ -115,9 +116,12 @@ def _get_make_variables(workspace_name, tools, flags, user_env_vars):
# Force absolutize of tool paths, which may relative to the exec root (e.g. hermetic toolchains built from source)
tool_value_absolute = _absolutize(workspace_name, tool_value, True)

# If the tool path contains whitespaces (e.g. C:\Program Files\...),
# MSYS2 requires that the path is wrapped in double quotes
if " " in tool_value_absolute:
# There are 2 conditions where we need to wrap the tool path in double quotes:
# 1. If the tool path contains whitespaces (e.g. C:\Program Files\...),
# MSYS2 requires that the path is wrapped in double quotes.
# 2. If nmake is used, it requires the tool path to be wrapped in double quotes,
# otherwise nmake will output the command as a string instead of executing it.
if " " in tool_value_absolute or _nmake_in_make_commands(make_commands):
tool_value_absolute = "\\\"" + tool_value_absolute + "\\\""

tools_dict[tool] = [tool_value_absolute]
Expand All @@ -140,3 +144,6 @@ def _absolutize(workspace_name, text, force = False):

def _join_flags_list(workspace_name, flags):
return " ".join([_absolutize(workspace_name, flag) for flag in flags])

def _nmake_in_make_commands(make_commands):
return make_commands and "nmake.exe" in make_commands[0]
2 changes: 1 addition & 1 deletion foreign_cc/private/make_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def create_make_script(
script.append("##symlink_contents_to_dir## $$EXT_BUILD_ROOT$$/{} $$BUILD_TMPDIR$$ False".format(root))

script.append("##enable_tracing##")
configure_vars = get_make_env_vars(workspace_name, tools, flags, env_vars, deps, inputs)
configure_vars = get_make_env_vars(workspace_name, tools, flags, env_vars, deps, inputs, make_commands)
script.extend(["{env_vars} {command}".format(
env_vars = configure_vars,
command = command,
Expand Down