handle missing GOPATH and cygwin considerations
This commit is contained in:
parent
9a2d5885ce
commit
6a85f5aed7
|
@ -1,6 +1,10 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
#
|
|
||||||
# This script builds the application from source for multiple platforms.
|
# This script builds the application from source for multiple platforms.
|
||||||
|
# Determine the arch/os combos we're building for
|
||||||
|
ALL_XC_ARCH="386 amd64 arm arm64 ppc64le"
|
||||||
|
ALL_XC_OS="linux darwin windows freebsd openbsd solaris"
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Get the parent directory of where this script is.
|
# Get the parent directory of where this script is.
|
||||||
|
@ -21,33 +25,82 @@ rm -f bin/*
|
||||||
rm -rf pkg/*
|
rm -rf pkg/*
|
||||||
mkdir -p bin/
|
mkdir -p bin/
|
||||||
|
|
||||||
OLDIFS=$IFS
|
# helpers for Cygwin-hosted builds
|
||||||
IFS=:
|
: ${OSTYPE:=`uname`}
|
||||||
case $(uname) in
|
|
||||||
MINGW*|MSYS*)
|
case $OSTYPE in
|
||||||
IFS=";"
|
MINGW*|MSYS*|cygwin|CYGWIN*)
|
||||||
|
# cygwin only translates ';' to ':' on select environment variables
|
||||||
|
PATHSEP=';'
|
||||||
;;
|
;;
|
||||||
|
*) PATHSEP=':'
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
function convert_path() {
|
||||||
|
local flag
|
||||||
|
[ "${1:0:1}" = '-' ] && { flag="$1"; shift; }
|
||||||
|
|
||||||
|
[ -n "$1" ] || return 0
|
||||||
|
case ${OSTYPE:-`uname`} in
|
||||||
|
cygwin|CYGWIN*)
|
||||||
|
cygpath $flag -- "$1"
|
||||||
|
;;
|
||||||
|
*) echo "$1"
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# XXX works in MINGW?
|
||||||
|
which go &>/dev/null || PATH+=":`convert_path "${GOROOT:?}"`/bin"
|
||||||
|
|
||||||
|
OLDIFS="$IFS"
|
||||||
|
|
||||||
|
# make sure GOPATH is consistent - Windows binaries can't handle Cygwin-style paths
|
||||||
|
IFS="$PATHSEP"
|
||||||
|
for d in ${GOPATH:-$(go env GOPATH)}; do
|
||||||
|
_GOPATH+="${_GOPATH:+$PATHSEP}$(convert_path --windows "$d")"
|
||||||
|
done
|
||||||
|
GOPATH="$_GOPATH"
|
||||||
|
|
||||||
|
# locate 'gox' and traverse GOPATH if needed
|
||||||
|
which "${GOX:=gox}" &>/dev/null || {
|
||||||
|
for d in $GOPATH; do
|
||||||
|
GOX="$(convert_path --unix "$d")/bin/gox"
|
||||||
|
[ -x "$GOX" ] && break || unset GOX
|
||||||
|
done
|
||||||
|
}
|
||||||
|
IFS="$OLDIFS"
|
||||||
|
|
||||||
# Build!
|
# Build!
|
||||||
echo "==> Building..."
|
echo "==> Building..."
|
||||||
|
|
||||||
|
# If in dev mode, only build for ourself
|
||||||
|
if [ -n "${PACKER_DEV+x}" ]; then
|
||||||
|
XC_OS=$(go env GOOS)
|
||||||
|
XC_ARCH=$(go env GOARCH)
|
||||||
|
fi
|
||||||
|
|
||||||
set +e
|
set +e
|
||||||
${GOX:-$GOPATH/bin/gox} \
|
${GOX:?command not found} \
|
||||||
-os="${XC_OS}" \
|
-os="${XC_OS:-$ALL_XC_OS}" \
|
||||||
-arch="${XC_ARCH}" \
|
-arch="${XC_ARCH:-$ALL_XC_ARCH}" \
|
||||||
-osarch="!darwin/arm !darwin/arm64" \
|
-osarch="!darwin/arm !darwin/arm64" \
|
||||||
-ldflags "${GOLDFLAGS}" \
|
-ldflags "${GOLDFLAGS}" \
|
||||||
-output "pkg/{{.OS}}_{{.Arch}}/packer" \
|
-output "pkg/{{.OS}}_{{.Arch}}/packer" \
|
||||||
.
|
.
|
||||||
|
|
||||||
IFS=$OLDIFS
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
# trim GOPATH to first element
|
||||||
|
IFS="$PATHSEP"
|
||||||
|
MAIN_GOPATH=($GOPATH)
|
||||||
|
MAIN_GOPATH="$(convert_path --unix "$MAIN_GOPATH")"
|
||||||
|
IFS=$OLDIFS
|
||||||
|
|
||||||
# Copy our OS/Arch to the bin/ directory
|
# Copy our OS/Arch to the bin/ directory
|
||||||
echo "==> Copying binaries for this platform..."
|
echo "==> Copying binaries for this platform..."
|
||||||
for F in $(find pkg/$(go env GOOS)_$(go env GOARCH) -mindepth 1 -maxdepth 1 -type f); do
|
DEV_PLATFORM="./pkg/$(go env GOOS)_$(go env GOARCH)"
|
||||||
|
for F in $(find ${DEV_PLATFORM} -mindepth 1 -maxdepth 1 -type f); do
|
||||||
cp -v ${F} bin/
|
cp -v ${F} bin/
|
||||||
cp -v ${F} ${GOPATH}/bin/
|
cp -v ${F} ${MAIN_GOPATH}/bin/
|
||||||
done
|
done
|
||||||
|
|
||||||
# Done!
|
# Done!
|
||||||
|
|
Loading…
Reference in New Issue