blob: 1690d0da55abf233f579d5cabbd3122e927ab2c7 [file] [log] [blame]
temporal40ee5512008-07-10 02:12:20 +00001#!/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.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
Jisi Liu5221dcb2016-01-29 13:51:05 -080013set -e
14
temporal40ee5512008-07-10 02:12:20 +000015if test ! -e src/google/protobuf/stubs/common.h; then
16 cat >&2 << __EOF__
17Could not find source code. Make sure you are running this script from the
18root of the distribution tree.
19__EOF__
20 exit 1
21fi
22
23if test ! -e src/Makefile; then
24 cat >&2 << __EOF__
25Could not find src/Makefile. You must run ./configure (and perhaps
26./autogen.sh) first.
27__EOF__
28 exit 1
29fi
30
kenton@google.com2f669cb2008-12-02 05:59:15 +000031cd src
Feng Xiao33c92802015-05-11 13:47:41 -070032
33declare -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 Liu885b6122015-02-28 14:51:22 -080046CORE_PROTO_IS_CORRECT=0
Bo Yang5db21732015-05-21 14:28:59 -070047PROCESS_ROUND=1
Jisi Liu5221dcb2016-01-29 13:51:05 -080048TMP=$(mktemp -d)
Bo Yang5db21732015-05-21 14:28:59 -070049echo "Updating descriptor protos..."
Jisi Liu885b6122015-02-28 14:51:22 -080050while [ $CORE_PROTO_IS_CORRECT -ne 1 ]
51do
Bo Yang5db21732015-05-21 14:28:59 -070052 echo "Round $PROCESS_ROUND"
Jisi Liu885b6122015-02-28 14:51:22 -080053 CORE_PROTO_IS_CORRECT=1
Jisi Liu885b6122015-02-28 14:51:22 -080054
Jisi Liu0b3cfc72015-03-02 10:54:10 -080055 make $@ protoc &&
Jisi Liu5221dcb2016-01-29 13:51:05 -080056 ./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 Liu885b6122015-02-28 14:51:22 -080058
Feng Xiao33c92802015-05-11 13:47:41 -070059 for PROTO_FILE in ${RUNTIME_PROTO_FILES[@]}; do
60 BASE_NAME=${PROTO_FILE%.*}
Jisi Liu5221dcb2016-01-29 13:51:05 -080061 diff ${BASE_NAME}.pb.h $TMP/${BASE_NAME}.pb.h > /dev/null
Feng Xiao33c92802015-05-11 13:47:41 -070062 if test $? -ne 0; then
63 CORE_PROTO_IS_CORRECT=0
64 fi
Jisi Liu5221dcb2016-01-29 13:51:05 -080065 diff ${BASE_NAME}.pb.cc $TMP/${BASE_NAME}.pb.cc > /dev/null
Feng Xiao33c92802015-05-11 13:47:41 -070066 if test $? -ne 0; then
67 CORE_PROTO_IS_CORRECT=0
68 fi
69 done
70
Jisi Liu5221dcb2016-01-29 13:51:05 -080071 diff google/protobuf/compiler/plugin.pb.h $TMP/google/protobuf/compiler/plugin.pb.h > /dev/null
Jisi Liu885b6122015-02-28 14:51:22 -080072 if test $? -ne 0; then
73 CORE_PROTO_IS_CORRECT=0
74 fi
Jisi Liu5221dcb2016-01-29 13:51:05 -080075 diff google/protobuf/compiler/plugin.pb.cc $TMP/google/protobuf/compiler/plugin.pb.cc > /dev/null
Jisi Liu885b6122015-02-28 14:51:22 -080076 if test $? -ne 0; then
77 CORE_PROTO_IS_CORRECT=0
78 fi
79
Jisi Liu5221dcb2016-01-29 13:51:05 -080080 # 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 Yang5db21732015-05-21 14:28:59 -070090
91 PROCESS_ROUND=$((PROCESS_ROUND + 1))
Jisi Liu885b6122015-02-28 14:51:22 -080092done
kenton@google.com2f669cb2008-12-02 05:59:15 +000093cd ..
Jisi Liuef50a292015-09-08 13:21:45 -070094
Thomas Van Lenten79a23c42016-03-17 10:04:21 -040095if test -x objectivec/generate_well_known_types.sh; then
Jisi Liuef50a292015-09-08 13:21:45 -070096 echo "Generating messages for objc."
Thomas Van Lenten79a23c42016-03-17 10:04:21 -040097 objectivec/generate_well_known_types.sh $@
Jisi Liuef50a292015-09-08 13:21:45 -070098fi
Jon Skeet957e8772016-02-15 10:33:13 +000099
100if test -x csharp/generate_protos.sh; then
101 echo "Generating messages for C#."
102 csharp/generate_protos.sh $@
103fi