Closed
Description
What version of Go are you using (go version
)?
$ go version go1.16rc1
Does this issue reproduce with the latest release?
Yes, it is only present in go1.16rc1, and not go1.16beta1
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GO111MODULE="on" GOARCH="amd64" GOBIN="" GOCACHE="/home/howardjohn/.cache/go-build" GOENV="/home/howardjohn/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/howardjohn/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/howardjohn/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/home/howardjohn/sdk/go1.16rc1" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/home/howardjohn/sdk/go1.16rc1/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.16rc1" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/home/howardjohn/go/src/istio.io/api/go.mod" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1862906774=/tmp/go-build -gno-record-gcc-switches"
What did you do?
On 1.16beta1:
$ git status
On branch master
Your branch is up to date with 'origin/master'.
$ ~/go/bin/go1.16beta1 mod download
$ git status
On branch master
Your branch is up to date with 'origin/master'.
On 1.16rc1:
$ git status
On branch master
Your branch is up to date with 'origin/master'.
$ ~/go/bin/go1.16rc1 mod download
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: go.sum
$ ~/go/bin/go1.16rc1 mod tidy
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Repo: https://github.com/istio/api
What did you expect to see?
Either go mod download
does not add to go.sum, OR go mod tidy
keeps what is added by go mod download
. In either case, the two tools should be consistent
What did you see instead?
go mod download
adds to go.sum
, which go mod tidy
removes
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
Workaround golang bug causing make gen to fail
[-]go mod download and go mod tidy conflict (1.16beta1 -> 1.16rc1 regression)[/-][+]cmd/go: mod download and go mod tidy conflict (1.16beta1 -> 1.16rc1 regression)[/+]Workaround golang bug causing make gen to fail (#1861)
bcmills commentedon Jan 29, 2021
go mod tidy
downloads source code only for those modules that are needed to provide packages transitively imported by the packages and tests in the main module (go list -deps -test ./...
).go mod tidy
reduces thego.sum
file to contain checksums for only those modules.In contrast,
go mod download
downloads source code for all modules in the module graph (go list -m all
; compare #41431). As a side-effect, it should also record the checksums for those modules.If
go mod download
fails spuriously due to missing checksums (or due to an error writing thego.sum
file), that's probably a bug we should fix, but if it is just recording more checksums thango mod tidy
does, that's an unfortunate but intentional difference between the current behavior of the two commands.CC @jayconrod @matloob
bcmills commentedon Jan 29, 2021
(Note that lazy loading — #36460 — should bring
go mod tidy
andgo mod download
closer together, but even thengo mod download
will still potentially download more thango mod tidy
.)howardjohn commentedon Jan 29, 2021
For more details on the impact: all of our CI enforces
go mod tidy
is run. Some of our CI was actually runninggo mod tidy
thengo mod download
, resulting in it generating a git diff which is rejected. The fix there is easy - just rungo mod tidy
last.However, in day to day use its pretty annoying that if I run
go mod download
mygo.sum
file is suddenly modified, and if I accidentally check it into git my PR will be rejected. I think this is a common practice in projects as well, and not unique to us to reject spurious go.sum changes.I am not sure there is a distinction in practice, but my concern is only about modifying/reverting go.sum - I don't mind if its downloading more or not.
bcmills commentedon Jan 29, 2021
Could you give some more detail about when you run
go mod download
in day-to-day use? I'm a little surprised that it's needed, and that may indicate that either we don't understand how people are using the tool or we need better documentation on the expected day-to-day workflow.(As part of #36460 I've been mulling over whether we should add a
go mod download
flag to download only what's relevant to the main module, but today that's a little redundant withgo list -test all
.)Agreed: we expect that a lot of projects will enforce that
go mod tidy
is a no-op for PRs. (See also #27005.)howardjohn commentedon Jan 29, 2021
Using
go mod download
in docker seems common for better layer caching.There are cases where I want my IDE completion to work, but need the modules first. I suppose I could just run
go mod tidy
instead, butgo mod download
worked before so I've just used that. Perhaps its not a great reason, but I am a bit confused whatgo mod download
is intended for if not this.bcmills commentedon Jan 29, 2021
For IDE completion,
gopls
should already be downloading the dependencies of the main module as needed. (If not, I'd suggest filing a separate issue for that.)bcmills commentedon Jan 29, 2021
The short answer, I think, is that
go mod download
is not really the right tool for anything. 😅(It is optimized for “give me a short command that does at least what I probably need and is easy to remember”.)
go list all
is probably the thing you want to run to prime a Docker cache, and perhaps to prime a non-gopls
IDE too.bcmills commentedon Jan 29, 2021
FWIW, the behavior change here was almost certainly CL 282692, for #41103.
23 remaining items