go: cmd/go: go list fails with submodules which have test-only dependencies
What version of Go are you using (go version
)?
$ go version go1.20.5
Does this issue reproduce with the latest release?
yes, I believe it is related to https://github.com/golang/go/issues/60001
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/smira/.cache/go-build" GOENV="/home/smira/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/smira/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/smira/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/home/smira/sdk/go1.20.5" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/home/smira/sdk/go1.20.5/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.20.5" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/home/smira/Documents/go-test-package-failure/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 -fdebug-prefix-map=/tmp/go-build337276505=/tmp/go-build -gno-record-gcc-switches"
What did you do?
I hit this on a big repository, but I reduced this down to https://github.com/smira/go-test-package-failure.
There’s a submodule which has an import of a package from _test.go
file.
What did you expect to see?
Switching to older version of Go “fixes” it:
$ ~/go/bin/go1.20.3 list -u -m -json all
{
"Path": "github.com/smira/go-test-package-failure",
"Main": true,
"Dir": "/home/smira/Documents/go-test-package-failure",
"GoMod": "/home/smira/Documents/go-test-package-failure/go.mod",
"GoVersion": "1.20"
}
{
"Path": "github.com/santhosh-tekuri/jsonschema/v5",
"Version": "v5.3.0",
"Time": "2023-04-04T18:54:33Z",
"Indirect": true,
"Dir": "/home/smira/go/pkg/mod/github.com/santhosh-tekuri/jsonschema/v5@v5.3.0"
}
{
"Path": "github.com/smira/go-test-failure/subpackage",
"Version": "v0.0.0-00010101000000-000000000000",
"Replace": {
"Path": "./subpackage",
"Dir": "/home/smira/Documents/go-test-package-failure/subpackage",
"GoMod": "/home/smira/Documents/go-test-package-failure/subpackage/go.mod",
"GoVersion": "1.20"
},
"Dir": "/home/smira/Documents/go-test-package-failure/subpackage",
"GoMod": "/home/smira/Documents/go-test-package-failure/subpackage/go.mod",
"GoVersion": "1.20"
}
What did you see instead?
In the checkout, the following fails:
$ ~/go/bin/go1.20.5 list -u -m -json all
go: updates to go.sum needed, disabled by -mod=readonly
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 4
- Comments: 17 (8 by maintainers)
Commits related to this issue
- fix: go.sum to avoid https://github.com/golang/go/issues/60667 — committed to joergjo/go-samples by joergjo a year ago
- [release-branch.go1.20] cmd/go: omit checksums for go.mod files needed for go version lines more often in pre-1.21 modules This updates the logic from CL 489075 to avoid trying to save extra sums if ... — committed to golang/go by bcmills a year ago
- [release-branch.go1.19] cmd/go: omit checksums for go.mod files needed for go version lines more often in pre-1.21 modules This updates the logic from CL 489075 to avoid trying to save extra sums if ... — committed to golang/go by bcmills a year ago
In the meantime you can work around this with one of the following:
-mod=mod
in thego list
command (to allow it to update thego.sum
file)go mod tidy -compat=1.16
(instead of justgo mod tidy
) to record all of the needed checksums upfront.Yes, I intend for it to be. (That, or we will roll back part of all of #60001 and #60000.)