temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [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. |
kenton@google.com | 80b1d62 | 2009-07-29 01:13:20 +0000 | [diff] [blame] | 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. |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 12 | |
Jisi Liu | 5221dcb | 2016-01-29 13:51:05 -0800 | [diff] [blame] | 13 | set -e |
| 14 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 15 | if test ! -e src/google/protobuf/stubs/common.h; then |
| 16 | cat >&2 << __EOF__ |
| 17 | Could not find source code. Make sure you are running this script from the |
| 18 | root of the distribution tree. |
| 19 | __EOF__ |
| 20 | exit 1 |
| 21 | fi |
| 22 | |
| 23 | if test ! -e src/Makefile; then |
| 24 | cat >&2 << __EOF__ |
| 25 | Could not find src/Makefile. You must run ./configure (and perhaps |
| 26 | ./autogen.sh) first. |
| 27 | __EOF__ |
| 28 | exit 1 |
| 29 | fi |
| 30 | |
kenton@google.com | 2f669cb | 2008-12-02 05:59:15 +0000 | [diff] [blame] | 31 | cd src |
Feng Xiao | 33c9280 | 2015-05-11 13:47:41 -0700 | [diff] [blame] | 32 | |
| 33 | declare -a RUNTIME_PROTO_FILES=(\ |
| 34 | google/protobuf/any.proto \ |
| 35 | google/protobuf/api.proto \ |
| 36 | google/protobuf/descriptor.proto \ |
| 37 | google/protobuf/duration.proto \ |
| 38 | google/protobuf/empty.proto \ |
| 39 | google/protobuf/field_mask.proto \ |
| 40 | google/protobuf/source_context.proto \ |
| 41 | google/protobuf/struct.proto \ |
| 42 | google/protobuf/timestamp.proto \ |
| 43 | google/protobuf/type.proto \ |
| 44 | google/protobuf/wrappers.proto) |
| 45 | |
Jisi Liu | 885b612 | 2015-02-28 14:51:22 -0800 | [diff] [blame] | 46 | CORE_PROTO_IS_CORRECT=0 |
Bo Yang | 5db2173 | 2015-05-21 14:28:59 -0700 | [diff] [blame] | 47 | PROCESS_ROUND=1 |
Jisi Liu | 5221dcb | 2016-01-29 13:51:05 -0800 | [diff] [blame] | 48 | TMP=$(mktemp -d) |
Bo Yang | 5db2173 | 2015-05-21 14:28:59 -0700 | [diff] [blame] | 49 | echo "Updating descriptor protos..." |
Jisi Liu | 885b612 | 2015-02-28 14:51:22 -0800 | [diff] [blame] | 50 | while [ $CORE_PROTO_IS_CORRECT -ne 1 ] |
| 51 | do |
Bo Yang | 5db2173 | 2015-05-21 14:28:59 -0700 | [diff] [blame] | 52 | echo "Round $PROCESS_ROUND" |
Jisi Liu | 885b612 | 2015-02-28 14:51:22 -0800 | [diff] [blame] | 53 | CORE_PROTO_IS_CORRECT=1 |
Jisi Liu | 885b612 | 2015-02-28 14:51:22 -0800 | [diff] [blame] | 54 | |
Jisi Liu | 0b3cfc7 | 2015-03-02 10:54:10 -0800 | [diff] [blame] | 55 | make $@ protoc && |
Jisi Liu | 5221dcb | 2016-01-29 13:51:05 -0800 | [diff] [blame] | 56 | ./protoc --cpp_out=dllexport_decl=LIBPROTOBUF_EXPORT:$TMP ${RUNTIME_PROTO_FILES[@]} && \ |
| 57 | ./protoc --cpp_out=dllexport_decl=LIBPROTOC_EXPORT:$TMP google/protobuf/compiler/plugin.proto |
Jisi Liu | 885b612 | 2015-02-28 14:51:22 -0800 | [diff] [blame] | 58 | |
Feng Xiao | 33c9280 | 2015-05-11 13:47:41 -0700 | [diff] [blame] | 59 | for PROTO_FILE in ${RUNTIME_PROTO_FILES[@]}; do |
| 60 | BASE_NAME=${PROTO_FILE%.*} |
Jisi Liu | 5221dcb | 2016-01-29 13:51:05 -0800 | [diff] [blame] | 61 | diff ${BASE_NAME}.pb.h $TMP/${BASE_NAME}.pb.h > /dev/null |
Feng Xiao | 33c9280 | 2015-05-11 13:47:41 -0700 | [diff] [blame] | 62 | if test $? -ne 0; then |
| 63 | CORE_PROTO_IS_CORRECT=0 |
| 64 | fi |
Jisi Liu | 5221dcb | 2016-01-29 13:51:05 -0800 | [diff] [blame] | 65 | diff ${BASE_NAME}.pb.cc $TMP/${BASE_NAME}.pb.cc > /dev/null |
Feng Xiao | 33c9280 | 2015-05-11 13:47:41 -0700 | [diff] [blame] | 66 | if test $? -ne 0; then |
| 67 | CORE_PROTO_IS_CORRECT=0 |
| 68 | fi |
| 69 | done |
| 70 | |
Jisi Liu | 5221dcb | 2016-01-29 13:51:05 -0800 | [diff] [blame] | 71 | diff google/protobuf/compiler/plugin.pb.h $TMP/google/protobuf/compiler/plugin.pb.h > /dev/null |
Jisi Liu | 885b612 | 2015-02-28 14:51:22 -0800 | [diff] [blame] | 72 | if test $? -ne 0; then |
| 73 | CORE_PROTO_IS_CORRECT=0 |
| 74 | fi |
Jisi Liu | 5221dcb | 2016-01-29 13:51:05 -0800 | [diff] [blame] | 75 | diff google/protobuf/compiler/plugin.pb.cc $TMP/google/protobuf/compiler/plugin.pb.cc > /dev/null |
Jisi Liu | 885b612 | 2015-02-28 14:51:22 -0800 | [diff] [blame] | 76 | if test $? -ne 0; then |
| 77 | CORE_PROTO_IS_CORRECT=0 |
| 78 | fi |
| 79 | |
Jisi Liu | 5221dcb | 2016-01-29 13:51:05 -0800 | [diff] [blame] | 80 | # Only override the output if the files are different to avoid re-compilation |
| 81 | # of the protoc. |
| 82 | if [ $CORE_PROTO_IS_CORRECT -ne 1 ]; then |
| 83 | for PROTO_FILE in ${RUNTIME_PROTO_FILES[@]}; do |
| 84 | BASE_NAME=${PROTO_FILE%.*} |
| 85 | mv $TMP/${BASE_NAME}.pb.h ${BASE_NAME}.pb.h |
| 86 | mv $TMP/${BASE_NAME}.pb.cc ${BASE_NAME}.pb.cc |
| 87 | done |
| 88 | mv $TMP/google/protobuf/compiler/plugin.pb.* google/protobuf/compiler/ |
| 89 | fi |
Bo Yang | 5db2173 | 2015-05-21 14:28:59 -0700 | [diff] [blame] | 90 | |
| 91 | PROCESS_ROUND=$((PROCESS_ROUND + 1)) |
Jisi Liu | 885b612 | 2015-02-28 14:51:22 -0800 | [diff] [blame] | 92 | done |
kenton@google.com | 2f669cb | 2008-12-02 05:59:15 +0000 | [diff] [blame] | 93 | cd .. |
Jisi Liu | ef50a29 | 2015-09-08 13:21:45 -0700 | [diff] [blame] | 94 | |
| 95 | if test -x objectivec/generate_descriptors_proto.sh; then |
| 96 | echo "Generating messages for objc." |
| 97 | objectivec/generate_descriptors_proto.sh $@ |
| 98 | fi |
Jon Skeet | 957e877 | 2016-02-15 10:33:13 +0000 | [diff] [blame] | 99 | |
| 100 | if test -x csharp/generate_protos.sh; then |
| 101 | echo "Generating messages for C#." |
| 102 | csharp/generate_protos.sh $@ |
| 103 | fi |