Skip to content

Commit

Permalink
scripts: update to use gox
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Nov 18, 2013
1 parent 7e5a5ee commit 8516e03
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 143 deletions.
101 changes: 0 additions & 101 deletions scripts/build.sh

This file was deleted.

52 changes: 52 additions & 0 deletions scripts/compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash
#
# This script compiles Packer for various platforms (specified by the
# PACKER_OS and PACKER_ARCH environmental variables).
set -e

NO_COLOR="\x1b[0m"
OK_COLOR="\x1b[32;01m"
ERROR_COLOR="\x1b[31;01m"
WARN_COLOR="\x1b[33;01m"

# 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)

# Determine the arch/os combos we're building for
XC_ARCH=${XC_ARCH:-"386 amd64 arm"}
XC_OS=${XC_OS:-linux darwin windows freebsd openbsd}

# Make sure that if we're killed, we kill all our subprocseses
trap "kill 0" SIGINT SIGTERM EXIT

echo -e "${OK_COLOR}==> Installing dependencies to speed up builds...${NO_COLOR}"
go get ./...

echo -e "${OK_COLOR}==> Beginning compile...${NO_COLOR}"
rm -rf pkg/
gox \
-os="${XC_OS}" \
-arch="${XC_ARCH}" \
-ldflags "-X github.com/mitchellh/packer/packer.GitCommit ${GIT_COMMIT}${GIT_DIRTY}" \
-output "pkg/{{.OS}}_{{.Arch}}/packer-{{.Dir}}" \
./...

# Make sure "packer-packer" is renamed properly
for PLATFORM in $(find ./pkg -mindepth 1 -maxdepth 1 -type d); do
set +e
mv ${PLATFORM}/packer-packer ${PLATFORM}/packer 2>/dev/null
mv ${PLATFORM}/packer-packer.exe ${PLATFORM}/packer.exe 2>/dev/null
set -e
done

# Reset signal trapping to avoid "Terminated: 15" at the end
trap - SIGINT SIGTERM EXIT
25 changes: 25 additions & 0 deletions scripts/devcompile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
#
# This script only builds the application from source.
set -e

NO_COLOR="\x1b[0m"
OK_COLOR="\x1b[32;01m"
ERROR_COLOR="\x1b[31;01m"
WARN_COLOR="\x1b[33;01m"

# 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

# Compile the thing
export XC_ARCH=$(go env GOARCH)
export XC_OS=$(go env GOOS)
./scripts/compile.sh

# Move all the compiled things to the PATH
cp pkg/${XC_OS}_${XC_ARCH}/* ${GOPATH}/bin
49 changes: 7 additions & 42 deletions scripts/dist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,6 @@ if [ ! -z $PREVERSION ]; then
VERSIONDIR="${VERSIONDIR}-${PREVERSION}"
fi

echo "Version: ${VERSION} ${PREVERSION}"

# Determine the arch/os combos we're building for
XC_ARCH=${XC_ARCH:-"386 amd64 arm"}
XC_OS=${XC_OS:-linux darwin windows freebsd openbsd}

echo "Arch: ${XC_ARCH}"
echo "OS: ${XC_OS}"

# This function builds whatever directory we're in...
xc() {
goxc \
-arch="$XC_ARCH" \
-os="$XC_OS" \
-d="${DIR}/pkg" \
-pv="${VERSION}" \
-pr="${PREVERSION}" \
$XC_OPTS \
go-install \
xc
}

# This function waits for all background tasks to complete
waitAll() {
RESULT=0
Expand All @@ -56,28 +34,15 @@ waitAll() {
fi
}

# Compile the main project
./scripts/compile.sh

# Make sure that if we're killed, we kill all our subprocseses
trap "kill 0" SIGINT SIGTERM EXIT

# Build our root project
xc

# Build all the plugins
for PLUGIN in $(find ./plugin -mindepth 1 -maxdepth 1 -type d); do
PLUGIN_NAME=$(basename ${PLUGIN})
find ./pkg \
-type f \
-name ${PLUGIN_NAME} \
-execdir mv ${PLUGIN_NAME} packer-${PLUGIN_NAME} ';'
find ./pkg \
-type f \
-name ${PLUGIN_NAME}.exe \
-execdir mv ${PLUGIN_NAME}.exe packer-${PLUGIN_NAME}.exe ';'
done

# Zip all the packages
mkdir -p ./pkg/${VERSIONDIR}/dist
for PLATFORM in $(find ./pkg/${VERSIONDIR} -mindepth 1 -maxdepth 1 -type d); do
mkdir -p ./pkg/dist
for PLATFORM in $(find ./pkg -mindepth 1 -maxdepth 1 -type d); do
PLATFORM_NAME=$(basename ${PLATFORM})
ARCHIVE_NAME="${VERSIONDIR}_${PLATFORM_NAME}"

Expand All @@ -87,15 +52,15 @@ for PLATFORM in $(find ./pkg/${VERSIONDIR} -mindepth 1 -maxdepth 1 -type d); do

(
pushd ${PLATFORM}
zip ${DIR}/pkg/${VERSIONDIR}/dist/${ARCHIVE_NAME}.zip ./*
zip ${DIR}/pkg/dist/${ARCHIVE_NAME}.zip ./*
popd
) &
done

waitAll

# Make the checksums
pushd ./pkg/${VERSIONDIR}/dist
pushd ./pkg/dist
shasum -a256 * > ./${VERSIONDIR}_SHA256SUMS
popd

Expand Down

0 comments on commit 8516e03

Please sign in to comment.