Skip to content

Commit a9c3d09

Browse files
committed
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>
1 parent 6c7bea6 commit a9c3d09

File tree

2 files changed

+20
-29
lines changed

2 files changed

+20
-29
lines changed

src/cmd/go/internal/load/pkg.go

+19-28
Original file line numberDiff line numberDiff line change
@@ -796,36 +796,27 @@ func FindVendor(path string) (index int, ok bool) {
796796
return 0, false
797797
}
798798

799-
type targetDir int
799+
type TargetDir int
800800

801801
const (
802-
ToRoot targetDir = iota // to bin dir inside package root (default)
803-
ToTool // GOROOT/pkg/tool
804-
StalePath // the old import path; fail to build
802+
ToTool TargetDir = iota // to GOROOT/pkg/tool (default for cmd/*)
803+
ToBin // to bin dir inside package root (default for non-cmd/*)
804+
StalePath // an old import path; fail to build
805805
)
806806

807-
// goTools is a map of Go program import path to install target directory.
808-
var GoTools = map[string]targetDir{
809-
"cmd/addr2line": ToTool,
810-
"cmd/api": ToTool,
811-
"cmd/asm": ToTool,
812-
"cmd/compile": ToTool,
813-
"cmd/cgo": ToTool,
814-
"cmd/cover": ToTool,
815-
"cmd/dist": ToTool,
816-
"cmd/doc": ToTool,
817-
"cmd/fix": ToTool,
818-
"cmd/link": ToTool,
819-
"cmd/newlink": ToTool,
820-
"cmd/nm": ToTool,
821-
"cmd/objdump": ToTool,
822-
"cmd/pack": ToTool,
823-
"cmd/pprof": ToTool,
824-
"cmd/trace": ToTool,
825-
"cmd/vet": ToTool,
826-
"code.google.com/p/go.tools/cmd/cover": StalePath,
827-
"code.google.com/p/go.tools/cmd/godoc": StalePath,
828-
"code.google.com/p/go.tools/cmd/vet": StalePath,
807+
// InstallTargetDir reports the target directory for installing the command p.
808+
func InstallTargetDir(p *Package) TargetDir {
809+
if strings.HasPrefix(p.ImportPath, "code.google.com/p/go.tools/cmd/") {
810+
return StalePath
811+
}
812+
if p.Goroot && strings.HasPrefix(p.ImportPath, "cmd/") && p.Name == "main" {
813+
switch p.ImportPath {
814+
case "cmd/go", "cmd/gofmt":
815+
return ToBin
816+
}
817+
return ToTool
818+
}
819+
return ToBin
829820
}
830821

831822
var cgoExclude = map[string]bool{
@@ -872,7 +863,7 @@ func (p *Package) load(stk *ImportStack, bp *build.Package, err error) {
872863

873864
if useBindir {
874865
// Report an error when the old code.google.com/p/go.tools paths are used.
875-
if GoTools[p.ImportPath] == StalePath {
866+
if InstallTargetDir(p) == StalePath {
876867
newPath := strings.Replace(p.ImportPath, "code.google.com/p/go.", "golang.org/x/", 1)
877868
e := fmt.Sprintf("the %v command has moved; use %v instead.", p.ImportPath, newPath)
878869
p.Error = &PackageError{Err: e}
@@ -893,7 +884,7 @@ func (p *Package) load(stk *ImportStack, bp *build.Package, err error) {
893884
p.Internal.GobinSubdir = true
894885
}
895886
}
896-
if GoTools[p.ImportPath] == ToTool {
887+
if InstallTargetDir(p) == ToTool {
897888
// This is for 'go tool'.
898889
// Override all the usual logic and force it into the tool directory.
899890
p.Internal.Target = filepath.Join(cfg.GOROOTpkg, "tool", full)

src/cmd/go/internal/work/build.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ func InstallPackages(args []string, forGet bool) {
594594
// This avoids installing assemblers/compilers that are being executed
595595
// by other steps in the build.
596596
a1 := b.AutoAction(ModeInstall, ModeInstall, p)
597-
if load.GoTools[p.ImportPath] == load.ToTool {
597+
if load.InstallTargetDir(p) == load.ToTool {
598598
a.Deps = append(a.Deps, a1.Deps...)
599599
a1.Deps = append(a1.Deps, a)
600600
tools = append(tools, a1)

0 commit comments

Comments
 (0)