genproto.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env bash
  2. #
  3. # Generate all etcd protobuf bindings.
  4. # Run from repository root.
  5. #
  6. set -e
  7. if ! [[ "$0" =~ "scripts/genproto.sh" ]]; then
  8. echo "must be run from repository root"
  9. exit 255
  10. fi
  11. # for now, be conservative about what version of protoc we expect
  12. if ! [[ $(protoc --version) =~ "3.0.0" ]]; then
  13. echo "could not find protoc 3.0.0, is it installed + in PATH?"
  14. exit 255
  15. fi
  16. PREFIX="github.com/coreos/etcd/Godeps/_workspace/src"
  17. ESCAPED_PREFIX=$(echo $PREFIX | sed -e 's/[\/&]/\\&/g')
  18. # directories containing protos to be built
  19. DIRS="./wal/walpb ./etcdserver/etcdserverpb ./snap/snappb ./raft/raftpb ./storage/storagepb"
  20. # exact version of protoc-gen-gogo to build
  21. SHA="932b70afa8b0bf4a8e167fdf0c3367cebba45903"
  22. # set up self-contained GOPATH for building
  23. export GOPATH=${PWD}/gopath
  24. export GOBIN=${PWD}/bin
  25. export PATH="${GOBIN}:${PATH}"
  26. COREOS_ROOT="${GOPATH}/src/github.com/coreos"
  27. ETCD_ROOT="${COREOS_ROOT}/etcd"
  28. GOGOPROTO_ROOT="${GOPATH}/src/github.com/gogo/protobuf"
  29. GOGOPROTO_PATH="${GOGOPROTO_ROOT}:${GOGOPROTO_ROOT}/protobuf"
  30. rm -f "${ETCD_ROOT}"
  31. mkdir -p "${COREOS_ROOT}"
  32. ln -s "${PWD}" "${ETCD_ROOT}"
  33. # Ensure we have the right version of protoc-gen-gogo by building it every time.
  34. # TODO(jonboulle): vendor this instead of `go get`ting it.
  35. go get github.com/gogo/protobuf/{proto,protoc-gen-gogo,gogoproto}
  36. pushd "${GOGOPROTO_ROOT}"
  37. git reset --hard "${SHA}"
  38. make install
  39. popd
  40. for dir in ${DIRS}; do
  41. pushd ${dir}
  42. protoc --gogofast_out=plugins=grpc,import_prefix=github.com/coreos/:. -I=.:"${GOGOPROTO_PATH}":"${COREOS_ROOT}" *.proto
  43. sed -i.bak -E "s/github\.com\/coreos\/(gogoproto|github\.com|golang\.org|google\.golang\.org)/${ESCAPED_PREFIX}\/\1/g" *.pb.go
  44. sed -i.bak -E 's/github\.com\/coreos\/(errors|fmt|io)/\1/g' *.pb.go
  45. rm -f *.bak
  46. popd
  47. done