genproto.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. # directories containing protos to be built
  17. DIRS="./wal/walpb ./etcdserver/etcdserverpb ./snap/snappb ./raft/raftpb ./storage/storagepb ./lease/leasepb ./auth/authpb"
  18. # exact version of protoc-gen-gogo to build
  19. SHA="c57e439bad574c2e0877ff18d514badcfced004d"
  20. # set up self-contained GOPATH for building
  21. export GOPATH=${PWD}/gopath
  22. export GOBIN=${PWD}/bin
  23. export PATH="${GOBIN}:${PATH}"
  24. COREOS_ROOT="${GOPATH}/src/github.com/coreos"
  25. ETCD_ROOT="${COREOS_ROOT}/etcd"
  26. GOGOPROTO_ROOT="${GOPATH}/src/github.com/gogo/protobuf"
  27. GOGOPROTO_PATH="${GOGOPROTO_ROOT}:${GOGOPROTO_ROOT}/protobuf"
  28. rm -f "${ETCD_ROOT}"
  29. mkdir -p "${COREOS_ROOT}"
  30. ln -s "${PWD}" "${ETCD_ROOT}"
  31. # Ensure we have the right version of protoc-gen-gogo by building it every time.
  32. # TODO(jonboulle): vendor this instead of `go get`ting it.
  33. go get github.com/gogo/protobuf/{proto,protoc-gen-gogo,gogoproto}
  34. go get golang.org/x/tools/cmd/goimports
  35. pushd "${GOGOPROTO_ROOT}"
  36. git reset --hard "${SHA}"
  37. make install
  38. popd
  39. for dir in ${DIRS}; do
  40. pushd ${dir}
  41. protoc --gogofast_out=plugins=grpc,import_prefix=github.com/coreos/:. -I=.:"${GOGOPROTO_PATH}":"${COREOS_ROOT}" *.proto
  42. sed -i.bak -E "s/github\.com\/coreos\/(gogoproto|github\.com|golang\.org|google\.golang\.org)/\1/g" *.pb.go
  43. sed -i.bak -E 's/github\.com\/coreos\/(errors|fmt|io)/\1/g' *.pb.go
  44. sed -i.bak -E 's/import _ \"gogoproto\"//g' *.pb.go
  45. sed -i.bak -E 's/import fmt \"fmt\"//g' *.pb.go
  46. rm -f *.bak
  47. goimports -w *.pb.go
  48. popd
  49. done