go.etcd.io/etcd@v3.3.27+incompatible/build (about) 1 #!/usr/bin/env bash 2 3 # set some environment variables 4 ORG_PATH="github.com/coreos" 5 REPO_PATH="${ORG_PATH}/etcd" 6 7 GIT_SHA=$(git rev-parse --short HEAD || echo "GitNotFound") 8 if [[ -n "$FAILPOINTS" ]]; then 9 GIT_SHA="$GIT_SHA"-FAILPOINTS 10 fi 11 12 # Set GO_LDFLAGS="-s" for building without symbols for debugging. 13 GO_LDFLAGS="$GO_LDFLAGS -X ${REPO_PATH}/version.GitSHA=${GIT_SHA}" 14 15 # enable/disable failpoints 16 toggle_failpoints() { 17 mode="$1" 18 if command -v gofail >/dev/null 2>&1; then 19 gofail "$mode" etcdserver/ mvcc/backend/ 20 elif [[ "$mode" != "disable" ]]; then 21 echo "FAILPOINTS set but gofail not found" 22 exit 1 23 fi 24 } 25 26 etcd_setup_gopath() { 27 echo "Setting GOPATH from vendor directory at 'gopath'" 28 d=$(dirname "$0") 29 CDIR=$(cd "$d" || return && pwd) 30 cd "$CDIR" || return 31 etcdGOPATH="${CDIR}/gopath" 32 # preserve old gopath to support building with unvendored tooling deps (e.g., gofail) 33 if [[ -n "$GOPATH" ]]; then 34 GOPATH=":$GOPATH" 35 fi 36 rm -rf "${etcdGOPATH:?}/" 37 mkdir -p "${etcdGOPATH}/vendor" "${etcdGOPATH}/etcd_src/src/github.com/coreos" 38 export GOPATH=${etcdGOPATH}/vendor:${etcdGOPATH}/etcd_src${GOPATH} 39 ln -s "${CDIR}/vendor" "${etcdGOPATH}/vendor/src" 40 ln -s "${CDIR}" "${etcdGOPATH}/etcd_src/src/github.com/coreos/etcd" 41 } 42 43 toggle_failpoints_default() { 44 mode="disable" 45 if [[ -n "$FAILPOINTS" ]]; then mode="enable"; fi 46 toggle_failpoints "$mode" 47 } 48 49 etcd_build() { 50 out="bin" 51 if [[ -n "${BINDIR}" ]]; then out="${BINDIR}"; fi 52 toggle_failpoints_default 53 54 # Static compilation is useful when etcd is run in a container. $GO_BUILD_FLAGS is OK 55 # shellcheck disable=SC2086 56 CGO_ENABLED=0 go build $GO_BUILD_FLAGS \ 57 -installsuffix cgo \ 58 -ldflags "$GO_LDFLAGS" \ 59 -o "${out}/etcd" ${REPO_PATH} || return 60 # shellcheck disable=SC2086 61 CGO_ENABLED=0 go build $GO_BUILD_FLAGS \ 62 -installsuffix cgo \ 63 -ldflags "$GO_LDFLAGS" \ 64 -o "${out}/etcdctl" ${REPO_PATH}/etcdctl || return 65 } 66 67 tools_build() { 68 out="bin" 69 if [[ -n "${BINDIR}" ]]; then out="${BINDIR}"; fi 70 tools_path="functional/cmd/etcd-agent 71 functional/cmd/etcd-proxy 72 functional/cmd/etcd-runner 73 functional/cmd/etcd-tester" 74 for tool in ${tools_path} 75 do 76 echo "Building" "'${tool}'"... 77 # shellcheck disable=SC2086 78 CGO_ENABLED=0 go build ${GO_BUILD_FLAGS} \ 79 -installsuffix cgo \ 80 -ldflags "${GO_LDFLAGS}" \ 81 -o "${out}/${tool}" "${REPO_PATH}/${tool}" || return 82 done 83 } 84 85 toggle_failpoints_default 86 87 if [[ "${ETCD_SETUP_GOPATH}" == "1" ]]; then 88 etcd_setup_gopath 89 fi 90 91 # only build when called directly, not sourced 92 if echo "$0" | grep "build$" >/dev/null; then 93 etcd_build 94 fi