1
2
3
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
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
28
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
38 if _, err := os.Stat(toolPath); err != nil {
39 fmt.Fprintf(os.Stderr, "go: no such tool %q\n", toolName)
40 SetExitStatus(2)
41 Exit()
42 }
43 return toolPath
44 }
45
View as plain text