1
0
mirror of https://github.com/golang/go synced 2024-10-02 02:18:33 -06:00

cmd/go: make cmd/* default to go tool installation

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>
This commit is contained in:
Russ Cox 2017-10-06 14:12:56 -04:00
parent 6c7bea6309
commit a9c3d09d0e
2 changed files with 20 additions and 29 deletions

View File

@ -796,36 +796,27 @@ func FindVendor(path string) (index int, ok bool) {
return 0, false return 0, false
} }
type targetDir int type TargetDir int
const ( const (
ToRoot targetDir = iota // to bin dir inside package root (default) ToTool TargetDir = iota // to GOROOT/pkg/tool (default for cmd/*)
ToTool // GOROOT/pkg/tool ToBin // to bin dir inside package root (default for non-cmd/*)
StalePath // the old import path; fail to build StalePath // an old import path; fail to build
) )
// goTools is a map of Go program import path to install target directory. // InstallTargetDir reports the target directory for installing the command p.
var GoTools = map[string]targetDir{ func InstallTargetDir(p *Package) TargetDir {
"cmd/addr2line": ToTool, if strings.HasPrefix(p.ImportPath, "code.google.com/p/go.tools/cmd/") {
"cmd/api": ToTool, return StalePath
"cmd/asm": ToTool, }
"cmd/compile": ToTool, if p.Goroot && strings.HasPrefix(p.ImportPath, "cmd/") && p.Name == "main" {
"cmd/cgo": ToTool, switch p.ImportPath {
"cmd/cover": ToTool, case "cmd/go", "cmd/gofmt":
"cmd/dist": ToTool, return ToBin
"cmd/doc": ToTool, }
"cmd/fix": ToTool, return ToTool
"cmd/link": ToTool, }
"cmd/newlink": ToTool, return ToBin
"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,
} }
var cgoExclude = map[string]bool{ var cgoExclude = map[string]bool{
@ -872,7 +863,7 @@ func (p *Package) load(stk *ImportStack, bp *build.Package, err error) {
if useBindir { if useBindir {
// Report an error when the old code.google.com/p/go.tools paths are used. // 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) 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) e := fmt.Sprintf("the %v command has moved; use %v instead.", p.ImportPath, newPath)
p.Error = &PackageError{Err: e} p.Error = &PackageError{Err: e}
@ -893,7 +884,7 @@ func (p *Package) load(stk *ImportStack, bp *build.Package, err error) {
p.Internal.GobinSubdir = true p.Internal.GobinSubdir = true
} }
} }
if GoTools[p.ImportPath] == ToTool { if InstallTargetDir(p) == ToTool {
// This is for 'go tool'. // This is for 'go tool'.
// Override all the usual logic and force it into the tool directory. // Override all the usual logic and force it into the tool directory.
p.Internal.Target = filepath.Join(cfg.GOROOTpkg, "tool", full) p.Internal.Target = filepath.Join(cfg.GOROOTpkg, "tool", full)

View File

@ -594,7 +594,7 @@ func InstallPackages(args []string, forGet bool) {
// This avoids installing assemblers/compilers that are being executed // This avoids installing assemblers/compilers that are being executed
// by other steps in the build. // by other steps in the build.
a1 := b.AutoAction(ModeInstall, ModeInstall, p) 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...) a.Deps = append(a.Deps, a1.Deps...)
a1.Deps = append(a1.Deps, a) a1.Deps = append(a1.Deps, a)
tools = append(tools, a1) tools = append(tools, a1)