build 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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}/internal/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/ internal/mvcc/backend/
  16. elif [ "$mode" != "disable" ]; then
  17. echo "FAILPOINTS set but gofail not found"
  18. exit 1
  19. fi
  20. }
  21. etcd_setup_gopath() {
  22. echo "Setting GOPATH from vendor directory at 'gopath'"
  23. d=$(dirname "$0")
  24. CDIR=$(cd "$d" && pwd)
  25. cd "$CDIR"
  26. etcdGOPATH="${CDIR}/gopath"
  27. # preserve old gopath to support building with unvendored tooling deps (e.g., gofail)
  28. if [ -n "$GOPATH" ]; then
  29. GOPATH="$GOPATH"
  30. fi
  31. rm -rf "${etcdGOPATH:?}/"
  32. mkdir -p "${etcdGOPATH}/vendor" "${etcdGOPATH}/etcd_src/src/github.com/coreos"
  33. export GOPATH=${etcdGOPATH}/vendor:${etcdGOPATH}/etcd_src:$GOPATH
  34. ln -s "${CDIR}/vendor" "${etcdGOPATH}/vendor/src"
  35. ln -s "${CDIR}" "${etcdGOPATH}/etcd_src/src/github.com/coreos/etcd"
  36. #ln -s "${CDIR}/vendor" "${etcdGOPATH}/src"
  37. #ln -s "${CDIR}" "${etcdGOPATH}/src/github.com/coreos"
  38. }
  39. toggle_failpoints_default() {
  40. mode="disable"
  41. if [ ! -z "$FAILPOINTS" ]; then mode="enable"; fi
  42. toggle_failpoints "$mode"
  43. }
  44. etcd_build() {
  45. out="bin"
  46. if [ -n "${BINDIR}" ]; then out="${BINDIR}"; fi
  47. toggle_failpoints_default
  48. # Static compilation is useful when etcd is run in a container. $GO_BUILD_FLAGS is OK
  49. # shellcheck disable=SC2086
  50. CGO_ENABLED=0 go build $GO_BUILD_FLAGS -installsuffix cgo -ldflags "$GO_LDFLAGS" -o "${out}/etcd" ${REPO_PATH} || return
  51. # shellcheck disable=SC2086
  52. CGO_ENABLED=0 go build $GO_BUILD_FLAGS -installsuffix cgo -ldflags "$GO_LDFLAGS" -o "${out}/etcdctl" ${REPO_PATH}/etcdctl || return
  53. }
  54. tools_build() {
  55. out="bin"
  56. if [ -n "${BINDIR}" ]; then out="${BINDIR}"; fi
  57. # shellcheck disable=SC2039
  58. tools=(
  59. benchmark
  60. etcd-dump-db
  61. etcd-dump-logs
  62. functional-tester/etcd-agent
  63. functional-tester/etcd-tester
  64. functional-tester/etcd-runner
  65. local-tester/bridge
  66. )
  67. # shellcheck disable=SC2039
  68. for tool in "${tools[@]}"
  69. do
  70. # shellcheck disable=SC2086
  71. CGO_ENABLED=0 go build $GO_BUILD_FLAGS -installsuffix cgo -ldflags "$GO_LDFLAGS" -o "${out}/${tool}" "${REPO_PATH}/tools/${tool}" || return
  72. done
  73. }
  74. toggle_failpoints_default
  75. # only build when called directly, not sourced
  76. if echo "$0" | grep "build$" >/dev/null; then
  77. etcd_build
  78. fi