Skip to content

Commit c12c99b

Browse files
committed
runc: embed version from VERSION file
This ensures that if runc is built without the provided Makefile, the version is still properly set. No change in the output. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent d54eaaf commit c12c99b

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ BUILDTAGS += $(EXTRA_BUILDTAGS)
1717

1818
COMMIT := $(shell git describe --dirty --long --always)
1919
EXTRA_VERSION :=
20-
VERSION := $(shell cat ./VERSION)$(EXTRA_VERSION)
21-
LDFLAGS_COMMON := -X main.gitCommit=$(COMMIT) -X main.version=$(VERSION)
20+
LDFLAGS_COMMON := -X main.gitCommit=$(COMMIT) \
21+
$(if $(strip $(EXTRA_VERSION)),-X main.extraVersion=$(EXTRA_VERSION),)
2222

2323
GOARCH := $(shell $(GO) env GOARCH)
2424

@@ -118,11 +118,11 @@ release: runcimage
118118
--rm -v $(CURDIR):/go/src/$(PROJECT) \
119119
-e RELEASE_ARGS=$(RELEASE_ARGS) \
120120
$(RUNC_IMAGE) make localrelease
121-
script/release_sign.sh -S $(GPG_KEYID) -r release/$(VERSION) -v $(VERSION)
121+
script/release_sign.sh -S $(GPG_KEYID)
122122

123123
.PHONY: localrelease
124124
localrelease: verify-changelog
125-
script/release_build.sh -r release/$(VERSION) -v $(VERSION) $(RELEASE_ARGS)
125+
script/release_build.sh $(RELEASE_ARGS)
126126

127127
.PHONY: dbuild
128128
dbuild: runcimage

main.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
_ "embed"
45
"errors"
56
"fmt"
67
"io"
@@ -19,12 +20,18 @@ import (
1920
"github.com/urfave/cli"
2021
)
2122

22-
// version must be set from the contents of VERSION file by go build's
23-
// -X main.version= option in the Makefile.
24-
var version = "unknown"
23+
// version is set from the contents of VERSION file.
24+
//
25+
//go:embed VERSION
26+
var version string
27+
28+
// extraVersion is an optional suffix appended to runc version.
29+
// It can be set via Makefile ("make EXTRA_VERSION=xxx") or by
30+
// adding -X main.extraVersion=xxx option to the go build command.
31+
var extraVersion = ""
2532

2633
// gitCommit will be the hash that the binary was built from
27-
// and will be populated by the Makefile
34+
// and will be populated by the Makefile.
2835
var gitCommit = ""
2936

3037
func printVersion(c *cli.Context) {
@@ -73,7 +80,7 @@ value for "bundle" is the current directory.`
7380
func main() {
7481
app := cli.NewApp()
7582
app.Name = "runc"
76-
app.Version = version
83+
app.Version = strings.TrimSpace(version) + extraVersion
7784
app.Usage = usage
7885

7986
cli.VersionPrinter = printVersion

0 commit comments

Comments
 (0)