build 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. # enable/disable failpoints
  12. toggle_failpoints() {
  13. FAILPKGS="etcdserver/"
  14. mode="disable"
  15. if [ ! -z "$FAILPOINTS" ]; then mode="enable"; fi
  16. if [ ! -z "$1" ]; then mode="$1"; fi
  17. if which gofail >/dev/null 2>&1; then
  18. gofail "$mode" $FAILPKGS
  19. elif [ "$mode" != "disable" ]; then
  20. echo "FAILPOINTS set but gofail not found"
  21. exit 1
  22. fi
  23. }
  24. etcd_build() {
  25. if [ -z "${GOARCH}" ] || [ "${GOARCH}" = "$(go env GOHOSTARCH)" ]; then
  26. out="bin"
  27. else
  28. out="bin/${GOARCH}"
  29. 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 "-s -X ${REPO_PATH}/cmd/vendor/${REPO_PATH}/version.GitSHA=${GIT_SHA}" -o ${out}/etcd ${REPO_PATH}/cmd
  33. CGO_ENABLED=0 go build $GO_BUILD_FLAGS -installsuffix cgo -ldflags "-s" -o ${out}/etcdctl ${REPO_PATH}/cmd/etcdctl
  34. }
  35. toggle_failpoints
  36. # don't build when sourced
  37. (echo "$0" | grep "/build$" > /dev/null) && etcd_build || true