full_mac_build.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. #!/bin/bash
  2. #
  3. # Helper to do build so you don't have to remember all the steps/args.
  4. set -eu
  5. # Some base locations.
  6. readonly ScriptDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")")
  7. readonly ProtoRootDir="${ScriptDir}/../.."
  8. printUsage() {
  9. NAME=$(basename "${0}")
  10. cat << EOF
  11. usage: ${NAME} [OPTIONS]
  12. This script does the common build steps needed.
  13. OPTIONS:
  14. General:
  15. -h, --help
  16. Show this message
  17. -c, --clean
  18. Issue a clean before the normal build.
  19. -a, --autogen
  20. Start by rerunning autogen & configure.
  21. -r, --regenerate-descriptors
  22. Run generate_descriptor_proto.sh to regenerate all the checked in
  23. proto sources.
  24. -j #, --jobs #
  25. Force the number of parallel jobs (useful for debugging build issues).
  26. --core-only
  27. Skip some of the core protobuf build/checks to shorten the build time.
  28. --skip-xcode
  29. Skip the invoke of Xcode to test the runtime on both iOS and OS X.
  30. --skip-xcode-ios
  31. Skip the invoke of Xcode to test the runtime on iOS.
  32. --skip-xcode-debug
  33. Skip the Xcode Debug configuration.
  34. --skip-xcode-release
  35. Skip the Xcode Release configuration.
  36. --skip-xcode-osx | --skip-xcode-macos
  37. Skip the invoke of Xcode to test the runtime on OS X.
  38. --skip-xcode-tvos
  39. Skip the invoke of Xcode to test the runtime on tvOS.
  40. --skip-objc-conformance
  41. Skip the Objective C conformance tests (run on OS X).
  42. --xcode-quiet
  43. Pass -quiet to xcodebuild.
  44. EOF
  45. }
  46. header() {
  47. echo ""
  48. echo "========================================================================"
  49. echo " ${@}"
  50. echo "========================================================================"
  51. }
  52. # Thanks to libtool, builds can fail in odd ways and since it eats some output
  53. # it can be hard to spot, so force error output if make exits with a non zero.
  54. wrapped_make() {
  55. set +e # Don't stop if the command fails.
  56. make $*
  57. MAKE_EXIT_STATUS=$?
  58. if [ ${MAKE_EXIT_STATUS} -ne 0 ]; then
  59. echo "Error: 'make $*' exited with status ${MAKE_EXIT_STATUS}"
  60. exit ${MAKE_EXIT_STATUS}
  61. fi
  62. set -e
  63. }
  64. NUM_MAKE_JOBS=$(/usr/sbin/sysctl -n hw.ncpu)
  65. if [[ "${NUM_MAKE_JOBS}" -lt 2 ]] ; then
  66. NUM_MAKE_JOBS=2
  67. fi
  68. DO_AUTOGEN=no
  69. DO_CLEAN=no
  70. REGEN_DESCRIPTORS=no
  71. CORE_ONLY=no
  72. DO_XCODE_IOS_TESTS=yes
  73. DO_XCODE_OSX_TESTS=yes
  74. DO_XCODE_TVOS_TESTS=yes
  75. DO_XCODE_DEBUG=yes
  76. DO_XCODE_RELEASE=yes
  77. DO_OBJC_CONFORMANCE_TESTS=yes
  78. XCODE_QUIET=no
  79. while [[ $# != 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-descriptors )
  92. REGEN_DESCRIPTORS=yes
  93. ;;
  94. -j | --jobs )
  95. shift
  96. NUM_MAKE_JOBS="${1}"
  97. ;;
  98. --core-only )
  99. CORE_ONLY=yes
  100. ;;
  101. --skip-xcode )
  102. DO_XCODE_IOS_TESTS=no
  103. DO_XCODE_OSX_TESTS=no
  104. DO_XCODE_TVOS_TESTS=no
  105. ;;
  106. --skip-xcode-ios )
  107. DO_XCODE_IOS_TESTS=no
  108. ;;
  109. --skip-xcode-osx | --skip-xcode-macos)
  110. DO_XCODE_OSX_TESTS=no
  111. ;;
  112. --skip-xcode-tvos )
  113. DO_XCODE_TVOS_TESTS=no
  114. ;;
  115. --skip-xcode-debug )
  116. DO_XCODE_DEBUG=no
  117. ;;
  118. --skip-xcode-release )
  119. DO_XCODE_RELEASE=no
  120. ;;
  121. --skip-objc-conformance )
  122. DO_OBJC_CONFORMANCE_TESTS=no
  123. ;;
  124. --xcode-quiet )
  125. XCODE_QUIET=yes
  126. ;;
  127. -*)
  128. echo "ERROR: Unknown option: ${1}" 1>&2
  129. printUsage
  130. exit 1
  131. ;;
  132. *)
  133. echo "ERROR: Unknown argument: ${1}" 1>&2
  134. printUsage
  135. exit 1
  136. ;;
  137. esac
  138. shift
  139. done
  140. # Into the proto dir.
  141. cd "${ProtoRootDir}"
  142. # if no Makefile, force the autogen.
  143. if [[ ! -f Makefile ]] ; then
  144. DO_AUTOGEN=yes
  145. fi
  146. if [[ "${DO_AUTOGEN}" == "yes" ]] ; then
  147. header "Running autogen & configure"
  148. ./autogen.sh
  149. ./configure \
  150. CPPFLAGS="-mmacosx-version-min=10.9 -Wunused-const-variable -Wunused-function"
  151. fi
  152. if [[ "${DO_CLEAN}" == "yes" ]] ; then
  153. header "Cleaning"
  154. wrapped_make clean
  155. if [[ "${DO_XCODE_IOS_TESTS}" == "yes" ]] ; then
  156. XCODEBUILD_CLEAN_BASE_IOS=(
  157. xcodebuild
  158. -project objectivec/ProtocolBuffers_iOS.xcodeproj
  159. -scheme ProtocolBuffers
  160. )
  161. if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
  162. "${XCODEBUILD_CLEAN_BASE_IOS[@]}" -configuration Debug clean
  163. fi
  164. if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
  165. "${XCODEBUILD_CLEAN_BASE_IOS[@]}" -configuration Release clean
  166. fi
  167. fi
  168. if [[ "${DO_XCODE_OSX_TESTS}" == "yes" ]] ; then
  169. XCODEBUILD_CLEAN_BASE_OSX=(
  170. xcodebuild
  171. -project objectivec/ProtocolBuffers_OSX.xcodeproj
  172. -scheme ProtocolBuffers
  173. )
  174. if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
  175. "${XCODEBUILD_CLEAN_BASE_OSX[@]}" -configuration Debug clean
  176. fi
  177. if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
  178. "${XCODEBUILD_CLEAN_BASE_OSX[@]}" -configuration Release clean
  179. fi
  180. fi
  181. if [[ "${DO_XCODE_TVOS_TESTS}" == "yes" ]] ; then
  182. XCODEBUILD_CLEAN_BASE_OSX=(
  183. xcodebuild
  184. -project objectivec/ProtocolBuffers_tvOS.xcodeproj
  185. -scheme ProtocolBuffers
  186. )
  187. if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
  188. "${XCODEBUILD_CLEAN_BASE_OSX[@]}" -configuration Debug clean
  189. fi
  190. if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
  191. "${XCODEBUILD_CLEAN_BASE_OSX[@]}" -configuration Release clean
  192. fi
  193. fi
  194. fi
  195. if [[ "${REGEN_DESCRIPTORS}" == "yes" ]] ; then
  196. header "Regenerating the descriptor sources."
  197. ./generate_descriptor_proto.sh -j "${NUM_MAKE_JOBS}"
  198. fi
  199. if [[ "${CORE_ONLY}" == "yes" ]] ; then
  200. header "Building core Only"
  201. wrapped_make -j "${NUM_MAKE_JOBS}"
  202. else
  203. header "Building"
  204. # Can't issue these together, when fully parallel, something sometimes chokes
  205. # at random.
  206. wrapped_make -j "${NUM_MAKE_JOBS}" all
  207. wrapped_make -j "${NUM_MAKE_JOBS}" check
  208. # Fire off the conformance tests also.
  209. cd conformance
  210. wrapped_make -j "${NUM_MAKE_JOBS}" test_cpp
  211. cd ..
  212. fi
  213. # Ensure the WKT sources checked in are current.
  214. objectivec/generate_well_known_types.sh --check-only -j "${NUM_MAKE_JOBS}"
  215. header "Checking on the ObjC Runtime Code"
  216. objectivec/DevTools/pddm_tests.py
  217. if ! objectivec/DevTools/pddm.py --dry-run objectivec/*.[hm] objectivec/Tests/*.[hm] ; then
  218. echo ""
  219. echo "Update by running:"
  220. echo " objectivec/DevTools/pddm.py objectivec/*.[hm] objectivec/Tests/*.[hm]"
  221. exit 1
  222. fi
  223. readonly XCODE_VERSION_LINE="$(xcodebuild -version | grep Xcode\ )"
  224. readonly XCODE_VERSION="${XCODE_VERSION_LINE/Xcode /}" # drop the prefix.
  225. if [[ "${DO_XCODE_IOS_TESTS}" == "yes" ]] ; then
  226. XCODEBUILD_TEST_BASE_IOS=(
  227. xcodebuild
  228. -project objectivec/ProtocolBuffers_iOS.xcodeproj
  229. -scheme ProtocolBuffers
  230. )
  231. if [[ "${XCODE_QUIET}" == "yes" ]] ; then
  232. XCODEBUILD_TEST_BASE_IOS+=( -quiet )
  233. fi
  234. # Don't need to worry about form factors or retina/non retina;
  235. # just pick a mix of OS Versions and 32/64 bit.
  236. # NOTE: Different Xcode have different simulated hardware/os support.
  237. case "${XCODE_VERSION}" in
  238. [6-8].* )
  239. echo "ERROR: The unittests include Swift code that is now Swift 4.0." 1>&2
  240. echo "ERROR: Xcode 9.0 or higher is required to build the test suite, but the library works with Xcode 7.x." 1>&2
  241. exit 11
  242. ;;
  243. 9.[0-2]* )
  244. XCODEBUILD_TEST_BASE_IOS+=(
  245. -destination "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
  246. -destination "platform=iOS Simulator,name=iPhone 7,OS=latest" # 64bit
  247. # 9.0-9.2 all seem to often fail running destinations in parallel
  248. -disable-concurrent-testing
  249. )
  250. ;;
  251. 9.[3-4]* )
  252. XCODEBUILD_TEST_BASE_IOS+=(
  253. # Xcode 9.3 chokes targeting iOS 8.x - http://www.openradar.me/39335367
  254. -destination "platform=iOS Simulator,name=iPhone 4s,OS=9.0" # 32bit
  255. -destination "platform=iOS Simulator,name=iPhone 7,OS=latest" # 64bit
  256. # 9.3 also seems to often fail running destinations in parallel
  257. -disable-concurrent-testing
  258. )
  259. ;;
  260. 10.*)
  261. XCODEBUILD_TEST_BASE_IOS+=(
  262. -destination "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
  263. -destination "platform=iOS Simulator,name=iPhone 7,OS=latest" # 64bit
  264. # 10.x also seems to often fail running destinations in parallel (with
  265. # 32bit one include at least)
  266. -disable-concurrent-destination-testing
  267. )
  268. ;;
  269. 11.* | 12.* | 13.*)
  270. # Dropped 32bit as Apple doesn't seem support the simulators either.
  271. XCODEBUILD_TEST_BASE_IOS+=(
  272. -destination "platform=iOS Simulator,name=iPhone 8,OS=latest" # 64bit
  273. )
  274. ;;
  275. * )
  276. echo ""
  277. echo "ATTENTION: Time to update the simulator targets for Xcode ${XCODE_VERSION}"
  278. echo ""
  279. echo "ERROR: Build aborted!"
  280. exit 2
  281. ;;
  282. esac
  283. if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
  284. header "Doing Xcode iOS build/tests - Debug"
  285. "${XCODEBUILD_TEST_BASE_IOS[@]}" -configuration Debug test
  286. fi
  287. if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
  288. header "Doing Xcode iOS build/tests - Release"
  289. "${XCODEBUILD_TEST_BASE_IOS[@]}" -configuration Release test
  290. fi
  291. # Don't leave the simulator in the developer's face.
  292. killall Simulator 2> /dev/null || true
  293. fi
  294. if [[ "${DO_XCODE_OSX_TESTS}" == "yes" ]] ; then
  295. XCODEBUILD_TEST_BASE_OSX=(
  296. xcodebuild
  297. -project objectivec/ProtocolBuffers_OSX.xcodeproj
  298. -scheme ProtocolBuffers
  299. # Since the ObjC 2.0 Runtime is required, 32bit OS X isn't supported.
  300. -destination "platform=OS X,arch=x86_64" # 64bit
  301. )
  302. if [[ "${XCODE_QUIET}" == "yes" ]] ; then
  303. XCODEBUILD_TEST_BASE_OSX+=( -quiet )
  304. fi
  305. case "${XCODE_VERSION}" in
  306. [6-8].* )
  307. echo "ERROR: The unittests include Swift code that is now Swift 4.0." 1>&2
  308. echo "ERROR: Xcode 9.0 or higher is required to build the test suite, but the library works with Xcode 7.x." 1>&2
  309. exit 11
  310. ;;
  311. esac
  312. if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
  313. header "Doing Xcode OS X build/tests - Debug"
  314. "${XCODEBUILD_TEST_BASE_OSX[@]}" -configuration Debug test
  315. fi
  316. if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
  317. header "Doing Xcode OS X build/tests - Release"
  318. "${XCODEBUILD_TEST_BASE_OSX[@]}" -configuration Release test
  319. fi
  320. fi
  321. if [[ "${DO_XCODE_TVOS_TESTS}" == "yes" ]] ; then
  322. XCODEBUILD_TEST_BASE_TVOS=(
  323. xcodebuild
  324. -project objectivec/ProtocolBuffers_tvOS.xcodeproj
  325. -scheme ProtocolBuffers
  326. )
  327. case "${XCODE_VERSION}" in
  328. [6-9].* )
  329. echo "ERROR: Xcode 10.0 or higher is required to build the test suite." 1>&2
  330. exit 11
  331. ;;
  332. 10.* | 11.* | 12.*)
  333. XCODEBUILD_TEST_BASE_TVOS+=(
  334. -destination "platform=tvOS Simulator,name=Apple TV 4K,OS=latest"
  335. )
  336. ;;
  337. 13.*)
  338. XCODEBUILD_TEST_BASE_TVOS+=(
  339. -destination "platform=tvOS Simulator,name=Apple TV 4K (2nd generation),OS=latest"
  340. )
  341. ;;
  342. * )
  343. echo ""
  344. echo "ATTENTION: Time to update the simulator targets for Xcode ${XCODE_VERSION}"
  345. echo ""
  346. echo "ERROR: Build aborted!"
  347. exit 2
  348. ;;
  349. esac
  350. if [[ "${XCODE_QUIET}" == "yes" ]] ; then
  351. XCODEBUILD_TEST_BASE_TVOS+=( -quiet )
  352. fi
  353. if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
  354. header "Doing Xcode tvOS build/tests - Debug"
  355. "${XCODEBUILD_TEST_BASE_TVOS[@]}" -configuration Debug test
  356. fi
  357. if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
  358. header "Doing Xcode tvOS build/tests - Release"
  359. "${XCODEBUILD_TEST_BASE_TVOS[@]}" -configuration Release test
  360. fi
  361. fi
  362. if [[ "${DO_OBJC_CONFORMANCE_TESTS}" == "yes" ]] ; then
  363. header "Running ObjC Conformance Tests"
  364. cd conformance
  365. wrapped_make -j "${NUM_MAKE_JOBS}" test_objc
  366. cd ..
  367. fi
  368. echo ""
  369. echo "$(basename "${0}"): Success!"