Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame^] | 1 | #!/bin/bash -eu |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 2 | # Invoked by the Xcode projects to build the protos needed for the unittests. |
| 3 | |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 4 | readonly OUTPUT_DIR="${PROJECT_DERIVED_FILE_DIR}/protos" |
| 5 | |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame^] | 6 | # ----------------------------------------------------------------------------- |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 7 | # Helper for bailing. |
| 8 | die() { |
| 9 | echo "Error: $1" |
| 10 | exit 2 |
| 11 | } |
| 12 | |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame^] | 13 | # ----------------------------------------------------------------------------- |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 14 | # What to do. |
| 15 | case "${ACTION}" in |
| 16 | "") |
| 17 | # Build, fall thru |
| 18 | ;; |
| 19 | "clean") |
| 20 | rm -rf "${OUTPUT_DIR}" |
| 21 | exit 0 |
| 22 | ;; |
| 23 | *) |
| 24 | die "Unknown action requested: ${ACTION}" |
| 25 | ;; |
| 26 | esac |
| 27 | |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame^] | 28 | # ----------------------------------------------------------------------------- |
| 29 | # Ensure the output dir exists |
| 30 | mkdir -p "${OUTPUT_DIR}/google/protobuf" |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 31 | |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame^] | 32 | # ----------------------------------------------------------------------------- |
| 33 | # Move to the top of the protobuf directories and ensure there is a protoc |
| 34 | # binary to use. |
| 35 | cd "${SRCROOT}/.." |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 36 | [[ -x src/protoc ]] || \ |
| 37 | die "Could not find the protoc binary; make sure you have built it (objectivec/DevTools/full_mac_build.sh -h)." |
| 38 | |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame^] | 39 | # ----------------------------------------------------------------------------- |
| 40 | # See the compiler or proto files have changed. |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 41 | RUN_PROTOC=no |
| 42 | if [[ ! -d "${OUTPUT_DIR}" ]] ; then |
| 43 | RUN_PROTOC=yes |
| 44 | else |
| 45 | # Find the newest input file (protos, compiler, and this script). |
| 46 | # (these patterns catch some extra stuff, but better to over sample than |
| 47 | # under) |
| 48 | readonly NewestInput=$(find \ |
| 49 | src/google/protobuf/*.proto \ |
| 50 | objectivec/Tests/*.proto \ |
| 51 | src/.libs src/*.la src/protoc \ |
| 52 | objectivec/DevTools/compile_testing_protos.sh \ |
| 53 | -type f -print0 \ |
| 54 | | xargs -0 stat -f "%m %N" \ |
| 55 | | sort -n | tail -n1 | cut -f2- -d" ") |
| 56 | # Find the oldest output file. |
| 57 | readonly OldestOutput=$(find \ |
| 58 | "${OUTPUT_DIR}" \ |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame^] | 59 | -type f -name "*pbobjc.[hm]" -print0 \ |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 60 | | xargs -0 stat -f "%m %N" \ |
| 61 | | sort -n -r | tail -n1 | cut -f2- -d" ") |
| 62 | # If the newest input is newer than the oldest output, regenerate. |
| 63 | if [[ "${NewestInput}" -nt "${OldestOutput}" ]] ; then |
| 64 | RUN_PROTOC=yes |
| 65 | fi |
| 66 | fi |
| 67 | |
| 68 | if [[ "${RUN_PROTOC}" != "yes" ]] ; then |
| 69 | # Up to date. |
| 70 | exit 0 |
| 71 | fi |
| 72 | |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame^] | 73 | # ----------------------------------------------------------------------------- |
| 74 | # Prune out all the files from previous generations to ensure we only have |
| 75 | # current ones. |
| 76 | find "${OUTPUT_DIR}" \ |
| 77 | -type f -name "*pbobjc.[hm]" -print0 \ |
| 78 | | xargs -0 rm -rf |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 79 | |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame^] | 80 | # ----------------------------------------------------------------------------- |
| 81 | # Helper to invoke protoc |
| 82 | compile_protos() { |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 83 | src/protoc \ |
| 84 | --objc_out="${OUTPUT_DIR}/google/protobuf" \ |
| 85 | --proto_path=src/google/protobuf/ \ |
| 86 | --proto_path=src \ |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame^] | 87 | "$@" |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 88 | } |
| 89 | |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame^] | 90 | # ----------------------------------------------------------------------------- |
| 91 | # Generate most of the proto files that exist in the C++ src tree. Several |
| 92 | # are used in the tests, but the extra don't hurt in that they ensure ObjC |
| 93 | # sources can be generated from them. |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 94 | |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame^] | 95 | CORE_PROTO_FILES=( |
| 96 | src/google/protobuf/any_test.proto |
| 97 | src/google/protobuf/unittest_arena.proto |
| 98 | src/google/protobuf/unittest_custom_options.proto |
| 99 | src/google/protobuf/unittest_enormous_descriptor.proto |
| 100 | src/google/protobuf/unittest_embed_optimize_for.proto |
| 101 | src/google/protobuf/unittest_empty.proto |
| 102 | src/google/protobuf/unittest_import.proto |
| 103 | src/google/protobuf/unittest_import_lite.proto |
| 104 | src/google/protobuf/unittest_lite.proto |
| 105 | src/google/protobuf/unittest_mset.proto |
| 106 | src/google/protobuf/unittest_mset_wire_format.proto |
| 107 | src/google/protobuf/unittest_no_arena.proto |
| 108 | src/google/protobuf/unittest_no_arena_import.proto |
| 109 | src/google/protobuf/unittest_no_generic_services.proto |
| 110 | src/google/protobuf/unittest_optimize_for.proto |
| 111 | src/google/protobuf/unittest.proto |
| 112 | src/google/protobuf/unittest_import_public.proto |
| 113 | src/google/protobuf/unittest_import_public_lite.proto |
| 114 | src/google/protobuf/unittest_drop_unknown_fields.proto |
| 115 | src/google/protobuf/unittest_preserve_unknown_enum.proto |
| 116 | src/google/protobuf/map_lite_unittest.proto |
| 117 | src/google/protobuf/map_proto2_unittest.proto |
| 118 | src/google/protobuf/map_unittest.proto |
| 119 | # The unittest_custom_options.proto extends the messages in descriptor.proto |
| 120 | # so we build it in to test extending in general. The library doesn't provide |
| 121 | # a descriptor as it doesn't use the classes/enums. |
| 122 | src/google/protobuf/descriptor.proto |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 123 | ) |
| 124 | |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame^] | 125 | # Note: there is overlap in package.Message names between some of the test |
| 126 | # files, so they can't be generated all at once. This works because the overlap |
| 127 | # isn't linked into a single binary. |
| 128 | for a_proto in "${CORE_PROTO_FILES[@]}" ; do |
| 129 | compile_protos "${a_proto}" |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 130 | done |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame^] | 131 | |
| 132 | # ----------------------------------------------------------------------------- |
| 133 | # Generate the Objective C specific testing protos. |
| 134 | compile_protos \ |
| 135 | --proto_path="objectivec/Tests" \ |
| 136 | objectivec/Tests/unittest_cycle.proto \ |
| 137 | objectivec/Tests/unittest_deprecated.proto \ |
| 138 | objectivec/Tests/unittest_deprecated_file.proto \ |
| 139 | objectivec/Tests/unittest_extension_chain_a.proto \ |
| 140 | objectivec/Tests/unittest_extension_chain_b.proto \ |
| 141 | objectivec/Tests/unittest_extension_chain_c.proto \ |
| 142 | objectivec/Tests/unittest_extension_chain_d.proto \ |
| 143 | objectivec/Tests/unittest_extension_chain_e.proto \ |
| 144 | objectivec/Tests/unittest_extension_chain_f.proto \ |
| 145 | objectivec/Tests/unittest_extension_chain_g.proto \ |
| 146 | objectivec/Tests/unittest_runtime_proto2.proto \ |
| 147 | objectivec/Tests/unittest_runtime_proto3.proto \ |
| 148 | objectivec/Tests/unittest_objc.proto \ |
| 149 | objectivec/Tests/unittest_objc_startup.proto |