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 adds unnecessary module dependency #34290

Closed
alanconway opened this issue Sep 13, 2019 · 12 comments
Closed

cmd/go: go adds unnecessary module dependency #34290

alanconway opened this issue Sep 13, 2019 · 12 comments

Comments

@alanconway
Copy link

@alanconway alanconway commented Sep 13, 2019

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

go version go1.12.9 linux/amd64

Does this issue reproduce with the latest release?

Don't know, using latest packaged release on Fedora.

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/aconway/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/aconway/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/golang"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/aconway/gomod/src/github.com/cloudevents/sdk-go/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-build160743641=/tmp/go-build -gno-record-gcc-switches"

What did you do?

$ git clone https://github.com/cloudevents/sdk-go
$ cd sdk-go
$ go list -m
github.com/cloudevents/sdk-go
$ go mod tidy
$ grep gogo go.mod # Note output is empty
$ go list -m
github.com/cloudevents/sdk-go
$ grep gogo go.mod # Just `go list -m` causes this dep to appear.
	github.com/gogo/protobuf v1.2.0 // indirect
$ go mod why github.com/gogo/protobuf
# github.com/gogo/protobuf
(main module does not need package github.com/gogo/protobuf)
$ go mod tidy
$ grep gogo go.mod # gogo is gone again!
$ 

What did you expect to see?

No incorrect dependencies in go.mod.
Agreement between go tools on what dependencies are required.
After a successful go build; go mod tidy, subsequent calls of go build or
go mod tidy with no code changes should not change go.mod.

What did you see instead?

Calling go list -m or any go comand (go build etc.) adds a line to go.mod

	github.com/gogo/protobuf v1.2.0 // indirect

Calling go tidy removes that line.

I suspect this may be some environmental factor on my machine as I haven't heard anyone else with this problem but I don't know what it might be.

@zikaeroh

This comment has been minimized.

Copy link

@zikaeroh zikaeroh commented Sep 13, 2019

Given you're still on 1.12, this is probably #31248, fixed in 1.13.

@n3wscott

This comment has been minimized.

Copy link

@n3wscott n3wscott commented Sep 13, 2019

/watch

@thepudds thepudds added the modules label Sep 13, 2019
@thepudds thepudds changed the title go adds unnecessary module dependency cmd/go: go adds unnecessary module dependency Sep 13, 2019
@thepudds

This comment has been minimized.

Copy link

@thepudds thepudds commented Sep 13, 2019

@alanconway As @zikaeroh mentioned, there were fixes in this area for Go 1.13. If you run through these steps with Go 1.13, does the problem still happen?

@alanconway

This comment has been minimized.

Copy link
Author

@alanconway alanconway commented Sep 16, 2019

Still happens on 1.13, I uninstalled the 1.12 installation to ensure I wasn't picking up any old libs.

My symptoms are different from #31248 - go tidy is behaving correctly, it is removing a package that is not needed. go why agrees that it is not needed. However go list, go build and other commands add it back. I built github.com/cloudevents/sdk-go with go dep in GOPATH mode to confirm that github.com/gogo/protobuf is really not required to build.

@douglarek

This comment has been minimized.

Copy link

@douglarek douglarek commented Sep 23, 2019

I got the same issue as @alanconway and I use go 1.13

@bcmills bcmills removed the WaitingForInfo label Sep 26, 2019
@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Sep 26, 2019

@alanconway, I'm unable to reproduce the behavior you observed using go1.13.1. Can you provide a specific commit of the repository that I can check out to reproduce the behavior?

This may be a duplicate of #34086, but without a current reproducer it's hard to be sure.

@alanconway

This comment has been minimized.

Copy link
Author

@alanconway alanconway commented Sep 27, 2019

@bcmills 1.13.1 works for me, looks like it's fixed :) Thanks.

@alanconway alanconway closed this Sep 27, 2019
@douglarek

This comment has been minimized.

Copy link

@douglarek douglarek commented Sep 29, 2019

Some supplement for this: it only works when you use go 1.13.1 and also use 1.13.1 in go.mod file.

And another question: when using a newer go version, should go.mod's go version be updated automatically @bcmills , thanks!

@alanconway alanconway reopened this Sep 30, 2019
@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Sep 30, 2019

it only works when you use go 1.13.1 and also use 1.13.1 in go.mod file.

The go.mod file specifies only the language version: go 1.13.1 in the go.mod file should not be accepted in the first place. (go 1.13, however, should.)

And another question: when using a newer go version, should go.mod's go version be updated automatically

No. Newer versions of the toolchain can compile older versions of the language spec, so in general it should not be necessary to update the go directive unless you need to enable newer language features.

@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Sep 30, 2019

@douglarek, the problem originally reported here does not seem to reproduce, so I'm going to close this issue.

If you're seeing something you believe to be a bug, please file a new issue with concrete steps to reproduce it — ideally, a repo that we can check out at a specific commit to demonstrate the problem.

@bcmills bcmills closed this Sep 30, 2019
@alanconway

This comment was marked as off-topic.

Copy link
Author

@alanconway alanconway commented Sep 30, 2019

Re-opened till other comments are addressed.

I see that 1.13.1 go mode adds a "go 1.13.1" line go go.mod if there's no existing go version, but if I add an explicit version like "go 1.11", then go mod leaves it alone, so it seems like upgrading to go.mod requires an explicit go version to stop the defaulting if you care about older versions.

@bcmills

This comment was marked as off-topic.

Copy link
Member

@bcmills bcmills commented Sep 30, 2019

Please keep issue threads on-topic: this discussion doesn't seem to have anything to do with the originally-reported issue.

Clarifying documentation about which go version to set is #30791.

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