aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/doc
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2022-03-16 14:45:42 -0400
committerBryan Mills <bcmills@google.com>2022-03-17 20:09:38 +0000
commit3046ae927d7664a63bb8c3a2fb3b9ca95bcf93de (patch)
tree6ddf15b6d46c4d60bf12678eb658cc83b7ccb0ba /src/cmd/doc
parent2b0ac284cf4b81badb1c29e4fa299ea25cb9318f (diff)
downloadgo-3046ae927d7664a63bb8c3a2fb3b9ca95bcf93de.tar.xz
cmd/doc: use the 'go' command from buildCtx.GOROOT, not whatever is in $PATH
For #51483. Change-Id: I6150fdf97763d858e9ab012e807515da3387c25f Reviewed-on: https://go-review.googlesource.com/c/go/+/393366 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/cmd/doc')
-rw-r--r--src/cmd/doc/dirs.go16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/cmd/doc/dirs.go b/src/cmd/doc/dirs.go
index cb4d45ac6c..489f490889 100644
--- a/src/cmd/doc/dirs.go
+++ b/src/cmd/doc/dirs.go
@@ -58,6 +58,14 @@ func dirsInit(extra ...Dir) {
go dirs.walk(codeRoots())
}
+// goCmd returns the "go" command path corresponding to buildCtx.GOROOT.
+func goCmd() string {
+ if buildCtx.GOROOT == "" {
+ return "go"
+ }
+ return filepath.Join(buildCtx.GOROOT, "bin", "go")
+}
+
// Reset puts the scan back at the beginning.
func (d *Dirs) Reset() {
d.offset = 0
@@ -181,7 +189,7 @@ func findCodeRoots() []Dir {
if !testGOPATH {
// Check for use of modules by 'go env GOMOD',
// which reports a go.mod file path if modules are enabled.
- stdout, _ := exec.Command("go", "env", "GOMOD").Output()
+ stdout, _ := exec.Command(goCmd(), "env", "GOMOD").Output()
gomod := string(bytes.TrimSpace(stdout))
usingModules = len(gomod) > 0
@@ -230,7 +238,7 @@ func findCodeRoots() []Dir {
return list
}
- cmd := exec.Command("go", "list", "-m", "-f={{.Path}}\t{{.Dir}}", "all")
+ cmd := exec.Command(goCmd(), "list", "-m", "-f={{.Path}}\t{{.Dir}}", "all")
cmd.Stderr = os.Stderr
out, _ := cmd.Output()
for _, line := range strings.Split(string(out), "\n") {
@@ -259,7 +267,7 @@ func vendorEnabled() (*moduleJSON, bool, error) {
return nil, false, err
}
- stdout, _ := exec.Command("go", "env", "GOFLAGS").Output()
+ stdout, _ := exec.Command(goCmd(), "env", "GOFLAGS").Output()
goflags := string(bytes.TrimSpace(stdout))
matches := modFlagRegexp.FindStringSubmatch(goflags)
var modFlag string
@@ -293,7 +301,7 @@ func getMainModuleAnd114() (*moduleJSON, bool, error) {
{{.GoVersion}}
{{range context.ReleaseTags}}{{if eq . "go1.14"}}{{.}}{{end}}{{end}}
`
- cmd := exec.Command("go", "list", "-m", "-f", format)
+ cmd := exec.Command(goCmd(), "list", "-m", "-f", format)
cmd.Stderr = os.Stderr
stdout, err := cmd.Output()
if err != nil {