build 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/sh -e
  2. CDIR=$(cd `dirname "$0"` && pwd)
  3. cd "$CDIR"
  4. # set some environment variables
  5. ORG_PATH="github.com/coreos"
  6. REPO_PATH="${ORG_PATH}/etcd"
  7. export GO15VENDOREXPERIMENT="1"
  8. eval $(go env)
  9. GIT_SHA=`git rev-parse --short HEAD || echo "GitNotFound"`
  10. if [ ! -z "$FAILPOINTS" ]; then
  11. GIT_SHA="$GIT_SHA"-FAILPOINTS
  12. fi
  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 "-s -X ${REPO_PATH}/cmd/vendor/${REPO_PATH}/version.GitSHA=${GIT_SHA}" -o ${out}/etcd ${REPO_PATH}/cmd
  32. CGO_ENABLED=0 go build $GO_BUILD_FLAGS -installsuffix cgo -ldflags "-s" -o ${out}/etcdctl ${REPO_PATH}/cmd/etcdctl
  33. }
  34. etcd_setup_gopath() {
  35. export GOPATH=${CDIR}/gopath
  36. rm -f $GOPATH/src
  37. mkdir -p $GOPATH
  38. ln -s ${CDIR}/cmd/vendor $GOPATH/src
  39. }
  40. toggle_failpoints
  41. etcd_setup_gopath
  42. # don't build when sourced
  43. (echo "$0" | grep "/build$" > /dev/null) && etcd_build || true