diff --git a/Makefile b/Makefile index 8006193..f4af28f 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,6 @@ VERSION= $(shell cat ./VERSION) +VERSION_STRING= v$(VERSION)/masyunis +LDFLAGS_VERSION= -X 'github.com/TecharoHQ/anubis.Version=$(VERSION_STRING)' GO?= go NPM?= npm @@ -19,8 +21,8 @@ assets: deps ./xess/build.sh build: assets - $(GO) build -o ./var/anubis ./cmd/anubis - $(GO) build -o ./var/robots2policy ./cmd/robots2policy + $(GO) build -o ./var/anubis -ldflags "$(LDFLAGS_VERSION)" ./cmd/anubis + $(GO) build -o ./var/robots2policy -ldflags "$(LDFLAGS_VERSION)" ./cmd/robots2policy @echo "Anubis is now built to ./var/anubis" lint: assets @@ -28,8 +30,8 @@ lint: assets $(GO) tool staticcheck ./... prebaked-build: - $(GO) build -o ./var/anubis -ldflags "-X 'github.com/TecharoHQ/anubis.Version=$(VERSION)'" ./cmd/anubis - $(GO) build -o ./var/robots2policy -ldflags "-X 'github.com/TecharoHQ/anubis.Version=$(VERSION)'" ./cmd/robots2policy + $(GO) build -o ./var/anubis -ldflags "$(LDFLAGS_VERSION)" ./cmd/anubis + $(GO) build -o ./var/robots2policy -ldflags "$(LDFLAGS_VERSION)" ./cmd/robots2policy test: assets $(GO) test ./... diff --git a/anubis.go b/anubis.go index 00626f9..438c05c 100644 --- a/anubis.go +++ b/anubis.go @@ -7,6 +7,12 @@ import ( ) func init() { + // masyunis: a version stamped at link time (see the Makefile, which sets + // it to v$(VERSION)/masyunis) takes precedence over the module version. + if Version != "devel" { + return + } + bi, ok := debug.ReadBuildInfo() if !ok { return @@ -14,14 +20,19 @@ func init() { // XXX(Xe): many things in this repo assume that the development version // of anubis is `devel` and ReadBuildInfo returns `(devel)`. Shim the gap. - if bi.Main.Version != "(devel)" { - Version = bi.Main.Version + if bi.Main.Version != "(devel)" && bi.Main.Version != "" { + Version = bi.Main.Version + ForkSuffix } } +// ForkSuffix marks builds of the Masyunis fork in the displayed version. +const ForkSuffix = "/masyunis" + // Version is the current version of Anubis. // -// This is set from the Go module runtime version. +// This is set from the Go module runtime version, or at link time with +// -ldflags "-X 'github.com/TecharoHQ/anubis.Version=...'". It stays "devel" +// for go run / go test so development-only behaviour keeps working. var Version = "devel" // CookieName is the name of the cookie that Anubis uses in order to validate