mirror of
https://github.com/golang/go
synced 2024-11-05 15:56:12 -07:00
79dbfd6c86
After godoc stopped being part of the Go distribution, the location of the godoc binary and the go binary can be different. Hence the old GOROOT finding logic does not work anymore. We shell out to "go env GOROOT" to return the new GOROOT. Fixes golang/go#23445 Change-Id: I16e4c0798e3f5cda13d9f6546cf82808a10c4a0b Reviewed-on: https://go-review.googlesource.com/c/tools/+/199279 Reviewed-by: Andrew Bonventre <andybons@golang.org> Run-TryBot: Andrew Bonventre <andybons@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
31 lines
666 B
Go
31 lines
666 B
Go
// 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"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"runtime"
|
|
"strings"
|
|
)
|
|
|
|
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
|
|
}
|
|
out, err := exec.Command("go", "env", "GOROOT").Output()
|
|
if err != nil {
|
|
return def
|
|
}
|
|
return strings.TrimSpace(string(out))
|
|
}
|