-LDFLAGS = '\
- -X "main.versionGit=$(shell git describe --long --tags --dirty --always) \
-$(shell git show --no-patch --pretty=format:%as)" \
- -X "main.versionGo=$(shell go version)" \
-'
# Build with `make GOFLAGS=` if -race is not supported
GOFLAGS=-race
safcm:
go fmt ./...
cd cmd/safcm-remote && ./build.sh
- go build $(GOFLAGS) -ldflags $(LDFLAGS) ruderich.org/simon/safcm/cmd/safcm
+ go build $(GOFLAGS) ruderich.org/simon/safcm/cmd/safcm
test:
./cmd/safcm/testdata/ssh/prepare.sh
go vet ./...
go test $(GOFLAGS) ./...
+ @# Make sure buildinfo can be read
+ ./safcm version > /dev/null
lint:
shellcheck ci/run
import (
"fmt"
-)
-
-// Set via -ldflags -X during build
-var (
- versionGit string
- versionGo string
+ "log"
+ "runtime/debug"
)
func MainVersion() error {
- fmt.Printf("safcm %s, compiled with %s\n", versionGit, versionGo)
+ info, ok := debug.ReadBuildInfo()
+ if !ok {
+ log.Fatal("ReadBuildInfo failed")
+ }
+
+ var vcsRev, vcsDirty, vcsTime, goos, goarch string
+ for _, x := range info.Settings {
+ switch x.Key {
+ case "vcs.revision":
+ vcsRev = x.Value[:7]
+ case "vcs.modified":
+ if x.Value == "true" {
+ vcsDirty = "-dirty"
+ }
+ case "vcs.time":
+ vcsTime = x.Value[:10] // "2006-01-02"
+ case "GOOS":
+ goos = x.Value
+ case "GOARCH":
+ goarch = x.Value
+ }
+ }
+
+ fmt.Printf("safcm %s%s %s, compiled with %s %s/%s\n",
+ vcsRev, vcsDirty, vcsTime,
+ info.GoVersion, goos, goarch)
return nil
}