1 // Copyright 2018 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.
15 func findGOROOT() string {
16 if env := os.Getenv("GOROOT"); env != "" {
17 return filepath.Clean(env)
19 def := filepath.Clean(runtime.GOROOT())
20 if runtime.Compiler == "gccgo" {
21 // gccgo has no real GOROOT, and it certainly doesn't
22 // depend on the executable's location.
25 out, err := exec.Command("go", "env", "GOROOT").Output()
29 return strings.TrimSpace(string(out))