Skip to content

Commit c39cd41

Browse files
author
Bryan C. Mills
committed
cmd/go: restore default vet analyzers for targets in GOROOT
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 <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent a15b5d3 commit c39cd41

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

src/cmd/go/internal/vet/vet.go

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func runVet(cmd *base.Command, args []string) {
5151

5252
work.BuildInit()
5353
work.VetFlags = vetFlags
54+
work.VetExplicit = true
5455
if vetTool != "" {
5556
var err error
5657
work.VetTool, err = filepath.Abs(vetTool)

src/cmd/go/internal/work/exec.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ func (b *Builder) vet(a *Action) error {
10361036
// There's too much unsafe.Pointer code
10371037
// that vet doesn't like in low-level packages
10381038
// like runtime, sync, and reflect.
1039-
vetFlags = append(vetFlags, string("-unsafeptr=false"))
1039+
vetFlags = []string{"-unsafeptr=false"}
10401040
}
10411041

10421042
// Note: We could decide that vet should compute export data for
@@ -1774,6 +1774,11 @@ func (b *Builder) fmtcmd(dir string, format string, args ...interface{}) string
17741774
}
17751775
if b.WorkDir != "" {
17761776
cmd = strings.ReplaceAll(cmd, b.WorkDir, "$WORK")
1777+
escaped := strconv.Quote(b.WorkDir)
1778+
escaped = escaped[1 : len(escaped)-1] // strip quote characters
1779+
if escaped != b.WorkDir {
1780+
cmd = strings.ReplaceAll(cmd, escaped, "$WORK")
1781+
}
17771782
}
17781783
return cmd
17791784
}
+32-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,34 @@
1-
env GO111MODULE=off
1+
env GO111MODULE=on
22

3-
# Issue 35837. Verify that "go vet -<analyzer> <std package>" works if 'pwd' is not $GOROOT/src
4-
# we utilize the package runtime/testdata/testprog as the issue is specific to vetting standard package
5-
6-
go vet -n -unreachable=false runtime/testdata/testprog
3+
# Regression test for issue 35837: "go vet -<analyzer> <std package>"
4+
# did not apply the requested analyzer.
5+
go vet -n -unreachable=false encoding/binary
76
stderr '-unreachable=false'
8-
stderr '-unsafeptr=false'
7+
! stderr '-unsafeptr=false'
8+
9+
[short] stop
10+
env GOCACHE=$WORK/gocache
11+
env GOTMPDIR=$WORK/tmp
12+
go env GOTMPDIR
13+
stdout '/tmp'
14+
15+
# "go test" on a user package should by default enable an explicit whitelist of analyzers.
16+
go test -x -run=none .
17+
stderr '[/\\]vet'$GOEXE'["]? .* -errorsas .* ["]?\$WORK[/\\][^ ]*[/\\]vet\.cfg'
18+
19+
# "go test" on a standard package should by default disable an explicit blacklist.
20+
go test -x -run=none encoding/binary
21+
stderr '[/\\]vet'$GOEXE'["]? -unsafeptr=false ["]?\$WORK[/\\][^ ]*[/\\]vet\.cfg'
22+
23+
# Both should allow users to override via the -vet flag.
24+
go test -x -vet=unreachable -run=none .
25+
stderr '[/\\]vet'$GOEXE'["]? -unreachable ["]?\$WORK[/\\][^ ]*[/\\]vet\.cfg'
26+
go test -x -vet=unreachable -run=none encoding/binary
27+
stderr '[/\\]vet'$GOEXE'["]? -unreachable ["]?\$WORK[/\\][^ ]*[/\\]vet\.cfg'
28+
29+
-- go.mod --
30+
module example.com/x
31+
-- x.go --
32+
package x
33+
-- x_test.go --
34+
package x

0 commit comments

Comments
 (0)