regenerate.bash 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/bash
  2. # Copyright 2018 The Go Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style
  4. # license that can be found in the LICENSE file.
  5. set -e
  6. go generate internal/cmd/generate-types/main.go
  7. # Install the working tree's protoc-gen-gen in a tempdir.
  8. tmpdir=$(mktemp -d -t protobuf-regen.XXXXXX)
  9. trap 'rm -rf $tmpdir' EXIT
  10. mkdir -p $tmpdir/bin
  11. PATH=$tmpdir/bin:$PATH
  12. GOBIN=$tmpdir/bin go install ./cmd/protoc-gen-go
  13. GOBIN=$tmpdir/bin go install ./cmd/protoc-gen-go-grpc
  14. # Generate various test protos.
  15. PROTO_DIRS=(
  16. cmd/protoc-gen-go/testdata
  17. cmd/protoc-gen-go-grpc/testdata
  18. internal/testprotos/test
  19. )
  20. for dir in ${PROTO_DIRS[@]}; do
  21. for p in `find $dir -name "*.proto"`; do
  22. echo "# $p"
  23. PROTOC_GEN_GO_ENABLE_REFLECT=1 protoc -I$dir \
  24. --go_out=paths=source_relative:$dir \
  25. --go-grpc_out=paths=source_relative:$dir \
  26. $p
  27. done
  28. done
  29. # Generate descriptor and plugin.
  30. # TODO: Make this more automated.
  31. echo "# types/descriptor/descriptor.proto"
  32. mkdir -p $tmpdir/src/google/protobuf
  33. cp ./types/descriptor/descriptor.proto $tmpdir/src/google/protobuf/descriptor.proto
  34. PROTOC_GEN_GO_ENABLE_REFLECT=1 protoc -I$tmpdir/src \
  35. --go_out=paths=source_relative:$tmpdir/src \
  36. $tmpdir/src/google/protobuf/descriptor.proto
  37. cp $tmpdir/src/google/protobuf/descriptor.pb.go ./types/descriptor/descriptor.pb.go
  38. echo "# types/plugin/plugin.proto"
  39. mkdir -p $tmpdir/src/google/protobuf/compiler
  40. cp ./types/plugin/plugin.proto $tmpdir/src/google/protobuf/compiler/plugin.proto
  41. PROTOC_GEN_GO_ENABLE_REFLECT=1 protoc -I$tmpdir/src \
  42. --go_out=paths=source_relative:$tmpdir/src \
  43. $tmpdir/src/google/protobuf/compiler/plugin.proto
  44. cp $tmpdir/src/google/protobuf/compiler/plugin.pb.go ./types/plugin/plugin.pb.go
  45. echo "# encoding/textpb/testprotos/pb?/test.proto"
  46. PROTOC_GEN_GO_ENABLE_REFLECT=1 protoc --go_out=paths=source_relative:. \
  47. encoding/textpb/testprotos/pb?/test.proto
  48. echo "# reflect/protoregistry/testprotos/test.proto"
  49. PROTOC_GEN_GO_ENABLE_REFLECT=1 protoc --go_out=paths=source_relative:. \
  50. reflect/protoregistry/testprotos/test.proto