refactor(gasm): report the toolchain-recorded version
Assisted-by: GLM 5.3 Flash
This commit is contained in:
+15
-7
@@ -18,6 +18,7 @@ import (
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"slices"
|
||||
"sort"
|
||||
"strconv"
|
||||
@@ -36,9 +37,16 @@ import (
|
||||
"sourcedock.dev/petrbalvin/gasm-devkit/verify"
|
||||
)
|
||||
|
||||
// version is the release version, stamped at build time via
|
||||
// -ldflags "-X main.version=…" (defaulting to the current release).
|
||||
var version = "0.33.0"
|
||||
// version reports the release the toolchain recorded for this build: the
|
||||
// tag on a tag, a pseudo-version below one, and (devel) outside version
|
||||
// control. Nothing is injected; the recorded value cannot go stale.
|
||||
func version() string {
|
||||
bi, ok := debug.ReadBuildInfo()
|
||||
if !ok || bi.Main.Version == "" {
|
||||
return "(devel)"
|
||||
}
|
||||
return bi.Main.Version
|
||||
}
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
@@ -88,9 +96,9 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
// cmdVersion prints the release version.
|
||||
// cmdVersion prints the recorded version.
|
||||
func cmdVersion() int {
|
||||
fmt.Printf("gasm %s\n", version)
|
||||
fmt.Printf("gasm %s\n", version())
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -119,7 +127,7 @@ func usage(w io.Writer) {
|
||||
bold, cyan, yellow, gray, reset = colorBold, colorCyan, colorYellow, colorGray, colorReset
|
||||
}
|
||||
|
||||
fmt.Fprintf(w, "%sgasm %s%s: developer tooling for Go's Plan 9 assembler (GAsm)%s\n\n", bold, version, reset, reset)
|
||||
fmt.Fprintf(w, "%sgasm %s%s: developer tooling for Go's Plan 9 assembler (GAsm)%s\n\n", bold, version(), reset, reset)
|
||||
fmt.Fprintf(w, "gasm bundles a lexer, parser, formatter, linter, standalone assembler and\n")
|
||||
fmt.Fprintf(w, "language server for Plan 9 assembly into one self-contained binary.\n\n")
|
||||
|
||||
@@ -442,7 +450,7 @@ hover, document symbols, diagnostics and semantic-token highlighting.
|
||||
`)
|
||||
fs.Parse(args)
|
||||
srv := lsp.New(os.Stdin, os.Stdout)
|
||||
srv.SetVersion(version)
|
||||
srv.SetVersion(version())
|
||||
if err := srv.Run(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "gasm lsp:", err)
|
||||
return 1
|
||||
|
||||
@@ -219,8 +219,9 @@ func TestCmdVersion(t *testing.T) {
|
||||
if code != 0 {
|
||||
t.Fatalf("code = %d", code)
|
||||
}
|
||||
if !strings.Contains(out, version) {
|
||||
t.Errorf("version output %q does not mention %q", out, version)
|
||||
got := version()
|
||||
if !strings.Contains(out, got) {
|
||||
t.Errorf("version output %q does not mention %q", out, got)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user