Skip to content

Commit cbac427

Browse files
author
Eugene Yakubovich
committed
Version embedding for Go 1.4 and 1.5
Go 1.5 linker has a slightly different -X flag format so the build script has to support both variants.
1 parent 4ebb088 commit cbac427

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

build

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
#!/bin/bash -e
22

3+
function linker_dashX {
4+
local version=$(go version)
5+
local regex="go([0-9]+).([0-9]+)."
6+
if [[ $version =~ $regex ]]; then
7+
if [ ${BASH_REMATCH[1]} -eq "1" -a ${BASH_REMATCH[2]} -le "4" ]; then
8+
echo "$1 \"$2\""
9+
else
10+
echo "$1=$2"
11+
fi
12+
else
13+
echo "could not determine Go version"
14+
exit 1
15+
fi
16+
}
17+
318
ORG_PATH="github.com/coreos"
419
REPO_PATH="${ORG_PATH}/flannel"
520
VERSION=$(git describe --dirty)
6-
GLDFLAGS="-X github.com/coreos/flannel/version.Version \"${VERSION}\""
21+
GLDFLAGS="-X $(linker_dashX github.com/coreos/flannel/version.Version ${VERSION})"
722

823
if [ ! -h gopath/src/${REPO_PATH} ]; then
924
mkdir -p gopath/src/${ORG_PATH}

dist/bump-release.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ replace_version ${VERSION}
2525
git tag -a -m "${VERSIONTAG}" "${VERSIONTAG}"
2626

2727
# bump ver to placeholder and push to origin
28-
replace_version "${VERSION}+was-not-built-properly"
28+
replace_version "${VERSION}+git"
2929
git push "${ORIGIN}" master
3030

3131
# push the tag

version/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414

1515
package version
1616

17-
var Version = "0.5.3+was-not-built-properly"
17+
var Version = "0.5.3+git"

0 commit comments

Comments
 (0)