Set verion info using -ldflags -X

Signed-off-by: Liu Chang <liuchang@qiniu.com>
This commit is contained in:
Liu Chang 2017-11-23 16:31:39 +08:00
parent 070b8bfdc5
commit e1424cd037
2 changed files with 5 additions and 3 deletions

View file

@ -23,6 +23,7 @@ PACKAGES ?= $(shell go list -tags "${BUILDTAGS}" ./... | grep -v github.com/kube
COMMIT_NO := $(shell git rev-parse HEAD 2> /dev/null || true) COMMIT_NO := $(shell git rev-parse HEAD 2> /dev/null || true)
GIT_COMMIT := $(if $(shell git status --porcelain --untracked-files=no),"${COMMIT_NO}-dirty","${COMMIT_NO}") GIT_COMMIT := $(if $(shell git status --porcelain --untracked-files=no),"${COMMIT_NO}-dirty","${COMMIT_NO}")
BUILD_INFO := $(shell date +%s) BUILD_INFO := $(shell date +%s)
VERSION := $(shell git describe --tags --always --dirty)
# If GOPATH not specified, use one in the local directory # If GOPATH not specified, use one in the local directory
ifeq ($(GOPATH),) ifeq ($(GOPATH),)
@ -31,11 +32,12 @@ unexport GOBIN
endif endif
GOPKGDIR := $(GOPATH)/src/$(PROJECT) GOPKGDIR := $(GOPATH)/src/$(PROJECT)
GOPKGBASEDIR := $(shell dirname "$(GOPKGDIR)") GOPKGBASEDIR := $(shell dirname "$(GOPKGDIR)")
VERSION_PATH := $(PROJECT)/version.Version
# Update VPATH so make finds .gopathok # Update VPATH so make finds .gopathok
VPATH := $(VPATH):$(GOPATH) VPATH := $(VPATH):$(GOPATH)
SHRINKFLAGS := -s -w SHRINKFLAGS := -s -w
BASE_LDFLAGS := ${SHRINKFLAGS} -X main.gitCommit=${GIT_COMMIT} -X main.buildInfo=${BUILD_INFO} BASE_LDFLAGS := ${SHRINKFLAGS} -X main.gitCommit=${GIT_COMMIT} -X main.buildInfo=${BUILD_INFO} -X ${VERSION_PATH}=${VERSION}
LDFLAGS := -ldflags '${BASE_LDFLAGS}' LDFLAGS := -ldflags '${BASE_LDFLAGS}'
all: binaries crio.conf docs all: binaries crio.conf docs

View file

@ -1,4 +1,4 @@
package version package version
// Version is the version of the build. // Version is the app-global version string, which should be substituted with a real value during build.
const Version = "1.9.0-dev" var Version = "UNKNOWN"