Khing | f9fc56c | 2016-09-07 14:46:50 +1000 | [diff] [blame] | 1 | #!/usr/bin/env bash |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [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. |
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 |
Mike Kruskal | ed5c57a | 2022-08-10 22:51:29 -0700 | [diff] [blame] | 10 | # to bazel when building protoc. This is particularly useful for passing |
kenton@google.com | 80b1d62 | 2009-07-29 01:13:20 +0000 | [diff] [blame] | 11 | # -j4 to run 4 jobs simultaneously. |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 12 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [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 | |
kenton@google.com | 2f669cb | 2008-12-02 05:59:15 +0000 | [diff] [blame] | 21 | cd src |
Feng Xiao | 33c9280 | 2015-05-11 13:47:41 -0700 | [diff] [blame] | 22 | |
| 23 | declare -a RUNTIME_PROTO_FILES=(\ |
| 24 | google/protobuf/any.proto \ |
| 25 | google/protobuf/api.proto \ |
| 26 | google/protobuf/descriptor.proto \ |
| 27 | google/protobuf/duration.proto \ |
| 28 | google/protobuf/empty.proto \ |
| 29 | google/protobuf/field_mask.proto \ |
| 30 | google/protobuf/source_context.proto \ |
| 31 | google/protobuf/struct.proto \ |
| 32 | google/protobuf/timestamp.proto \ |
| 33 | google/protobuf/type.proto \ |
| 34 | google/protobuf/wrappers.proto) |
| 35 | |
Feng Xiao | d36c0c5 | 2017-03-29 14:32:48 -0700 | [diff] [blame] | 36 | declare -a COMPILER_PROTO_FILES=(\ |
Jisi Liu | 09354db | 2017-07-18 15:38:30 -0700 | [diff] [blame] | 37 | google/protobuf/compiler/plugin.proto) |
Feng Xiao | d36c0c5 | 2017-03-29 14:32:48 -0700 | [diff] [blame] | 38 | |
Jisi Liu | 885b612 | 2015-02-28 14:51:22 -0800 | [diff] [blame] | 39 | CORE_PROTO_IS_CORRECT=0 |
Bo Yang | 5db2173 | 2015-05-21 14:28:59 -0700 | [diff] [blame] | 40 | PROCESS_ROUND=1 |
Jisi Liu | 09354db | 2017-07-18 15:38:30 -0700 | [diff] [blame] | 41 | BOOTSTRAP_PROTOC="" |
| 42 | while [ $# -gt 0 ]; do |
| 43 | case $1 in |
| 44 | --bootstrap_protoc) |
| 45 | BOOTSTRAP_PROTOC=$2 |
Josh Haberman | d61aede | 2018-09-04 10:58:54 -0700 | [diff] [blame] | 46 | shift 2 |
Jisi Liu | 09354db | 2017-07-18 15:38:30 -0700 | [diff] [blame] | 47 | ;; |
| 48 | *) |
| 49 | break |
| 50 | ;; |
| 51 | esac |
| 52 | shift |
| 53 | done |
Jisi Liu | 5221dcb | 2016-01-29 13:51:05 -0800 | [diff] [blame] | 54 | TMP=$(mktemp -d) |
Bo Yang | 5db2173 | 2015-05-21 14:28:59 -0700 | [diff] [blame] | 55 | echo "Updating descriptor protos..." |
Jisi Liu | 885b612 | 2015-02-28 14:51:22 -0800 | [diff] [blame] | 56 | while [ $CORE_PROTO_IS_CORRECT -ne 1 ] |
| 57 | do |
Bo Yang | 5db2173 | 2015-05-21 14:28:59 -0700 | [diff] [blame] | 58 | echo "Round $PROCESS_ROUND" |
Jisi Liu | 885b612 | 2015-02-28 14:51:22 -0800 | [diff] [blame] | 59 | CORE_PROTO_IS_CORRECT=1 |
Jisi Liu | 885b612 | 2015-02-28 14:51:22 -0800 | [diff] [blame] | 60 | |
Jisi Liu | 09354db | 2017-07-18 15:38:30 -0700 | [diff] [blame] | 61 | if [ "$BOOTSTRAP_PROTOC" != "" ]; then |
| 62 | PROTOC=$BOOTSTRAP_PROTOC |
| 63 | BOOTSTRAP_PROTOC="" |
| 64 | else |
Mike Kruskal | f0ef44d | 2023-02-02 15:53:04 -0800 | [diff] [blame] | 65 | ${BAZEL:-bazel} ${BAZEL_STARTUP_FLAGS:-} build $@ //:protoc ${BAZEL_FLAGS:-} |
Jisi Liu | 09354db | 2017-07-18 15:38:30 -0700 | [diff] [blame] | 66 | if test $? -ne 0; then |
| 67 | echo "Failed to build protoc." |
| 68 | exit 1 |
| 69 | fi |
Mike Kruskal | ed5c57a | 2022-08-10 22:51:29 -0700 | [diff] [blame] | 70 | PROTOC="../bazel-bin/protoc" |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 71 | fi |
| 72 | |
Josh Haberman | d61aede | 2018-09-04 10:58:54 -0700 | [diff] [blame] | 73 | $PROTOC --cpp_out=dllexport_decl=PROTOBUF_EXPORT:$TMP ${RUNTIME_PROTO_FILES[@]} && \ |
| 74 | $PROTOC --cpp_out=dllexport_decl=PROTOC_EXPORT:$TMP ${COMPILER_PROTO_FILES[@]} |
Jisi Liu | 885b612 | 2015-02-28 14:51:22 -0800 | [diff] [blame] | 75 | |
Feng Xiao | d36c0c5 | 2017-03-29 14:32:48 -0700 | [diff] [blame] | 76 | for PROTO_FILE in ${RUNTIME_PROTO_FILES[@]} ${COMPILER_PROTO_FILES[@]}; do |
Feng Xiao | 33c9280 | 2015-05-11 13:47:41 -0700 | [diff] [blame] | 77 | BASE_NAME=${PROTO_FILE%.*} |
Jisi Liu | 5221dcb | 2016-01-29 13:51:05 -0800 | [diff] [blame] | 78 | diff ${BASE_NAME}.pb.h $TMP/${BASE_NAME}.pb.h > /dev/null |
Feng Xiao | 33c9280 | 2015-05-11 13:47:41 -0700 | [diff] [blame] | 79 | if test $? -ne 0; then |
| 80 | CORE_PROTO_IS_CORRECT=0 |
| 81 | fi |
Jisi Liu | 5221dcb | 2016-01-29 13:51:05 -0800 | [diff] [blame] | 82 | diff ${BASE_NAME}.pb.cc $TMP/${BASE_NAME}.pb.cc > /dev/null |
Feng Xiao | 33c9280 | 2015-05-11 13:47:41 -0700 | [diff] [blame] | 83 | if test $? -ne 0; then |
| 84 | CORE_PROTO_IS_CORRECT=0 |
| 85 | fi |
| 86 | done |
| 87 | |
Jisi Liu | 5221dcb | 2016-01-29 13:51:05 -0800 | [diff] [blame] | 88 | # Only override the output if the files are different to avoid re-compilation |
| 89 | # of the protoc. |
| 90 | if [ $CORE_PROTO_IS_CORRECT -ne 1 ]; then |
Feng Xiao | d36c0c5 | 2017-03-29 14:32:48 -0700 | [diff] [blame] | 91 | for PROTO_FILE in ${RUNTIME_PROTO_FILES[@]} ${COMPILER_PROTO_FILES[@]}; do |
Jisi Liu | 5221dcb | 2016-01-29 13:51:05 -0800 | [diff] [blame] | 92 | BASE_NAME=${PROTO_FILE%.*} |
| 93 | mv $TMP/${BASE_NAME}.pb.h ${BASE_NAME}.pb.h |
| 94 | mv $TMP/${BASE_NAME}.pb.cc ${BASE_NAME}.pb.cc |
| 95 | done |
Jisi Liu | 5221dcb | 2016-01-29 13:51:05 -0800 | [diff] [blame] | 96 | fi |
Bo Yang | 5db2173 | 2015-05-21 14:28:59 -0700 | [diff] [blame] | 97 | |
| 98 | PROCESS_ROUND=$((PROCESS_ROUND + 1)) |
Jisi Liu | 885b612 | 2015-02-28 14:51:22 -0800 | [diff] [blame] | 99 | done |
kenton@google.com | 2f669cb | 2008-12-02 05:59:15 +0000 | [diff] [blame] | 100 | cd .. |
Jisi Liu | ef50a29 | 2015-09-08 13:21:45 -0700 | [diff] [blame] | 101 | |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 102 | if test -x objectivec/generate_well_known_types.sh; then |
Jisi Liu | ef50a29 | 2015-09-08 13:21:45 -0700 | [diff] [blame] | 103 | echo "Generating messages for objc." |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 104 | objectivec/generate_well_known_types.sh $@ |
Jisi Liu | ef50a29 | 2015-09-08 13:21:45 -0700 | [diff] [blame] | 105 | fi |
Jon Skeet | 957e877 | 2016-02-15 10:33:13 +0000 | [diff] [blame] | 106 | |
| 107 | if test -x csharp/generate_protos.sh; then |
| 108 | echo "Generating messages for C#." |
| 109 | csharp/generate_protos.sh $@ |
| 110 | fi |
Paul Yang | 6b27c1f | 2017-03-17 11:08:06 -0700 | [diff] [blame] | 111 | |
| 112 | if test -x php/generate_descriptor_protos.sh; then |
| 113 | echo "Generating messages for PHP." |
| 114 | php/generate_descriptor_protos.sh $@ |
| 115 | fi |