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

cmd/go: go mod tidy removes needed dependencies #65054

Closed
hyangah opened this issue Jan 11, 2024 · 1 comment
Closed

cmd/go: go mod tidy removes needed dependencies #65054

hyangah opened this issue Jan 11, 2024 · 1 comment
Labels
GoCommand cmd/go modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@hyangah
Copy link
Contributor

hyangah commented Jan 11, 2024

Go version

go1.22rc1

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='~/Library/Caches/go-build'
GOENV='~/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='~/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='~/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='~/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22rc1.darwin-amd64'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='go1.22rc1'
GOTOOLDIR='~/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22rc1.darwin-amd64/pkg/tool/darwin_amd64'
GOVCS=''
GOVERSION='go1.22rc1'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='~/projects/vscode-go/extension/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 -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/5p/zn7ykc111kn3lm09h_47mz2w001py5/T/go-build2103652819=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

Reorganizing our project repo structure for golang/vscode-go#3121

The desired state is

github.com/golang/vscode-go (A) module hosts a small binary.
github.com/golang/vscode-go/extension (B) module requires github.com/golang/vscode-go, to use the binary in its testing. (B->A)

https://go-review.googlesource.com/c/vscode-go/+/554316 is the CL.

To enforce B->A dependency, I've tested blank import, go:generate, ... like:
https://go-review.googlesource.com/c/vscode-go/+/554316/9/extension/doc.go
https://go-review.googlesource.com/c/vscode-go/+/554316/9/extension/go.mod

In this state, go build works:

$ go run github.com/golang/vscode-go/vscgo version
vscgo: v0.0.0-00010101000000-000000000000
go: go1.22rc1

But if I run go mod tidy, this dependency is pruned.

$ go mod tidy
~/projects/vscode-go/extension$ git diff
diff --git a/extension/go.mod b/extension/go.mod
index 74acac558..cf12f6ee5 100644
--- a/extension/go.mod
+++ b/extension/go.mod
@@ -26,12 +26,10 @@ require (
        go4.org v0.0.0-20180809161055-417644f6feb5 // indirect
        golang.org/x/crypto v0.16.0 // indirect
        golang.org/x/exp v0.0.0-20230809094429-853ea248256d // indirect
-       golang.org/x/mod v0.14.0 // indirect
        golang.org/x/net v0.19.0 // indirect
        golang.org/x/oauth2 v0.15.0 // indirect
        golang.org/x/sync v0.5.0 // indirect
        golang.org/x/sys v0.16.0 // indirect
-       golang.org/x/telemetry v0.0.0-20240104150930-463b4b688e47 // indirect
        ...

Build fails.

$ cd extension
$ go run github.com/golang/vscode-go/vscgo version
../vscgo/main.go:20:2: missing go.sum entry for module providing package golang.org/x/telemetry/counter (imported by github.com/golang/vscode-go/vscgo); to add:
        go get github.com/golang/vscode-go/vscgo@v0.0.0-00010101000000-000000000000

Extra info:

  • go mod why -m: same result before/after go mod tidy
$ go mod why -m github.com/golang/vscode-go
# github.com/golang/vscode-go
github.com/golang/vscode-go/extension
github.com/golang/vscode-go
  • git status
$ git status --short --untracked=all | grep '\.go'
$
  • This change is the very first one that makes A module include the vscgo package, so I used v0.0.0-00010101000000-000000000000.

What did you see happen?

Enforce my tool dependency requirements, and go mod tidy agrees :-)

What did you expect to see?

go mod tidy removes the dependency and makes the code unbuildable state.

@mauri870 mauri870 added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go modules labels Jan 11, 2024
@bcmills
Copy link
Contributor

bcmills commented Jan 11, 2024

The dummy import in extension/doc.go is of package github.com/golang/vscode-go.

If you want to be able to build the package github.com/golang/vscode-go/vscgo specifically, then the dummy import needs to refer to that specific package so that its transitive dependencies will also be included.

~/src/github.com/golang/vscode-go/extension$ git diff
diff --git i/extension/doc.go w/extension/doc.go
index 53bc3ada..2fd96e3c 100644
--- i/extension/doc.go
+++ w/extension/doc.go
@@ -8,8 +8,10 @@ package extension

 // Dummy command to add dependency on vscgo.

+//go:build tools
+
 import (
-       _ "github.com/golang/vscode-go"
+       _ "github.com/golang/vscode-go/vscgo"
 )

 //go:generate go run github.com/golang/vscode-go/vscgo version

~/src/github.com/golang/vscode-go/extension$ go mod tidy

~/src/github.com/golang/vscode-go/extension$ go run github.com/golang/vscode-go/vscgo version
vscgo: v0.0.0-00010101000000-000000000000
go: devel go1.22-e9b3ff15f4 Wed Jan 10 17:35:49 2024 +0000

@bcmills bcmills closed this as not planned Won't fix, can't repro, duplicate, stale Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants