Skip to content

x/tools/gopls: released version v0.17.1 depends on a dev version of golang.org/x/tools which is removed by go mod tidy without a replace directive #71427

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

Closed
Zemnmez opened this issue Jan 24, 2025 · 2 comments
Labels
BugReport Issues describing a possible bug in the Go implementation. gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@Zemnmez
Copy link

Zemnmez commented Jan 24, 2025

Go version

1.23.5

Output of go env in your module/workspace:

Zemnmez ➜ /workspaces/monorepo (6999e71122) $ go env
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/codespace/.cache/go-build'
GOENV='/home/codespace/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/codespace/.cache/bazel/_bazel_codespace/f4ac7acc8046f57d430e720e89de5487/external/rules_go++go_sdk+monorepo__download_0'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/home/codespace/.cache/bazel/_bazel_codespace/f4ac7acc8046f57d430e720e89de5487/external/rules_go++go_sdk+monorepo__download_0/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.5'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/codespace/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/workspaces/monorepo/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3892102254=/tmp/go-build -gno-record-gcc-switches'
@Zemnmez ➜ /workspaces/monorepo (6999e71122) $

What did you do?

I have gopls in my tools.go so it is controlled by go.mod: https://github.com/zemn-me/monorepo/blob/91a487a370933573cf8ba6b46e3563a39c617ecb/sh/tools.go#L12

[email protected] (@latest) depends on a weird dev version of x/tools (v0.27.1-0.20241219162658-575221bfbda3): https://cs.opensource.google/go/x/tools/+/refs/tags/gopls/v0.17.1:gopls/go.mod;l=15

When I run go mod tidy, it reverts the version to x/[email protected] (@latest), which I think is correct as per semver. This breaks the build as gopls is incompatible with that version.

What did you see happen?

Without replace directive (zemn-me/monorepo@91a487a):

@Zemnmez ➜ /workspaces/monorepo (6999e71122) $ go mod tidy
@Zemnmez ➜ /workspaces/monorepo (6999e71122) $ bazel run //sh/bin:gopls
WARNING: Option 'experimental_remote_cache_compression' is deprecated: Use --remote_cache_compression instead
INFO: Invocation ID: 883ed3fd-68a7-47fd-bb41-e09d06494785
INFO: Streaming build results to: https://app.buildbuddy.io/invocation/883ed3fd-68a7-47fd-bb41-e09d06494785
WARNING: Option 'experimental_remote_cache_compression' is deprecated: Use --remote_cache_compression instead
INFO: Analyzed target //sh/bin:gopls (100 packages loaded, 622 targets configured).
ERROR: /home/codespace/.cache/bazel/_bazel_codespace/f4ac7acc8046f57d430e720e89de5487/external/gazelle++go_deps+org_golang_x_tools_gopls/internal/analysis/fillreturns/BUILD.bazel:3:11: GoCompilePkg external/gazelle++go_deps+org_golang_x_tools_gopls/internal/analysis/fillreturns/fillreturns.a failed: (Exit 1): builder failed: error executing GoCompilePkg command (from target @@gazelle++go_deps+org_golang_x_tools_gopls//internal/analysis/fillreturns:fillreturns) bazel-out/k8-opt-exec-ST-d57f47055a04/bin/external/rules_go++go_sdk+monorepo__download_0/builder_reset/builder compilepkg -sdk external/rules_go++go_sdk+monorepo__download_0 -goroot ... (remaining 37 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
external/gazelle++go_deps+org_golang_x_tools_gopls/internal/analysis/fillreturns/fillreturns.go:187:23: assignment mismatch: 1 variable but typesinternal.ZeroExpr returns 2 values
external/gazelle++go_deps+org_golang_x_tools_gopls/internal/analysis/fillreturns/fillreturns.go:187:62: too many arguments in call to typesinternal.ZeroExpr
        have (*ast.File, *types.Package, types.Type)
        want (types.Type, types.Qualifier)
compilepkg: error running subcommand external/rules_go++go_sdk+monorepo__download_0/pkg/tool/linux_amd64/compile: exit status 2
Target @@gazelle++go_deps+org_golang_x_tools_gopls//:gopls failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 1.387s, Critical Path: 0.31s
INFO: 49 processes: 35 action cache hit, 40 disk cache hit, 7 internal, 2 linux-sandbox.
ERROR: Build did NOT complete successfully
ERROR: Build failed. Not running target
FAILED: 
Waiting for build events upload: Build Event Service 23s

What did you expect to see?

I fixed this issue with a replace directive, added to go.mod (zemn-me/monorepo@6999e71):

replace golang.org/x/tools => golang.org/x/tools v0.27.1-0.20241219162658-575221bfbda3

It fixes the issue, but it seems like it should not be needed:

@Zemnmez ➜ /workspaces/monorepo (6999e71122) $ go mod tidy
b@Zemnmez ➜ /workspaces/monorepo (6999e71122) $ bazel run //sh/bin:gopls
WARNING: Option 'experimental_remote_cache_compression' is deprecated: Use --remote_cache_compression instead
INFO: Invocation ID: 5a745502-d7a1-4d3f-aeee-82272d42ce48
INFO: Streaming build results to: https://app.buildbuddy.io/invocation/5a745502-d7a1-4d3f-aeee-82272d42ce48
WARNING: Option 'experimental_remote_cache_compression' is deprecated: Use --remote_cache_compression instead
INFO: Analyzed target //sh/bin:gopls (100 packages loaded, 620 targets configured).
INFO: Found 1 target...
Target @@gazelle++go_deps+org_golang_x_tools_gopls//:gopls up-to-date:
  dist/bin/external/gazelle++go_deps+org_golang_x_tools_gopls/gopls_/gopls
INFO: Elapsed time: 1.092s, Critical Path: 0.04s
INFO: 49 processes: 288 action cache hit, 48 disk cache hit, 1 internal.
INFO: Build completed successfully, 49 total actions
INFO: Running command line: dist/bin/external/gazelle++go_deps+org_golang_x_tools_gopls/gopls_/gopls
INFO: 
@dmitshur dmitshur changed the title Gopls depends on a dev version of golang.org/x/tools which is removed by go mod tidy without a replace directive. x/tools/gopls: released version v0.17.1 depends on a dev version of golang.org/x/tools which is removed by go mod tidy without a replace directive Jan 24, 2025
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Jan 24, 2025
@gopherbot gopherbot added this to the Unreleased milestone Jan 24, 2025
@seankhliao
Copy link
Member

I'm not sure there's anything to do here. given that x/tools will see internal refactors, upgrading past the version declared may not work.
Using versions of both x/tools and x/tools/gopls from the same point in time/commit should work (e.g. current master for both).

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jan 24, 2025
@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation. gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants