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

Move PATH env-var computation to GoContextInfo #4037

Merged
merged 1 commit into from
Aug 13, 2024
Merged
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
64 changes: 32 additions & 32 deletions go/private/context.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -516,41 +516,13 @@ def go_context(ctx, attr = None):
if mode.arm:
env["GOARM"] = mode.arm

if not cgo_context_info:
cc_toolchain_files = depset()
cgo_tools = None
else:
if cgo_context_info:
env.update(cgo_context_info.env)
cc_toolchain_files = cgo_context_info.cc_toolchain_files

# Add C toolchain directories to PATH.
# On ARM, go tool link uses some features of gcc to complete its work,
# so PATH is needed on ARM.
path_set = {}
if "PATH" in env:
for p in env["PATH"].split(ctx.configuration.host_path_separator):
path_set[p] = None
cgo_tools = cgo_context_info.cgo_tools
tool_paths = [
cgo_tools.c_compiler_path,
cgo_tools.ld_executable_path,
cgo_tools.ld_static_lib_path,
cgo_tools.ld_dynamic_lib_path,
]
for tool_path in tool_paths:
tool_dir = tool_path[:tool_path.rfind("/")]
path_set[tool_dir] = None
paths = sorted(path_set.keys())
if ctx.configuration.host_path_separator == ":":
# HACK: ":" is a proxy for a UNIX-like host.
# The tools returned above may be bash scripts that reference commands
# in directories we might not otherwise include. For example,
# on macOS, wrapped_ar calls dirname.
if "/bin" not in path_set:
paths.append("/bin")
if "/usr/bin" not in path_set:
paths.append("/usr/bin")
env["PATH"] = ctx.configuration.host_path_separator.join(paths)
else:
cc_toolchain_files = depset()
cgo_tools = None

_check_importpaths(ctx)
importpath, importmap, pathtype = _infer_importpath(ctx, attr)
Expand Down Expand Up @@ -827,6 +799,34 @@ def _cgo_context_data_impl(ctx):
cc_toolchain.target_gnu_system_name,
)

# Add C toolchain directories to PATH.
fmeum marked this conversation as resolved.
Show resolved Hide resolved
# On ARM, go tool link uses some features of gcc to complete its work,
# so PATH is needed on ARM.
path_set = {}
if "PATH" in env:
for p in env["PATH"].split(ctx.configuration.host_path_separator):
path_set[p] = None
tool_paths = [
c_compiler_path,
ld_executable_path,
ld_static_lib_path,
ld_dynamic_lib_path,
]
for tool_path in tool_paths:
tool_dir = tool_path[:tool_path.rfind("/")]
path_set[tool_dir] = None
paths = sorted(path_set.keys())
if ctx.configuration.host_path_separator == ":":
# HACK: ":" is a proxy for a UNIX-like host.
# The tools returned above may be bash scripts that reference commands
# in directories we might not otherwise include. For example,
# on macOS, wrapped_ar calls dirname.
if "/bin" not in path_set:
paths.append("/bin")
if "/usr/bin" not in path_set:
paths.append("/usr/bin")
env["PATH"] = ctx.configuration.host_path_separator.join(paths)

return [CgoContextInfo(
cc_toolchain_files = cc_toolchain.all_files,
tags = tags,
Expand Down