Skip to content

Commit

Permalink
Remove Latin-1 workaround on Bazel 6.4.0+
Browse files Browse the repository at this point in the history
The fix for Latin-1 encoded files was landed in [6.4.0] after
being landed on Bazel [master].

We can conditionally use the old, unhermetic, `tar` workaround
on modern Bazel versions.

[master]: bazelbuild/bazel#18448
[6.4.0]: bazelbuild/bazel#19765
  • Loading branch information
mattyclarkson committed Feb 25, 2024
1 parent 8c014fd commit cf1d7e6
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions go/private/sdk.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ load("//go/private:common.bzl", "executable_path")
load("//go/private:nogo.bzl", "go_register_nogo")
load("//go/private/skylib/lib:versions.bzl", "versions")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "patch", "read_user_netrc", "use_netrc")
load("@io_bazel_rules_go_bazel_features//features.bzl", "bazel_features")

MIN_SUPPORTED_VERSION = (1, 14, 0)

Expand Down Expand Up @@ -434,14 +435,22 @@ def _remote_sdk(ctx, urls, strip_prefix, sha256):
# Docker on macOS with a bind mount).
#
# For .tar.gz files (available for most platforms), we work around this bug
# by using the system tar instead of ctx.download_and_extract.
# by using the system tar instead of ctx.download_and_extract. We could make
# this hermetic by using `@ape-tar//:entrypoint`/`@ape-gzip//:entrypoint`.
#
# For .zip files, we use ctx.download_and_extract but with rename_files,
# changing certain paths that trigger the bug. This is only available
# in Bazel 6.0.0+ (bazelbuild/bazel#16052). The only situation where
# .zip files are needed seems to be a macOS host using a Windows toolchain
# for remote execution.
if urls[0].endswith(".tar.gz"):
if io_bazel_rules_go_bazel_features.external_deps.extract_supports_unicode_filenames:
ctx.download_and_extract(
url = urls,
stripPrefix = strip_prefix,
sha256 = sha256,
auth = auth,
)
elif urls[0].endswith(".tar.gz"):
if strip_prefix != "go":
fail("strip_prefix not supported")
ctx.download(
Expand Down Expand Up @@ -470,12 +479,7 @@ def _remote_sdk(ctx, urls, strip_prefix, sha256):
auth = auth,
)
else:
ctx.download_and_extract(
url = urls,
stripPrefix = strip_prefix,
sha256 = sha256,
auth = auth,
)
fail("No supported workaround for extracting Go SDK non-ASCII filenames. More recent versions of Bazel have correct support for unpacking the Go SDK.")

def _local_sdk(ctx, path):
for entry in ctx.path(path).readdir():
Expand Down

0 comments on commit cf1d7e6

Please sign in to comment.