bazel-contrib / bazel-gazelle

Gazelle is a Bazel build file generator for Bazel projects. It natively supports Go and protobuf, and it may be extended to support new languages and custom rule sets.
Apache License 2.0
1.19k stars 378 forks source link

GOTOOLCHAIN local env parameter breaks the fetch of external go repositories #1858

Closed lbcjbb closed 2 months ago

lbcjbb commented 2 months ago

What version of gazelle are you using?

0.38.0

What version of rules_go are you using?

0.49.0

What version of Bazel are you using?

7.2.1

Does this issue reproduce with the latest releases of all the above?

Yes

What operating system and processor architecture are you using?

All

What did you do?

With an empty bazel workspace + the following MODULE.bazel:

module(name = "sandbox")

bazel_dep(name = "rules_go", version = "0.49.0")
bazel_dep(name = "gazelle", version = "0.38.0")

go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(
    name = "go_sdk",
    version = "1.22.6",
)
use_repo(go_sdk, "go_sdk")
$ go env -w GOTOOLCHAIN=go1.22.5 # Use a Go version different of the Go version defined in `go_sdk`
$ bazel fetch --repo @@gazelle~~go_deps~org_golang_x_sync

What did you expect to see?

INFO: All requested repos fetched successfully.

What did you see instead?

INFO: Repository gazelle~~go_deps~org_golang_x_sync instantiated at:
  <builtin>: in <toplevel>
Repository rule go_repository defined at:
  <output_base>/external/gazelle~/internal/go_repository.bzl:363:32: in <toplevel>
ERROR: An error occurred during the fetch of repository 'gazelle~~go_deps~org_golang_x_sync':
   Traceback (most recent call last):
    File "<output_base>/external/gazelle~/internal/go_repository.bzl", line 282, column 13, in _go_repository_impl
        fail("%s: %s" % (ctx.name, result.stderr))
Error in fail: gazelle~~go_deps~org_golang_x_sync: fetch_repo: go mod download output format: `<output_base>/external/rules_go~~go_sdk~go_sdk/bin/go mod download -json -modcacherw golang.org/x/sync@v0.6.0`: parsing JSON: "" stderr: "
  go: downloading go1.22.5 (linux/amd64)
  go: download go1.22.5: golang.org/toolchain@v0.0.1-go1.22.5.linux-amd64: verifying module: checksum database disabled by GOSUMDB=off
" error: unexpected end of JSON input