genproto.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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="64f27bf06efee53589314a6e5a4af34cdd85adf6"
  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
  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. for dir in ${DIRS}; do
  32. pushd ${dir}
  33. protoc --gogofast_out=plugins=grpc:. -I=.:${GOPATH}/src/github.com/gogo/protobuf/protobuf:${GOPATH}/src *.proto
  34. sed -i".bak" -e "s|github.com/gogo/protobuf/proto|${PREFIX}/github.com/gogo/protobuf/proto|" *.go
  35. rm -f *.bak
  36. popd
  37. done