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
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
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") {
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
{{.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 {
--- /dev/null
+# cmd/doc should use GOROOT to locate the 'go' command,
+# not use whatever is in $PATH.
+
+# Remove 'go' from $PATH. (It can still be located via $GOROOT/bin/go, and the
+# test script's built-in 'go' command still knows where to find it.)
+env PATH=''
+[plan9] env path=''
+
+go doc p.X
+
+-- go.mod --
+module example
+
+go 1.19
+
+require example.com/p v0.1.0
+
+replace example.com/p => ./pfork
+-- example.go --
+package example
+
+import _ "example.com/p"
+-- pfork/go.mod --
+module example.com/p
+
+go 1.19
+-- pfork/p.go --
+package p
+
+const X = 42