Reimplement ExtensionSet::MergeFrom for the copy case for better performance.
[google-protobuf.git] / generate_descriptor_proto.sh
blob0eb158146fef517f5c6e77791ef6d02f0bf95579
1 #!/usr/bin/env bash
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.
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
14 cat >&2 << __EOF__
15 Could not find source code. Make sure you are running this script from the
16 root of the distribution tree.
17 __EOF__
18 exit 1
21 cd src
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
41 PROCESS_ROUND=1
42 BOOTSTRAP_PROTOC=""
43 while [ $# -gt 0 ]; do
44 case $1 in
45 --bootstrap_protoc)
46 BOOTSTRAP_PROTOC=$2
47 shift 2
50 break
52 esac
53 shift
54 done
55 TMP=$(mktemp -d)
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
64 BOOTSTRAP_PROTOC=""
65 else
66 ${BAZEL:-bazel} ${BAZEL_STARTUP_FLAGS:-} build $@ //:protoc ${BAZEL_FLAGS:-}
67 if test $? -ne 0; then
68 echo "Failed to build protoc."
69 exit 1
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
87 done
89 # Only override the output if the files are different to avoid re-compilation
90 # of the protoc.
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
96 done
99 PROCESS_ROUND=$((PROCESS_ROUND + 1))
100 done
101 cd ..
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 $@