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 mod tidy adds an indirect dependency and then `go mod why' tells I don't need it #27696

Closed
ghost opened this issue Sep 15, 2018 · 8 comments
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@ghost
Copy link

ghost commented Sep 15, 2018

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

go1.11 linux/amd64

Does this issue reproduce with the latest release?

Yes.

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/opennota/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/opennota/gocode"
GOPROXY=""
GORACE=""
GOROOT="/home/opennota/go"
GOTMPDIR=""
GOTOOLDIR="/home/opennota/go/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-build560781445=/tmp/go-build -gno-record-gcc-switches"

What did you do?

~/gocode/src/gitlab.com/opennota/fb2index $ GO111MODULE=on go mod tidy
go: finding google.golang.org/appengine/cloudsql latest

~/gocode/src/gitlab.com/opennota/fb2index $ cat go.mod 
module gitlab.com/opennota/fb2index

require (
        github.com/go-sql-driver/mysql v1.4.0 // indirect
        github.com/jmoiron/sqlx v0.0.0-20180614180643-0dae4fefe7c0
        github.com/lib/pq v1.0.0 // indirect
        github.com/mattn/go-sqlite3 v1.9.0
        golang.org/x/text v0.3.0
        google.golang.org/appengine v1.1.0 // indirect
)

~/gocode/src/gitlab.com/opennota/fb2index $ GO111MODULE=on go mod why google.golang.org/appengine
go: finding github.com/golang/protobuf/proto latest
go: finding golang.org/x/net/context latest
go: finding golang.org/x/net latest
# google.golang.org/appengine
(main module does not need package google.golang.org/appengine)

What did you expect to see?

go mod why shows why go mod tidy added google.golang.org/appengine to go.mod.

What did you see instead?

(main module does not need package google.golang.org/appengine)

@ghost ghost changed the title cmd/go: go mod tidy adds an indirect dependency and then tells I don't need it cmd/go: go mod tidy adds an indirect dependency and then `go mod why' tells I don't need it Sep 15, 2018
@bcmills bcmills added modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Sep 17, 2018
@bcmills bcmills added this to the Go1.12 milestone Sep 17, 2018
@bcmills
Copy link
Contributor

bcmills commented Sep 17, 2018

In order to track this down, we're probably going to need an input that reproduces it.

Can you share a (hopefully minimal) set of Go source files that reproduce the problem?

@bcmills bcmills added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Sep 17, 2018
@ghost
Copy link
Author

ghost commented Sep 17, 2018

The code is here: https://gitlab.com/opennota/fb2index
I can try to minimize it tomorrow.
google.golang.org/appengine seems to be coming from /home/opennota/gocode/pkg/mod/github.com/go-sql-driver/mysql@v1.4.0/appengine.go, but go mod why doesn't see this. go-sql-driver/mysql is itself an indirect dependency.

@bcmills bcmills removed the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Sep 17, 2018
@bcmills
Copy link
Contributor

bcmills commented Sep 17, 2018

Thanks, that's at least a good start. I assume it still reproduces at the current commit (ee9d8829)?

@ghost
Copy link
Author

ghost commented Sep 17, 2018

Yes.

@ghost
Copy link
Author

ghost commented Sep 17, 2018

Here is a simpler reproducer:

package a

import _ "github.com/jmoiron/sqlx"
go mod init example
go mod tidy
cat go.mod
go mod why google.golang.org/appengine

@ghost
Copy link
Author

ghost commented Sep 19, 2018

Looks like I was doing it wrong. go mod why -m google.golang.org/appengine does show why the module is in go.mod. Without -m it doesn't. go help mod why says that

Why shows a shortest path in the import graph from the main module to
each of the listed packages. If the -m flag is given, why treats the
arguments as a list of modules and finds a path to any package in each
of the modules.

The main module depends on google.golang.org/appengine/cloudsql, not on google.golang.org/appengine.

@ghost ghost closed this as completed Sep 19, 2018
@bcmills
Copy link
Contributor

bcmills commented Sep 19, 2018

Thanks for the explanation. It's always good to find out what went wrong even when things are working as documented: if we notice a pattern we can at least improve the documentation.

@ghost
Copy link
Author

ghost commented Sep 20, 2018

Perhaps go mod why could detect when it is given a name present in go.mod without -m and print a warning.

@golang golang locked and limited conversation to collaborators Sep 20, 2019
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

2 participants