1
0
mirror of https://github.com/golang/go synced 2024-11-19 12:34:47 -07: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
}
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)

View 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)