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