From e1424cd037d988c54d62caa2bde27c11a1aaa9d6 Mon Sep 17 00:00:00 2001 From: Liu Chang Date: Thu, 23 Nov 2017 16:31:39 +0800 Subject: [PATCH] Set verion info using -ldflags -X Signed-off-by: Liu Chang --- Makefile | 4 +++- version/version.go | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 5f3a74a3..7fbfca3b 100644 --- a/Makefile +++ b/Makefile @@ -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) GIT_COMMIT := $(if $(shell git status --porcelain --untracked-files=no),"${COMMIT_NO}-dirty","${COMMIT_NO}") BUILD_INFO := $(shell date +%s) +VERSION := $(shell git describe --tags --always --dirty) # If GOPATH not specified, use one in the local directory ifeq ($(GOPATH),) @@ -31,11 +32,12 @@ unexport GOBIN endif GOPKGDIR := $(GOPATH)/src/$(PROJECT) GOPKGBASEDIR := $(shell dirname "$(GOPKGDIR)") +VERSION_PATH := $(PROJECT)/version.Version # Update VPATH so make finds .gopathok VPATH := $(VPATH):$(GOPATH) 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}' all: binaries crio.conf docs diff --git a/version/version.go b/version/version.go index 7eaa12c4..3b9a5abc 100644 --- a/version/version.go +++ b/version/version.go @@ -1,4 +1,4 @@ package version -// Version is the version of the build. -const Version = "1.9.0-dev" +// Version is the app-global version string, which should be substituted with a real value during build. +var Version = "UNKNOWN"