github.com/riscv/riscv-go@v0.0.0-20200123204226-124ebd6fcc8e/src/cmd/go/internal/vet/vet.go (about) 1 // Copyright 2011 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package vet implements the ``go vet'' command. 6 package vet 7 8 import ( 9 "path/filepath" 10 11 "cmd/go/internal/base" 12 "cmd/go/internal/cfg" 13 "cmd/go/internal/load" 14 "cmd/go/internal/str" 15 "cmd/go/internal/work" 16 ) 17 18 func init() { 19 work.AddBuildFlags(CmdVet) 20 } 21 22 var CmdVet = &base.Command{ 23 Run: runVet, 24 UsageLine: "vet [-n] [-x] [build flags] [packages]", 25 Short: "run go tool vet on packages", 26 Long: ` 27 Vet runs the Go vet command on the packages named by the import paths. 28 29 For more about vet, see 'go doc cmd/vet'. 30 For more about specifying packages, see 'go help packages'. 31 32 To run the vet tool with specific options, run 'go tool vet'. 33 34 The -n flag prints commands that would be executed. 35 The -x flag prints commands as they are executed. 36 37 For more about build flags, see 'go help build'. 38 39 See also: go fmt, go fix. 40 `, 41 } 42 43 func runVet(cmd *base.Command, args []string) { 44 for _, p := range load.Packages(args) { 45 // Vet expects to be given a set of files all from the same package. 46 // Run once for package p and once for package p_test. 47 if len(p.GoFiles)+len(p.CgoFiles)+len(p.TestGoFiles) > 0 { 48 runVetFiles(p, str.StringList(p.GoFiles, p.CgoFiles, p.TestGoFiles, p.SFiles)) 49 } 50 if len(p.XTestGoFiles) > 0 { 51 runVetFiles(p, str.StringList(p.XTestGoFiles)) 52 } 53 } 54 } 55 56 func runVetFiles(p *load.Package, files []string) { 57 for i := range files { 58 files[i] = filepath.Join(p.Dir, files[i]) 59 } 60 base.Run(cfg.BuildToolexec, base.Tool("vet"), base.RelPaths(files)) 61 }