make+build: compile build tags into binary

This commit is contained in:
Conner Fromknecht 2020-04-09 17:04:55 -07:00
parent 75a1a1fbab
commit 07420835d0
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
2 changed files with 25 additions and 6 deletions

View File

@ -23,8 +23,6 @@ ANDROID_BUILD := $(ANDROID_BUILD_DIR)/Lndmobile.aar
COMMIT := $(shell git describe --abbrev=40 --dirty)
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) | \
@ -53,6 +51,14 @@ include make/testing_flags.mk
DEV_TAGS := $(if ${tags},$(DEV_TAGS) ${tags},$(DEV_TAGS))
make_ldflags = $(shell echo -ldflags \"-X $(PKG)/build.Commit=$(COMMIT) \
-X $(PKG)/build.CommitHash=$(COMMIT_HASH) \
-X $(PKG)/build.RawTags=$(shell echo $(1) | sed -e 's/ /,/g')\")
LDFLAGS := $(call make_ldflags, ${tags})
DEV_LDFLAGS := $(call make_ldflags, $(DEV_TAGS))
ITEST_LDFLAGS := $(call make_ldflags, $(ITEST_TAGS))
# Linting uses a lot of memory, so keep it under control by limiting the number
# of workers if requested.
ifneq ($(workers),)
@ -97,13 +103,13 @@ btcd:
build:
@$(call print, "Building debug lnd and lncli.")
$(GOBUILD) -tags="$(DEV_TAGS)" -o lnd-debug $(LDFLAGS) $(PKG)/cmd/lnd
$(GOBUILD) -tags="$(DEV_TAGS)" -o lncli-debug $(LDFLAGS) $(PKG)/cmd/lncli
$(GOBUILD) -tags="$(DEV_TAGS)" -o lnd-debug $(DEV_LDFLAGS) $(PKG)/cmd/lnd
$(GOBUILD) -tags="$(DEV_TAGS)" -o lncli-debug $(DEV_LDFLAGS) $(PKG)/cmd/lncli
build-itest:
@$(call print, "Building itest lnd and lncli.")
$(GOBUILD) -tags="$(ITEST_TAGS)" -o lnd-itest $(LDFLAGS) $(PKG)/cmd/lnd
$(GOBUILD) -tags="$(ITEST_TAGS)" -o lncli-itest $(LDFLAGS) $(PKG)/cmd/lncli
$(GOBUILD) -tags="$(ITEST_TAGS)" -o lnd-itest $(ITEST_LDFLAGS) $(PKG)/cmd/lnd
$(GOBUILD) -tags="$(ITEST_TAGS)" -o lncli-itest $(ITEST_LDFLAGS) $(PKG)/cmd/lncli
install:
@$(call print, "Installing lnd and lncli.")

View File

@ -20,6 +20,10 @@ var (
// CommitHash stores the current commit hash of this build, this should
// be set using the -ldflags during compilation.
CommitHash string
// RawTags contains the raw set of build tags, separated by commas. This
// should be set using -ldflags during compilation.
RawTags string
)
// semanticAlphabet is the set of characters that are permitted for use in an
@ -74,3 +78,12 @@ func Version() string {
return version
}
// Tags returns the list of build tags that were compiled into the executable.
func Tags() []string {
if len(RawTags) == 0 {
return nil
}
return strings.Split(RawTags, ",")
}