generate_descriptor_proto.sh 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. if test ! -e src/google/protobuf/stubs/common.h; then
  12. cat >&2 << __EOF__
  13. Could not find source code. Make sure you are running this script from the
  14. root of the distribution tree.
  15. __EOF__
  16. exit 1
  17. fi
  18. if test ! -e src/Makefile; then
  19. cat >&2 << __EOF__
  20. Could not find src/Makefile. You must run ./configure (and perhaps
  21. ./autogen.sh) first.
  22. __EOF__
  23. exit 1
  24. fi
  25. cd src
  26. declare -a RUNTIME_PROTO_FILES=(\
  27. google/protobuf/any.proto \
  28. google/protobuf/api.proto \
  29. google/protobuf/descriptor.proto \
  30. google/protobuf/duration.proto \
  31. google/protobuf/empty.proto \
  32. google/protobuf/field_mask.proto \
  33. google/protobuf/source_context.proto \
  34. google/protobuf/struct.proto \
  35. google/protobuf/timestamp.proto \
  36. google/protobuf/type.proto \
  37. google/protobuf/wrappers.proto)
  38. CORE_PROTO_IS_CORRECT=0
  39. PROCESS_ROUND=1
  40. echo "Updating descriptor protos..."
  41. while [ $CORE_PROTO_IS_CORRECT -ne 1 ]
  42. do
  43. echo "Round $PROCESS_ROUND"
  44. CORE_PROTO_IS_CORRECT=1
  45. for PROTO_FILE in ${RUNTIME_PROTO_FILES[@]}; do
  46. BASE_NAME=${PROTO_FILE%.*}
  47. cp ${BASE_NAME}.pb.h ${BASE_NAME}.pb.h.tmp
  48. cp ${BASE_NAME}.pb.cc ${BASE_NAME}.pb.cc.tmp
  49. done
  50. cp google/protobuf/compiler/plugin.pb.h google/protobuf/compiler/plugin.pb.h.tmp
  51. cp google/protobuf/compiler/plugin.pb.cc google/protobuf/compiler/plugin.pb.cc.tmp
  52. make $@ protoc &&
  53. ./protoc --cpp_out=dllexport_decl=LIBPROTOBUF_EXPORT:. ${RUNTIME_PROTO_FILES[@]} && \
  54. ./protoc --cpp_out=dllexport_decl=LIBPROTOC_EXPORT:. google/protobuf/compiler/plugin.proto
  55. for PROTO_FILE in ${RUNTIME_PROTO_FILES[@]}; do
  56. BASE_NAME=${PROTO_FILE%.*}
  57. diff ${BASE_NAME}.pb.h ${BASE_NAME}.pb.h.tmp > /dev/null
  58. if test $? -ne 0; then
  59. CORE_PROTO_IS_CORRECT=0
  60. fi
  61. diff ${BASE_NAME}.pb.cc ${BASE_NAME}.pb.cc.tmp > /dev/null
  62. if test $? -ne 0; then
  63. CORE_PROTO_IS_CORRECT=0
  64. fi
  65. done
  66. diff google/protobuf/compiler/plugin.pb.h google/protobuf/compiler/plugin.pb.h.tmp > /dev/null
  67. if test $? -ne 0; then
  68. CORE_PROTO_IS_CORRECT=0
  69. fi
  70. diff google/protobuf/compiler/plugin.pb.cc google/protobuf/compiler/plugin.pb.cc.tmp > /dev/null
  71. if test $? -ne 0; then
  72. CORE_PROTO_IS_CORRECT=0
  73. fi
  74. for PROTO_FILE in ${RUNTIME_PROTO_FILES[@]}; do
  75. BASE_NAME=${PROTO_FILE%.*}
  76. rm ${BASE_NAME}.pb.h.tmp
  77. rm ${BASE_NAME}.pb.cc.tmp
  78. done
  79. rm google/protobuf/compiler/plugin.pb.h.tmp
  80. rm google/protobuf/compiler/plugin.pb.cc.tmp
  81. PROCESS_ROUND=$((PROCESS_ROUND + 1))
  82. done
  83. cd ..