Skip to content

Commit

Permalink
cmd/go: update go bug to be more consistent with Github issue template
Browse files Browse the repository at this point in the history
As a result of using go env, the following new environment variables are
shown as part of the env section:

+CGO_CFLAGS="-g -O2"
+CGO_CPPFLAGS=""
+CGO_CXXFLAGS="-g -O2"
+CGO_FFLAGS="-g -O2"
+CGO_LDFLAGS="-g -O2"
+PKG_CONFIG="pkg-config"
+GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build612849170=/tmp/go-build -gno-record-gcc-switches"

Fixes golang#26751

Change-Id: I32baca1c3c06d08068dad0041a43a1f5532bd91e
  • Loading branch information
joshblakeley authored and myitcv committed Mar 25, 2019
1 parent 24f846e commit 7e1e56b
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 46 deletions.
79 changes: 33 additions & 46 deletions src/cmd/go/internal/bug/bug.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (

"cmd/go/internal/base"
"cmd/go/internal/cfg"
"cmd/go/internal/envcmd"
"cmd/go/internal/web"
)

Expand All @@ -43,23 +42,10 @@ func runBug(cmd *base.Command, args []string) {
}
var buf bytes.Buffer
buf.WriteString(bugHeader)
inspectGoVersion(&buf)
fmt.Fprint(&buf, "#### System details\n\n")
fmt.Fprintln(&buf, "```")
fmt.Fprintf(&buf, "go version %s %s/%s\n", runtime.Version(), runtime.GOOS, runtime.GOARCH)
env := cfg.CmdEnv
env = append(env, envcmd.ExtraEnvVars()...)
for _, e := range env {
// Hide the TERM environment variable from "go bug".
// See issue #18128
if e.Name != "TERM" {
fmt.Fprintf(&buf, "%s=\"%s\"\n", e.Name, e.Value)
}
}
printGoDetails(&buf)
printOSDetails(&buf)
printCDetails(&buf)
fmt.Fprintln(&buf, "```")
printGoVersion(&buf)
buf.WriteString("### Does this issue reproduce with the latest release?\n\n\n")
printEnvDetails(&buf)
buf.WriteString(bugFooter)

body := buf.String()
url := "https://github.com/golang/go/issues/new?body=" + web.QueryEscape(body)
Expand All @@ -69,22 +55,47 @@ func runBug(cmd *base.Command, args []string) {
}
}

const bugHeader = `Please answer these questions before submitting your issue. Thanks!
const bugHeader = `<!-- Please answer these questions before submitting your issue. Thanks! -->
`
const bugFooter = `### What did you do?
#### What did you do?
<!--
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
-->
#### What did you expect to see?
### What did you expect to see?
#### What did you see instead?
### What did you see instead?
`

func printGoVersion(w io.Writer) {
fmt.Fprintf(w, "### What version of Go are you using (`go version`)?\n\n")
fmt.Fprintf(w, "<pre>\n")
fmt.Fprintf(w, "$ go version\n")
printCmdOut(w, "", "go", "version")
fmt.Fprintf(w, "</pre>\n")
fmt.Fprintf(w, "\n")
}

func printEnvDetails(w io.Writer) {
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")
printCmdOut(w, "", "go", "env")
printGoDetails(w)
printOSDetails(w)
printCDetails(w)
fmt.Fprintf(w, "</pre></details>\n\n")
}

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")
Expand Down Expand Up @@ -129,30 +140,6 @@ func printCDetails(w io.Writer) {
}
}

func inspectGoVersion(w io.Writer) {
data, err := web.Get("https://golang.org/VERSION?m=text")
if err != nil {
if cfg.BuildV {
fmt.Printf("failed to read from golang.org/VERSION: %v\n", err)
}
return
}

// golang.org/VERSION currently returns a whitespace-free string,
// but just in case, protect against that changing.
// Similarly so for runtime.Version.
release := string(bytes.TrimSpace(data))
vers := strings.TrimSpace(runtime.Version())

if vers == release {
// Up to date
return
}

// Devel version or outdated release. Either way, this request is apropos.
fmt.Fprintf(w, "#### Does this issue reproduce with the latest release (%s)?\n\n\n", release)
}

// printCmdOut prints the output of running the given command.
// It ignores failures; 'go bug' is best effort.
func printCmdOut(w io.Writer, prefix, path string, args ...string) {
Expand Down
47 changes: 47 additions & 0 deletions src/cmd/go/testdata/script/bug.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Verify that go bug creates the appropriate URL issue body

[!linux] skip

go install
env BROWSER=$GOPATH/bin/browser
go bug
exists $TMPDIR/browser
grep '^go version' $TMPDIR/browser
grep '^GOROOT/bin/go version: go version' $TMPDIR/browser
grep '^GOROOT/bin/go tool compile -V: compile version' $TMPDIR/browser
grep '^uname -sr: Linux' $TMPDIR/browser
grep 'GNU C Library' $TMPDIR/browser

-- go.mod --
module browser

-- main.go --
package main

import (
"fmt"
"net/url"
"os"
"path/filepath"
)

func main() {
u, err := url.Parse(os.Args[1])
if err != nil {
panic(err)
}
body, err := url.PathUnescape(u.Query().Get("body"))
if err != nil {
panic(err)
}
out := filepath.Join(os.TempDir(), "browser")
f, err := os.Create(out)
if err != nil {
panic(err)
}
fmt.Fprintln(f, body)
if err := f.Close(); err != nil {
panic(err)
}
}

0 comments on commit 7e1e56b

Please sign in to comment.