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/vet: -<analyzer> flags don't work when outside of GOROOT #35837

Closed
shawn-xdji opened this issue Nov 26, 2019 · 7 comments
Closed

cmd/vet: -<analyzer> flags don't work when outside of GOROOT #35837

shawn-xdji opened this issue Nov 26, 2019 · 7 comments

Comments

@shawn-xdji
Copy link
Contributor

@shawn-xdji shawn-xdji commented Nov 26, 2019

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

$ go version
go version devel +95be9b7559 Fri Nov 22 04:26:34 2019 +0000 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
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/xiaji01/.cache/go-build"
GOENV="/home/xiaji01/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/xiaji01/.go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/xiaji01/util/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/xiaji01/util/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build905003963=/tmp/go-build -gno-record-gcc-switches"

What did you do?

~/util/go$ go vet runtime/testdata/testprog
# runtime/testdata/testprog
src/runtime/testdata/testprog/deadlock.go:45:2: unreachable code
src/runtime/testdata/testprog/deadlock.go:50:2: unreachable code

~/util/go$ go vet -unreachable=false runtime/testdata/testprog
# runtime/testdata/testprog
src/runtime/testdata/testprog/deadlock.go:45:2: unreachable code
src/runtime/testdata/testprog/deadlock.go:50:2: unreachable code

What did you expect to see?

-unreachable=false works even running 'go vet' outside <go root>/src

What did you see instead?

the unreachable warning is not suppressed.

@shawn-xdji
Copy link
Contributor Author

@shawn-xdji shawn-xdji commented Nov 26, 2019

I have a local fix, would like to send it for reviewing if this is a bug.

@dmitshur dmitshur added this to the Backlog milestone Nov 26, 2019
@dmitshur
Copy link
Member

@dmitshur dmitshur commented Nov 26, 2019

@alandonovan
Copy link
Contributor

@alandonovan alandonovan commented Nov 26, 2019

Thanks, this does indeed look like a bug. Please do share your fix.

$ go version
go version devel +4a378d712d Tue Nov 26 20:21:04 2019 +0000 linux/amd64

$ cd $GOROOT/src
$ go vet -unreachable=true runtime/testdata/testprog
# runtime/testdata/testprog
runtime/testdata/testprog/deadlock.go:45:2: unreachable code
runtime/testdata/testprog/deadlock.go:50:2: unreachable code
$ go vet -unreachable=false runtime/testdata/testprog
$

$ cd $HOME
$ go vet -unreachable=true runtime/testdata/testprog
# runtime/testdata/testprog
go-again/src/runtime/testdata/testprog/deadlock.go:45:2: unreachable code
go-again/src/runtime/testdata/testprog/deadlock.go:50:2: unreachable code
$ go vet -unreachable=false runtime/testdata/testprog
# runtime/testdata/testprog
go-again/src/runtime/testdata/testprog/deadlock.go:45:2: unreachable code
go-again/src/runtime/testdata/testprog/deadlock.go:50:2: unreachable code
@alandonovan alandonovan changed the title cmd/vet: vet flags for specifying 'analyzer' doesn't work cmd/vet: -<analyzer> flags don't work when outside of GOROOT Nov 26, 2019
@shawn-xdji
Copy link
Contributor Author

@shawn-xdji shawn-xdji commented Nov 29, 2019

Thanks for confirming.
The flags specified on 'go vet' command line will be overwritten if:
1. the package under vetting is resolved by searching under $GOROOT/src (after the local import fails to find a matched one), and
2. no options for 'go tool vet' are specified
3. no vettool is specified
There might be various fixes, I chose to replace the overwriting with appending, thought it would minimize the impact, make sense?

@gopherbot
Copy link

@gopherbot gopherbot commented Dec 2, 2019

Change https://golang.org/cl/209498 mentions this issue: cmd/vet: honor analyzer flags when running vet outside $GOROOT/src

@gopherbot gopherbot closed this in 2ac1ca9 Dec 3, 2019
@gopherbot
Copy link

@gopherbot gopherbot commented Dec 11, 2019

Change https://golang.org/cl/210937 mentions this issue: cmd/go: restore default vet analyzers for targets in GOROOT

gopherbot pushed a commit that referenced this issue Dec 12, 2019
This fixes a regression introduced in CL 209498,
found while investigating #32471.

Also fix $WORK replacement in cmd/go/internal/work.(*Builder).Showcmd
when b.WorkDir includes a backslash and appears in a quoted string.
That fix is needed in order to write a precise test that passes under Windows,
since Windows directories nearly always include backslashes.

Updates #35837

Change-Id: I5fddc5435d5d283a3e598989209d873b59b0a39c
Reviewed-on: https://go-review.googlesource.com/c/go/+/210937
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
@gopherbot
Copy link

@gopherbot gopherbot commented Feb 5, 2020

Change https://golang.org/cl/217897 mentions this issue: cmd/go/internal/vet: only set work.VetExplicit if the list of explicit flags is non-empty

gopherbot pushed a commit that referenced this issue Feb 5, 2020
…t flags is non-empty

Updates #35837
Fixes #37030

Change-Id: Ifd3435803622a8624bab55a0f3fbc8855025282f
Reviewed-on: https://go-review.googlesource.com/c/go/+/217897
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
@golang golang locked and limited conversation to collaborators Feb 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants