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
9 # HINT: Flags passed to generate_descriptor_proto.sh will be passed directly
10 # to bazel when building protoc. This is particularly useful for passing
11 # -j4 to run 4 jobs simultaneously.
13 if test ! -e src
/google
/protobuf
/stubs
/common.h
; then
15 Could not find source code. Make sure you are running this script from the
16 root of the distribution tree.
23 declare -a RUNTIME_PROTO_FILES
=(\
24 google
/protobuf
/any.proto \
25 google
/protobuf
/api.proto \
26 google
/protobuf
/cpp_features.proto \
27 google
/protobuf
/descriptor.proto \
28 google
/protobuf
/duration.proto \
29 google
/protobuf
/empty.proto \
30 google
/protobuf
/field_mask.proto \
31 google
/protobuf
/source_context.proto \
32 google
/protobuf
/struct.proto \
33 google
/protobuf
/timestamp.proto \
34 google
/protobuf
/type.proto \
35 google
/protobuf
/wrappers.proto
)
37 declare -a COMPILER_PROTO_FILES
=(\
38 google
/protobuf
/compiler
/plugin.proto
)
40 CORE_PROTO_IS_CORRECT
=0
43 while [ $# -gt 0 ]; do
56 echo "Updating descriptor protos..."
57 while [ $CORE_PROTO_IS_CORRECT -ne 1 ]
59 echo "Round $PROCESS_ROUND"
60 CORE_PROTO_IS_CORRECT
=1
62 if [ "$BOOTSTRAP_PROTOC" != "" ]; then
63 PROTOC
=$BOOTSTRAP_PROTOC
66 ${BAZEL:-bazel} ${BAZEL_STARTUP_FLAGS:-} build $@ //:protoc ${BAZEL_FLAGS:-}
67 if test $?
-ne 0; then
68 echo "Failed to build protoc."
71 PROTOC
="../bazel-bin/protoc"
74 $PROTOC --cpp_out=dllexport_decl
=PROTOBUF_EXPORT
:$TMP ${RUNTIME_PROTO_FILES[@]} && \
75 $PROTOC --cpp_out=dllexport_decl
=PROTOC_EXPORT
:$TMP ${COMPILER_PROTO_FILES[@]}
77 for PROTO_FILE
in ${RUNTIME_PROTO_FILES[@]} ${COMPILER_PROTO_FILES[@]}; do
78 BASE_NAME
=${PROTO_FILE%.*}
79 diff ${BASE_NAME}.pb.h
$TMP/${BASE_NAME}.pb.h
> /dev
/null
80 if test $?
-ne 0; then
81 CORE_PROTO_IS_CORRECT
=0
83 diff ${BASE_NAME}.pb.cc
$TMP/${BASE_NAME}.pb.cc
> /dev
/null
84 if test $?
-ne 0; then
85 CORE_PROTO_IS_CORRECT
=0
89 # Only override the output if the files are different to avoid re-compilation
91 if [ $CORE_PROTO_IS_CORRECT -ne 1 ]; then
92 for PROTO_FILE
in ${RUNTIME_PROTO_FILES[@]} ${COMPILER_PROTO_FILES[@]}; do
93 BASE_NAME
=${PROTO_FILE%.*}
94 mv $TMP/${BASE_NAME}.pb.h
${BASE_NAME}.pb.h
95 mv $TMP/${BASE_NAME}.pb.cc
${BASE_NAME}.pb.cc
99 PROCESS_ROUND
=$
((PROCESS_ROUND
+ 1))
103 if test -x objectivec
/generate_well_known_types.sh
; then
104 echo "Generating messages for objc."
105 objectivec
/generate_well_known_types.sh $@
108 if test -x csharp
/generate_protos.sh
; then
109 echo "Generating messages for C#."
110 csharp
/generate_protos.sh $@
113 if test -x php
/generate_descriptor_protos.sh
; then
114 echo "Generating messages for PHP."
115 php
/generate_descriptor_protos.sh $@