diff --git a/Makefile b/Makefile index ba7048e3fe3d39db21a656fc2287e6eee95389e5..1ae718c5aeedf54a58bdf16974be15aac1a47122 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ SHELL := /bin/bash REPO := $(shell pwd) GOFILES_NOVENDOR := $(shell go list -f "{{.Dir}}" ./...) PACKAGES_NOVENDOR := $(shell go list ./...) +COMMIT := $(shell git rev-parse --short HEAD) # Bosmarmot integration testing BOSMARMOT_PROJECT := github.com/monax/bosmarmot BOSMARMOT_GOPATH := ${REPO}/.gopath_bos @@ -99,7 +100,7 @@ build_race: check build_race_db build_race_client # build burrow .PHONY: build_db build_db: - go build -o ${REPO}/bin/burrow ./cmd/burrow + go build -ldflags "-X github.com/hyperledger/burrow/project.commit=${COMMIT}" -o ${REPO}/bin/burrow ./cmd/burrow # build burrow-client .PHONY: build_client diff --git a/cmd/burrow/main.go b/cmd/burrow/main.go index d7d56f08ef7059ecd7dad1c405c0a3469c463de9..61c270aee1928791df6b64e372978520844ef1ad 100644 --- a/cmd/burrow/main.go +++ b/cmd/burrow/main.go @@ -34,7 +34,7 @@ func main() { burrow.Action = func() { if *versionOpt { - fmt.Println(project.History.CurrentVersion().String()) + fmt.Println(project.FullVersion()) os.Exit(0) } // We need to reflect on whether this obscures where values are coming from diff --git a/project/history.go b/project/history.go index 96fb36e6505599b20c4661f8758bebc7560c95c5..d4d1b5aeb2c14da54e11cb5489a9453c4b60e199 100644 --- a/project/history.go +++ b/project/history.go @@ -4,6 +4,23 @@ import ( "github.com/monax/relic" ) +// Can be used to set the commit hash version of the binary at build time with: +// `go build -ldflags "-X github.com/hyperledger/burrow/project.commit=$(git rev-parse --short HEAD)" ./cmd/burrow` + +var commit = "" + +func Commit() string { + return commit +} + +func FullVersion() string { + version := History.CurrentVersion().String() + if commit != "" { + return version + "+commit." + commit + } + return version +} + // The releases described by version string and changes, newest release first. // The current release is taken to be the first release in the slice, and its // version determines the single authoritative version for the next release.