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 removes too much when modules are used for multiple packages #31059

Closed
integrii opened this issue Mar 26, 2019 · 1 comment

Comments

Projects
None yet
1 participant
@integrii
Copy link

commented Mar 26, 2019

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

go version go1.12.1 darwin/amd64

Does this issue reproduce with the latest release?

yes

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

go env Output
GOARCH="amd64"
GOBIN="/Users/egreer200/go/bin"
GOCACHE="/Users/egreer200/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/egreer200/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.1/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/7h/qd9xrbq10lb03g4lkqcl_cdr0000gp/T/go-build194066640=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I have a module that has a couple layers of packages under it. The module is here. Specifically notice that the checks directory has other packages within it.

I can go mod tidy from the pkg/ directory linked above.

What did you expect to see?

A few packages that were not used possibly being removed.

What did you see instead?

Nearly all packages were removed, but some were kept. It looked like this:

image
image
and so on.

It appears that tidy is targeting only one (or a few) of the packages. Perhaps only the packages at the first level of directory depth under the pkg/ dir were analyzed?

In short, it looks like go mod tidy will not work when a module is used for multiple packages.

@integrii

This comment has been minimized.

Copy link
Author

commented Mar 26, 2019

Actually, I think this is because when I created this module, I ran go build ... and it started building literally everything in my gopath... I am opening a new issue. I believe go mod tidy is actually correct. After running a tidy, I can run go build ./... and the project builds fine!

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