2013-06-30 08:13:01 -04:00
|
|
|
#!/bin/bash
|
2013-07-08 18:37:01 -04:00
|
|
|
#
|
|
|
|
# This script only builds the application from source.
|
2013-07-09 15:42:54 -04:00
|
|
|
set -e
|
|
|
|
|
2013-05-24 00:57:30 -04:00
|
|
|
NO_COLOR="\x1b[0m"
|
|
|
|
OK_COLOR="\x1b[32;01m"
|
|
|
|
ERROR_COLOR="\x1b[31;01m"
|
|
|
|
WARN_COLOR="\x1b[33;01m"
|
|
|
|
|
2013-06-20 01:44:02 -04:00
|
|
|
# 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
|
2013-05-24 00:57:30 -04:00
|
|
|
|
2013-07-08 18:37:01 -04:00
|
|
|
# Get the git commit
|
2013-08-12 12:17:03 -04:00
|
|
|
GIT_COMMIT=$(git rev-parse HEAD)
|
2013-07-09 01:24:19 -04:00
|
|
|
GIT_DIRTY=$(test -n "`git status --porcelain`" && echo "+CHANGES" || true)
|
2013-07-08 18:37:01 -04:00
|
|
|
|
2013-09-06 14:34:01 -04:00
|
|
|
# If we're building on Windows, specify an extension
|
|
|
|
EXTENSION=""
|
|
|
|
if [ "$(go env GOOS)" = "windows" ]; then
|
|
|
|
EXTENSION=".exe"
|
|
|
|
fi
|
|
|
|
|
2013-09-22 13:03:04 -04:00
|
|
|
# Make sure that if we're killed, we kill all our subprocseses
|
|
|
|
trap "kill 0" SIGINT SIGTERM EXIT
|
|
|
|
|
2013-08-21 14:15:09 -04:00
|
|
|
# If we're building a race-enabled build, then set that up.
|
|
|
|
if [ ! -z $PACKER_RACE ]; then
|
|
|
|
echo -e "${OK_COLOR}--> Building with race detection enabled${NO_COLOR}"
|
|
|
|
PACKER_RACE="-race"
|
|
|
|
fi
|
|
|
|
|
2013-08-21 14:20:55 -04:00
|
|
|
echo -e "${OK_COLOR}--> Installing dependencies to speed up builds...${NO_COLOR}"
|
|
|
|
go get ./...
|
|
|
|
|
2013-09-22 12:58:34 -04:00
|
|
|
# This function waits for all background tasks to complete
|
|
|
|
waitAll() {
|
|
|
|
RESULT=0
|
|
|
|
for job in `jobs -p`; do
|
|
|
|
wait $job
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
RESULT=1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ $RESULT -ne 0 ]; then
|
|
|
|
exit $RESULT
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2013-09-22 13:03:04 -04:00
|
|
|
waitSingle() {
|
|
|
|
if [ ! -z $PACKER_NO_BUILD_PARALLEL ]; then
|
|
|
|
waitAll
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ -z $PACKER_NO_BUILD_PARALLEL ]; then
|
|
|
|
echo -e "${OK_COLOR}--> NOTE: Compilation of components " \
|
|
|
|
"will be done in parallel.${NO_COLOR}"
|
|
|
|
fi
|
2013-09-22 12:58:34 -04:00
|
|
|
|
2013-05-24 00:57:30 -04:00
|
|
|
# Compile the main Packer app
|
2013-06-30 08:13:01 -04:00
|
|
|
echo -e "${OK_COLOR}--> Compiling Packer${NO_COLOR}"
|
2013-09-22 12:58:34 -04:00
|
|
|
(
|
2013-07-08 18:37:01 -04:00
|
|
|
go build \
|
2013-08-21 14:15:09 -04:00
|
|
|
${PACKER_RACE} \
|
2013-07-08 18:37:01 -04:00
|
|
|
-ldflags "-X github.com/mitchellh/packer/packer.GitCommit ${GIT_COMMIT}${GIT_DIRTY}" \
|
|
|
|
-v \
|
2013-09-06 14:34:01 -04:00
|
|
|
-o bin/packer${EXTENSION} .
|
2013-09-22 12:58:34 -04:00
|
|
|
) &
|
2013-05-24 00:57:30 -04:00
|
|
|
|
2013-09-22 13:03:04 -04:00
|
|
|
waitSingle
|
|
|
|
|
2013-05-24 00:57:30 -04:00
|
|
|
# Go over each plugin and build it
|
2013-06-18 17:07:36 -04:00
|
|
|
for PLUGIN in $(find ./plugin -mindepth 1 -maxdepth 1 -type d); do
|
2013-05-24 00:57:30 -04:00
|
|
|
PLUGIN_NAME=$(basename ${PLUGIN})
|
2013-06-30 08:13:01 -04:00
|
|
|
echo -e "${OK_COLOR}--> Compiling Plugin: ${PLUGIN_NAME}${NO_COLOR}"
|
2013-09-22 12:58:34 -04:00
|
|
|
(
|
2013-07-08 18:37:01 -04:00
|
|
|
go build \
|
2013-08-21 14:15:09 -04:00
|
|
|
${PACKER_RACE} \
|
2013-07-08 18:37:01 -04:00
|
|
|
-ldflags "-X github.com/mitchellh/packer/packer.GitCommit ${GIT_COMMIT}${GIT_DIRTY}" \
|
|
|
|
-v \
|
2013-09-06 14:34:01 -04:00
|
|
|
-o bin/packer-${PLUGIN_NAME}${EXTENSION} ${PLUGIN}
|
2013-09-22 12:58:34 -04:00
|
|
|
) &
|
2013-09-22 13:03:04 -04:00
|
|
|
|
|
|
|
waitSingle
|
2013-05-24 00:57:30 -04:00
|
|
|
done
|
2013-09-22 12:58:34 -04:00
|
|
|
|
|
|
|
waitAll
|
2013-09-27 06:27:47 -04:00
|
|
|
|
|
|
|
# Reset signal trapping to avoid "Terminated: 15" at the end
|
|
|
|
trap - SIGINT SIGTERM EXIT
|