Skip to content

Commit 0ffd0a3

Browse files
committed
cmd/gorebuild: add gorebuild version to report
For golang/go#57120. Change-Id: Ic741fe1d856a9d853f25288ce29ad40a289653ef Reviewed-on: https://go-review.googlesource.com/c/build/+/515356 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: Russ Cox <rsc@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
1 parent 1ddff20 commit 0ffd0a3

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

cmd/gorebuild/report.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os"
1212
"path/filepath"
1313
"runtime"
14+
"runtime/debug"
1415
"sort"
1516
"strings"
1617
"sync"
@@ -20,6 +21,10 @@ import (
2021
// A Report is the report about this reproduction attempt.
2122
// It also holds unexported state for use during the attempt.
2223
type Report struct {
24+
Version string // module@version of gorebuild command
25+
GoVersion string // version of go command gorebuild was built with
26+
GOOS string
27+
GOARCH string
2328
Start time.Time // time reproduction started
2429
End time.Time // time reproduction ended
2530
Work string // work directory
@@ -122,12 +127,23 @@ func (l *Log) Printf(format string, args ...any) {
122127
// Run runs the rebuilds indicated by args and returns the resulting report.
123128
func Run(args []string) *Report {
124129
r := &Report{
125-
Start: time.Now(),
126-
Full: runtime.GOOS == "linux" && runtime.GOARCH == "amd64",
130+
Version: "(unknown)",
131+
GoVersion: runtime.Version(),
132+
GOOS: runtime.GOOS,
133+
GOARCH: runtime.GOARCH,
134+
Start: time.Now(),
135+
Full: runtime.GOOS == "linux" && runtime.GOARCH == "amd64",
127136
}
128137
defer func() {
129138
r.End = time.Now()
130139
}()
140+
if info, ok := debug.ReadBuildInfo(); ok {
141+
m := &info.Main
142+
if m.Replace != nil {
143+
m = m.Replace
144+
}
145+
r.Version = m.Path + "@" + m.Version
146+
}
131147

132148
var err error
133149
defer func() {

cmd/gorebuild/report.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ pre { margin-left: 2em; }
2626

2727
{{define "autoopen"}} {{if not (eq . "PASS")}} open {{end}} {{end}}
2828

29+
Gorebuild version {{.Version}}.<br>
30+
Built with Go version {{.GoVersion}}, {{.GOOS}}-{{.GOARCH}}.<br>
31+
<br>
2932
Rebuild started at {{.Start.UTC.Format "2006-01-02 15:04:05"}} UTC.<br>
3033
Rebuild finished at {{.End.UTC.Format "2006-01-02 15:04:05"}} UTC.<br>
3134
Elapsed time: {{(.End.Sub .Start).Round 1e9}}.

0 commit comments

Comments
 (0)