generate_protos.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 vsprojects/Debug/protoc.exe ]; then
  23. PROTOC=vsprojects/Debug/protoc.exe
  24. elif [ -x vsprojects/Release/protoc.exe ]; then
  25. PROTOC=vsprojects/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/ProtocolBuffers/DescriptorProtos \
  37. src/google/protobuf/descriptor_proto_file.proto
  38. rm src/google/protobuf/descriptor_proto_file.proto
  39. # ProtocolBuffers.Test protos
  40. $PROTOC -Isrc --csharp_out=csharp/src/ProtocolBuffers.Test/TestProtos \
  41. src/google/protobuf/unittest.proto \
  42. src/google/protobuf/unittest_custom_options.proto \
  43. src/google/protobuf/unittest_drop_unknown_fields.proto \
  44. src/google/protobuf/unittest_enormous_descriptor.proto \
  45. src/google/protobuf/unittest_import.proto \
  46. src/google/protobuf/unittest_import_public.proto \
  47. src/google/protobuf/unittest_mset.proto \
  48. src/google/protobuf/unittest_optimize_for.proto \
  49. src/google/protobuf/unittest_no_field_presence.proto \
  50. src/google/protobuf/unknown_enum_test.proto
  51. $PROTOC -Icsharp/protos/extest --csharp_out=csharp/src/ProtocolBuffers.Test/TestProtos \
  52. csharp/protos/extest/unittest_extras_xmltest.proto \
  53. csharp/protos/extest/unittest_issues.proto
  54. $PROTOC -Ibenchmarks --csharp_out=csharp/src/ProtocolBuffers.Test/TestProtos \
  55. benchmarks/google_size.proto \
  56. benchmarks/google_speed.proto
  57. # ProtocolBuffersLite.Test protos
  58. $PROTOC -Isrc --csharp_out=csharp/src/ProtocolBuffersLite.Test/TestProtos \
  59. src/google/protobuf/unittest.proto \
  60. src/google/protobuf/unittest_import.proto \
  61. src/google/protobuf/unittest_import_lite.proto \
  62. src/google/protobuf/unittest_import_public.proto \
  63. src/google/protobuf/unittest_import_public_lite.proto \
  64. src/google/protobuf/unittest_lite.proto \
  65. src/google/protobuf/unittest_lite_imports_nonlite.proto
  66. $PROTOC -Icsharp/protos/extest --csharp_out=csharp/src/ProtocolBuffersLite.Test/TestProtos \
  67. csharp/protos/extest/unittest_extras_full.proto \
  68. csharp/protos/extest/unittest_extras_lite.proto
  69. # TODO(jonskeet): Remove fixup; see issue #307
  70. sed -i -e 's/RepeatedFieldsGenerator\.Group/RepeatedFieldsGenerator.Types.Group/g' \
  71. csharp/src/ProtocolBuffers.Test/TestProtos/Unittest.cs \
  72. csharp/src/ProtocolBuffersLite.Test/TestProtos/Unittest.cs \
  73. csharp/src/ProtocolBuffersLite.Test/TestProtos/UnittestLite.cs
  74. # TODO(jonskeet): Remove fixup
  75. sed -i -e 's/DescriptorProtos\.Descriptor\./DescriptorProtos.DescriptorProtoFile./g' \
  76. csharp/src/ProtocolBuffers.Test/TestProtos/UnittestCustomOptions.cs
  77. # AddressBook sample protos
  78. $PROTOC -Iexamples --csharp_out=csharp/src/AddressBook \
  79. examples/addressbook.proto