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: mod tidy removes lines that build seems to need #31248

Closed
zombiezen opened this issue Apr 3, 2019 · 10 comments

Comments

@zombiezen
Copy link
Contributor

commented Apr 3, 2019

(I haven't dug into exactly what dependency is causing this or why, but I've managed to whittle the issue down to a fairly manageable no-code repro case.)

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

$ go version
go 1.12.1

Does this issue reproduce with the latest release?

Yes. I haven't checked against tip.

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

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

What did you do?

git clone https://gist.github.com/5513fc51a179cfd757dcdd1d7c1e4995.git mod-tidy-issue
cd mod-tidy-issue
go mod tidy
go build -mod=readonly

main.go + go.mod gist

What did you expect to see?

A successful build of the binary.

What did you see instead?

go: updates to go.mod needed, disabled by -mod=readonly

Additional surrounding steps

Running go build will cause go build -mod=readonly to pass. Doing this adds lines (all marked "indirect") for:

  • github.com/golang/mock
  • gopkg.in/check.v1
  • gopkg.in/yaml.v2

However, running go mod tidy on this go.mod will unceremoniously remove these added lines. Most confusingly, go mod why doesn't seem to know why these lines are there either:

$ go mod why -m gopkg.in/yaml.v2
# gopkg.in/yaml.v2
(main module does not need module gopkg.in/yaml.v2)

@zombiezen zombiezen added the modules label Apr 3, 2019

@andybons

This comment has been minimized.

Copy link
Member

commented Apr 4, 2019

@andybons andybons added this to the Unplanned milestone Apr 4, 2019

@jayconrod jayconrod self-assigned this Apr 4, 2019

@bcmills

This comment has been minimized.

Copy link
Member

commented Apr 4, 2019

We should check for similarities with #29773. (I don't know whether it will turn out to be related, but it's a known source of missing dependencies.)

@prymitive

This comment has been minimized.

Copy link

commented Jun 7, 2019

Hit the same issue - go build and go mod tidy keep fighting over what should be in go.mod
gist for reference - https://gist.github.com/prymitive/9f8ac72d9a88f1704efa8ebfdf133bd1

$ git st
On branch master
[...]
	new file:   go.mod
	new file:   go.sum
	new file:   main.go
$ go build
$ git diff
diff --git a/go.mod b/go.mod
index 6980ec7..7e79628 100644
--- a/go.mod
+++ b/go.mod
@@ -15,6 +15,7 @@ require (
        github.com/gin-gonic/contrib v0.0.0-20190526021735-7fb7810ed2a0
        github.com/gin-gonic/gin v1.4.0
        github.com/go-bindata/go-bindata v3.1.1+incompatible
+       github.com/go-logfmt/logfmt v0.4.0 // indirect
        github.com/go-openapi/errors v0.19.0
        github.com/go-openapi/runtime v0.19.0
        github.com/go-openapi/strfmt v0.19.0
$ go mod tidy
$ git diff
[no diff]
$ go build
$ git diff
diff --git a/go.mod b/go.mod
index 6980ec7..7e79628 100644
--- a/go.mod
+++ b/go.mod
@@ -15,6 +15,7 @@ require (
        github.com/gin-gonic/contrib v0.0.0-20190526021735-7fb7810ed2a0
        github.com/gin-gonic/gin v1.4.0
        github.com/go-bindata/go-bindata v3.1.1+incompatible
+       github.com/go-logfmt/logfmt v0.4.0 // indirect
        github.com/go-openapi/errors v0.19.0
        github.com/go-openapi/runtime v0.19.0
        github.com/go-openapi/strfmt v0.19.0

prymitive added a commit to prymitive/karma that referenced this issue Jun 7, 2019

fix(backend): add a workaround for Go modules issue
go.mod keeps getting updated on build but go mod tidy reverts these changes

See golang/go#31248 (comment)
@bcmills

This comment has been minimized.

Copy link
Member

commented Jun 7, 2019

@prymitive, can you provide a more compact example, or at least compare the output of go list -m all and go mod graph? As noted above, it would be good to rule out duplicates of #29773.

@prymitive

This comment has been minimized.

Copy link

commented Jun 8, 2019

Narrowed down needed modules to just two:

github.com/prometheus/client_golang v0.9.4
github.com/spf13/viper v1.4.0

https://gist.github.com/prymitive/9f8ac72d9a88f1704efa8ebfdf133bd1 updated to reflect that
Also added the output of these 2 commands

@gopherbot

This comment has been minimized.

Copy link

commented Jul 17, 2019

Change https://golang.org/cl/186537 mentions this issue: cmd/go/internal/mvs: retain modules required by older versions

@gopherbot

This comment has been minimized.

Copy link

commented Jul 17, 2019

Change https://golang.org/cl/186557 mentions this issue: cmd/go/internal/mvs: in Req, omit versions implied by older-than-selected versions already in the graph

@bcmills

This comment has been minimized.

Copy link
Member

commented Jul 17, 2019

I found a minimal repro. A consistent reproducer requires two modules that depend on some module X. One of the modules must depend on the newer version of X and on the other module. The other module must depend on the older X, which must pull in some indirect dependency I that the newer X does not. Then mvs.Req normally adds I to the build list, but since I is not required by the selected versions and is also not needed for the import graph, go mod tidy removes it.

https://go-review.googlesource.com/c/go/+/186557/2/src/cmd/go/testdata/script/mod_indirect_tidy.txt

@bcmills bcmills assigned bcmills and unassigned jayconrod Jul 17, 2019

@bcmills bcmills modified the milestones: Unplanned, Go1.13 Jul 18, 2019

gopherbot pushed a commit that referenced this issue Jul 18, 2019

cmd/go/internal/mvs: retain modules required by older versions
Fixes #29773
Updates #31248

Change-Id: Ic1923119c8cf3a60c586df1b270c3af0c9095f29
Reviewed-on: https://go-review.googlesource.com/c/go/+/186537
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>

@gopherbot gopherbot closed this in 52fdd62 Jul 18, 2019

@jgiles

This comment has been minimized.

Copy link

commented Aug 6, 2019

I'm seeing an issue that looks like this on go1.12.7 . Is there anything I can do to confirm that I have a repro of this issue, or if I should file a separate bug?

@horgh

This comment has been minimized.

Copy link
Contributor

commented Aug 6, 2019

You could see if the behaviour you're seeing is fixed using gotip as described here: #33435 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
9 participants
You can’t perform that action at this time.