From 75a1a1fbab31f42856a87ff8c06514876bbbf0f0 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 9 Apr 2020 17:04:25 -0700 Subject: [PATCH] make+build: compile SHA1 commit hash into binary --- Makefile | 4 +++- build/version.go | 14 +++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 5ecd4929..d9b05519 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,9 @@ ANDROID_BUILD_DIR := $(MOBILE_BUILD_DIR)/android ANDROID_BUILD := $(ANDROID_BUILD_DIR)/Lndmobile.aar COMMIT := $(shell git describe --abbrev=40 --dirty) -LDFLAGS := -ldflags "-X $(PKG)/build.Commit=$(COMMIT)" +COMMIT_HASH := $(shell git rev-parse HEAD) +LDFLAGS := -ldflags "-X $(PKG)/build.Commit=$(COMMIT) \ + -X $(PKG)/build.CommitHash=$(COMMIT_HASH)" BTCD_COMMIT := $(shell cat go.mod | \ grep $(BTCD_PKG) | \ diff --git a/build/version.go b/build/version.go index 4985ed6c..3e3a147f 100644 --- a/build/version.go +++ b/build/version.go @@ -10,9 +10,17 @@ import ( "strings" ) -// Commit stores the current commit hash of this build, this should be set using -// the -ldflags during compilation. -var Commit string +var ( + // Commit stores the current commit of this build, which includes the + // most recent tag, the number of commits since that tag (if non-zero), + // the commit hash, and a dirty marker. This should be set using the + // -ldflags during compilation. + Commit string + + // CommitHash stores the current commit hash of this build, this should + // be set using the -ldflags during compilation. + CommitHash string +) // semanticAlphabet is the set of characters that are permitted for use in an // AppPreRelease.