build 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. FAILPKGS="etcdserver/ mvcc/backend/"
  14. mode="$1"
  15. if which gofail >/dev/null 2>&1; then
  16. gofail "$mode" $FAILPKGS
  17. elif [ "$mode" != "disable" ]; then
  18. echo "FAILPOINTS set but gofail not found"
  19. exit 1
  20. fi
  21. }
  22. toggle_failpoints_default() {
  23. mode="disable"
  24. if [ ! -z "$FAILPOINTS" ]; then mode="enable"; fi
  25. toggle_failpoints "$mode"
  26. }
  27. etcd_build() {
  28. out="bin"
  29. if [ -n "${BINDIR}" ]; then out="${BINDIR}"; fi
  30. toggle_failpoints_default
  31. # Static compilation is useful when etcd is run in a container
  32. CGO_ENABLED=0 go build $GO_BUILD_FLAGS -installsuffix cgo -ldflags "$GO_LDFLAGS" -o ${out}/etcd ${REPO_PATH}/cmd/etcd || return
  33. CGO_ENABLED=0 go build $GO_BUILD_FLAGS -installsuffix cgo -ldflags "$GO_LDFLAGS" -o ${out}/etcdctl ${REPO_PATH}/cmd/etcdctl || return
  34. }
  35. etcd_setup_gopath() {
  36. d=$(dirname "$0")
  37. CDIR=$(cd "$d" && pwd)
  38. cd "$CDIR"
  39. etcdGOPATH="${CDIR}/gopath"
  40. # preserve old gopath to support building with unvendored tooling deps (e.g., gofail)
  41. if [ -n "$GOPATH" ]; then
  42. GOPATH=":$GOPATH"
  43. fi
  44. export GOPATH=${etcdGOPATH}$GOPATH
  45. rm -rf ${etcdGOPATH}/src
  46. mkdir -p ${etcdGOPATH}
  47. ln -s ${CDIR}/cmd/vendor ${etcdGOPATH}/src
  48. }
  49. toggle_failpoints_default
  50. # only build when called directly, not sourced
  51. if echo "$0" | grep "build$" >/dev/null; then
  52. # force new gopath so builds outside of gopath work
  53. etcd_setup_gopath
  54. etcd_build
  55. fi