Commit 58963354 authored by Alan Donovan's avatar Alan Donovan

cmd/go: vet: revert $GOVETTOOL env var, restore -vettool flag

The environment variable is no longer necessary as we now plan to
transition to the new vet by replacing it in a single step,
and we really don't want to add more environment variables.

Fixes #28636

Change-Id: Ib85e5c0d61213b7b9f6a53d9376fec29525df971
Reviewed-on: https://go-review.googlesource.com/c/148497
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBryan C. Mills <bcmills@google.com>
parent 5e9ad4a9
...@@ -23,20 +23,39 @@ import ( ...@@ -23,20 +23,39 @@ import (
// go vet flag processing // go vet flag processing
// //
// We query the flags of the tool specified by GOVETTOOL (default: // We query the flags of the tool specified by -vettool and accept any
// cmd/vet) and accept any of those flags plus any flag valid for 'go // of those flags plus any flag valid for 'go build'. The tool must
// build'. The tool must support -flags, which prints a description of // support -flags, which prints a description of its flags in JSON to
// its flags in JSON to stdout. // stdout.
// GOVETTOOL specifies the vet command to run. // vetTool specifies the vet command to run.
// This must be an environment variable because // Any tool that supports the (still unpublished) vet
// we need it before flag processing, as we execute // command-line protocol may be supplied; see
// $GOVETTOOL to discover the set of flags it supports. // golang.org/x/tools/go/analysis/unitchecker for one
// implementation. It is also used by tests.
// //
// Using an environment variable also makes it easy for users to opt in // The default behavior (vetTool=="") runs 'go tool vet'.
// to (and later, opt out of) the new cmd/vet analysis driver during the //
// transition. It is also used by tests. var vetTool string // -vettool
var vetTool = os.Getenv("GOVETTOOL")
func init() {
// Extract -vettool by ad hoc flag processing:
// its value is needed even before we can declare
// the flags available during main flag processing.
for i, arg := range os.Args {
if arg == "-vettool" || arg == "--vettool" {
if i+1 >= len(os.Args) {
log.Fatalf("%s requires a filename", arg)
}
vetTool = os.Args[i+1]
break
} else if strings.HasPrefix(arg, "-vettool=") ||
strings.HasPrefix(arg, "--vettool=") {
vetTool = arg[strings.IndexByte(arg, '=')+1:]
break
}
}
}
// vetFlags processes the command line, splitting it at the first non-flag // vetFlags processes the command line, splitting it at the first non-flag
// into the list of flags and list of packages. // into the list of flags and list of packages.
...@@ -94,6 +113,9 @@ func vetFlags(usage func(), args []string) (passToVet, packageNames []string) { ...@@ -94,6 +113,9 @@ func vetFlags(usage func(), args []string) (passToVet, packageNames []string) {
// Add build flags to vetFlagDefn. // Add build flags to vetFlagDefn.
var cmd base.Command var cmd base.Command
work.AddBuildFlags(&cmd) work.AddBuildFlags(&cmd)
// This flag declaration is a placeholder:
// -vettool is actually parsed by the init function above.
cmd.Flag.StringVar(new(string), "vettool", "", "path to vet tool binary")
cmd.Flag.VisitAll(func(f *flag.Flag) { cmd.Flag.VisitAll(func(f *flag.Flag) {
vetFlagDefn = append(vetFlagDefn, &cmdflag.Defn{ vetFlagDefn = append(vetFlagDefn, &cmdflag.Defn{
Name: f.Name, Name: f.Name,
......
...@@ -178,7 +178,8 @@ func (b *Builder) toolID(name string) string { ...@@ -178,7 +178,8 @@ func (b *Builder) toolID(name string) string {
path := base.Tool(name) path := base.Tool(name)
desc := "go tool " + name desc := "go tool " + name
// Special case: undocumented $GOVETTOOL overrides usual vet, for testing vet. // Special case: undocumented -vettool overrides usual vet,
// for testing vet or supplying an alternative analysis tool.
if name == "vet" && VetTool != "" { if name == "vet" && VetTool != "" {
path = VetTool path = VetTool
desc = VetTool desc = VetTool
......
...@@ -118,12 +118,11 @@ func TestVetPrint(t *testing.T) { ...@@ -118,12 +118,11 @@ func TestVetPrint(t *testing.T) {
Build(t) Build(t)
file := filepath.Join("testdata", "print.go") file := filepath.Join("testdata", "print.go")
cmd := exec.Command( cmd := exec.Command(
"go", "vet", "go", "vet", "-vettool="+binary,
"-printf", "-printf",
"-printfuncs=Warn:1,Warnf:1", "-printfuncs=Warn:1,Warnf:1",
file, file,
) )
cmd.Env = append(os.Environ(), "GOVETTOOL="+binary)
errchk(cmd, []string{file}, t) errchk(cmd, []string{file}, t)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment