Home | History | Annotate | Download | only in objectivec
      1 #!/bin/bash
      2 
      3 # Run this script to regenerate *.pbobjc.{h,m} for the well known types after
      4 # the protocol compiler changes.
      5 
      6 # HINT:  Flags passed to generate_well_known_types.sh will be passed directly
      7 #   to make when building protoc.  This is particularly useful for passing
      8 #   -j4 to run 4 jobs simultaneously.
      9 
     10 set -eu
     11 
     12 readonly ScriptDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")")
     13 readonly ProtoRootDir="${ScriptDir}/.."
     14 
     15 # Flag for continuous integration to check that everything is current.
     16 CHECK_ONLY=0
     17 if [[ $# -ge 1 && ( "$1" == "--check-only" ) ]] ; then
     18   CHECK_ONLY=1
     19   shift
     20 fi
     21 
     22 pushd "${ProtoRootDir}" > /dev/null
     23 
     24 if test ! -e src/google/protobuf/stubs/common.h; then
     25   cat >&2 << __EOF__
     26 Could not find source code.  Make sure you are running this script from the
     27 root of the distribution tree.
     28 __EOF__
     29   exit 1
     30 fi
     31 
     32 if test ! -e src/Makefile; then
     33   cat >&2 << __EOF__
     34 Could not find src/Makefile.  You must run ./configure (and perhaps
     35 ./autogen.sh) first.
     36 __EOF__
     37   exit 1
     38 fi
     39 
     40 # Make sure the compiler is current.
     41 cd src
     42 make $@ protoc
     43 
     44 declare -a RUNTIME_PROTO_FILES=( \
     45   google/protobuf/any.proto \
     46   google/protobuf/api.proto \
     47   google/protobuf/duration.proto \
     48   google/protobuf/empty.proto \
     49   google/protobuf/field_mask.proto \
     50   google/protobuf/source_context.proto \
     51   google/protobuf/struct.proto \
     52   google/protobuf/timestamp.proto \
     53   google/protobuf/type.proto \
     54   google/protobuf/wrappers.proto)
     55 
     56 # Generate to a temp directory to see if they match.
     57 TMP_DIR=$(mktemp -d)
     58 trap "rm -rf ${TMP_DIR}" EXIT
     59 ./protoc --objc_out="${TMP_DIR}" ${RUNTIME_PROTO_FILES[@]}
     60 set +e
     61 diff -r "${TMP_DIR}/google" "${ProtoRootDir}/objectivec/google" > /dev/null
     62 if [[ $? -eq 0 ]] ; then
     63   echo "Generated source for WellKnownTypes is current."
     64   exit 0
     65 fi
     66 set -e
     67 
     68 # If check only mode, error out.
     69 if [[ "${CHECK_ONLY}" == 1 ]] ; then
     70   echo "ERROR: The WKTs need to be regenerated! Run $0"
     71   exit 1
     72 fi
     73 
     74 # Copy them over.
     75 echo "Copying over updated WellKnownType sources."
     76 cp -r "${TMP_DIR}/google/." "${ProtoRootDir}/objectivec/google/"
     77