Browse Source

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.
Eugene Yakubovich 9 years ago
parent
commit
cbac427350
3 changed files with 18 additions and 3 deletions
  1. 16 1
      build
  2. 1 1
      dist/bump-release.sh
  3. 1 1
      version/version.go

+ 16 - 1
build

@@ -1,9 +1,24 @@
 #!/bin/bash -e
 
+function linker_dashX {
+	local version=$(go version)
+	local regex="go([0-9]+).([0-9]+)."
+	if [[ $version =~ $regex ]]; then
+		if [ ${BASH_REMATCH[1]} -eq "1" -a ${BASH_REMATCH[2]} -le "4" ]; then
+			echo "$1 \"$2\""
+		else
+			echo "$1=$2"
+		fi
+	else
+		echo "could not determine Go version"
+		exit 1
+	fi
+}
+
 ORG_PATH="github.com/coreos"
 REPO_PATH="${ORG_PATH}/flannel"
 VERSION=$(git describe --dirty)
-GLDFLAGS="-X github.com/coreos/flannel/version.Version \"${VERSION}\""
+GLDFLAGS="-X $(linker_dashX github.com/coreos/flannel/version.Version ${VERSION})"
 
 if [ ! -h gopath/src/${REPO_PATH} ]; then
 	mkdir -p gopath/src/${ORG_PATH}

+ 1 - 1
dist/bump-release.sh

@@ -25,7 +25,7 @@ replace_version ${VERSION}
 git tag -a -m "${VERSIONTAG}" "${VERSIONTAG}"
 
 # bump ver to placeholder and push to origin
-replace_version "${VERSION}+was-not-built-properly"
+replace_version "${VERSION}+git"
 git push "${ORIGIN}" master
 
 # push the tag

+ 1 - 1
version/version.go

@@ -14,4 +14,4 @@
 
 package version
 
-var Version = "0.5.3+was-not-built-properly"
+var Version = "0.5.3+git"