commit efa2cc1
delthas
·
2026-06-02 17:29:48 +0000 UTC
parent 4b426b9
Support setting the version via -ldflags Add a package-level version variable that can be stamped at build time with -ldflags "-X git.sr.ht/~delthas/senpai.version=...", letting the release script and package maintainers report a clean version. The Makefile wires this through a VERSION variable. BuildVersion now prefers the injected value and falls back to the build info only when it carries a real version, so plain builds no longer report "(devel)". Fixes: https://todo.sr.ht/~delthas/senpai/206
M
Makefile
+2,
-1
1@@ -7,6 +7,7 @@ INSTALL ?= install
2 SCDOC ?= scdoc
3 GIT ?= git
4 GOFLAGS ?=
5+VERSION ?=
6 PREFIX ?= /usr/local
7 BINDIR ?= bin
8 MANDIR ?= share/man
9@@ -20,7 +21,7 @@ endif
10 all: senpai doc
11
12 senpai:
13- $(GO) build $(GOFLAGS) ./cmd/senpai
14+ $(GO) build $(GOFLAGS) -ldflags "-X git.sr.ht/~delthas/senpai.version=$(VERSION)" ./cmd/senpai
15
16 ifeq (, $(shell which $(SCDOC) 2>/dev/null))
17 $(warning "$(SCDOC) not found, skipping building documentation")
M
app.go
+8,
-3
1@@ -2750,12 +2750,17 @@ func dropBackslash(s string) string {
2 return sb.String()
3 }
4
5+// version is set via -ldflags "-X git.sr.ht/~delthas/senpai.version=...".
6+var version string
7+
8 func BuildVersion() (string, bool) {
9- if bi, ok := debug.ReadBuildInfo(); ok {
10+ if version != "" {
11+ return version, true
12+ }
13+ if bi, ok := debug.ReadBuildInfo(); ok && bi.Main.Version != "" && bi.Main.Version != "(devel)" {
14 return bi.Main.Version, true
15- } else {
16- return "", false
17 }
18+ return "", false
19 }
20
21 type ReadProgress struct {