Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.0.0-20201105173854-bc9fc8d8c4bc / cmd / godoc / goroot.go
diff --git a/.config/coc/extensions/coc-go-data/tools/pkg/mod/golang.org/x/tools@v0.0.0-20201105173854-bc9fc8d8c4bc/cmd/godoc/goroot.go b/.config/coc/extensions/coc-go-data/tools/pkg/mod/golang.org/x/tools@v0.0.0-20201105173854-bc9fc8d8c4bc/cmd/godoc/goroot.go
new file mode 100644 (file)
index 0000000..755069d
--- /dev/null
@@ -0,0 +1,30 @@
+// 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))
+}