Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use go1.16 "embed" to set version from VERSION file #3163

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ BUILDTAGS += $(EXTRA_BUILDTAGS)

COMMIT ?= $(shell git describe --dirty --long --always)
VERSION ?= $(shell cat ./VERSION)
LDFLAGS_COMMON := -X main.gitCommit=$(COMMIT) -X main.version=$(VERSION)
LDFLAGS_COMMON := -X main.gitCommit=$(COMMIT)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change will we still need the VERSION variable in Makefile. ?

Another concern is, the patch will make changes in 9d9273c ineffective. The use case was someone should be able to pass a custom version without editing the VERSION file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thaJeztah it looks like VERSION should be removed from the Makefile altogether.

Also, this needs another rebase.


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

Expand Down
9 changes: 5 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
_ "embed"
"errors"
"fmt"
"io"
Expand All @@ -19,9 +20,9 @@ import (
"github.com/urfave/cli"
)

// version must be set from the contents of VERSION file by go build's
// -X main.version= option in the Makefile.
var version = "unknown"
// version is automatically set from the contents of VERSION file on go1.16+.
//go:embed VERSION
var version string
kolyshkin marked this conversation as resolved.
Show resolved Hide resolved

// gitCommit will be the hash that the binary was built from
// and will be populated by the Makefile
Expand Down Expand Up @@ -59,7 +60,7 @@ func main() {
app.Name = "runc"
app.Usage = usage

v := []string{version}
v := []string{strings.TrimSpace(version)}

if gitCommit != "" {
v = append(v, "commit: "+gitCommit)
Expand Down
Loading