blob: e533d05b431a8a9a3f8b44ce3a4863de69456b2a [file] [log] [blame]
Khingf9fc56c2016-09-07 14:46:50 +10001#!/usr/bin/env bash
temporal40ee5512008-07-10 02:12:20 +00002
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.com80b1d622009-07-29 01:13:20 +00008#
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.
temporal40ee5512008-07-10 02:12:20 +000012
temporal40ee5512008-07-10 02:12:20 +000013if test ! -e src/google/protobuf/stubs/common.h; then
14 cat >&2 << __EOF__
15Could not find source code. Make sure you are running this script from the
16root of the distribution tree.
17__EOF__
18 exit 1
19fi
20
kenton@google.com2f669cb2008-12-02 05:59:15 +000021cd src
Feng Xiao33c92802015-05-11 13:47:41 -070022
23declare -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 Xiaod36c0c52017-03-29 14:32:48 -070036declare -a COMPILER_PROTO_FILES=(\
Jisi Liu09354db2017-07-18 15:38:30 -070037 google/protobuf/compiler/plugin.proto)
Feng Xiaod36c0c52017-03-29 14:32:48 -070038
Jisi Liu885b6122015-02-28 14:51:22 -080039CORE_PROTO_IS_CORRECT=0
Bo Yang5db21732015-05-21 14:28:59 -070040PROCESS_ROUND=1
Jisi Liu09354db2017-07-18 15:38:30 -070041BOOTSTRAP_PROTOC=""
42while [ $# -gt 0 ]; do
43 case $1 in
44 --bootstrap_protoc)
45 BOOTSTRAP_PROTOC=$2
Josh Habermand61aede2018-09-04 10:58:54 -070046 shift 2
Jisi Liu09354db2017-07-18 15:38:30 -070047 ;;
48 *)
49 break
50 ;;
51 esac
52 shift
53done
Jisi Liu5221dcb2016-01-29 13:51:05 -080054TMP=$(mktemp -d)
Bo Yang5db21732015-05-21 14:28:59 -070055echo "Updating descriptor protos..."
Jisi Liu885b6122015-02-28 14:51:22 -080056while [ $CORE_PROTO_IS_CORRECT -ne 1 ]
57do
Bo Yang5db21732015-05-21 14:28:59 -070058 echo "Round $PROCESS_ROUND"
Jisi Liu885b6122015-02-28 14:51:22 -080059 CORE_PROTO_IS_CORRECT=1
Jisi Liu885b6122015-02-28 14:51:22 -080060
Jisi Liu09354db2017-07-18 15:38:30 -070061 if [ "$BOOTSTRAP_PROTOC" != "" ]; then
62 PROTOC=$BOOTSTRAP_PROTOC
63 BOOTSTRAP_PROTOC=""
64 else
65 make $@ protoc
66 if test $? -ne 0; then
67 echo "Failed to build protoc."
68 exit 1
69 fi
70 PROTOC="./protoc"
Jisi Liu3b3c8ab2016-03-30 11:39:59 -070071 fi
72
Josh Habermand61aede2018-09-04 10:58:54 -070073 $PROTOC --cpp_out=dllexport_decl=PROTOBUF_EXPORT:$TMP ${RUNTIME_PROTO_FILES[@]} && \
74 $PROTOC --cpp_out=dllexport_decl=PROTOC_EXPORT:$TMP ${COMPILER_PROTO_FILES[@]}
Jisi Liu885b6122015-02-28 14:51:22 -080075
Feng Xiaod36c0c52017-03-29 14:32:48 -070076 for PROTO_FILE in ${RUNTIME_PROTO_FILES[@]} ${COMPILER_PROTO_FILES[@]}; do
Feng Xiao33c92802015-05-11 13:47:41 -070077 BASE_NAME=${PROTO_FILE%.*}
Jisi Liu5221dcb2016-01-29 13:51:05 -080078 diff ${BASE_NAME}.pb.h $TMP/${BASE_NAME}.pb.h > /dev/null
Feng Xiao33c92802015-05-11 13:47:41 -070079 if test $? -ne 0; then
80 CORE_PROTO_IS_CORRECT=0
81 fi
Jisi Liu5221dcb2016-01-29 13:51:05 -080082 diff ${BASE_NAME}.pb.cc $TMP/${BASE_NAME}.pb.cc > /dev/null
Feng Xiao33c92802015-05-11 13:47:41 -070083 if test $? -ne 0; then
84 CORE_PROTO_IS_CORRECT=0
85 fi
86 done
87
Jisi Liu5221dcb2016-01-29 13:51:05 -080088 # 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 Xiaod36c0c52017-03-29 14:32:48 -070091 for PROTO_FILE in ${RUNTIME_PROTO_FILES[@]} ${COMPILER_PROTO_FILES[@]}; do
Jisi Liu5221dcb2016-01-29 13:51:05 -080092 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 Liu5221dcb2016-01-29 13:51:05 -080096 fi
Bo Yang5db21732015-05-21 14:28:59 -070097
98 PROCESS_ROUND=$((PROCESS_ROUND + 1))
Jisi Liu885b6122015-02-28 14:51:22 -080099done
kenton@google.com2f669cb2008-12-02 05:59:15 +0000100cd ..
Jisi Liuef50a292015-09-08 13:21:45 -0700101
Thomas Van Lenten79a23c42016-03-17 10:04:21 -0400102if test -x objectivec/generate_well_known_types.sh; then
Jisi Liuef50a292015-09-08 13:21:45 -0700103 echo "Generating messages for objc."
Thomas Van Lenten79a23c42016-03-17 10:04:21 -0400104 objectivec/generate_well_known_types.sh $@
Jisi Liuef50a292015-09-08 13:21:45 -0700105fi
Jon Skeet957e8772016-02-15 10:33:13 +0000106
107if test -x csharp/generate_protos.sh; then
108 echo "Generating messages for C#."
109 csharp/generate_protos.sh $@
110fi
Paul Yang6b27c1f2017-03-17 11:08:06 -0700111
112if test -x php/generate_descriptor_protos.sh; then
113 echo "Generating messages for PHP."
114 php/generate_descriptor_protos.sh $@
115fi