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