blob: 44006b2c2db384324de14640362f4b534137c411 [file] [log] [blame]
Brian Silverman9c614bc2016-02-15 20:20:02 -05001#!/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.
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
13set -e
14
15if 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
31cd src
32
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
46CORE_PROTO_IS_CORRECT=0
47PROCESS_ROUND=1
48TMP=$(mktemp -d)
49echo "Updating descriptor protos..."
50while [ $CORE_PROTO_IS_CORRECT -ne 1 ]
51do
52 echo "Round $PROCESS_ROUND"
53 CORE_PROTO_IS_CORRECT=1
54
55 make $@ protoc &&
56 ./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
58
59 for PROTO_FILE in ${RUNTIME_PROTO_FILES[@]}; do
60 BASE_NAME=${PROTO_FILE%.*}
61 diff ${BASE_NAME}.pb.h $TMP/${BASE_NAME}.pb.h > /dev/null
62 if test $? -ne 0; then
63 CORE_PROTO_IS_CORRECT=0
64 fi
65 diff ${BASE_NAME}.pb.cc $TMP/${BASE_NAME}.pb.cc > /dev/null
66 if test $? -ne 0; then
67 CORE_PROTO_IS_CORRECT=0
68 fi
69 done
70
71 diff google/protobuf/compiler/plugin.pb.h $TMP/google/protobuf/compiler/plugin.pb.h > /dev/null
72 if test $? -ne 0; then
73 CORE_PROTO_IS_CORRECT=0
74 fi
75 diff google/protobuf/compiler/plugin.pb.cc $TMP/google/protobuf/compiler/plugin.pb.cc > /dev/null
76 if test $? -ne 0; then
77 CORE_PROTO_IS_CORRECT=0
78 fi
79
80 # 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
90
91 PROCESS_ROUND=$((PROCESS_ROUND + 1))
92done
93cd ..
94
95if test -x objectivec/generate_descriptors_proto.sh; then
96 echo "Generating messages for objc."
97 objectivec/generate_descriptors_proto.sh $@
98fi