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 vet' cannot resolve imports of vendored packages #17571

Closed
leonklingele opened this issue Oct 24, 2016 · 9 comments
Closed

cmd/go: 'go vet' cannot resolve imports of vendored packages #17571

leonklingele opened this issue Oct 24, 2016 · 9 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@leonklingele
Copy link
Contributor

Follow-up of https://groups.google.com/forum/#!topic/golang-nuts/W8lvnNlcO2o

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

1.7.3

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

darwin/amd64, linux/amd64

Steps to reproduce

$ git clone https://github.com/bndw/pick -b develop
$ cd pick
$ make goget # (to install dependencies)
$ sed -i "s/go tool vet/go tool vet -v/" Makefile # (to enable vet's verbose mode)
$ make govet

Output

..
vet: crypto/scrypt/scrypt.go:6:2: could not import golang.org/x/crypto/scrypt (can't find import: golang.org/x/crypto/scrypt)
..
commands/version.go:15: can't check non-constant format in call to Printf
..

There are two main issues:

  • could not import / can't find import
  • commands/version.go:15: can't check non-constant format in call to Printf

Is this a bug in go tool vet? How to fix these "issues"?

@robpike
Copy link
Contributor

robpike commented Oct 25, 2016

The problem is simple at root: vet can't find the imports, and without the imports it cannot type-check.

You need to figure out why on your machine those imports are not available, or at least appear not to be available to vet. Perhaps you have multiple go installations, or different GOPATHs set, or have simply not installed those dependencies.

But this is not a vet bug.

@rakyll
Copy link
Contributor

rakyll commented Oct 25, 2016

The problem seems to be somewhere in your Makefile, it is not a tool bug.

$ go get github.com/bndw/pick
$ go vet github.com/bndw/pick/...
$ echo $?
0

@rakyll rakyll closed this as completed Oct 25, 2016
@leonklingele
Copy link
Contributor Author

leonklingele commented Oct 25, 2016

Perhaps you have multiple go installations

No

or different GOPATHs set

Well, we do overwrite the original GOPATH to support compilations from outside the user-GOPATH. This works fine with all Go commands but go tool vet.

Please try it yourself — do not use go get but use the Steps to reproduce provided above.

@rakyll rakyll changed the title go tool vet -v throwing errors for no apparent reason cmd/vet: go tool vet -v throwing errors for no apparent reason Oct 25, 2016
@rakyll
Copy link
Contributor

rakyll commented Oct 25, 2016

Looks like an inconsistency bug.

I can reproduce with your specific example but it also does much work such as maintaining a copy of the GOPATH under vendor directory. A smaller reproducible would be nice to have.

@rakyll rakyll reopened this Oct 25, 2016
@leonklingele
Copy link
Contributor Author

leonklingele commented Oct 26, 2016

$ git clone https://github.com/leonklingele/go-tool-vet-v-issues
$ cd go-tool-vet-v-issues
$ make
$ make govet

Fails with:

vet: hello/hello.go:7:2: could not import golang.org/x/crypto/pbkdf2 (can't find import: golang.org/x/crypto/pbkdf2)
Checking file hello/hello.go
make: *** [govet] Error 1
$ bin/hello # Works fine

@quentinmit quentinmit added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 1, 2016
@quentinmit quentinmit added this to the Go1.8Maybe milestone Nov 1, 2016
@rsc
Copy link
Contributor

rsc commented Nov 2, 2016

The problem here is that vet is trying to process an import of a vendored package, but it has not been given the mapping from import paths to expanded vendor paths like the compiler has available. That map probably needs to be passed from cmd/go to vet much as it is for compile. And then vet has to pass it to go/internal/gcimporter. Would like to fix this but it's been broken since Go 1.6, so I think it can wait another release.

Note that 'go tool vet' is never going to get this right. You want to be using 'go vet' instead.

We should probably make 'go vet -v' pass the -v through to the vet invocation though.

@rsc rsc modified the milestones: Go1.9, Go1.8Maybe Nov 2, 2016
@rsc rsc changed the title cmd/vet: go tool vet -v throwing errors for no apparent reason cmd/go: 'go vet' cannot resolve imports of vendored packages Nov 2, 2016
@rsc rsc added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Nov 2, 2016
@rsc rsc modified the milestones: Go1.10, Go1.9 Jun 22, 2017
@rsc
Copy link
Contributor

rsc commented Jun 22, 2017

Vet will need even more work along these lines with the new caching work planned for Go 1.10. But then things will be better, and this will be fixed.

@bgaifullin
Copy link
Contributor

I have the similar issue on go 1.9, command go vet -v tells that it cannot import package, event the package is in GOPATH and go build, go test executes without error.

@gopherbot
Copy link

Change https://golang.org/cl/74750 mentions this issue: cmd/go: pass package config to vet during "go vet"

@golang golang locked and limited conversation to collaborators Nov 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

7 participants