| // 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. |
| exec "golang.org/x/sys/execabs" |
| 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. |
| out, err := exec.Command("go", "env", "GOROOT").Output() |
| return strings.TrimSpace(string(out)) |