golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.46k stars 17.59k forks source link

cmd/go: GO111MODULE=on and unset GOPATH generate incompatible module checksums #29664

Closed jayschwa closed 5 years ago

jayschwa commented 5 years ago

What version of Go are you using (go version)?

$ go version
go version go1.11.4 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/jay/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/jay/spell"
GOPROXY=""
GORACE=""
GOROOT="/snap/go/3095"
GOTMPDIR=""
GOTOOLDIR="/snap/go/3095/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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-build944689084=/tmp/go-build -gno-record-gcc-switches"

What did you do?

$ rm go.sum
$ GO111MODULE=on go mod tidy
$ (unset GOPATH && go mod tidy)
go: verifying github.com/docker/docker@v0.7.3-0.20181128160009-852542b39767: checksum mismatch
    downloaded: h1:l6MPrA7HbTIeBptIanRxdS9gn7DhOjBUJr6gxO0ssKc=
    go.sum:     h1:KA+HbwLQPSH8VOiw6Pgn/7UP6s1LfkaxJO+48QIS/zk=

$ rm go.sum
$ (unset GOPATH && go mod tidy)
$ GO111MODULE=on go mod tidy
go: verifying github.com/docker/docker@v0.7.3-0.20181128160009-852542b39767: checksum mismatch
    downloaded: h1:KA+HbwLQPSH8VOiw6Pgn/7UP6s1LfkaxJO+48QIS/zk=
    go.sum:     h1:l6MPrA7HbTIeBptIanRxdS9gn7DhOjBUJr6gxO0ssKc=

What did you expect to see?

I expected the same (or at least compatible) go.sum to be generated

julieqiu commented 5 years ago

/cc @bcmills

bcmills commented 5 years ago

Dup of #29278. Run go clean -modcache and clear out the go.sum entries for any modules whose repos contain symlinks.

jayschwa commented 5 years ago

@bcmills, this is not a duplicate. The problem still occurs after go clean -modcache.

bcmills commented 5 years ago

Yes, it is a duplicate. Read the whole reply.

and clear out the go.sum entries for any modules whose repos contain symlinks.

~/src/github.com/docker/docker$ find ./* -type l
./integration-cli/fixtures/https/server-key.pem
./integration-cli/fixtures/https/client-cert.pem
./integration-cli/fixtures/https/server-cert.pem
./integration-cli/fixtures/https/client-key.pem
./integration-cli/fixtures/https/ca.pem
jayschwa commented 5 years ago

Read the whole bug report. The first step of my example is rm go.sum.

bcmills commented 5 years ago

Yes, and you ran unset GOPATH && go mod tidy. Did you also unset GOPATH when you ran go clean -modcache?

Here's what I get, starting from a clean GOPATH:

``` $ go1.11.4 mod init golang.org/issue/scratch go: creating new go.mod: module golang.org/issue/scratch $ cat >main.go <
The error in your snippet is telling you exactly what is wrong: the module cache in your default `GOPATH` (that is, `$USER/go/pkg/mod`) has an incorrect (pre-1.11.4) copy of the module, while the cache in your actual `GOPATH` (`$GOPATH/pkg/mod`) has the correct one.
jayschwa commented 5 years ago

Did you also unset GOPATH when you ran go clean -modcache?

No, that explains it. Sorry for the bother (and salt).