2018-02-27 21:39:34 +03:00
|
|
|
#!/usr/bin/env bash
|
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-10-11 10:05:46 +03:00
|
|
|
|
2017-09-06 20:38:08 +03:00
|
|
|
GIT_SHA=$(git rev-parse --short HEAD || echo "GitNotFound")
|
2018-02-27 21:39:34 +03:00
|
|
|
if [[ ! -z "$FAILPOINTS" ]]; then
|
2016-06-21 22:44:11 +03:00
|
|
|
GIT_SHA="$GIT_SHA"-FAILPOINTS
|
|
|
|
fi
|
|
|
|
|
2016-10-19 09:15:38 +03:00
|
|
|
# Set GO_LDFLAGS="-s" for building without symbols for debugging.
|
2018-03-17 10:35:31 +03:00
|
|
|
GO_LDFLAGS="$GO_LDFLAGS -X ${REPO_PATH}/version.GitSHA=${GIT_SHA}"
|
2016-10-15 00:21:20 +03:00
|
|
|
|
2016-06-21 22:44:11 +03:00
|
|
|
# enable/disable failpoints
|
|
|
|
toggle_failpoints() {
|
2017-06-03 21:02:08 +03:00
|
|
|
mode="$1"
|
2016-06-21 22:44:11 +03:00
|
|
|
if which gofail >/dev/null 2>&1; then
|
2018-03-17 10:35:31 +03:00
|
|
|
gofail "$mode" etcdserver/ mvcc/backend/
|
2018-02-27 21:39:34 +03:00
|
|
|
elif [[ "$mode" != "disable" ]]; then
|
2016-06-21 22:44:11 +03:00
|
|
|
echo "FAILPOINTS set but gofail not found"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
2015-05-09 02:49:12 +03:00
|
|
|
|
2018-02-26 09:21:53 +03:00
|
|
|
etcd_setup_gopath() {
|
|
|
|
echo "Setting GOPATH from vendor directory at 'gopath'"
|
|
|
|
d=$(dirname "$0")
|
2018-02-27 21:39:34 +03:00
|
|
|
CDIR=$(cd "$d" || return && pwd)
|
|
|
|
cd "$CDIR" || return
|
2018-02-26 09:21:53 +03:00
|
|
|
etcdGOPATH="${CDIR}/gopath"
|
|
|
|
# preserve old gopath to support building with unvendored tooling deps (e.g., gofail)
|
2018-02-27 21:39:34 +03:00
|
|
|
if [[ -n "$GOPATH" ]]; then
|
2018-02-27 07:37:35 +03:00
|
|
|
GOPATH=":$GOPATH"
|
2018-02-26 09:21:53 +03:00
|
|
|
fi
|
|
|
|
rm -rf "${etcdGOPATH:?}/"
|
|
|
|
mkdir -p "${etcdGOPATH}/vendor" "${etcdGOPATH}/etcd_src/src/github.com/coreos"
|
2018-02-27 07:37:35 +03:00
|
|
|
export GOPATH=${etcdGOPATH}/vendor:${etcdGOPATH}/etcd_src${GOPATH}
|
2018-02-26 09:21:53 +03:00
|
|
|
ln -s "${CDIR}/vendor" "${etcdGOPATH}/vendor/src"
|
|
|
|
ln -s "${CDIR}" "${etcdGOPATH}/etcd_src/src/github.com/coreos/etcd"
|
|
|
|
}
|
|
|
|
|
2017-06-03 21:02:08 +03:00
|
|
|
toggle_failpoints_default() {
|
|
|
|
mode="disable"
|
2018-02-27 21:39:34 +03:00
|
|
|
if [[ ! -z "$FAILPOINTS" ]]; then mode="enable"; fi
|
2017-06-03 21:02:08 +03:00
|
|
|
toggle_failpoints "$mode"
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:12:50 +03:00
|
|
|
etcd_build() {
|
2016-07-16 20:10:41 +03:00
|
|
|
out="bin"
|
2018-02-27 21:39:34 +03:00
|
|
|
if [[ -n "${BINDIR}" ]]; then out="${BINDIR}"; fi
|
2017-06-03 21:02:08 +03:00
|
|
|
toggle_failpoints_default
|
2017-09-06 20:38:08 +03:00
|
|
|
|
2018-02-27 21:39:34 +03:00
|
|
|
# Static compilation is useful when etcd is run in a container. $GO_BUILD_FLAGS is OK
|
2017-09-06 20:38:08 +03:00
|
|
|
# shellcheck disable=SC2086
|
2018-02-27 21:39:34 +03:00
|
|
|
CGO_ENABLED=0 go build $GO_BUILD_FLAGS \
|
|
|
|
-installsuffix cgo \
|
|
|
|
-ldflags "$GO_LDFLAGS" \
|
|
|
|
-o "${out}/etcd" ${REPO_PATH} || return
|
2017-09-06 20:38:08 +03:00
|
|
|
# shellcheck disable=SC2086
|
2018-02-27 21:39:34 +03:00
|
|
|
CGO_ENABLED=0 go build $GO_BUILD_FLAGS \
|
|
|
|
-installsuffix cgo \
|
|
|
|
-ldflags "$GO_LDFLAGS" \
|
|
|
|
-o "${out}/etcdctl" ${REPO_PATH}/etcdctl || return
|
2016-07-17 13:43:34 +03:00
|
|
|
}
|
|
|
|
|
2018-02-26 09:21:53 +03:00
|
|
|
tools_build() {
|
|
|
|
out="bin"
|
2018-02-27 21:39:34 +03:00
|
|
|
if [[ -n "${BINDIR}" ]]; then out="${BINDIR}"; fi
|
2018-04-09 21:54:12 +03:00
|
|
|
tools_path="tools/benchmark
|
|
|
|
tools/etcd-dump-db
|
|
|
|
tools/etcd-dump-logs
|
|
|
|
tools/local-tester/bridge
|
|
|
|
functional/cmd/etcd-agent
|
|
|
|
functional/cmd/etcd-proxy
|
|
|
|
functional/cmd/etcd-runner
|
|
|
|
functional/cmd/etcd-tester"
|
2018-02-26 22:21:23 +03:00
|
|
|
for tool in ${tools_path}
|
2018-02-26 09:21:53 +03:00
|
|
|
do
|
2018-02-26 22:21:23 +03:00
|
|
|
echo "Building" "'${tool}'"...
|
2018-02-26 23:33:29 +03:00
|
|
|
# shellcheck disable=SC2086
|
2018-02-26 22:21:23 +03:00
|
|
|
CGO_ENABLED=0 go build ${GO_BUILD_FLAGS} \
|
|
|
|
-installsuffix cgo \
|
|
|
|
-ldflags "${GO_LDFLAGS}" \
|
2018-04-09 21:54:12 +03:00
|
|
|
-o "${out}/${tool}" "${REPO_PATH}/${tool}" || return
|
2018-02-26 09:21:53 +03:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2017-06-03 21:02:08 +03:00
|
|
|
toggle_failpoints_default
|
2016-06-21 22:44:11 +03:00
|
|
|
|
2018-02-27 21:23:14 +03:00
|
|
|
if [[ "${ETCD_SETUP_GOPATH}" == "1" ]]; then
|
|
|
|
etcd_setup_gopath
|
|
|
|
fi
|
|
|
|
|
2016-08-17 03:05:36 +03:00
|
|
|
# only build when called directly, not sourced
|
|
|
|
if echo "$0" | grep "build$" >/dev/null; then
|
|
|
|
etcd_build
|
|
|
|
fi
|