Fix small typo (#19993)
[google-protobuf.git] / objectivec / generate_well_known_types.sh
blob4b77412056d930fbcf630f499529e6596b88f4d6
1 #!/bin/bash
3 # Run this script to regenerate *.pbobjc.{h,m} for the well known types after
4 # the protocol compiler changes.
6 set -eu
8 readonly ScriptDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")")
9 readonly ObjCDir="${ScriptDir}"
10 readonly ProtoRootDir="${ObjCDir}/.."
12 cd "${ProtoRootDir}"
14 # Flag for continuous integration to check that everything is current.
15 CHECK_ONLY=0
16 if [[ $# -ge 1 && ( "$1" == "--check-only" ) ]] ; then
17 CHECK_ONLY=1
18 shift
21 readonly PROTOC_PATH="${PROTOC:-${ProtoRootDir}/bazel-bin/protoc}"
22 if [[ ! -x "${PROTOC_PATH}" ]] ; then
23 echo "Failed to find executable protoc: ${PROTOC_PATH}"
24 exit 1
27 if [[ ! -e src/google/protobuf/stubs/common.h ]]; then
28 cat >&2 << __EOF__
29 Could not find source code. Make sure you are running this script from the
30 root of the distribution tree.
31 __EOF__
32 exit 1
35 cd src
36 declare -a RUNTIME_PROTO_FILES=( \
37 google/protobuf/any.proto \
38 google/protobuf/api.proto \
39 google/protobuf/duration.proto \
40 google/protobuf/empty.proto \
41 google/protobuf/field_mask.proto \
42 google/protobuf/source_context.proto \
43 google/protobuf/struct.proto \
44 google/protobuf/timestamp.proto \
45 google/protobuf/type.proto \
46 google/protobuf/wrappers.proto)
48 declare -a OBJC_EXTENSIONS=( .pbobjc.h .pbobjc.m )
50 # Generate to a temp directory to see if they match.
51 TMP_DIR=$(mktemp -d)
52 trap "rm -rf ${TMP_DIR}" EXIT
53 "${PROTOC_PATH}" --objc_out="${TMP_DIR}" ${RUNTIME_PROTO_FILES[@]}
55 DID_COPY=0
56 for PROTO_FILE in "${RUNTIME_PROTO_FILES[@]}"; do
57 DIR=${PROTO_FILE%/*}
58 BASE_NAME=${PROTO_FILE##*/}
59 # Drop the extension
60 BASE_NAME=${BASE_NAME%.*}
61 OBJC_NAME=$(echo "${BASE_NAME}" | awk -F _ '{for(i=1; i<=NF; i++) printf "%s", toupper(substr($i,1,1)) substr($i,2);}')
63 for EXT in "${OBJC_EXTENSIONS[@]}"; do
64 if ! diff "${ObjCDir}/GPB${OBJC_NAME}${EXT}" "${TMP_DIR}/${DIR}/${OBJC_NAME}${EXT}" > /dev/null 2>&1 ; then
65 if [[ "${CHECK_ONLY}" == 1 ]] ; then
66 echo "ERROR: The WKTs need to be regenerated! Run $0"
67 diff -u "${ObjCDir}/GPB${OBJC_NAME}${EXT}" "${TMP_DIR}/${DIR}/${OBJC_NAME}${EXT}"
68 exit 1
71 echo "INFO: Updating GPB${OBJC_NAME}${EXT}"
72 cp "${TMP_DIR}/${DIR}/${OBJC_NAME}${EXT}" "${ObjCDir}/GPB${OBJC_NAME}${EXT}"
73 DID_COPY=1
75 done
76 done
78 if [[ "${DID_COPY}" == 0 ]]; then
79 echo "INFO: Generated source for WellKnownTypes is current."
80 exit 0