regenerate.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/bash
  2. set -e
  3. # Install the working tree's protoc-gen-gen in a tempdir.
  4. tmpdir=$(mktemp -d -t regen-wkt.XXXXXX)
  5. trap 'rm -rf $tmpdir' EXIT
  6. mkdir -p $tmpdir/bin
  7. PATH=$tmpdir/bin:$PATH
  8. GOBIN=$tmpdir/bin go install ./protoc-gen-go
  9. # Public imports require at least Go 1.9.
  10. supportTypeAliases=""
  11. if go list -f '{{context.ReleaseTags}}' runtime | grep -q go1.9; then
  12. supportTypeAliases=1
  13. fi
  14. # Generate various test protos.
  15. PROTO_DIRS=(
  16. jsonpb/jsonpb_test_proto
  17. proto
  18. protoc-gen-go/testdata
  19. )
  20. for dir in ${PROTO_DIRS[@]}; do
  21. for p in `find $dir -name "*.proto"`; do
  22. if [[ $p == */import_public/* && ! $supportTypeAliases ]]; then
  23. echo "# $p (skipped)"
  24. continue;
  25. fi
  26. echo "# $p"
  27. protoc -I$dir --go_out=plugins=grpc,paths=source_relative:$dir $p
  28. done
  29. done
  30. # Deriving the location of the source protos from the path to the
  31. # protoc binary may be a bit odd, but this is what protoc itself does.
  32. PROTO_INCLUDE=$(dirname $(dirname $(which protoc)))/include
  33. # Well-known types.
  34. WKT_PROTOS=(any duration empty struct timestamp wrappers)
  35. for p in ${WKT_PROTOS[@]}; do
  36. echo "# google/protobuf/$p.proto"
  37. protoc --go_out=paths=source_relative:$tmpdir google/protobuf/$p.proto
  38. cp $tmpdir/google/protobuf/$p.pb.go ptypes/$p
  39. cp $PROTO_INCLUDE/google/protobuf/$p.proto ptypes/$p
  40. done
  41. # descriptor.proto.
  42. echo "# google/protobuf/descriptor.proto"
  43. protoc --go_out=paths=source_relative:$tmpdir google/protobuf/descriptor.proto
  44. cp $tmpdir/google/protobuf/descriptor.pb.go protoc-gen-go/descriptor
  45. cp $PROTO_INCLUDE/google/protobuf/descriptor.proto protoc-gen-go/descriptor