blob: e9c5fe611ba3fd7ec4a10ea41aeb24c746508d2c [file] [log] [blame]
Brian Silverman9c614bc2016-02-15 20:20:02 -05001#!/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
95compile_proto() {
96 src/protoc \
97 --objc_out="${OUTPUT_DIR}/google/protobuf" \
98 --proto_path=src/google/protobuf/ \
99 --proto_path=src \
100 $*
101}
102
103for a_proto in "${CORE_PROTO_FILES[@]}" ; do
104 compile_proto "${a_proto}"
105done
106
107OBJC_PROTO_FILES=( \
108 objectivec/Tests/unittest_cycle.proto \
109 objectivec/Tests/unittest_runtime_proto2.proto \
110 objectivec/Tests/unittest_runtime_proto3.proto \
111 objectivec/Tests/unittest_objc.proto \
112 objectivec/Tests/unittest_objc_startup.proto \
113)
114
115for a_proto in "${OBJC_PROTO_FILES[@]}" ; do
116 compile_proto --proto_path="objectivec/Tests" "${a_proto}"
117done