From c4942a62ee0af585a3f629d3d4b8ae01f932d679 Mon Sep 17 00:00:00 2001 From: Sudharshan S Date: Mon, 16 Dec 2013 18:50:57 +0530 Subject: [PATCH 1/2] The minimum go version to build packer is 1.2, not 1.1. Change the documentation accordingly. 'ne' template function was added as part of go 1.2. http://golang.org/doc/go1.2#text_template --- CONTRIBUTING.md | 5 ++--- README.md | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 93b398a4d..fe691d1f6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -53,9 +53,8 @@ it raises the chances we can quickly merge or address your contributions. If you have never worked with Go before, you will have to complete the following steps in order to be able to compile and test Packer. -1. Install Go. On a Mac, you can `brew install go`. Make sure the Go - version is at least Go 1.1. Packer will not work with anything less than - Go 1.1. +1. Install Go. Make sure the Go version is at least Go 1.2. Packer will not work with anything less than + Go 1.2. On a Mac, you can `brew install go` to install Go 1.2. 2. Set and export the `GOPATH` environment variable. For example, you can add `export GOPATH=$HOME/Documents/golang` to your `.bash_profile`. diff --git a/README.md b/README.md index ef498b853..755a43c00 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ http://www.packer.io/docs ## Developing Packer If you wish to work on Packer itself, you'll first need [Go](http://golang.org) -installed (version 1.1+ is _required_). Make sure you have Go properly installed, +installed (version 1.2+ is _required_). Make sure you have Go properly installed, including setting up your [GOPATH](http://golang.org/doc/code.html#GOPATH). For some additional dependencies, Go needs [Mercurial](http://mercurial.selenic.com/) From d22b2a011da5a6da2f6ac786f3eebda1c64d0d73 Mon Sep 17 00:00:00 2001 From: Sudharshan S Date: Mon, 16 Dec 2013 18:52:37 +0530 Subject: [PATCH 2/2] Verify go version when building packer. Check if the installed version is greater than the required version. Error out if that's not the case --- scripts/devcompile.sh | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/scripts/devcompile.sh b/scripts/devcompile.sh index 0813ceb32..51f1b18f0 100755 --- a/scripts/devcompile.sh +++ b/scripts/devcompile.sh @@ -8,6 +8,40 @@ OK_COLOR="\x1b[32;01m" ERROR_COLOR="\x1b[31;01m" WARN_COLOR="\x1b[33;01m" +# http://stackoverflow.com/questions/4023830/bash-how-compare-two-strings-in-version-format +verify_go () { + if [[ $1 == $2 ]] + then + return 0 + fi + local IFS=. + local i ver1=($1) ver2=($2) + + for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)) + do + ver1[i]=0 + done + for ((i=0; i<${#ver1[@]}; i++)) + do + if [[ -z ${ver2[i]} ]] + then + ver2[i]=0 + fi + if ((10#${ver1[i]} > 10#${ver2[i]})) + then + echo -e "${ERROR_COLOR}==> Required Go version $1 not installed. Found $2 instead" + exit 1 + fi + done +} + +GO_MINIMUM_VERSION=1.2 +GO_INSTALLED_VERSION=$(go version | cut -d ' ' -f 3) +GO_INSTALLED_VERSION=${GO_INSTALLED_VERSION#"go"} + +echo -e "${OK_COLOR}==> Verifying Go" +verify_go $GO_MINIMUM_VERSION $GO_INSTALLED_VERSION + # Get the parent directory of where this script is. SOURCE="${BASH_SOURCE[0]}" while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done