blob: c170c837e0ac3549dca5cfee4ce6864fb8a294d0 [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
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
21if test ! -e src/Makefile; then
22 cat >&2 << __EOF__
23Could not find src/Makefile. You must run ./configure (and perhaps
24./autogen.sh) first.
25__EOF__
26 exit 1
27fi
28
kenton@google.com2f669cb2008-12-02 05:59:15 +000029cd src
Feng Xiao33c92802015-05-11 13:47:41 -070030
31declare -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
Jisi Liu885b6122015-02-28 14:51:22 -080044CORE_PROTO_IS_CORRECT=0
Bo Yang5db21732015-05-21 14:28:59 -070045PROCESS_ROUND=1
Jisi Liu5221dcb2016-01-29 13:51:05 -080046TMP=$(mktemp -d)
Bo Yang5db21732015-05-21 14:28:59 -070047echo "Updating descriptor protos..."
Jisi Liu885b6122015-02-28 14:51:22 -080048while [ $CORE_PROTO_IS_CORRECT -ne 1 ]
49do
Bo Yang5db21732015-05-21 14:28:59 -070050 echo "Round $PROCESS_ROUND"
Jisi Liu885b6122015-02-28 14:51:22 -080051 CORE_PROTO_IS_CORRECT=1
Jisi Liu885b6122015-02-28 14:51:22 -080052
Jisi Liu3b3c8ab2016-03-30 11:39:59 -070053 make $@ protoc
54 if test $? -ne 0; then
55 echo "Failed to build protoc."
56 exit 1
57 fi
58
59 ./protoc --cpp_out=dllexport_decl=LIBPROTOBUF_EXPORT:$TMP ${RUNTIME_PROTO_FILES[@]} && \
60 ./protoc --cpp_out=dllexport_decl=LIBPROTOC_EXPORT:$TMP google/protobuf/compiler/plugin.proto
Jisi Liu885b6122015-02-28 14:51:22 -080061
Feng Xiao33c92802015-05-11 13:47:41 -070062 for PROTO_FILE in ${RUNTIME_PROTO_FILES[@]}; do
63 BASE_NAME=${PROTO_FILE%.*}
Jisi Liu5221dcb2016-01-29 13:51:05 -080064 diff ${BASE_NAME}.pb.h $TMP/${BASE_NAME}.pb.h > /dev/null
Feng Xiao33c92802015-05-11 13:47:41 -070065 if test $? -ne 0; then
66 CORE_PROTO_IS_CORRECT=0
67 fi
Jisi Liu5221dcb2016-01-29 13:51:05 -080068 diff ${BASE_NAME}.pb.cc $TMP/${BASE_NAME}.pb.cc > /dev/null
Feng Xiao33c92802015-05-11 13:47:41 -070069 if test $? -ne 0; then
70 CORE_PROTO_IS_CORRECT=0
71 fi
72 done
73
Jisi Liu5221dcb2016-01-29 13:51:05 -080074 diff google/protobuf/compiler/plugin.pb.h $TMP/google/protobuf/compiler/plugin.pb.h > /dev/null
Jisi Liu885b6122015-02-28 14:51:22 -080075 if test $? -ne 0; then
76 CORE_PROTO_IS_CORRECT=0
77 fi
Jisi Liu5221dcb2016-01-29 13:51:05 -080078 diff google/protobuf/compiler/plugin.pb.cc $TMP/google/protobuf/compiler/plugin.pb.cc > /dev/null
Jisi Liu885b6122015-02-28 14:51:22 -080079 if test $? -ne 0; then
80 CORE_PROTO_IS_CORRECT=0
81 fi
82
Jisi Liu5221dcb2016-01-29 13:51:05 -080083 # Only override the output if the files are different to avoid re-compilation
84 # of the protoc.
85 if [ $CORE_PROTO_IS_CORRECT -ne 1 ]; then
86 for PROTO_FILE in ${RUNTIME_PROTO_FILES[@]}; do
87 BASE_NAME=${PROTO_FILE%.*}
88 mv $TMP/${BASE_NAME}.pb.h ${BASE_NAME}.pb.h
89 mv $TMP/${BASE_NAME}.pb.cc ${BASE_NAME}.pb.cc
90 done
91 mv $TMP/google/protobuf/compiler/plugin.pb.* google/protobuf/compiler/
92 fi
Bo Yang5db21732015-05-21 14:28:59 -070093
94 PROCESS_ROUND=$((PROCESS_ROUND + 1))
Jisi Liu885b6122015-02-28 14:51:22 -080095done
kenton@google.com2f669cb2008-12-02 05:59:15 +000096cd ..
Jisi Liuef50a292015-09-08 13:21:45 -070097
Thomas Van Lenten79a23c42016-03-17 10:04:21 -040098if test -x objectivec/generate_well_known_types.sh; then
Jisi Liuef50a292015-09-08 13:21:45 -070099 echo "Generating messages for objc."
Thomas Van Lenten79a23c42016-03-17 10:04:21 -0400100 objectivec/generate_well_known_types.sh $@
Jisi Liuef50a292015-09-08 13:21:45 -0700101fi
Jon Skeet957e8772016-02-15 10:33:13 +0000102
103if test -x csharp/generate_protos.sh; then
104 echo "Generating messages for C#."
105 csharp/generate_protos.sh $@
106fi