aerc: add build info to version string
Example: $ aerc -v aerc 0.11.0 +notmuch (go1.18.4 amd64 linux) Also include that version information in the debug and panic logs. debug.ReadBuildInfo() is only available in go 1.18+. Add a new variable set at build time to store $GOFLAGS. Suggested-by: Tim Culverhouse <tim@timculverhouse.com> Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Moritz Poldrack <moritz@poldrack.dev>
This commit is contained in:
parent
45e506e6ae
commit
d7e6dc3649
3 changed files with 22 additions and 3 deletions
1
Makefile
1
Makefile
|
@ -14,6 +14,7 @@ BUILD_OPTS?=-trimpath
|
||||||
# ignore environment variable
|
# ignore environment variable
|
||||||
GO_LDFLAGS:=
|
GO_LDFLAGS:=
|
||||||
GO_LDFLAGS+=-X main.Version=$(VERSION)
|
GO_LDFLAGS+=-X main.Version=$(VERSION)
|
||||||
|
GO_LDFLAGS+=-X main.Flags=$(GOFLAGS)
|
||||||
GO_LDFLAGS+=-X git.sr.ht/~rjarry/aerc/config.shareDir=$(SHAREDIR)
|
GO_LDFLAGS+=-X git.sr.ht/~rjarry/aerc/config.shareDir=$(SHAREDIR)
|
||||||
GO_LDFLAGS+=$(GO_EXTRA_LDFLAGS)
|
GO_LDFLAGS+=$(GO_EXTRA_LDFLAGS)
|
||||||
|
|
||||||
|
|
18
aerc.go
18
aerc.go
|
@ -5,7 +5,9 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.sr.ht/~sircmpwn/getopt"
|
"git.sr.ht/~sircmpwn/getopt"
|
||||||
|
@ -89,6 +91,17 @@ func getCompletions(aerc *widgets.Aerc, cmd string) []string {
|
||||||
|
|
||||||
// set at build time
|
// set at build time
|
||||||
var Version string
|
var Version string
|
||||||
|
var Flags string
|
||||||
|
|
||||||
|
func buildInfo() string {
|
||||||
|
info := Version
|
||||||
|
if strings.Contains(Flags, "notmuch") {
|
||||||
|
info += " +notmuch"
|
||||||
|
}
|
||||||
|
info += fmt.Sprintf(" (%s %s %s)",
|
||||||
|
runtime.Version(), runtime.GOARCH, runtime.GOOS)
|
||||||
|
return info
|
||||||
|
}
|
||||||
|
|
||||||
func usage(msg string) {
|
func usage(msg string) {
|
||||||
fmt.Fprintln(os.Stderr, msg)
|
fmt.Fprintln(os.Stderr, msg)
|
||||||
|
@ -124,9 +137,10 @@ func main() {
|
||||||
usage("error: " + err.Error())
|
usage("error: " + err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
logging.BuildInfo = buildInfo()
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
if opt.Option == 'v' {
|
if opt.Option == 'v' {
|
||||||
fmt.Println("aerc " + Version)
|
fmt.Println("aerc " + logging.BuildInfo)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,7 +163,7 @@ func main() {
|
||||||
if !isatty.IsTerminal(os.Stdout.Fd()) {
|
if !isatty.IsTerminal(os.Stdout.Fd()) {
|
||||||
logging.Init()
|
logging.Init()
|
||||||
}
|
}
|
||||||
logging.Infof("Starting up")
|
logging.Infof("Starting up version %s", logging.BuildInfo)
|
||||||
|
|
||||||
conf, err := config.LoadConfigFromFile(nil)
|
conf, err := config.LoadConfigFromFile(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -9,7 +9,10 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var UICleanup = func() {}
|
var (
|
||||||
|
UICleanup = func() {}
|
||||||
|
BuildInfo string
|
||||||
|
)
|
||||||
|
|
||||||
// PanicHandler tries to restore the terminal. A stack trace is written to
|
// PanicHandler tries to restore the terminal. A stack trace is written to
|
||||||
// aerc-crash.log and then passed on if a panic occurs.
|
// aerc-crash.log and then passed on if a panic occurs.
|
||||||
|
@ -41,6 +44,7 @@ func PanicHandler() {
|
||||||
fmt.Fprintln(panicLog, time.Now().Format("2006-01-02T15:04:05.000000-0700"))
|
fmt.Fprintln(panicLog, time.Now().Format("2006-01-02T15:04:05.000000-0700"))
|
||||||
fmt.Fprintln(panicLog, strings.Repeat("#", 80))
|
fmt.Fprintln(panicLog, strings.Repeat("#", 80))
|
||||||
fmt.Fprintf(outputs, "%s\n", panicMessage)
|
fmt.Fprintf(outputs, "%s\n", panicMessage)
|
||||||
|
fmt.Fprintf(outputs, "Version: %s\n", BuildInfo)
|
||||||
fmt.Fprintf(panicLog, "Error: %v\n\n", r)
|
fmt.Fprintf(panicLog, "Error: %v\n\n", r)
|
||||||
panicLog.Write(debug.Stack()) //nolint:errcheck // we are already in a panic, so not much we can do here
|
panicLog.Write(debug.Stack()) //nolint:errcheck // we are already in a panic, so not much we can do here
|
||||||
fmt.Fprintf(os.Stderr, "\nThis error was also written to: %s\n", filename)
|
fmt.Fprintf(os.Stderr, "\nThis error was also written to: %s\n", filename)
|
||||||
|
|
Loading…
Reference in a new issue