regenerate.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. conformance/internal/conformance_proto
  17. jsonpb/jsonpb_test_proto
  18. proto
  19. protoc-gen-go/testdata
  20. )
  21. for dir in ${PROTO_DIRS[@]}; do
  22. for p in `find $dir -name "*.proto"`; do
  23. if [[ $p == */import_public/* && ! $supportTypeAliases ]]; then
  24. echo "# $p (skipped)"
  25. continue;
  26. fi
  27. echo "# $p"
  28. protoc -I$dir --go_out=plugins=grpc,paths=source_relative:$dir $p
  29. done
  30. done
  31. # Deriving the location of the source protos from the path to the
  32. # protoc binary may be a bit odd, but this is what protoc itself does.
  33. PROTO_INCLUDE=$(dirname $(dirname $(which protoc)))/include
  34. # Well-known types.
  35. WKT_PROTOS=(any duration empty struct timestamp wrappers)
  36. for p in ${WKT_PROTOS[@]}; do
  37. echo "# google/protobuf/$p.proto"
  38. protoc --go_out=paths=source_relative:$tmpdir google/protobuf/$p.proto
  39. cp $tmpdir/google/protobuf/$p.pb.go ptypes/$p
  40. cp $PROTO_INCLUDE/google/protobuf/$p.proto ptypes/$p
  41. done
  42. # descriptor.proto.
  43. echo "# google/protobuf/descriptor.proto"
  44. protoc --go_out=paths=source_relative:$tmpdir google/protobuf/descriptor.proto
  45. cp $tmpdir/google/protobuf/descriptor.pb.go protoc-gen-go/descriptor
  46. cp $PROTO_INCLUDE/google/protobuf/descriptor.proto protoc-gen-go/descriptor