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. export GO15VENDOREXPERIMENT="1"
  6. eval $(go env)
  7. GIT_SHA=`git rev-parse --short HEAD || echo "GitNotFound"`
  8. if [ ! -z "$FAILPOINTS" ]; then
  9. GIT_SHA="$GIT_SHA"-FAILPOINTS
  10. fi
  11. # Set GO_LDFLAGS="" for building with all symbols for debugging.
  12. if [ -z "${GO_LDFLAGS+x}" ]; then GO_LDFLAGS="-s"; fi
  13. GO_LDFLAGS="$GO_LDFLAGS -X ${REPO_PATH}/cmd/vendor/${REPO_PATH}/version.GitSHA=${GIT_SHA}"
  14. # enable/disable failpoints
  15. toggle_failpoints() {
  16. FAILPKGS="etcdserver/ mvcc/backend/"
  17. mode="disable"
  18. if [ ! -z "$FAILPOINTS" ]; then mode="enable"; fi
  19. if [ ! -z "$1" ]; then mode="$1"; fi
  20. if which gofail >/dev/null 2>&1; then
  21. gofail "$mode" $FAILPKGS
  22. elif [ "$mode" != "disable" ]; then
  23. echo "FAILPOINTS set but gofail not found"
  24. exit 1
  25. fi
  26. }
  27. etcd_build() {
  28. out="bin"
  29. if [ -n "${BINDIR}" ]; then out="${BINDIR}"; fi
  30. toggle_failpoints
  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. CDIR=$(cd `dirname "$0"` && pwd)
  37. cd "$CDIR"
  38. etcdGOPATH=${CDIR}/gopath
  39. # preserve old gopath to support building with unvendored tooling deps (e.g., gofail)
  40. if [ -n "$GOPATH" ]; then
  41. GOPATH=":$GOPATH"
  42. fi
  43. export GOPATH=${etcdGOPATH}$GOPATH
  44. rm -f ${etcdGOPATH}/src
  45. mkdir -p ${etcdGOPATH}
  46. ln -s ${CDIR}/cmd/vendor ${etcdGOPATH}/src
  47. }
  48. toggle_failpoints
  49. # only build when called directly, not sourced
  50. if echo "$0" | grep "build$" >/dev/null; then
  51. # force new gopath so builds outside of gopath work
  52. etcd_setup_gopath
  53. etcd_build
  54. fi