genproto.sh 1.2 KB

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