Skip to content

Commit

Permalink
build: use "bash" syntax, clean up
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
  • Loading branch information
gyuho committed Feb 27, 2018
1 parent f1374cd commit b3259e5
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 47 deletions.
33 changes: 18 additions & 15 deletions build
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand All @@ -26,44 +26,47 @@ 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:?}/"
mkdir -p "${etcdGOPATH}/vendor" "${etcdGOPATH}/etcd_src/src/github.com/coreos"
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
Expand Down
64 changes: 32 additions & 32 deletions test
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 \
Expand All @@ -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
}

Expand Down

0 comments on commit b3259e5

Please sign in to comment.