]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: make cmd/* default to go tool installation
authorRuss Cox <rsc@golang.org>
Fri, 6 Oct 2017 18:12:56 +0000 (14:12 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 11 Oct 2017 17:47:17 +0000 (17:47 +0000)
Every cmd/thing is 'go tool thing' except for go and gofmt.
But the table in cmd/go enumerates all the things instead of
saying that go and gofmt are the exceptions.
Change that, so that when adding new tools it's not
necessary to update this table.

Change-Id: Ia6fef41b4d967249b19971a0d03e5acb0317ea82
Reviewed-on: https://go-review.googlesource.com/69052
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
src/cmd/go/internal/load/pkg.go
src/cmd/go/internal/work/build.go

index 1d89512b669db0797fd8660103f4648f263097df..ae9aad4fffb22c3ef3a31aaa2130ebd75f013850 100644 (file)
@@ -796,36 +796,27 @@ func FindVendor(path string) (index int, ok bool) {
        return 0, false
 }
 
-type targetDir int
+type TargetDir int
 
 const (
-       ToRoot    targetDir = iota // to bin dir inside package root (default)
-       ToTool                     // GOROOT/pkg/tool
-       StalePath                  // the old import path; fail to build
+       ToTool    TargetDir = iota // to GOROOT/pkg/tool (default for cmd/*)
+       ToBin                      // to bin dir inside package root (default for non-cmd/*)
+       StalePath                  // an old import path; fail to build
 )
 
-// goTools is a map of Go program import path to install target directory.
-var GoTools = map[string]targetDir{
-       "cmd/addr2line": ToTool,
-       "cmd/api":       ToTool,
-       "cmd/asm":       ToTool,
-       "cmd/compile":   ToTool,
-       "cmd/cgo":       ToTool,
-       "cmd/cover":     ToTool,
-       "cmd/dist":      ToTool,
-       "cmd/doc":       ToTool,
-       "cmd/fix":       ToTool,
-       "cmd/link":      ToTool,
-       "cmd/newlink":   ToTool,
-       "cmd/nm":        ToTool,
-       "cmd/objdump":   ToTool,
-       "cmd/pack":      ToTool,
-       "cmd/pprof":     ToTool,
-       "cmd/trace":     ToTool,
-       "cmd/vet":       ToTool,
-       "code.google.com/p/go.tools/cmd/cover": StalePath,
-       "code.google.com/p/go.tools/cmd/godoc": StalePath,
-       "code.google.com/p/go.tools/cmd/vet":   StalePath,
+// InstallTargetDir reports the target directory for installing the command p.
+func InstallTargetDir(p *Package) TargetDir {
+       if strings.HasPrefix(p.ImportPath, "code.google.com/p/go.tools/cmd/") {
+               return StalePath
+       }
+       if p.Goroot && strings.HasPrefix(p.ImportPath, "cmd/") && p.Name == "main" {
+               switch p.ImportPath {
+               case "cmd/go", "cmd/gofmt":
+                       return ToBin
+               }
+               return ToTool
+       }
+       return ToBin
 }
 
 var cgoExclude = map[string]bool{
@@ -872,7 +863,7 @@ func (p *Package) load(stk *ImportStack, bp *build.Package, err error) {
 
        if useBindir {
                // Report an error when the old code.google.com/p/go.tools paths are used.
-               if GoTools[p.ImportPath] == StalePath {
+               if InstallTargetDir(p) == StalePath {
                        newPath := strings.Replace(p.ImportPath, "code.google.com/p/go.", "golang.org/x/", 1)
                        e := fmt.Sprintf("the %v command has moved; use %v instead.", p.ImportPath, newPath)
                        p.Error = &PackageError{Err: e}
@@ -893,7 +884,7 @@ func (p *Package) load(stk *ImportStack, bp *build.Package, err error) {
                                p.Internal.GobinSubdir = true
                        }
                }
-               if GoTools[p.ImportPath] == ToTool {
+               if InstallTargetDir(p) == ToTool {
                        // This is for 'go tool'.
                        // Override all the usual logic and force it into the tool directory.
                        p.Internal.Target = filepath.Join(cfg.GOROOTpkg, "tool", full)
index 4fc39f94119c94cc722c5e0e6bf258b27c7e007f..88d880152da6b63c2f95296d49caf4030b500516 100644 (file)
@@ -594,7 +594,7 @@ func InstallPackages(args []string, forGet bool) {
                // This avoids installing assemblers/compilers that are being executed
                // by other steps in the build.
                a1 := b.AutoAction(ModeInstall, ModeInstall, p)
-               if load.GoTools[p.ImportPath] == load.ToTool {
+               if load.InstallTargetDir(p) == load.ToTool {
                        a.Deps = append(a.Deps, a1.Deps...)
                        a1.Deps = append(a1.Deps, a)
                        tools = append(tools, a1)