build 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/sh -e
  2. # set some environment variables
  3. ORG_PATH="github.com/coreos"
  4. REPO_PATH="${ORG_PATH}/etcd"
  5. GIT_SHA=$(git rev-parse --short HEAD || echo "GitNotFound")
  6. if [ ! -z "$FAILPOINTS" ]; then
  7. GIT_SHA="$GIT_SHA"-FAILPOINTS
  8. fi
  9. # Set GO_LDFLAGS="-s" for building without symbols for debugging.
  10. GO_LDFLAGS="$GO_LDFLAGS -X ${REPO_PATH}/cmd/vendor/${REPO_PATH}/version.GitSHA=${GIT_SHA}"
  11. # enable/disable failpoints
  12. toggle_failpoints() {
  13. mode="$1"
  14. if which gofail >/dev/null 2>&1; then
  15. gofail "$mode" etcdserver/ mvcc/backend/
  16. elif [ "$mode" != "disable" ]; then
  17. echo "FAILPOINTS set but gofail not found"
  18. exit 1
  19. fi
  20. }
  21. toggle_failpoints_default() {
  22. mode="disable"
  23. if [ ! -z "$FAILPOINTS" ]; then mode="enable"; fi
  24. toggle_failpoints "$mode"
  25. }
  26. etcd_build() {
  27. out="bin"
  28. if [ -n "${BINDIR}" ]; then out="${BINDIR}"; fi
  29. toggle_failpoints_default
  30. # Static compilation is useful when etcd is run in a container. $GO_BUILD_FLAGS is OK
  31. # shellcheck disable=SC2086
  32. CGO_ENABLED=0 go build $GO_BUILD_FLAGS -installsuffix cgo -ldflags "$GO_LDFLAGS" -o "${out}/etcd" ${REPO_PATH}/cmd/etcd || return
  33. # shellcheck disable=SC2086
  34. CGO_ENABLED=0 go build $GO_BUILD_FLAGS -installsuffix cgo -ldflags "$GO_LDFLAGS" -o "${out}/etcdctl" ${REPO_PATH}/cmd/etcdctl || return
  35. }
  36. etcd_setup_gopath() {
  37. d=$(dirname "$0")
  38. CDIR=$(cd "$d" && pwd)
  39. cd "$CDIR"
  40. etcdGOPATH="${CDIR}/gopath"
  41. # preserve old gopath to support building with unvendored tooling deps (e.g., gofail)
  42. if [ -n "$GOPATH" ]; then
  43. GOPATH=":$GOPATH"
  44. fi
  45. export GOPATH=${etcdGOPATH}$GOPATH
  46. rm -rf "${etcdGOPATH}/src"
  47. mkdir -p "${etcdGOPATH}"
  48. ln -s "${CDIR}/cmd/vendor" "${etcdGOPATH}/src"
  49. }
  50. toggle_failpoints_default
  51. # only build when called directly, not sourced
  52. if echo "$0" | grep "build$" >/dev/null; then
  53. # force new gopath so builds outside of gopath work
  54. etcd_setup_gopath
  55. etcd_build
  56. fi