generate_descriptor_proto.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/bin/sh
  2. # Run this script to regenerate descriptor.pb.{h,cc} after the protocol
  3. # compiler changes. Since these files are compiled into the protocol compiler
  4. # itself, they cannot be generated automatically by a make rule. "make check"
  5. # will fail if these files do not match what the protocol compiler would
  6. # generate.
  7. #
  8. # HINT: Flags passed to generate_descriptor_proto.sh will be passed directly
  9. # to make when building protoc. This is particularly useful for passing
  10. # -j4 to run 4 jobs simultaneously.
  11. set -e
  12. if test ! -e src/google/protobuf/stubs/common.h; then
  13. cat >&2 << __EOF__
  14. Could not find source code. Make sure you are running this script from the
  15. root of the distribution tree.
  16. __EOF__
  17. exit 1
  18. fi
  19. if test ! -e src/Makefile; then
  20. cat >&2 << __EOF__
  21. Could not find src/Makefile. You must run ./configure (and perhaps
  22. ./autogen.sh) first.
  23. __EOF__
  24. exit 1
  25. fi
  26. cd src
  27. declare -a RUNTIME_PROTO_FILES=(\
  28. google/protobuf/any.proto \
  29. google/protobuf/api.proto \
  30. google/protobuf/descriptor.proto \
  31. google/protobuf/duration.proto \
  32. google/protobuf/empty.proto \
  33. google/protobuf/field_mask.proto \
  34. google/protobuf/source_context.proto \
  35. google/protobuf/struct.proto \
  36. google/protobuf/timestamp.proto \
  37. google/protobuf/type.proto \
  38. google/protobuf/wrappers.proto)
  39. CORE_PROTO_IS_CORRECT=0
  40. PROCESS_ROUND=1
  41. TMP=$(mktemp -d)
  42. echo "Updating descriptor protos..."
  43. while [ $CORE_PROTO_IS_CORRECT -ne 1 ]
  44. do
  45. echo "Round $PROCESS_ROUND"
  46. CORE_PROTO_IS_CORRECT=1
  47. make $@ protoc &&
  48. ./protoc --cpp_out=dllexport_decl=LIBPROTOBUF_EXPORT:$TMP ${RUNTIME_PROTO_FILES[@]} && \
  49. ./protoc --cpp_out=dllexport_decl=LIBPROTOC_EXPORT:$TMP google/protobuf/compiler/plugin.proto
  50. for PROTO_FILE in ${RUNTIME_PROTO_FILES[@]}; do
  51. BASE_NAME=${PROTO_FILE%.*}
  52. diff ${BASE_NAME}.pb.h $TMP/${BASE_NAME}.pb.h > /dev/null
  53. if test $? -ne 0; then
  54. CORE_PROTO_IS_CORRECT=0
  55. fi
  56. diff ${BASE_NAME}.pb.cc $TMP/${BASE_NAME}.pb.cc > /dev/null
  57. if test $? -ne 0; then
  58. CORE_PROTO_IS_CORRECT=0
  59. fi
  60. done
  61. diff google/protobuf/compiler/plugin.pb.h $TMP/google/protobuf/compiler/plugin.pb.h > /dev/null
  62. if test $? -ne 0; then
  63. CORE_PROTO_IS_CORRECT=0
  64. fi
  65. diff google/protobuf/compiler/plugin.pb.cc $TMP/google/protobuf/compiler/plugin.pb.cc > /dev/null
  66. if test $? -ne 0; then
  67. CORE_PROTO_IS_CORRECT=0
  68. fi
  69. # Only override the output if the files are different to avoid re-compilation
  70. # of the protoc.
  71. if [ $CORE_PROTO_IS_CORRECT -ne 1 ]; then
  72. for PROTO_FILE in ${RUNTIME_PROTO_FILES[@]}; do
  73. BASE_NAME=${PROTO_FILE%.*}
  74. mv $TMP/${BASE_NAME}.pb.h ${BASE_NAME}.pb.h
  75. mv $TMP/${BASE_NAME}.pb.cc ${BASE_NAME}.pb.cc
  76. done
  77. mv $TMP/google/protobuf/compiler/plugin.pb.* google/protobuf/compiler/
  78. fi
  79. PROCESS_ROUND=$((PROCESS_ROUND + 1))
  80. done
  81. cd ..
  82. if test -x objectivec/generate_descriptors_proto.sh; then
  83. echo "Generating messages for objc."
  84. objectivec/generate_descriptors_proto.sh $@
  85. fi
  86. if test -x csharp/generate_protos.sh; then
  87. echo "Generating messages for C#."
  88. csharp/generate_protos.sh $@
  89. fi