From effe895d22fd2660a23384e880157078134cd7c5 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 29 May 2014 17:51:11 -0700 Subject: [PATCH] scripts: build script --- scripts/build.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 scripts/build.sh diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100644 index 000000000..72069d690 --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# +# This script builds the application from source for only this platform. +set -e + +# Get the parent directory of where this script is. +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done +DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )" + +# Change into that directory +cd $DIR + +# Get the git commit +GIT_COMMIT=$(git rev-parse HEAD) +GIT_DIRTY=$(test -n "`git status --porcelain`" && echo "+CHANGES" || true) + +# If we're building on Windows, specify an extension +EXTENSION="" +if [ "$(go env GOOS)" = "windows" ]; then + EXTENSION=".exe" +fi + +GOPATHSINGLE=${GOPATH%%:*} +if [ "$(go env GOOS)" = "windows" ]; then + GOPATHSINGLE=${GOPATH%%;*} +fi + +# Install dependencies +echo "--> Getting dependencies..." +go get ./... + +# Build! +echo "--> Building..." +gox \ + -os="$(go env GOOS)" \ + -arch="$(go env GOARCH)" \ + -ldflags "-X main.GitCommit ${GIT_COMMIT}${GIT_DIRTY}" \ + -output "bin/terraform-{{.Dir}}" \ + ./... +mv bin/terraform-terraform${EXTENSION} bin/terraform${EXTENSION} +cp bin/terraform* ${GOPATHSINGLE}/bin + +# Done! +echo +echo "--> Results:" +ls -l bin/