build 1.7 KB

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