Skip to content

Commit c9a066e

Browse files
committed
specs-go: make Version a string literal
Version is initialized during package initialization, which happens on every start of any program importing this package (for example, runc, which re-executes itself on every container start and exec). Using fmt.Sprintf for that takes about 4us and 5 allocations (2920 bytes). Remove all this, making it a plain string literal. Kept as a variable rather than a constant, since some users overwrite it, and changing it to a constant would break them. Add a test to make sure Version is in sync with the constants, and update the release checklist accordingly. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
1 parent 73f00a8 commit c9a066e

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

‎RELEASES.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ Releases usually follow a few steps:
6161
* [ ] delete the `(^M|^A|^D)` lines, `:%!grep -vE '(^M|^A|^D)'`
6262
* [ ] merge multi-commit PRs (so each line has a `(#num)` suffix)
6363
* [ ] drop hash and indent, `:'<,'> s/^\w* /^I* /`
64-
* [ ] a commit bumping `./specs-go/version.go` to next version and empty the `VersionDev` variable
65-
* [ ] a commit adding back the "+dev" to `VersionDev`
64+
* [ ] a commit bumping `./specs-go/version.go` to next version and empty the `VersionDev` variable (update `Version` accordingly)
65+
* [ ] a commit adding back the "+dev" to `VersionDev` and `Version`
6666
* [ ] send email to <dev@opencontainers.org>
6767
* [ ] copy the exact commit hash for bumping the version from the pull-request (since master always stays as "-dev")
6868
* [ ] count the PRs since last release (that this version is tracking, in the cases of multiple branching), like `git log --pretty=oneline --no-merges --decorate $priorTag..$versionBumpCommit | grep \(pr\/ | wc -l`

‎specs-go/version.go‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package specs
22

3-
import "fmt"
4-
53
const (
64
// VersionMajor is for an API incompatible changes
75
VersionMajor = 1
@@ -15,4 +13,4 @@ const (
1513
)
1614

1715
// Version is the specification version that the package types support.
18-
var Version = fmt.Sprintf("%d.%d.%d%s", VersionMajor, VersionMinor, VersionPatch, VersionDev)
16+
var Version = "1.3.0+dev"

‎specs-go/version_test.go‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package specs
2+
3+
import (
4+
"strconv"
5+
"testing"
6+
)
7+
8+
func TestVersionSynced(t *testing.T) {
9+
wantVer := strconv.Itoa(VersionMajor) + "." + strconv.Itoa(VersionMinor) + "." + strconv.Itoa(VersionPatch) + VersionDev
10+
if Version != wantVer {
11+
t.Fatalf("Version mismatch: got %q, want %q", Version, wantVer)
12+
}
13+
}

0 commit comments

Comments
 (0)