1#!/bin/bash 2 3# Invoked by the Xcode projects to build the protos needed for the unittests. 4 5set -eu 6 7readonly OUTPUT_DIR="${PROJECT_DERIVED_FILE_DIR}/protos" 8 9# Helper for bailing. 10die() { 11 echo "Error: $1" 12 exit 2 13} 14 15# What to do. 16case "${ACTION}" in 17 "") 18 # Build, fall thru 19 ;; 20 "clean") 21 rm -rf "${OUTPUT_DIR}" 22 exit 0 23 ;; 24 *) 25 die "Unknown action requested: ${ACTION}" 26 ;; 27esac 28 29# Move to the top of the protobuf directories. 30cd "${SRCROOT}/.." 31 32[[ -x src/protoc ]] || \ 33 die "Could not find the protoc binary; make sure you have built it (objectivec/DevTools/full_mac_build.sh -h)." 34 35RUN_PROTOC=no 36if [[ ! -d "${OUTPUT_DIR}" ]] ; then 37 RUN_PROTOC=yes 38else 39 # Find the newest input file (protos, compiler, and this script). 40 # (these patterns catch some extra stuff, but better to over sample than 41 # under) 42 readonly NewestInput=$(find \ 43 src/google/protobuf/*.proto \ 44 objectivec/Tests/*.proto \ 45 src/.libs src/*.la src/protoc \ 46 objectivec/DevTools/compile_testing_protos.sh \ 47 -type f -print0 \ 48 | xargs -0 stat -f "%m %N" \ 49 | sort -n | tail -n1 | cut -f2- -d" ") 50 # Find the oldest output file. 51 readonly OldestOutput=$(find \ 52 "${OUTPUT_DIR}" \ 53 -type f -print0 \ 54 | xargs -0 stat -f "%m %N" \ 55 | sort -n -r | tail -n1 | cut -f2- -d" ") 56 # If the newest input is newer than the oldest output, regenerate. 57 if [[ "${NewestInput}" -nt "${OldestOutput}" ]] ; then 58 RUN_PROTOC=yes 59 fi 60fi 61 62if [[ "${RUN_PROTOC}" != "yes" ]] ; then 63 # Up to date. 64 exit 0 65fi 66 67# Ensure the output dir exists 68mkdir -p "${OUTPUT_DIR}/google/protobuf" 69 70CORE_PROTO_FILES=( 71 src/google/protobuf/unittest_arena.proto 72 src/google/protobuf/unittest_custom_options.proto 73 src/google/protobuf/unittest_enormous_descriptor.proto 74 src/google/protobuf/unittest_embed_optimize_for.proto 75 src/google/protobuf/unittest_empty.proto 76 src/google/protobuf/unittest_import.proto 77 src/google/protobuf/unittest_import_lite.proto 78 src/google/protobuf/unittest_lite.proto 79 src/google/protobuf/unittest_mset.proto 80 src/google/protobuf/unittest_mset_wire_format.proto 81 src/google/protobuf/unittest_no_arena.proto 82 src/google/protobuf/unittest_no_arena_import.proto 83 src/google/protobuf/unittest_no_generic_services.proto 84 src/google/protobuf/unittest_optimize_for.proto 85 src/google/protobuf/unittest.proto 86 src/google/protobuf/unittest_import_public.proto 87 src/google/protobuf/unittest_import_public_lite.proto 88 src/google/protobuf/unittest_drop_unknown_fields.proto 89 src/google/protobuf/unittest_preserve_unknown_enum.proto 90 src/google/protobuf/map_lite_unittest.proto 91 src/google/protobuf/map_proto2_unittest.proto 92 src/google/protobuf/map_unittest.proto 93) 94 95# The unittest_custom_options.proto extends the messages in descriptor.proto 96# so we build it in to test extending in general. The library doesn't provide 97# a descriptor as it doesn't use the classes/enums. 98CORE_PROTO_FILES+=( 99 src/google/protobuf/descriptor.proto 100) 101 102compile_proto() { 103 src/protoc \ 104 --objc_out="${OUTPUT_DIR}/google/protobuf" \ 105 --proto_path=src/google/protobuf/ \ 106 --proto_path=src \ 107 $* 108} 109 110for a_proto in "${CORE_PROTO_FILES[@]}" ; do 111 compile_proto "${a_proto}" 112done 113 114OBJC_PROTO_FILES=( 115 objectivec/Tests/unittest_cycle.proto 116 objectivec/Tests/unittest_runtime_proto2.proto 117 objectivec/Tests/unittest_runtime_proto3.proto 118 objectivec/Tests/unittest_objc.proto 119 objectivec/Tests/unittest_objc_startup.proto 120) 121 122for a_proto in "${OBJC_PROTO_FILES[@]}" ; do 123 compile_proto --proto_path="objectivec/Tests" "${a_proto}" 124done 125