Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame^] | 1 | #!/usr/bin/env bash |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 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 | |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 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 | |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame^] | 44 | declare -a COMPILER_PROTO_FILES=(\ |
| 45 | google/protobuf/compiler/plugin.proto) |
| 46 | |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 47 | CORE_PROTO_IS_CORRECT=0 |
| 48 | PROCESS_ROUND=1 |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame^] | 49 | BOOTSTRAP_PROTOC="" |
| 50 | while [ $# -gt 0 ]; do |
| 51 | case $1 in |
| 52 | --bootstrap_protoc) |
| 53 | BOOTSTRAP_PROTOC=$2 |
| 54 | shift |
| 55 | ;; |
| 56 | *) |
| 57 | break |
| 58 | ;; |
| 59 | esac |
| 60 | shift |
| 61 | done |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 62 | TMP=$(mktemp -d) |
| 63 | echo "Updating descriptor protos..." |
| 64 | while [ $CORE_PROTO_IS_CORRECT -ne 1 ] |
| 65 | do |
| 66 | echo "Round $PROCESS_ROUND" |
| 67 | CORE_PROTO_IS_CORRECT=1 |
| 68 | |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame^] | 69 | if [ "$BOOTSTRAP_PROTOC" != "" ]; then |
| 70 | PROTOC=$BOOTSTRAP_PROTOC |
| 71 | BOOTSTRAP_PROTOC="" |
| 72 | else |
| 73 | make $@ protoc |
| 74 | if test $? -ne 0; then |
| 75 | echo "Failed to build protoc." |
| 76 | exit 1 |
| 77 | fi |
| 78 | PROTOC="./protoc" |
| 79 | fi |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 80 | |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame^] | 81 | $PROTOC --cpp_out=dllexport_decl=LIBPROTOBUF_EXPORT:$TMP ${RUNTIME_PROTO_FILES[@]} && \ |
| 82 | $PROTOC --cpp_out=dllexport_decl=LIBPROTOC_EXPORT:$TMP ${COMPILER_PROTO_FILES[@]} |
| 83 | |
| 84 | for PROTO_FILE in ${RUNTIME_PROTO_FILES[@]} ${COMPILER_PROTO_FILES[@]}; do |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 85 | BASE_NAME=${PROTO_FILE%.*} |
| 86 | diff ${BASE_NAME}.pb.h $TMP/${BASE_NAME}.pb.h > /dev/null |
| 87 | if test $? -ne 0; then |
| 88 | CORE_PROTO_IS_CORRECT=0 |
| 89 | fi |
| 90 | diff ${BASE_NAME}.pb.cc $TMP/${BASE_NAME}.pb.cc > /dev/null |
| 91 | if test $? -ne 0; then |
| 92 | CORE_PROTO_IS_CORRECT=0 |
| 93 | fi |
| 94 | done |
| 95 | |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 96 | # Only override the output if the files are different to avoid re-compilation |
| 97 | # of the protoc. |
| 98 | if [ $CORE_PROTO_IS_CORRECT -ne 1 ]; then |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame^] | 99 | for PROTO_FILE in ${RUNTIME_PROTO_FILES[@]} ${COMPILER_PROTO_FILES[@]}; do |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 100 | BASE_NAME=${PROTO_FILE%.*} |
| 101 | mv $TMP/${BASE_NAME}.pb.h ${BASE_NAME}.pb.h |
| 102 | mv $TMP/${BASE_NAME}.pb.cc ${BASE_NAME}.pb.cc |
| 103 | done |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 104 | fi |
| 105 | |
| 106 | PROCESS_ROUND=$((PROCESS_ROUND + 1)) |
| 107 | done |
| 108 | cd .. |
| 109 | |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame^] | 110 | if test -x objectivec/generate_well_known_types.sh; then |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 111 | echo "Generating messages for objc." |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame^] | 112 | objectivec/generate_well_known_types.sh $@ |
| 113 | fi |
| 114 | |
| 115 | if test -x csharp/generate_protos.sh; then |
| 116 | echo "Generating messages for C#." |
| 117 | csharp/generate_protos.sh $@ |
| 118 | fi |
| 119 | |
| 120 | if test -x php/generate_descriptor_protos.sh; then |
| 121 | echo "Generating messages for PHP." |
| 122 | php/generate_descriptor_protos.sh $@ |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 123 | fi |