Skip to content

cmd/go: go mod graph shows indirect dependencies as requirements of main module #27309

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

Closed
misha-ridge opened this issue Aug 28, 2018 · 4 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

@misha-ridge
Copy link

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

Go 1.11

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/dottedmag/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/dottedmag/go"
GOPROXY=""
GORACE=""
GOROOT="/Users/dottedmag/kobold/deps/go1.11.darwin-amd64/dist"
GOTMPDIR=""
GOTOOLDIR="/Users/dottedmag/kobold/deps/go1.11.darwin-amd64/dist/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/dottedmag/tmp/bar/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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/mt/1tmwnxv96cg2vl1nz74_c9cm0000gn/T/go-build032453213=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

$ go mod init foo.bar
$ go get github.com/tendermint/go-amino
$ echo 'package main

import amino "github.com/tendermint/go-amino"

func main() {
    print(amino.Version)
}' > main.go
$ go mod tidy
$ go mod graph

What did you expect to see?

github.com/tendermint/[email protected] github.com/davecgh/[email protected]
github.com/tendermint/[email protected] github.com/google/[email protected]
github.com/davecgh/[email protected] github.com/pmezard/[email protected]
github.com/tendermint/[email protected] github.com/stretchr/[email protected]
foo.bar github.com/tendermint/[email protected]

What did you see instead?

foo.bar github.com/davecgh/[email protected]
foo.bar github.com/google/[email protected]
foo.bar github.com/pmezard/[email protected]
foo.bar github.com/stretchr/[email protected]
foo.bar github.com/tendermint/[email protected]

Only happens with indirect dependencies.

@rajender
Copy link
Contributor

I am also facing this issue.

[root@dev backend]# cat go.mod
module backend

require (
github.com/360EntSecGroup-Skylar/excelize v1.3.0
github.com/aws/aws-lambda-go v1.6.0
github.com/aws/aws-sdk-go v1.15.22
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/uuid v0.0.0-20180827204232-d460ce9f8df2 // indirect
github.com/gopherjs/gopherjs v0.0.0-20180825215210-0210a2f0f73c // indirect
github.com/jtolds/gls v4.2.1+incompatible // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
github.com/pborman/uuid v0.0.0-20180827223501-4c1ecd6722e8
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sergi/go-diff v1.0.0 // indirect
github.com/smartystreets/assertions v0.0.0-20180820201707-7c9eb446e3cf // indirect
github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a // indirect
github.com/stretchr/testify v1.2.2 // indirect
github.com/stripe/stripe-go v43.0.0+incompatible
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d // indirect
golang.org/x/text v0.3.0 // indirect
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2 // indirect
googlemaps.github.io/maps v0.0.0-20180819235337-ce25c900cc16
)
[root@dev backend]# go mod graph
backend github.com/360EntSecGroup-Skylar/[email protected]
backend github.com/aws/[email protected]
backend github.com/aws/[email protected]
backend github.com/davecgh/[email protected]
backend github.com/google/[email protected]
backend github.com/gopherjs/[email protected]
backend github.com/jtolds/[email protected]+incompatible
backend github.com/mohae/[email protected]
backend github.com/nfnt/[email protected]
backend github.com/pborman/[email protected]
backend github.com/pmezard/[email protected]
backend github.com/sergi/[email protected]
backend github.com/smartystreets/[email protected]
backend github.com/smartystreets/[email protected]
backend github.com/stretchr/[email protected]
backend github.com/stripe/[email protected]+incompatible
backend golang.org/x/[email protected]
backend golang.org/x/[email protected]
backend golang.org/x/[email protected]
backend googlemaps.github.io/[email protected]
github.com/aws/[email protected] github.com/go-ini/[email protected]
github.com/aws/[email protected] github.com/jmespath/[email protected]

@rajender
Copy link
Contributor

@gopherbot add label modules

@FiloSottile FiloSottile added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 30, 2018
@FiloSottile FiloSottile added this to the Go1.12 milestone Aug 30, 2018
vito added a commit to concourse/concourse that referenced this issue Sep 21, 2018
note: I'm not sure why things like runc and other somewhat 'heavy'
things are added here, and 'go mod graph' doesn't really explain
anything. I've tried pruning and recreating both but they just come
back.

hopefully golang/go#27309 can provide some
answers.
@myitcv
Copy link
Member

myitcv commented Nov 13, 2018

I believe this is working as intended. Quoting go help modules:

As part of maintaining the require statements in go.mod, the go command
tracks which ones provide packages imported directly by the current module
and which ones provide packages only used indirectly by other module
dependencies. Requirements needed only for indirect uses are marked with a
"// indirect" comment in the go.mod file. Indirect requirements are
automatically removed from the go.mod file once they are implied by other
direct requirements. Indirect requirements only arise when using modules
that fail to state some of their own dependencies or when explicitly
upgrading a module's dependencies ahead of its own stated requirements.

The critical sentence is the last one.

This might help: https://github.com/go-modules-by-example/index/blob/master/018_go_list_mod_graph_why/README.md

cc @bcmills but I'm going to mark this as closed.

@myitcv myitcv closed this as completed Nov 13, 2018
@bcmills
Copy link
Contributor

bcmills commented Nov 14, 2018

go mod graph displays the module graph as it exists. A missing requirement in a dependency doesn't impose any constraints on what version is used to satisfy the import, so it doesn't belong in the graph: you need some version of github.com/davecgh/go-spew to satisfy github.com/tendermint/go-amino, but you don't need v1.1.1 specifically (and an older version would likely work just fine).

go mod why explains the relationship between the package import graph and the module graph. That's the tool to use here.

@golang golang locked and limited conversation to collaborators Nov 14, 2019
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

6 participants