3 # Run this script to regenerate *.pbobjc.{h,m} for the well known types after
4 # the protocol compiler changes.
8 readonly ScriptDir
=$
(dirname "$(echo $0 | sed -e "s
,^\
([^
/]\
),$
(pwd)/\
1,")")
9 readonly ObjCDir
="${ScriptDir}"
10 readonly ProtoRootDir
="${ObjCDir}/.."
14 # Flag for continuous integration to check that everything is current.
16 if [[ $# -ge 1 && ( "$1" == "--check-only" ) ]] ; then
21 readonly PROTOC_PATH
="${PROTOC:-${ProtoRootDir}/bazel-bin/protoc}"
22 if [[ ! -x "${PROTOC_PATH}" ]] ; then
23 echo "Failed to find executable protoc: ${PROTOC_PATH}"
27 if [[ ! -e src
/google
/protobuf
/stubs
/common.h
]]; then
29 Could not find source code. Make sure you are running this script from the
30 root of the distribution tree.
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.
52 trap "rm -rf ${TMP_DIR}" EXIT
53 "${PROTOC_PATH}" --objc_out="${TMP_DIR}" ${RUNTIME_PROTO_FILES[@]}
56 for PROTO_FILE in "${RUNTIME_PROTO_FILES[@]}"; do
58 BASE_NAME=${PROTO_FILE##*/}
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}"
71 echo "INFO
: Updating GPB
${OBJC_NAME}${EXT}"
72 cp "${TMP_DIR}/${DIR}/${OBJC_NAME}${EXT}" "${ObjCDir}/GPB${OBJC_NAME}${EXT}"
78 if [[ "${DID_COPY}" == 0 ]]; then
79 echo "INFO
: Generated
source for WellKnownTypes is current.
"