diff options
Diffstat (limited to 'src/cmd/api')
| -rw-r--r-- | src/cmd/api/goapi.go | 12 | ||||
| -rw-r--r-- | src/cmd/api/goapi_test.go | 2 |
2 files changed, 11 insertions, 3 deletions
diff --git a/src/cmd/api/goapi.go b/src/cmd/api/goapi.go index 2a0e109575..b2a023a9b7 100644 --- a/src/cmd/api/goapi.go +++ b/src/cmd/api/goapi.go @@ -34,9 +34,11 @@ func goCmd() string { if runtime.GOOS == "windows" { exeSuffix = ".exe" } - path := filepath.Join(runtime.GOROOT(), "bin", "go"+exeSuffix) - if _, err := os.Stat(path); err == nil { - return path + if goroot := build.Default.GOROOT; goroot != "" { + path := filepath.Join(goroot, "bin", "go"+exeSuffix) + if _, err := os.Stat(path); err == nil { + return path + } } return "go" } @@ -127,6 +129,10 @@ var internalPkg = regexp.MustCompile(`(^|/)internal($|/)`) func main() { flag.Parse() + if build.Default.GOROOT == "" { + log.Fatalf("GOROOT not found. (If binary was built with -trimpath, $GOROOT must be set.)") + } + if !strings.Contains(runtime.Version(), "weekly") && !strings.Contains(runtime.Version(), "devel") { if *nextFiles != "" { fmt.Printf("Go version is %q, ignoring -next %s\n", runtime.Version(), *nextFiles) diff --git a/src/cmd/api/goapi_test.go b/src/cmd/api/goapi_test.go index 16e0058e5e..862ab183b2 100644 --- a/src/cmd/api/goapi_test.go +++ b/src/cmd/api/goapi_test.go @@ -9,6 +9,7 @@ import ( "flag" "fmt" "go/build" + "internal/testenv" "os" "path/filepath" "sort" @@ -22,6 +23,7 @@ func TestMain(m *testing.M) { for _, c := range contexts { c.Compiler = build.Default.Compiler } + build.Default.GOROOT = testenv.GOROOT(nil) // Warm up the import cache in parallel. var wg sync.WaitGroup |
