tile38/build.sh

111 lines
2.6 KiB
Bash
Raw Normal View History

2016-03-05 02:08:16 +03:00
#!/bin/bash
set -e
2016-04-03 01:32:13 +03:00
VERSION="1.1.0"
2016-03-08 16:12:39 +03:00
PROTECTED_MODE="no"
# Hardcode some values to the core package
LDFLAGS="$LDFLAGS -X github.com/tidwall/tile38/core.Version=${VERSION}"
2016-03-14 02:39:04 +03:00
if [ -d ".git" ]; then
LDFLAGS="$LDFLAGS -X github.com/tidwall/tile38/core.GitSHA=$(git rev-parse --short HEAD)"
fi
2016-03-08 16:12:39 +03:00
LDFLAGS="$LDFLAGS -X github.com/tidwall/tile38/core.BuildTime=$(date +%FT%T%z)"
if [ "$PROTECTED_MODE" == "no" ]; then
LDFLAGS="$LDFLAGS -X github.com/tidwall/tile38/core.ProtectedMode=no"
fi
2016-03-05 02:08:16 +03:00
2016-03-17 22:15:35 +03:00
# Check go install
2016-03-17 21:55:50 +03:00
if [ "$(which go)" == "" ]; then
echo "error: Go is not installed. Please download and follow installation instructions at https://golang.org/dl to continue."
exit 1
fi
2016-03-17 22:15:35 +03:00
# Check go version
2016-03-17 21:55:50 +03:00
GOVERS="$(go version | cut -d " " -f 3)"
2016-03-17 22:02:10 +03:00
if [ "$GOVERS" != "devel" ]; then
2016-03-17 22:15:35 +03:00
vercomp () {
if [[ $1 == $2 ]]
then
echo "0"
return
fi
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++))
do
if [[ -z ${ver2[i]} ]]
then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]}))
then
echo "1"
return
fi
if ((10#${ver1[i]} < 10#${ver2[i]}))
then
echo "-1"
return
fi
done
echo "0"
return
}
GOVERS="${GOVERS:2}"
2016-03-17 22:02:10 +03:00
EQRES=$(vercomp "$GOVERS" "1.5")
if [ "$EQRES" == "-1" ]; then
2016-03-17 22:15:35 +03:00
echo "error: Go '1.5' or greater is required and '$GOVERS' is currently installed. Please upgrade Go at https://golang.org/dl to continue."
exit 1
2016-03-17 22:02:10 +03:00
fi
2016-03-17 21:55:50 +03:00
fi
2016-03-05 02:28:32 +03:00
export GO15VENDOREXPERIMENT=1
2016-03-05 02:08:16 +03:00
cd $(dirname "${BASH_SOURCE[0]}")
OD="$(pwd)"
2016-03-08 03:37:16 +03:00
# temp directory for storing isolated environment.
2016-03-05 02:28:32 +03:00
TMP="$(mktemp -d -t tile38.XXXX)"
2016-03-05 02:08:16 +03:00
function rmtemp {
2016-03-17 22:15:35 +03:00
rm -rf "$TMP"
2016-03-05 02:08:16 +03:00
}
trap rmtemp EXIT
2016-03-08 03:37:16 +03:00
if [ "$NOCOPY" != "1" ]; then
# copy all files to an isloated directory.
WD="$TMP/src/github.com/tidwall/tile38"
2016-03-17 21:55:50 +03:00
export GOPATH="$TMP"
2016-03-08 03:37:16 +03:00
for file in `find . -type f`; do
# TODO: use .gitignore to ignore, or possibly just use git to determine the file list.
if [[ "$file" != "." && "$file" != ./.git* && "$file" != ./data* && "$file" != ./tile38-* ]]; then
mkdir -p "$WD/$(dirname "${file}")"
cp -P "$file" "$WD/$(dirname "${file}")"
fi
done
cd $WD
fi
2016-03-08 16:21:12 +03:00
#core/gen.sh
2016-03-05 02:08:16 +03:00
# build and store objects into original directory.
go build -ldflags "$LDFLAGS" -o "$OD/tile38-server" cmd/tile38-server/*.go
go build -ldflags "$LDFLAGS" -o "$OD/tile38-cli" cmd/tile38-cli/*.go
2016-03-07 16:44:38 +03:00
# test if requested
if [ "$1" == "test" ]; then
$OD/tile38-server -p 9876 -d "$TMP" -q &
PID=$!
function testend {
2016-03-17 22:15:35 +03:00
kill $PID &
2016-03-07 16:44:38 +03:00
}
trap testend EXIT
go test $(go list ./... | grep -v /vendor/)
fi
2016-03-05 02:08:16 +03:00