Follow-up of https://groups.google.com/forum/#!topic/golang-nuts/W8lvnNlcO2o
go version)?1.7.3
go env)?darwin/amd64, linux/amd64
$ 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
..
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 importcommands/version.go:15: can't check non-constant format in call to PrintfIs this a bug in go tool vet? How to fix these "issues"?
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.
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
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.
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.
$ 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
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.
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.
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.
Change https://golang.org/cl/74750 mentions this issue: cmd/go: pass package config to vet during "go vet"
Most helpful comment
I have the similar issue on go 1.9, command
go vet -vtells that it cannot import package, event the package is in GOPATH andgo build,go testexecutes without error.