generate_protos.sh 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/bash
  2. # Generates C# source files from .proto files.
  3. # You first need to make sure protoc has been built (see instructions on
  4. # building protoc in root of this repository)
  5. # This script performs a few fix-ups as part of generation. These are:
  6. # - descriptor.proto is renamed to descriptor_proto_file.proto before
  7. # generation, to avoid the naming collision between the class for the file
  8. # descriptor and its Descriptor property
  9. # - This change also impacts UnittestCustomOptions, which expects to
  10. # use a class of Descriptor when it's actually been renamed to
  11. # DescriptorProtoFile.
  12. # - Issue 307 (codegen for double-nested types) breaks Unittest.proto and
  13. # its lite equivalents.
  14. set -ex
  15. # cd to repository root
  16. cd $(dirname $0)/..
  17. # Protocol buffer compiler to use. If the PROTOC variable is set,
  18. # use that. Otherwise, probe for expected locations under both
  19. # Windows and Unix.
  20. if [ -z "$PROTOC" ]; then
  21. # TODO(jonskeet): Use an array and a for loop instead?
  22. if [ -x cmake/build/Debug/protoc.exe ]; then
  23. PROTOC=cmake/build/Debug/protoc.exe
  24. elif [ -x cmake/build/Release/protoc.exe ]; then
  25. PROTOC=cmake/build/Release/protoc.exe
  26. elif [ -x src/protoc ]; then
  27. PROTOC=src/protoc
  28. else
  29. echo "Unable to find protocol buffer compiler."
  30. exit 1
  31. fi
  32. fi
  33. # Descriptor proto
  34. # TODO(jonskeet): Remove fixup
  35. cp src/google/protobuf/descriptor.proto src/google/protobuf/descriptor_proto_file.proto
  36. $PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf/Reflection \
  37. src/google/protobuf/descriptor_proto_file.proto
  38. rm src/google/protobuf/descriptor_proto_file.proto
  39. $PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf/WellKnownTypes \
  40. src/google/protobuf/any.proto \
  41. src/google/protobuf/api.proto \
  42. src/google/protobuf/duration.proto \
  43. src/google/protobuf/empty.proto \
  44. src/google/protobuf/field_mask.proto \
  45. src/google/protobuf/source_context.proto \
  46. src/google/protobuf/struct.proto \
  47. src/google/protobuf/timestamp.proto \
  48. src/google/protobuf/type.proto \
  49. src/google/protobuf/wrappers.proto
  50. $PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf.Test/TestProtos \
  51. src/google/protobuf/map_unittest_proto3.proto \
  52. src/google/protobuf/unittest_proto3.proto \
  53. src/google/protobuf/unittest_import_proto3.proto \
  54. src/google/protobuf/unittest_import_public_proto3.proto \
  55. src/google/protobuf/unittest_well_known_types.proto
  56. $PROTOC -Icsharp/protos --csharp_out=csharp/src/Google.Protobuf.Test/TestProtos \
  57. csharp/protos/unittest_issues.proto
  58. # AddressBook sample protos
  59. $PROTOC -Iexamples --csharp_out=csharp/src/AddressBook \
  60. examples/addressbook.proto
  61. $PROTOC -Iconformance --csharp_out=csharp/src/Google.Protobuf.Conformance \
  62. conformance/conformance.proto