libgo: update to Go 1.10.2 release
[official-gcc.git] / libgo / go / cmd / go / internal / vet / vet.go
bloba737ebd669ffcc8dae856c8f0b191f48c987aca3
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.
5 // Package vet implements the ``go vet'' command.
6 package vet
8 import (
9 "cmd/go/internal/base"
10 "cmd/go/internal/load"
11 "cmd/go/internal/work"
12 "path/filepath"
15 var CmdVet = &base.Command{
16 Run: runVet,
17 CustomFlags: true,
18 UsageLine: "vet [-n] [-x] [build flags] [vet flags] [packages]",
19 Short: "report likely mistakes in packages",
20 Long: `
21 Vet runs the Go vet command on the packages named by the import paths.
23 For more about vet and its flags, see 'go doc cmd/vet'.
24 For more about specifying packages, see 'go help packages'.
26 The -n flag prints commands that would be executed.
27 The -x flag prints commands as they are executed.
29 The build flags supported by go vet are those that control package resolution
30 and execution, such as -n, -x, -v, -tags, and -toolexec.
31 For more about these flags, see 'go help build'.
33 See also: go fmt, go fix.
37 func runVet(cmd *base.Command, args []string) {
38 vetFlags, pkgArgs := vetFlags(args)
40 work.BuildInit()
41 work.VetFlags = vetFlags
42 if vetTool != "" {
43 var err error
44 work.VetTool, err = filepath.Abs(vetTool)
45 if err != nil {
46 base.Fatalf("%v", err)
50 pkgs := load.PackagesForBuild(pkgArgs)
51 if len(pkgs) == 0 {
52 base.Fatalf("no packages to vet")
55 var b work.Builder
56 b.Init()
58 root := &work.Action{Mode: "go vet"}
59 for _, p := range pkgs {
60 ptest, pxtest, err := load.GetTestPackagesFor(p, false)
61 if err != nil {
62 base.Errorf("%v", err)
63 continue
65 if len(ptest.GoFiles) == 0 && len(ptest.CgoFiles) == 0 && pxtest == nil {
66 base.Errorf("go vet %s: no Go files in %s", p.ImportPath, p.Dir)
67 continue
69 if len(ptest.GoFiles) > 0 || len(ptest.CgoFiles) > 0 {
70 root.Deps = append(root.Deps, b.VetAction(work.ModeBuild, work.ModeBuild, ptest))
72 if pxtest != nil {
73 root.Deps = append(root.Deps, b.VetAction(work.ModeBuild, work.ModeBuild, pxtest))
76 b.Do(root)