2015-05-30 09:34:54 +03:00
|
|
|
#!/bin/sh -e
|
2014-09-09 10:06:03 +04:00
|
|
|
|
2016-06-21 22:12:50 +03:00
|
|
|
# set some environment variables
|
2014-09-09 10:06:03 +04:00
|
|
|
ORG_PATH="github.com/coreos"
|
|
|
|
REPO_PATH="${ORG_PATH}/etcd"
|
2016-03-23 03:15:33 +03:00
|
|
|
export GO15VENDOREXPERIMENT="1"
|
2016-10-11 10:05:46 +03:00
|
|
|
|
2014-09-09 10:06:03 +04:00
|
|
|
eval $(go env)
|
2015-06-05 03:07:28 +03:00
|
|
|
GIT_SHA=`git rev-parse --short HEAD || echo "GitNotFound"`
|
2016-06-21 22:44:11 +03:00
|
|
|
if [ ! -z "$FAILPOINTS" ]; then
|
|
|
|
GIT_SHA="$GIT_SHA"-FAILPOINTS
|
|
|
|
fi
|
|
|
|
|
2016-10-19 09:15:38 +03:00
|
|
|
# Set GO_LDFLAGS="-s" for building without symbols for debugging.
|
2016-10-15 00:21:20 +03:00
|
|
|
GO_LDFLAGS="$GO_LDFLAGS -X ${REPO_PATH}/cmd/vendor/${REPO_PATH}/version.GitSHA=${GIT_SHA}"
|
|
|
|
|
2016-06-21 22:44:11 +03:00
|
|
|
# enable/disable failpoints
|
|
|
|
toggle_failpoints() {
|
2016-07-04 10:26:30 +03:00
|
|
|
FAILPKGS="etcdserver/ mvcc/backend/"
|
2016-06-21 22:44:11 +03:00
|
|
|
|
|
|
|
mode="disable"
|
|
|
|
if [ ! -z "$FAILPOINTS" ]; then mode="enable"; fi
|
|
|
|
if [ ! -z "$1" ]; then mode="$1"; fi
|
|
|
|
|
|
|
|
if which gofail >/dev/null 2>&1; then
|
|
|
|
gofail "$mode" $FAILPKGS
|
|
|
|
elif [ "$mode" != "disable" ]; then
|
|
|
|
echo "FAILPOINTS set but gofail not found"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
2015-05-09 02:49:12 +03:00
|
|
|
|
2016-06-21 22:12:50 +03:00
|
|
|
etcd_build() {
|
2016-07-16 20:10:41 +03:00
|
|
|
out="bin"
|
|
|
|
if [ -n "${BINDIR}" ]; then out="${BINDIR}"; fi
|
2016-06-21 22:44:11 +03:00
|
|
|
toggle_failpoints
|
2016-06-21 22:12:50 +03:00
|
|
|
# Static compilation is useful when etcd is run in a container
|
2016-10-11 10:05:46 +03:00
|
|
|
CGO_ENABLED=0 go build $GO_BUILD_FLAGS -installsuffix cgo -ldflags "$GO_LDFLAGS" -o ${out}/etcd ${REPO_PATH}/cmd/etcd || return
|
|
|
|
CGO_ENABLED=0 go build $GO_BUILD_FLAGS -installsuffix cgo -ldflags "$GO_LDFLAGS" -o ${out}/etcdctl ${REPO_PATH}/cmd/etcdctl || return
|
2016-06-21 22:12:50 +03:00
|
|
|
}
|
2016-04-30 00:54:40 +03:00
|
|
|
|
2016-07-17 13:43:34 +03:00
|
|
|
etcd_setup_gopath() {
|
2016-08-17 03:05:36 +03:00
|
|
|
CDIR=$(cd `dirname "$0"` && pwd)
|
|
|
|
cd "$CDIR"
|
2016-08-16 23:46:07 +03:00
|
|
|
etcdGOPATH=${CDIR}/gopath
|
|
|
|
# preserve old gopath to support building with unvendored tooling deps (e.g., gofail)
|
2016-09-27 20:18:25 +03:00
|
|
|
if [ -n "$GOPATH" ]; then
|
|
|
|
GOPATH=":$GOPATH"
|
|
|
|
fi
|
|
|
|
export GOPATH=${etcdGOPATH}$GOPATH
|
2016-08-16 23:46:07 +03:00
|
|
|
rm -f ${etcdGOPATH}/src
|
|
|
|
mkdir -p ${etcdGOPATH}
|
|
|
|
ln -s ${CDIR}/cmd/vendor ${etcdGOPATH}/src
|
2016-07-17 13:43:34 +03:00
|
|
|
}
|
|
|
|
|
2016-06-21 22:44:11 +03:00
|
|
|
toggle_failpoints
|
|
|
|
|
2016-08-17 03:05:36 +03:00
|
|
|
# only build when called directly, not sourced
|
|
|
|
if echo "$0" | grep "build$" >/dev/null; then
|
|
|
|
# force new gopath so builds outside of gopath work
|
|
|
|
etcd_setup_gopath
|
|
|
|
etcd_build
|
|
|
|
fi
|