blob: 4d4930dc9cd16a6a7227e835893ca0462872e19f [file] [log] [blame]
Thomas Van Lenten1dcc3292015-05-21 17:14:52 -04001#!/bin/bash
2#
3# Helper to do build so you don't have to remember all the steps/args.
4
5
6set -eu
7
8# Some base locations.
9readonly ScriptDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")")
10readonly ProtoRootDir="${ScriptDir}/../.."
11
12printUsage() {
13 NAME=$(basename "${0}")
14 cat << EOF
15usage: ${NAME} [OPTIONS]
16
17This script does the common build steps needed.
18
19OPTIONS:
20
21 General:
22
23 -h, --help
24 Show this message
25 -c, --clean
26 Issue a clean before the normal build.
27 -a, --autogen
28 Start by rerunning autogen & configure.
Thomas Van Lentenf1a3c8f2015-11-04 17:26:03 -050029 -r, --regenerate-cpp-descriptors
Thomas Van Lenten1dcc3292015-05-21 17:14:52 -040030 The descriptor.proto is checked in generated, cause it to regenerate.
31 -j #, --jobs #
32 Force the number of parallel jobs (useful for debugging build issues).
Thomas Van Lentenf1a3c8f2015-11-04 17:26:03 -050033 --core-only
34 Skip some of the core protobuf build/checks to shorten the build time.
Thomas Van Lenten1dcc3292015-05-21 17:14:52 -040035 --skip-xcode
36 Skip the invoke of Xcode to test the runtime on both iOS and OS X.
37 --skip-xcode-ios
38 Skip the invoke of Xcode to test the runtime on iOS.
39 --skip-xcode-osx
40 Skip the invoke of Xcode to test the runtime on OS X.
Thomas Van Lenten1745f7e2015-11-17 10:18:49 -050041 --skip-objc-conformance
42 Skip the Objective C conformance tests (run on OS X).
Thomas Van Lenten1dcc3292015-05-21 17:14:52 -040043
44EOF
45}
46
47header() {
48 echo ""
49 echo "========================================================================"
50 echo " ${@}"
51 echo "========================================================================"
52}
53
54# Thanks to libtool, builds can fail in odd ways and since it eats some output
55# it can be hard to spot, so force error output if make exits with a non zero.
56wrapped_make() {
57 set +e # Don't stop if the command fails.
58 make $*
59 MAKE_EXIT_STATUS=$?
60 if [ ${MAKE_EXIT_STATUS} -ne 0 ]; then
61 echo "Error: 'make $*' exited with status ${MAKE_EXIT_STATUS}"
62 exit ${MAKE_EXIT_STATUS}
63 fi
64 set -e
65}
66
67NUM_MAKE_JOBS=$(/usr/sbin/sysctl -n hw.ncpu)
68if [[ "${NUM_MAKE_JOBS}" -lt 4 ]] ; then
69 NUM_MAKE_JOBS=4
70fi
71
72DO_AUTOGEN=no
73DO_CLEAN=no
74REGEN_CPP_DESCRIPTORS=no
Thomas Van Lentenf1a3c8f2015-11-04 17:26:03 -050075CORE_ONLY=no
Thomas Van Lenten1dcc3292015-05-21 17:14:52 -040076DO_XCODE_IOS_TESTS=yes
77DO_XCODE_OSX_TESTS=yes
Thomas Van Lenten1745f7e2015-11-17 10:18:49 -050078DO_OBJC_CONFORMANCE_TESTS=yes
Thomas Van Lenten1dcc3292015-05-21 17:14:52 -040079while [[ $# != 0 ]]; do
80 case "${1}" in
81 -h | --help )
82 printUsage
83 exit 0
84 ;;
85 -c | --clean )
86 DO_CLEAN=yes
87 ;;
88 -a | --autogen )
89 DO_AUTOGEN=yes
90 ;;
91 -r | --regenerate-cpp-descriptors )
92 REGEN_CPP_DESCRIPTORS=yes
93 ;;
94 -j | --jobs )
95 shift
96 NUM_MAKE_JOBS="${1}"
97 ;;
Thomas Van Lentenf1a3c8f2015-11-04 17:26:03 -050098 --core-only )
99 CORE_ONLY=yes
100 ;;
Thomas Van Lenten1dcc3292015-05-21 17:14:52 -0400101 --skip-xcode )
102 DO_XCODE_IOS_TESTS=no
103 DO_XCODE_OSX_TESTS=no
104 ;;
105 --skip-xcode-ios )
106 DO_XCODE_IOS_TESTS=no
107 ;;
108 --skip-xcode-osx )
109 DO_XCODE_OSX_TESTS=no
110 ;;
Thomas Van Lenten1745f7e2015-11-17 10:18:49 -0500111 --skip-objc-conformance )
112 DO_OBJC_CONFORMANCE_TESTS=no
113 ;;
Thomas Van Lenten1dcc3292015-05-21 17:14:52 -0400114 -*)
115 echo "ERROR: Unknown option: ${1}" 1>&2
116 printUsage
117 exit 1
118 ;;
119 *)
120 echo "ERROR: Unknown argument: ${1}" 1>&2
121 printUsage
122 exit 1
123 ;;
124 esac
125 shift
126done
127
128# Into the proto dir.
Thomas Van Lentenf0411ec2015-11-04 15:10:49 -0500129cd "${ProtoRootDir}"
Thomas Van Lenten1dcc3292015-05-21 17:14:52 -0400130
131# if no Makefile, force the autogen.
132if [[ ! -f Makefile ]] ; then
133 DO_AUTOGEN=yes
134fi
135
136if [[ "${DO_AUTOGEN}" == "yes" ]] ; then
137 header "Running autogen & configure"
138 ./autogen.sh
Thomas Van Lenten69d713f2015-12-02 11:48:14 -0500139 ./configure \
140 CPPFLAGS="-mmacosx-version-min=10.9 -Wunused-const-variable -Wunused-function" \
141 CXXFLAGS="-Wnon-virtual-dtor -Woverloaded-virtual"
Thomas Van Lenten1dcc3292015-05-21 17:14:52 -0400142fi
143
144if [[ "${DO_CLEAN}" == "yes" ]] ; then
145 header "Cleaning"
146 wrapped_make clean
147 if [[ "${DO_XCODE_IOS_TESTS}" == "yes" ]] ; then
148 XCODEBUILD_CLEAN_BASE_IOS=(
149 xcodebuild
150 -project objectivec/ProtocolBuffers_iOS.xcodeproj
151 -scheme ProtocolBuffers
152 )
153 "${XCODEBUILD_CLEAN_BASE_IOS[@]}" -configuration Debug clean
154 "${XCODEBUILD_CLEAN_BASE_IOS[@]}" -configuration Release clean
155 fi
156 if [[ "${DO_XCODE_OSX_TESTS}" == "yes" ]] ; then
157 XCODEBUILD_CLEAN_BASE_OSX=(
158 xcodebuild
159 -project objectivec/ProtocolBuffers_OSX.xcodeproj
160 -scheme ProtocolBuffers
161 )
162 "${XCODEBUILD_CLEAN_BASE_OSX[@]}" -configuration Debug clean
163 "${XCODEBUILD_CLEAN_BASE_OSX[@]}" -configuration Release clean
164 fi
165fi
166
167if [[ "${REGEN_CPP_DESCRIPTORS}" == "yes" ]] ; then
168 header "Regenerating the C++ descriptor sources."
169 ./generate_descriptor_proto.sh -j "${NUM_MAKE_JOBS}"
170fi
171
Thomas Van Lentenf1a3c8f2015-11-04 17:26:03 -0500172if [[ "${CORE_ONLY}" == "yes" ]] ; then
173 header "Building core Only"
174 wrapped_make -j "${NUM_MAKE_JOBS}"
175else
176 header "Building"
177 # Can't issue these together, when fully parallel, something sometimes chokes
178 # at random.
179 wrapped_make -j "${NUM_MAKE_JOBS}" all
180 wrapped_make -j "${NUM_MAKE_JOBS}" check
181 # Fire off the conformance tests also.
182 cd conformance
Thomas Van Lenten1745f7e2015-11-17 10:18:49 -0500183 wrapped_make -j "${NUM_MAKE_JOBS}" test_cpp
Thomas Van Lentenf1a3c8f2015-11-04 17:26:03 -0500184 cd ..
185fi
Thomas Van Lenten1dcc3292015-05-21 17:14:52 -0400186
187header "Ensuring the ObjC descriptors are current."
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400188# Find the newest input file (protos, compiler, and the generator script).
Thomas Van Lenten1dcc3292015-05-21 17:14:52 -0400189# (these patterns catch some extra stuff, but better to over sample than under)
190readonly NewestInput=$(find \
191 src/google/protobuf/*.proto \
192 src/.libs src/*.la src/protoc \
Thomas Van Lenten79a23c42016-03-17 10:04:21 -0400193 objectivec/generate_well_known_types.sh \
Thomas Van Lenten1dcc3292015-05-21 17:14:52 -0400194 -type f -print0 \
195 | xargs -0 stat -f "%m %N" \
196 | sort -n | tail -n1 | cut -f2- -d" ")
197# Find the oldest output file.
198readonly OldestOutput=$(find \
199 "${ProtoRootDir}/objectivec/google" \
200 -type f -print0 \
201 | xargs -0 stat -f "%m %N" \
202 | sort -n -r | tail -n1 | cut -f2- -d" ")
203# If the newest input is newer than the oldest output, regenerate.
204if [[ "${NewestInput}" -nt "${OldestOutput}" ]] ; then
205 echo ">> Newest input is newer than oldest output, regenerating."
Thomas Van Lenten79a23c42016-03-17 10:04:21 -0400206 objectivec/generate_well_known_types.sh -j "${NUM_MAKE_JOBS}"
Thomas Van Lenten1dcc3292015-05-21 17:14:52 -0400207else
208 echo ">> Newest input is older than oldest output, no need to regenerating."
209fi
210
211header "Checking on the ObjC Runtime Code"
212objectivec/DevTools/pddm_tests.py
213if ! objectivec/DevTools/pddm.py --dry-run objectivec/*.[hm] objectivec/Tests/*.[hm] ; then
214 echo ""
215 echo "Update by running:"
216 echo " objectivec/DevTools/pddm.py objectivec/*.[hm] objectivec/Tests/*.[hm]"
217 exit 1
218fi
219
220if [[ "${DO_XCODE_IOS_TESTS}" == "yes" ]] ; then
221 XCODEBUILD_TEST_BASE_IOS=(
222 xcodebuild
223 -project objectivec/ProtocolBuffers_iOS.xcodeproj
224 -scheme ProtocolBuffers
Thomas Van Lenten1dcc3292015-05-21 17:14:52 -0400225 )
Thomas Van Lentenf1a3c8f2015-11-04 17:26:03 -0500226 # Don't need to worry about form factors or retina/non retina;
227 # just pick a mix of OS Versions and 32/64 bit.
228 # NOTE: Different Xcode have different simulated hardware/os support.
229 readonly XCODE_VERSION_LINE="$(xcodebuild -version | grep Xcode\ )"
230 readonly XCODE_VERSION="${XCODE_VERSION_LINE/Xcode /}" # drop the prefix.
231 IOS_SIMULATOR_NAME="Simulator"
232 case "${XCODE_VERSION}" in
233 6.* )
Thomas Van Lenten938ba412015-12-10 15:49:53 -0500234 echo "ERROR: Xcode 6.3/6.4 no longer supported for building, please use 7.0 or higher." 1>&2
235 exit 10
Thomas Van Lentenf1a3c8f2015-11-04 17:26:03 -0500236 ;;
Thomas Van Lenten13241192016-02-16 09:19:50 -0500237 7.1* )
Thomas Van Lentenf1a3c8f2015-11-04 17:26:03 -0500238 XCODEBUILD_TEST_BASE_IOS+=(
239 -destination "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
240 -destination "platform=iOS Simulator,name=iPhone 6,OS=9.0" # 64bit
241 -destination "platform=iOS Simulator,name=iPad 2,OS=8.1" # 32bit
242 -destination "platform=iOS Simulator,name=iPad Air,OS=9.0" # 64bit
243 )
244 ;;
Geoffrey Wisemanf98d2f52016-04-06 15:29:52 -0400245 7.3* )
246 XCODEBUILD_TEST_BASE_IOS+=(
247 -destination "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
248 -destination "platform=iOS Simulator,name=iPhone 6,OS=9.3" # 64bit
249 -destination "platform=iOS Simulator,name=iPad 2,OS=8.1" # 32bit
250 -destination "platform=iOS Simulator,name=iPad Air,OS=9.3" # 64bit
251 )
252 ;;
Thomas Van Lenten13241192016-02-16 09:19:50 -0500253 7.* )
254 XCODEBUILD_TEST_BASE_IOS+=(
255 -destination "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
256 -destination "platform=iOS Simulator,name=iPhone 6,OS=9.2" # 64bit
257 -destination "platform=iOS Simulator,name=iPad 2,OS=8.1" # 32bit
258 -destination "platform=iOS Simulator,name=iPad Air,OS=9.2" # 64bit
259 )
260 ;;
Thomas Van Lentenf1a3c8f2015-11-04 17:26:03 -0500261 * )
262 echo "Time to update the simulator targets for Xcode ${XCODE_VERSION}"
263 exit 2
264 ;;
265 esac
Thomas Van Lenten1dcc3292015-05-21 17:14:52 -0400266 header "Doing Xcode iOS build/tests - Debug"
267 "${XCODEBUILD_TEST_BASE_IOS[@]}" -configuration Debug test
268 header "Doing Xcode iOS build/tests - Release"
269 "${XCODEBUILD_TEST_BASE_IOS[@]}" -configuration Release test
270 # Don't leave the simulator in the developer's face.
Thomas Van Lentenf1a3c8f2015-11-04 17:26:03 -0500271 killall "${IOS_SIMULATOR_NAME}"
Thomas Van Lenten1dcc3292015-05-21 17:14:52 -0400272fi
273if [[ "${DO_XCODE_OSX_TESTS}" == "yes" ]] ; then
274 XCODEBUILD_TEST_BASE_OSX=(
275 xcodebuild
276 -project objectivec/ProtocolBuffers_OSX.xcodeproj
277 -scheme ProtocolBuffers
278 # Since the ObjC 2.0 Runtime is required, 32bit OS X isn't supported.
279 -destination "platform=OS X,arch=x86_64" # 64bit
280 )
281 header "Doing Xcode OS X build/tests - Debug"
282 "${XCODEBUILD_TEST_BASE_OSX[@]}" -configuration Debug test
283 header "Doing Xcode OS X build/tests - Release"
284 "${XCODEBUILD_TEST_BASE_OSX[@]}" -configuration Release test
285fi
Thomas Van Lenten1745f7e2015-11-17 10:18:49 -0500286
287if [[ "${DO_OBJC_CONFORMANCE_TESTS}" == "yes" ]] ; then
288 cd conformance
289 wrapped_make -j "${NUM_MAKE_JOBS}" test_objc
290 cd ..
291fi