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

x/tools/cmd/goimports: error "root package %s is missing" #29297

Closed
thatguystone opened this issue Dec 16, 2018 · 7 comments
Closed

x/tools/cmd/goimports: error "root package %s is missing" #29297

thatguystone opened this issue Dec 16, 2018 · 7 comments

Comments

@thatguystone
Copy link

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

$ go version
go version go1.11.4 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="~/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="~/Dev/go"
GOPROXY=""
GORACE=""
GOROOT="~/.gimme/versions/go1.11.4.linux.amd64"
GOTMPDIR=""
GOTOOLDIR="~/.gimme/versions/go1.11.4.linux.amd64/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="~/Desktop/test/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-build909428892=/tmp/go-build -gno-record-gcc-switches"

What did you do?

~ $ git clone git@gist.github.com:0ce7246431ace4c03a7ae82400ed9050.git
Cloning into '0ce7246431ace4c03a7ae82400ed9050'...
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (4/4), done.
~ $ cd 0ce7246431ace4c03a7ae82400ed9050/
0ce7246431ace4c03a7ae82400ed9050 $ goimports -w .
root package strings is missing

What did you expect to see?

goimports should do nothing. If I rm go.mod, it works correctly (in that it doesn't report an error).

What did you see instead?

goimports prints "root package strings is missing" and exits with status 2.

This seems to be a bug introduced from @heschik's fix for #27287.

@gopherbot gopherbot added this to the Unreleased milestone Dec 16, 2018
@heschi
Copy link
Contributor

heschi commented Dec 17, 2018

I won't be able to try your repro today but I suspect this is an issue with your Go installation. Can you set GOPACKAGESPRINTGOLISTERRORS=1 and attach the output?

@thatguystone
Copy link
Author

Here it is:

$ GOPACKAGESPRINTGOLISTERRORS=1 goimports -w .
GOROOT=~/.gimme/versions/go1.11.4.linux.amd64 GOPATH=~/Dev/go GO111MODULE= PWD=~/Desktop/0ce7246431ace4c03a7ae82400ed9050 go [list -e -json -compiled -test=false -export=true -deps=true -- strings .] stderr: <<# github.com/thatguystone/foo
./foo.go:4:9: undefined: strings
>>
root package strings is missing```

@heschi
Copy link
Contributor

heschi commented Dec 18, 2018

Weird. I can't reproduce the problem, so I still think this is an issue with your installation of Go. But I'm not sure what it is.

Can you try running the command printed on the first line there? It should pretty much work if you strip the brackets off the arguments. We're expecting json output that doesn't include an entry for "strings" for some reason. It might also be interesting to run go install std to see if something weird happens there.

@matloob, @ianthehat in case they have any clue.

@matloob
Copy link
Contributor

matloob commented Dec 18, 2018

+1 on heschi's suggestion. I'm curious what the following command produces:

GOROOT=~/.gimme/versions/go1.11.4.linux.amd64 GOPATH=~/Dev/go GO111MODULE= PWD=~/Desktop/0ce7246431ace4c03a7ae82400ed9050 go list -e -json -compiled -test=false -export=true -deps=true -- strings .

Could you give us some information about what "gimme" is? If it's having trouble finding a standard library package, my guess is that it has to do with your GOROOT.

@thatguystone
Copy link
Author

thatguystone commented Dec 18, 2018

I dug into this a bit more, and it looks this happens when there's another package named "strings". I've updated the test case with a dependency that has such a package (specifically, it's github.com/gobwas/glob/util/strings).

0ce7246431ace4c03a7ae82400ed9050 $ mkdir ../go
0ce7246431ace4c03a7ae82400ed9050 $ export GOPATH=`pwd`/../go
0ce7246431ace4c03a7ae82400ed9050 $ go mod tidy
go: finding github.com/gobwas/glob v0.2.3
go: downloading github.com/gobwas/glob v0.2.3
0ce7246431ace4c03a7ae82400ed9050 $ goimports -w foo.go 
root package strings is missing

If I remove the dependency from foo.go, the problem doesn't go away.

0ce7246431ace4c03a7ae82400ed9050 $ cat go.mod
module github.com/thatguystone/foo

require github.com/gobwas/glob v0.2.3
0ce7246431ace4c03a7ae82400ed9050 $ go mod tidy
0ce7246431ace4c03a7ae82400ed9050 $ cat go.mod
module github.com/thatguystone/foo
0ce7246431ace4c03a7ae82400ed9050 $ goimports -w foo.go 
root package strings is missing

If I actually remove the package from the cache, then it works:

0ce7246431ace4c03a7ae82400ed9050 $ chmod u+rw -R ../go/pkg/mod/github.com/gobwas/
0ce7246431ace4c03a7ae82400ed9050 $ rm -rf !$
rm -rf ../go/pkg/mod/github.com/gobwas/
0ce7246431ace4c03a7ae82400ed9050 $ goimports -w foo.go

@heschik

Can you try running the command printed on the first line there? It should pretty much work if you strip the brackets off the arguments. We're expecting json output that doesn't include an entry for "strings" for some reason.

Output here: https://gist.github.com/thatguystone/0ce7246431ace4c03a7ae82400ed9050#file-golist-json

It might also be interesting to run go install std to see if something weird happens there.

Nothing weird happened there: it exited with status 0 and printed nothing.

@matloob

Could you give us some information about what "gimme" is? If it's having trouble finding a standard library package, my guess is that it has to do with your GOROOT.

gimme is the tool travis-ci uses to switch go versions for builds (https://github.com/travis-ci/gimme/)

@heschi
Copy link
Contributor

heschi commented Dec 18, 2018

Thanks for the excellent repro. I understand the problem now. It's a pretty simple bug in the guts of go/packages when a query finds the same package through multiple paths, in this case both via a module dependency and a module cache scan. Not sure how our tests missed this.

Anyway, I should have a CL soon, probably tomorrow.

@gopherbot
Copy link

Change https://golang.org/cl/155020 mentions this issue: go/packages: deduplicate roots

@golang golang locked and limited conversation to collaborators Dec 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants