Skip to content

Commit 3a46197

Browse files
author
Ma Shimiao
committed
add version file
It will be more convenient to control version with version file. Signed-off-by: Ma Shimiao <mashimiao.fnst@cn.fujitsu.com>
1 parent afb01db commit 3a46197

4 files changed

Lines changed: 23 additions & 5 deletions

File tree

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ BINDIR ?= $(DESTDIR)/usr/bin
44
BUILDTAGS=
55
RUNTIME ?= runc
66
COMMIT=$(shell git rev-parse HEAD 2> /dev/null || true)
7+
VERSION := ${shell cat ./VERSION}
78

89
all: tool runtimetest
910

1011
tool:
11-
go build -tags "$(BUILDTAGS)" -ldflags "-X main.gitCommit=${COMMIT}" -o oci-runtime-tool ./cmd/oci-runtime-tool
12+
go build -tags "$(BUILDTAGS)" -ldflags "-X main.gitCommit=${COMMIT} -X main.version=${VERSION}" -o oci-runtime-tool ./cmd/oci-runtime-tool
1213

1314
.PHONY: runtimetest
1415
runtimetest:
15-
CGO_ENABLED=0 go build -installsuffix cgo -tags "$(BUILDTAGS)" -o runtimetest ./cmd/runtimetest
16+
CGO_ENABLED=0 go build -installsuffix cgo -tags "$(BUILDTAGS)" -ldflags "-X main.gitCommit=${COMMIT} -X main.version=${VERSION}" -o runtimetest ./cmd/runtimetest
1617

1718
.PHONY: man
1819
man:

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.3.0

cmd/oci-runtime-tool/main.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@ import (
1212
// and will be populated by the Makefile
1313
var gitCommit = ""
1414

15+
// version will be populated by the Makefile, read from
16+
// VERSION file of the source code.
17+
var version = ""
18+
1519
func main() {
1620
app := cli.NewApp()
1721
app.Name = "oci-runtime-tool"
1822
if gitCommit != "" {
19-
app.Version = fmt.Sprintf("0.3.0, commit: %s", gitCommit)
23+
app.Version = fmt.Sprintf("%s, commit: %s", version, gitCommit)
2024
} else {
21-
app.Version = "0.3.0"
25+
app.Version = version
2226
}
2327
app.Usage = "OCI (Open Container Initiative) runtime tools"
2428
app.Flags = []cli.Flag{

cmd/runtimetest/main.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ import (
2626
"github.com/opencontainers/runtime-tools/specerror"
2727
)
2828

29+
// gitCommit will be the hash that the binary was built from
30+
// and will be populated by the Makefile
31+
var gitCommit = ""
32+
33+
// version will be populated by the Makefile, read from
34+
// VERSION file of the source code.
35+
var version = ""
36+
2937
// PrGetNoNewPrivs isn't exposed in Golang so we define it ourselves copying the value from
3038
// the kernel
3139
const PrGetNoNewPrivs = 39
@@ -825,7 +833,11 @@ func run(context *cli.Context) error {
825833
func main() {
826834
app := cli.NewApp()
827835
app.Name = "runtimetest"
828-
app.Version = "0.3.0"
836+
if gitCommit != "" {
837+
app.Version = fmt.Sprintf("%s, commit: %s", version, gitCommit)
838+
} else {
839+
app.Version = version
840+
}
829841
app.Usage = "Compare the environment with an OCI configuration"
830842
app.Description = "runtimetest compares its current environment with an OCI runtime configuration read from config.json in its current working directory. The tests are fairly generic and cover most configurations used by the runtime validation suite, but there are corner cases where a container launched by a valid runtime would not satisfy runtimetest."
831843
app.Flags = []cli.Flag{

0 commit comments

Comments
 (0)