build: use "bash" syntax, clean up

Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
This commit is contained in:
Gyuho Lee 2018-02-27 10:39:34 -08:00
parent d7092b360d
commit 1da0818186
2 changed files with 50 additions and 47 deletions

33
build
View File

@ -1,11 +1,11 @@
#!/bin/sh -e
#!/usr/bin/env bash
# set some environment variables
ORG_PATH="github.com/coreos"
REPO_PATH="${ORG_PATH}/etcd"
GIT_SHA=$(git rev-parse --short HEAD || echo "GitNotFound")
if [ ! -z "$FAILPOINTS" ]; then
if [[ ! -z "$FAILPOINTS" ]]; then
GIT_SHA="$GIT_SHA"-FAILPOINTS
fi
@ -17,7 +17,7 @@ toggle_failpoints() {
mode="$1"
if which gofail >/dev/null 2>&1; then
gofail "$mode" etcdserver/ internal/mvcc/backend/
elif [ "$mode" != "disable" ]; then
elif [[ "$mode" != "disable" ]]; then
echo "FAILPOINTS set but gofail not found"
exit 1
fi
@ -26,11 +26,11 @@ toggle_failpoints() {
etcd_setup_gopath() {
echo "Setting GOPATH from vendor directory at 'gopath'"
d=$(dirname "$0")
CDIR=$(cd "$d" && pwd)
cd "$CDIR"
CDIR=$(cd "$d" || return && pwd)
cd "$CDIR" || return
etcdGOPATH="${CDIR}/gopath"
# preserve old gopath to support building with unvendored tooling deps (e.g., gofail)
if [ -n "$GOPATH" ]; then
if [[ -n "$GOPATH" ]]; then
GOPATH=":$GOPATH"
fi
rm -rf "${etcdGOPATH:?}/"
@ -38,32 +38,35 @@ etcd_setup_gopath() {
export GOPATH=${etcdGOPATH}/vendor:${etcdGOPATH}/etcd_src${GOPATH}
ln -s "${CDIR}/vendor" "${etcdGOPATH}/vendor/src"
ln -s "${CDIR}" "${etcdGOPATH}/etcd_src/src/github.com/coreos/etcd"
#ln -s "${CDIR}/vendor" "${etcdGOPATH}/src"
#ln -s "${CDIR}" "${etcdGOPATH}/src/github.com/coreos"
}
toggle_failpoints_default() {
mode="disable"
if [ ! -z "$FAILPOINTS" ]; then mode="enable"; fi
if [[ ! -z "$FAILPOINTS" ]]; then mode="enable"; fi
toggle_failpoints "$mode"
}
etcd_build() {
out="bin"
if [ -n "${BINDIR}" ]; then out="${BINDIR}"; fi
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
# Static compilation is useful when etcd is run in a container. $GO_BUILD_FLAGS is OK
# shellcheck disable=SC2086
CGO_ENABLED=0 go build $GO_BUILD_FLAGS -installsuffix cgo -ldflags "$GO_LDFLAGS" -o "${out}/etcd" ${REPO_PATH} || return
CGO_ENABLED=0 go build $GO_BUILD_FLAGS \
-installsuffix cgo \
-ldflags "$GO_LDFLAGS" \
-o "${out}/etcd" ${REPO_PATH} || return
# shellcheck disable=SC2086
CGO_ENABLED=0 go build $GO_BUILD_FLAGS -installsuffix cgo -ldflags "$GO_LDFLAGS" -o "${out}/etcdctl" ${REPO_PATH}/etcdctl || return
CGO_ENABLED=0 go build $GO_BUILD_FLAGS \
-installsuffix cgo \
-ldflags "$GO_LDFLAGS" \
-o "${out}/etcdctl" ${REPO_PATH}/etcdctl || return
}
tools_build() {
out="bin"
if [ -n "${BINDIR}" ]; then out="${BINDIR}"; fi
if [[ -n "${BINDIR}" ]]; then out="${BINDIR}"; fi
tools_path="benchmark
etcd-dump-db
etcd-dump-logs

64
test
View File

@ -277,32 +277,6 @@ function release_pass {
mv /tmp/etcd ./bin/etcd-last-release
}
function gofmt_pass {
fmtRes=$(gofmt -l -s -d "${FMT[@]}")
if [ -n "${fmtRes}" ]; then
echo -e "gofmt checking failed:\n${fmtRes}"
exit 255
fi
}
function govet_pass {
vetRes=$(go vet "${TEST[@]}")
if [ -n "${vetRes}" ]; then
echo -e "govet checking failed:\n${vetRes}"
exit 255
fi
}
function govet_shadow_pass {
fmtpkgs=$(for a in "${FMT[@]}"; do dirname "$a"; done | sort | uniq | grep -v "\\.")
fmtpkgs=($fmtpkgs)
vetRes=$(go tool vet -all -shadow "${fmtpkgs[@]}" 2>&1 | grep -v '/gw/' || true)
if [ -n "${vetRes}" ]; then
echo -e "govet -all -shadow checking failed:\n${vetRes}"
exit 255
fi
}
function shellcheck_pass {
if which shellcheck >/dev/null; then
shellcheckResult=$(shellcheck -fgcc build test scripts/* 2>&1 || true)
@ -360,6 +334,32 @@ function goword_pass {
fi
}
function gofmt_pass {
fmtRes=$(gofmt -l -s -d "${FMT[@]}")
if [ -n "${fmtRes}" ]; then
echo -e "gofmt checking failed:\n${fmtRes}"
exit 255
fi
}
function govet_pass {
vetRes=$(go vet "${TEST[@]}")
if [ -n "${vetRes}" ]; then
echo -e "govet checking failed:\n${vetRes}"
exit 255
fi
}
function govet_shadow_pass {
fmtpkgs=$(for a in "${FMT[@]}"; do dirname "$a"; done | sort | uniq | grep -v "\\.")
fmtpkgs=($fmtpkgs)
vetRes=$(go tool vet -all -shadow "${fmtpkgs[@]}" 2>&1 | grep -v '/gw/' || true)
if [ -n "${vetRes}" ]; then
echo -e "govet -all -shadow checking failed:\n${vetRes}"
exit 255
fi
}
function gosimple_pass {
if which gosimple >/dev/null; then
gosimpleResult=$(gosimple "${STATIC_ANALYSIS_PATHS[@]}" 2>&1 || true)
@ -483,13 +483,13 @@ function commit_title_pass {
function fmt_pass {
toggle_failpoints disable
for p in gofmt \
govet \
govet_shadow \
shellcheck \
for p in shellcheck \
markdown_you \
markdown_marker \
goword \
gofmt \
govet \
govet_shadow \
gosimple \
unused \
staticcheck \
@ -499,9 +499,9 @@ function fmt_pass {
receiver_name \
commit_title \
; do
echo "Starting '$p' pass at $(date)"
echo "'$p' started at $(date)"
"${p}"_pass "$@"
echo "Finished '$p' pass at $(date)"
echo "'$p' completed at $(date)"
done
}