full_mac_build.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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
  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 )
  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. CXXFLAGS="-Wnon-virtual-dtor -Woverloaded-virtual"
  152. fi
  153. if [[ "${DO_CLEAN}" == "yes" ]] ; then
  154. header "Cleaning"
  155. wrapped_make clean
  156. if [[ "${DO_XCODE_IOS_TESTS}" == "yes" ]] ; then
  157. XCODEBUILD_CLEAN_BASE_IOS=(
  158. xcodebuild
  159. -project objectivec/ProtocolBuffers_iOS.xcodeproj
  160. -scheme ProtocolBuffers
  161. )
  162. if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
  163. "${XCODEBUILD_CLEAN_BASE_IOS[@]}" -configuration Debug clean
  164. fi
  165. if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
  166. "${XCODEBUILD_CLEAN_BASE_IOS[@]}" -configuration Release clean
  167. fi
  168. fi
  169. if [[ "${DO_XCODE_OSX_TESTS}" == "yes" ]] ; then
  170. XCODEBUILD_CLEAN_BASE_OSX=(
  171. xcodebuild
  172. -project objectivec/ProtocolBuffers_OSX.xcodeproj
  173. -scheme ProtocolBuffers
  174. )
  175. if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
  176. "${XCODEBUILD_CLEAN_BASE_OSX[@]}" -configuration Debug clean
  177. fi
  178. if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
  179. "${XCODEBUILD_CLEAN_BASE_OSX[@]}" -configuration Release clean
  180. fi
  181. fi
  182. if [[ "${DO_XCODE_TVOS_TESTS}" == "yes" ]] ; then
  183. XCODEBUILD_CLEAN_BASE_OSX=(
  184. xcodebuild
  185. -project objectivec/ProtocolBuffers_tvOS.xcodeproj
  186. -scheme ProtocolBuffers
  187. )
  188. if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
  189. "${XCODEBUILD_CLEAN_BASE_OSX[@]}" -configuration Debug clean
  190. fi
  191. if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
  192. "${XCODEBUILD_CLEAN_BASE_OSX[@]}" -configuration Release clean
  193. fi
  194. fi
  195. fi
  196. if [[ "${REGEN_DESCRIPTORS}" == "yes" ]] ; then
  197. header "Regenerating the descriptor sources."
  198. ./generate_descriptor_proto.sh -j "${NUM_MAKE_JOBS}"
  199. fi
  200. if [[ "${CORE_ONLY}" == "yes" ]] ; then
  201. header "Building core Only"
  202. wrapped_make -j "${NUM_MAKE_JOBS}"
  203. else
  204. header "Building"
  205. # Can't issue these together, when fully parallel, something sometimes chokes
  206. # at random.
  207. wrapped_make -j "${NUM_MAKE_JOBS}" all
  208. wrapped_make -j "${NUM_MAKE_JOBS}" check
  209. # Fire off the conformance tests also.
  210. cd conformance
  211. wrapped_make -j "${NUM_MAKE_JOBS}" test_cpp
  212. cd ..
  213. fi
  214. # Ensure the WKT sources checked in are current.
  215. objectivec/generate_well_known_types.sh --check-only -j "${NUM_MAKE_JOBS}"
  216. header "Checking on the ObjC Runtime Code"
  217. objectivec/DevTools/pddm_tests.py
  218. if ! objectivec/DevTools/pddm.py --dry-run objectivec/*.[hm] objectivec/Tests/*.[hm] ; then
  219. echo ""
  220. echo "Update by running:"
  221. echo " objectivec/DevTools/pddm.py objectivec/*.[hm] objectivec/Tests/*.[hm]"
  222. exit 1
  223. fi
  224. readonly XCODE_VERSION_LINE="$(xcodebuild -version | grep Xcode\ )"
  225. readonly XCODE_VERSION="${XCODE_VERSION_LINE/Xcode /}" # drop the prefix.
  226. if [[ "${DO_XCODE_IOS_TESTS}" == "yes" ]] ; then
  227. XCODEBUILD_TEST_BASE_IOS=(
  228. xcodebuild
  229. -project objectivec/ProtocolBuffers_iOS.xcodeproj
  230. -scheme ProtocolBuffers
  231. )
  232. if [[ "${XCODE_QUIET}" == "yes" ]] ; then
  233. XCODEBUILD_TEST_BASE_IOS+=( -quiet )
  234. fi
  235. # Don't need to worry about form factors or retina/non retina;
  236. # just pick a mix of OS Versions and 32/64 bit.
  237. # NOTE: Different Xcode have different simulated hardware/os support.
  238. case "${XCODE_VERSION}" in
  239. [6-8].* )
  240. echo "ERROR: The unittests include Swift code that is now Swift 4.0." 1>&2
  241. echo "ERROR: Xcode 9.0 or higher is required to build the test suite, but the library works with Xcode 7.x." 1>&2
  242. exit 11
  243. ;;
  244. 9.[0-2]* )
  245. XCODEBUILD_TEST_BASE_IOS+=(
  246. -destination "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
  247. -destination "platform=iOS Simulator,name=iPhone 7,OS=latest" # 64bit
  248. # 9.0-9.2 all seem to often fail running destinations in parallel
  249. -disable-concurrent-testing
  250. )
  251. ;;
  252. 9.[3-4]* )
  253. XCODEBUILD_TEST_BASE_IOS+=(
  254. # Xcode 9.3 chokes targeting iOS 8.x - http://www.openradar.me/39335367
  255. -destination "platform=iOS Simulator,name=iPhone 4s,OS=9.0" # 32bit
  256. -destination "platform=iOS Simulator,name=iPhone 7,OS=latest" # 64bit
  257. # 9.3 also seems to often fail running destinations in parallel
  258. -disable-concurrent-testing
  259. )
  260. ;;
  261. 10.[0-1]* )
  262. XCODEBUILD_TEST_BASE_IOS+=(
  263. -destination "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
  264. -destination "platform=iOS Simulator,name=iPhone 7,OS=latest" # 64bit
  265. # 10.x also seems to often fail running destinations in parallel (with
  266. # 32bit one include atleast)
  267. -disable-concurrent-destination-testing
  268. )
  269. ;;
  270. * )
  271. echo ""
  272. echo "ATTENTION: Time to update the simulator targets for Xcode ${XCODE_VERSION}"
  273. echo ""
  274. echo "ERROR: Build aborted!"
  275. exit 2
  276. ;;
  277. esac
  278. if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
  279. header "Doing Xcode iOS build/tests - Debug"
  280. "${XCODEBUILD_TEST_BASE_IOS[@]}" -configuration Debug test
  281. fi
  282. if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
  283. header "Doing Xcode iOS build/tests - Release"
  284. "${XCODEBUILD_TEST_BASE_IOS[@]}" -configuration Release test
  285. fi
  286. # Don't leave the simulator in the developer's face.
  287. killall Simulator 2> /dev/null || true
  288. fi
  289. if [[ "${DO_XCODE_OSX_TESTS}" == "yes" ]] ; then
  290. XCODEBUILD_TEST_BASE_OSX=(
  291. xcodebuild
  292. -project objectivec/ProtocolBuffers_OSX.xcodeproj
  293. -scheme ProtocolBuffers
  294. # Since the ObjC 2.0 Runtime is required, 32bit OS X isn't supported.
  295. -destination "platform=OS X,arch=x86_64" # 64bit
  296. )
  297. if [[ "${XCODE_QUIET}" == "yes" ]] ; then
  298. XCODEBUILD_TEST_BASE_OSX+=( -quiet )
  299. fi
  300. case "${XCODE_VERSION}" in
  301. [6-8].* )
  302. echo "ERROR: The unittests include Swift code that is now Swift 4.0." 1>&2
  303. echo "ERROR: Xcode 9.0 or higher is required to build the test suite, but the library works with Xcode 7.x." 1>&2
  304. exit 11
  305. ;;
  306. esac
  307. if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
  308. header "Doing Xcode OS X build/tests - Debug"
  309. "${XCODEBUILD_TEST_BASE_OSX[@]}" -configuration Debug test
  310. fi
  311. if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
  312. header "Doing Xcode OS X build/tests - Release"
  313. "${XCODEBUILD_TEST_BASE_OSX[@]}" -configuration Release test
  314. fi
  315. fi
  316. if [[ "${DO_XCODE_TVOS_TESTS}" == "yes" ]] ; then
  317. XCODEBUILD_TEST_BASE_TVOS=(
  318. xcodebuild
  319. -project objectivec/ProtocolBuffers_tvOS.xcodeproj
  320. -scheme ProtocolBuffers
  321. # Test on the oldest and current.
  322. -destination "platform=tvOS Simulator,name=Apple TV 1080p,OS=9.0"
  323. -destination "platform=tvOS Simulator,name=Apple TV,OS=latest"
  324. )
  325. if [[ "${XCODE_QUIET}" == "yes" ]] ; then
  326. XCODEBUILD_TEST_BASE_TVOS+=( -quiet )
  327. fi
  328. if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
  329. header "Doing Xcode tvOS build/tests - Debug"
  330. "${XCODEBUILD_TEST_BASE_TVOS[@]}" -configuration Debug test
  331. fi
  332. if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
  333. header "Doing Xcode tvOS build/tests - Release"
  334. "${XCODEBUILD_TEST_BASE_TVOS[@]}" -configuration Release test
  335. fi
  336. fi
  337. if [[ "${DO_OBJC_CONFORMANCE_TESTS}" == "yes" ]] ; then
  338. header "Running ObjC Conformance Tests"
  339. cd conformance
  340. wrapped_make -j "${NUM_MAKE_JOBS}" test_objc
  341. cd ..
  342. fi
  343. echo ""
  344. echo "$(basename "${0}"): Success!"