1
2
3
4
5 package base
6
7 import (
8 "fmt"
9 "go/build"
10 "os"
11 "path/filepath"
12
13 "cmd/go/internal/cfg"
14 "cmd/go/internal/par"
15 )
16
17
18
19 func Tool(toolName string) string {
20 toolPath, err := ToolPath(toolName)
21 if err != nil && len(cfg.BuildToolexec) == 0 {
22
23 fmt.Fprintf(os.Stderr, "go: no such tool %q\n", toolName)
24 SetExitStatus(2)
25 Exit()
26 }
27 return toolPath
28 }
29
30
31
32 func ToolPath(toolName string) (string, error) {
33 toolPath := filepath.Join(build.ToolDir, toolName) + cfg.ToolExeSuffix()
34 err := toolStatCache.Do(toolPath, func() error {
35 _, err := os.Stat(toolPath)
36 return err
37 })
38 return toolPath, err
39 }
40
41 var toolStatCache par.Cache[string, error]
42
View as plain text