summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorDan Duvall <dduvall@wikimedia.org>2017-10-16 09:47:43 -0700
committerDan Duvall <dduvall@wikimedia.org>2017-10-18 14:46:15 -0700
commitd53a06a138106c1652fff0b8576ae907a29a727c (patch)
tree4e9ec388de0effbd1752a030d34aec0737df3f3c /Makefile
parent01f3533a0b4819ce868d4f89c83a090eae6cfd08 (diff)
downloadblubber-d53a06a138106c1652fff0b8576ae907a29a727c.tar.gz
Capture and expose build-time meta data
Summary: The `go build` tool can accept linker options that dynamically set variable values at build time. Let's make use of that in our `Makefile` and `debian/rules` to know and expose meta data such as version and Git commit at runtime. Test Plan: Run `make bin/blubber && bin/blubber --version` and verify that it outputs "0.0.1-[git head commit]". Build and install the debian package and verify the same using the installed binary. Reviewers: thcipriani, hashar, Joe, #release-engineering-team Reviewed By: thcipriani, #release-engineering-team Tags: #release-engineering-team Differential Revision: https://phabricator.wikimedia.org/D816
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile6
1 files changed, 5 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index bfd7ab8..116e2b9 100644
--- a/Makefile
+++ b/Makefile
@@ -3,6 +3,10 @@ PACKAGE := phabricator.wikimedia.org/source/blubber
export BUILD_DIR=$(GOPATH)/src/$(PACKAGE)
BINARY :=$(CURDIR)/bin/blubber
+GO_LDFLAGS := \
+ -X $(PACKAGE)/meta.Version=$(shell cat VERSION) \
+ -X $(PACKAGE)/meta.GitCommit=$(shell git rev-parse --short HEAD)
+
all: clean bin/blubber
clean:
@@ -13,7 +17,7 @@ bin/blubber:
mkdir -p $(dir $(BUILD_DIR))
ln -s $(CURDIR) $(BUILD_DIR)
cd $(BUILD_DIR) && go get ./...
- cd $(BUILD_DIR) && go build -v -i
+ cd $(BUILD_DIR) && go build -v -i -ldflags "$(GO_LDFLAGS)"
mkdir -p $(CURDIR)/bin && mv $(BUILD_DIR)/blubber $(BINARY)