genproto.sh 1.6 KB

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