github.com/flyinox/gosm@v0.0.0-20171117061539-16768cb62077/src/cmd/go/internal/base/tool.go (about) 1 // Copyright 2017 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. 4 5 package base 6 7 import ( 8 "fmt" 9 "go/build" 10 "os" 11 "path/filepath" 12 "runtime" 13 14 "cmd/go/internal/cfg" 15 ) 16 17 // Configuration for finding tool binaries. 18 var ( 19 ToolGOOS = runtime.GOOS 20 ToolGOARCH = runtime.GOARCH 21 ToolIsWindows = ToolGOOS == "windows" 22 ToolDir = build.ToolDir 23 ) 24 25 const ToolWindowsExtension = ".exe" 26 27 // Tool returns the path to the named tool (for example, "vet"). 28 // If the tool cannot be found, Tool exits the process. 29 func Tool(toolName string) string { 30 toolPath := filepath.Join(ToolDir, toolName) 31 if ToolIsWindows { 32 toolPath += ToolWindowsExtension 33 } 34 if len(cfg.BuildToolexec) > 0 { 35 return toolPath 36 } 37 // Give a nice message if there is no tool with that name. 38 if _, err := os.Stat(toolPath); err != nil { 39 if isInGoToolsRepo(toolName) { 40 fmt.Fprintf(os.Stderr, "go tool: no such tool %q; to install:\n\tgo get golang.org/x/tools/cmd/%s\n", toolName, toolName) 41 } else { 42 fmt.Fprintf(os.Stderr, "go tool: no such tool %q\n", toolName) 43 } 44 SetExitStatus(2) 45 Exit() 46 } 47 return toolPath 48 } 49 50 // TODO: Delete. 51 func isInGoToolsRepo(toolName string) bool { 52 return false 53 }