From 152ee95380ef1935d6ca214feb806e4eda9217e4 Mon Sep 17 00:00:00 2001 From: Qiang Huang Date: Mon, 30 May 2016 10:24:22 +0800 Subject: [PATCH] Add VERSION file to contain the version info We need this because we need to get version info out of go code, eg. build rpm package. Signed-off-by: Qiang Huang --- Makefile | 6 ++++-- VERSION | 1 + main.go | 11 ++++++++--- 3 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 VERSION diff --git a/Makefile b/Makefile index c1bbafaa..6ff7fc3a 100644 --- a/Makefile +++ b/Makefile @@ -20,11 +20,13 @@ MAN_PAGES = $(shell ls $(MAN_DIR)/*.8) MAN_PAGES_BASE = $(notdir $(MAN_PAGES)) MAN_INSTALL_PATH := ${PREFIX}/share/man/man8/ +VERSION := ${shell cat ./VERSION} + all: $(RUNC_LINK) - go build -i -ldflags "-X main.gitCommit=${COMMIT}" -tags "$(BUILDTAGS)" -o runc . + go build -i -ldflags "-X main.gitCommit=${COMMIT} -X main.version=${VERSION}" -tags "$(BUILDTAGS)" -o runc . static: $(RUNC_LINK) - CGO_ENABLED=1 go build -i -tags "$(BUILDTAGS) cgo static_build" -ldflags "-w -extldflags -static -X main.gitCommit=${COMMIT}" -o runc . + CGO_ENABLED=1 go build -i -tags "$(BUILDTAGS) cgo static_build" -ldflags "-w -extldflags -static -X main.gitCommit=${COMMIT} -X main.version=${VERSION}" -o runc . $(RUNC_LINK): ln -sfn $(CURDIR) $(RUNC_LINK) diff --git a/VERSION b/VERSION new file mode 100644 index 00000000..17e51c38 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1.1 diff --git a/main.go b/main.go index 1b0df8a2..73b98cd8 100644 --- a/main.go +++ b/main.go @@ -10,12 +10,15 @@ import ( "github.com/opencontainers/runtime-spec/specs-go" ) +// version will be populated by the Makefile, read from +// VERSION file of the source code. +var version = "" + // gitCommit will be the hash that the binary was built from // and will be populated by the Makefile var gitCommit = "" const ( - version = "0.1.1" specConfig = "config.json" usage = `Open Container Initiative runtime @@ -46,8 +49,10 @@ func main() { app := cli.NewApp() app.Name = "runc" app.Usage = usage - v := []string{ - version, + + var v []string + if version != "" { + v = append(v, version) } if gitCommit != "" { v = append(v, fmt.Sprintf("commit: %s", gitCommit))