"cmd/go/internal/base"
"cmd/go/internal/cfg"
+ "cmd/go/internal/envcmd"
"cmd/go/internal/web"
)
fmt.Fprintf(w, "### What operating system and processor architecture are you using (`go env`)?\n\n")
fmt.Fprintf(w, "<details><summary><code>go env</code> Output</summary><br><pre>\n")
fmt.Fprintf(w, "$ go env\n")
- goexe, err := os.Executable()
- if err != nil {
- goexe = filepath.Join(runtime.GOROOT(), "bin/go")
- }
- printCmdOut(w, "", goexe, "env")
+ printGoEnv(w)
printGoDetails(w)
printOSDetails(w)
printCDetails(w)
fmt.Fprintf(w, "</pre></details>\n\n")
}
+func printGoEnv(w io.Writer) {
+ env := envcmd.MkEnv()
+ env = append(env, envcmd.ExtraEnvVars()...)
+ env = append(env, envcmd.ExtraEnvVarsCostly()...)
+ envcmd.PrintEnv(w, env)
+}
+
func printGoDetails(w io.Writer) {
printCmdOut(w, "GOROOT/bin/go version: ", filepath.Join(runtime.GOROOT(), "bin/go"), "version")
printCmdOut(w, "GOROOT/bin/go tool compile -V: ", filepath.Join(runtime.GOROOT(), "bin/go"), "tool", "compile", "-V")
"encoding/json"
"fmt"
"go/build"
+ "io"
"os"
"path/filepath"
"runtime"
return
}
+ PrintEnv(os.Stdout, env)
+}
+
+// PrintEnv prints the environment variables to w.
+func PrintEnv(w io.Writer, env []cfg.EnvVar) {
for _, e := range env {
if e.Name != "TERM" {
switch runtime.GOOS {
default:
- fmt.Printf("%s=\"%s\"\n", e.Name, e.Value)
+ fmt.Fprintf(w, "%s=\"%s\"\n", e.Name, e.Value)
case "plan9":
if strings.IndexByte(e.Value, '\x00') < 0 {
- fmt.Printf("%s='%s'\n", e.Name, strings.ReplaceAll(e.Value, "'", "''"))
+ fmt.Fprintf(w, "%s='%s'\n", e.Name, strings.ReplaceAll(e.Value, "'", "''"))
} else {
v := strings.Split(e.Value, "\x00")
- fmt.Printf("%s=(", e.Name)
+ fmt.Fprintf(w, "%s=(", e.Name)
for x, s := range v {
if x > 0 {
- fmt.Printf(" ")
+ fmt.Fprintf(w, " ")
}
- fmt.Printf("%s", s)
+ fmt.Fprintf(w, "%s", s)
}
- fmt.Printf(")\n")
+ fmt.Fprintf(w, ")\n")
}
case "windows":
- fmt.Printf("set %s=%s\n", e.Name, e.Value)
+ fmt.Fprintf(w, "set %s=%s\n", e.Name, e.Value)
}
}
}