mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
99 lines
2.4 KiB
Bash
Executable File
99 lines
2.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
source ./scripts/test_lib.sh
|
|
|
|
# set some environment variables
|
|
ORG_PATH="go.etcd.io"
|
|
REPO_PATH="${ORG_PATH}/etcd/v3"
|
|
|
|
GIT_SHA=$(git rev-parse --short HEAD || echo "GitNotFound")
|
|
if [[ -n "$FAILPOINTS" ]]; then
|
|
GIT_SHA="$GIT_SHA"-FAILPOINTS
|
|
fi
|
|
|
|
# Set GO_LDFLAGS="-s" for building without symbols for debugging.
|
|
GO_LDFLAGS="$GO_LDFLAGS -X ${REPO_PATH}/version.GitSHA=${GIT_SHA}"
|
|
|
|
# enable/disable failpoints
|
|
toggle_failpoints() {
|
|
mode="$1"
|
|
if command -v gofail >/dev/null 2>&1; then
|
|
run gofail "$mode" etcdserver/ mvcc/backend/
|
|
elif [[ "$mode" != "disable" ]]; then
|
|
log_error "FAILPOINTS set but gofail not found"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
toggle_failpoints_default() {
|
|
mode="disable"
|
|
if [[ -n "$FAILPOINTS" ]]; then mode="enable"; fi
|
|
toggle_failpoints "$mode"
|
|
}
|
|
|
|
etcd_build() {
|
|
out="bin"
|
|
if [[ -n "${BINDIR}" ]]; then out="${BINDIR}"; fi
|
|
toggle_failpoints_default
|
|
|
|
# Static compilation is useful when etcd is run in a container. $GO_BUILD_FLAGS is OK
|
|
# shellcheck disable=SC2086
|
|
CGO_ENABLED=0 run go build $GO_BUILD_FLAGS \
|
|
-installsuffix=cgo \
|
|
"-ldflags='${GO_LDFLAGS}'" \
|
|
-o="${out}/etcd" . || return
|
|
# shellcheck disable=SC2086
|
|
CGO_ENABLED=0 run go build $GO_BUILD_FLAGS \
|
|
-installsuffix=cgo \
|
|
"-ldflags='${GO_LDFLAGS}'" \
|
|
-o="${out}/etcdctl" ./etcdctl || return
|
|
}
|
|
|
|
tools_build() {
|
|
out="bin"
|
|
if [[ -n "${BINDIR}" ]]; then out="${BINDIR}"; fi
|
|
tools_path="tools/benchmark
|
|
tools/etcd-dump-db
|
|
tools/etcd-dump-logs
|
|
tools/local-tester/bridge"
|
|
for tool in ${tools_path}
|
|
do
|
|
echo "Building" "'${tool}'"...
|
|
# shellcheck disable=SC2086
|
|
CGO_ENABLED=0 run go build ${GO_BUILD_FLAGS} \
|
|
-installsuffix=cgo \
|
|
"-ldflags='${GO_LDFLAGS}'" \
|
|
-o="${out}/${tool}" "./${tool}" || return
|
|
done
|
|
tests_build "${@}"
|
|
}
|
|
|
|
tests_build() {
|
|
out="bin"
|
|
if [[ -n "${BINDIR}" ]]; then out="${BINDIR}"; fi
|
|
tools_path="
|
|
functional/cmd/etcd-agent
|
|
functional/cmd/etcd-proxy
|
|
functional/cmd/etcd-runner
|
|
functional/cmd/etcd-tester"
|
|
(
|
|
cd tests || exit 2
|
|
for tool in ${tools_path}; do
|
|
echo "Building" "'${tool}'"...
|
|
|
|
# shellcheck disable=SC2086
|
|
CGO_ENABLED=0 run go build ${GO_BUILD_FLAGS} \
|
|
-installsuffix=cgo \
|
|
"-ldflags='${GO_LDFLAGS}'" \
|
|
-o="../${out}/${tool}" "./${tool}" || return
|
|
done
|
|
)
|
|
}
|
|
|
|
toggle_failpoints_default
|
|
|
|
# only build when called directly, not sourced
|
|
if echo "$0" | grep "build$" >/dev/null; then
|
|
etcd_build
|
|
fi
|