2018-06-11 17:34:51 -06:00
|
|
|
// Copyright 2018 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2019-10-05 03:33:56 -06:00
|
|
|
"os/exec"
|
2018-06-11 17:34:51 -06:00
|
|
|
"path/filepath"
|
|
|
|
"runtime"
|
2019-10-05 03:33:56 -06:00
|
|
|
"strings"
|
2018-06-11 17:34:51 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func findGOROOT() string {
|
|
|
|
if env := os.Getenv("GOROOT"); env != "" {
|
|
|
|
return filepath.Clean(env)
|
|
|
|
}
|
|
|
|
def := filepath.Clean(runtime.GOROOT())
|
|
|
|
if runtime.Compiler == "gccgo" {
|
|
|
|
// gccgo has no real GOROOT, and it certainly doesn't
|
|
|
|
// depend on the executable's location.
|
|
|
|
return def
|
|
|
|
}
|
2019-10-05 03:33:56 -06:00
|
|
|
out, err := exec.Command("go", "env", "GOROOT").Output()
|
2018-06-11 17:34:51 -06:00
|
|
|
if err != nil {
|
2019-10-05 03:33:56 -06:00
|
|
|
return def
|
2018-06-11 17:34:51 -06:00
|
|
|
}
|
2019-10-05 03:33:56 -06:00
|
|
|
return strings.TrimSpace(string(out))
|
2018-06-11 17:34:51 -06:00
|
|
|
}
|