full_mac_build.sh 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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-objc-conformance
  39. Skip the Objective C conformance tests (run on OS X).
  40. EOF
  41. }
  42. header() {
  43. echo ""
  44. echo "========================================================================"
  45. echo " ${@}"
  46. echo "========================================================================"
  47. }
  48. # Thanks to libtool, builds can fail in odd ways and since it eats some output
  49. # it can be hard to spot, so force error output if make exits with a non zero.
  50. wrapped_make() {
  51. set +e # Don't stop if the command fails.
  52. make $*
  53. MAKE_EXIT_STATUS=$?
  54. if [ ${MAKE_EXIT_STATUS} -ne 0 ]; then
  55. echo "Error: 'make $*' exited with status ${MAKE_EXIT_STATUS}"
  56. exit ${MAKE_EXIT_STATUS}
  57. fi
  58. set -e
  59. }
  60. NUM_MAKE_JOBS=$(/usr/sbin/sysctl -n hw.ncpu)
  61. if [[ "${NUM_MAKE_JOBS}" -lt 2 ]] ; then
  62. NUM_MAKE_JOBS=2
  63. fi
  64. DO_AUTOGEN=no
  65. DO_CLEAN=no
  66. REGEN_DESCRIPTORS=no
  67. CORE_ONLY=no
  68. DO_XCODE_IOS_TESTS=yes
  69. DO_XCODE_OSX_TESTS=yes
  70. DO_XCODE_DEBUG=yes
  71. DO_XCODE_RELEASE=yes
  72. DO_OBJC_CONFORMANCE_TESTS=yes
  73. while [[ $# != 0 ]]; do
  74. case "${1}" in
  75. -h | --help )
  76. printUsage
  77. exit 0
  78. ;;
  79. -c | --clean )
  80. DO_CLEAN=yes
  81. ;;
  82. -a | --autogen )
  83. DO_AUTOGEN=yes
  84. ;;
  85. -r | --regenerate-descriptors )
  86. REGEN_DESCRIPTORS=yes
  87. ;;
  88. -j | --jobs )
  89. shift
  90. NUM_MAKE_JOBS="${1}"
  91. ;;
  92. --core-only )
  93. CORE_ONLY=yes
  94. ;;
  95. --skip-xcode )
  96. DO_XCODE_IOS_TESTS=no
  97. DO_XCODE_OSX_TESTS=no
  98. ;;
  99. --skip-xcode-ios )
  100. DO_XCODE_IOS_TESTS=no
  101. ;;
  102. --skip-xcode-osx )
  103. DO_XCODE_OSX_TESTS=no
  104. ;;
  105. --skip-xcode-debug )
  106. DO_XCODE_DEBUG=no
  107. ;;
  108. --skip-xcode-release )
  109. DO_XCODE_RELEASE=no
  110. ;;
  111. --skip-objc-conformance )
  112. DO_OBJC_CONFORMANCE_TESTS=no
  113. ;;
  114. -*)
  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
  126. done
  127. # Into the proto dir.
  128. cd "${ProtoRootDir}"
  129. # if no Makefile, force the autogen.
  130. if [[ ! -f Makefile ]] ; then
  131. DO_AUTOGEN=yes
  132. fi
  133. if [[ "${DO_AUTOGEN}" == "yes" ]] ; then
  134. header "Running autogen & configure"
  135. ./autogen.sh
  136. ./configure \
  137. CPPFLAGS="-mmacosx-version-min=10.9 -Wunused-const-variable -Wunused-function" \
  138. CXXFLAGS="-Wnon-virtual-dtor -Woverloaded-virtual"
  139. fi
  140. if [[ "${DO_CLEAN}" == "yes" ]] ; then
  141. header "Cleaning"
  142. wrapped_make clean
  143. if [[ "${DO_XCODE_IOS_TESTS}" == "yes" ]] ; then
  144. XCODEBUILD_CLEAN_BASE_IOS=(
  145. xcodebuild
  146. -project objectivec/ProtocolBuffers_iOS.xcodeproj
  147. -scheme ProtocolBuffers
  148. )
  149. if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
  150. "${XCODEBUILD_CLEAN_BASE_IOS[@]}" -configuration Debug clean
  151. fi
  152. if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
  153. "${XCODEBUILD_CLEAN_BASE_IOS[@]}" -configuration Release clean
  154. fi
  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. if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
  163. "${XCODEBUILD_CLEAN_BASE_OSX[@]}" -configuration Debug clean
  164. fi
  165. if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
  166. "${XCODEBUILD_CLEAN_BASE_OSX[@]}" -configuration Release clean
  167. fi
  168. fi
  169. fi
  170. if [[ "${REGEN_DESCRIPTORS}" == "yes" ]] ; then
  171. header "Regenerating the descriptor sources."
  172. ./generate_descriptor_proto.sh -j "${NUM_MAKE_JOBS}"
  173. fi
  174. if [[ "${CORE_ONLY}" == "yes" ]] ; then
  175. header "Building core Only"
  176. wrapped_make -j "${NUM_MAKE_JOBS}"
  177. else
  178. header "Building"
  179. # Can't issue these together, when fully parallel, something sometimes chokes
  180. # at random.
  181. wrapped_make -j "${NUM_MAKE_JOBS}" all
  182. wrapped_make -j "${NUM_MAKE_JOBS}" check
  183. # Fire off the conformance tests also.
  184. cd conformance
  185. wrapped_make -j "${NUM_MAKE_JOBS}" test_cpp
  186. cd ..
  187. fi
  188. # Ensure the WKT sources checked in are current.
  189. objectivec/generate_well_known_types.sh --check-only -j "${NUM_MAKE_JOBS}"
  190. header "Checking on the ObjC Runtime Code"
  191. objectivec/DevTools/pddm_tests.py
  192. if ! objectivec/DevTools/pddm.py --dry-run objectivec/*.[hm] objectivec/Tests/*.[hm] ; then
  193. echo ""
  194. echo "Update by running:"
  195. echo " objectivec/DevTools/pddm.py objectivec/*.[hm] objectivec/Tests/*.[hm]"
  196. exit 1
  197. fi
  198. if [[ "${DO_XCODE_IOS_TESTS}" == "yes" ]] ; then
  199. XCODEBUILD_TEST_BASE_IOS=(
  200. xcodebuild
  201. -project objectivec/ProtocolBuffers_iOS.xcodeproj
  202. -scheme ProtocolBuffers
  203. )
  204. # Don't need to worry about form factors or retina/non retina;
  205. # just pick a mix of OS Versions and 32/64 bit.
  206. # NOTE: Different Xcode have different simulated hardware/os support.
  207. readonly XCODE_VERSION_LINE="$(xcodebuild -version | grep Xcode\ )"
  208. readonly XCODE_VERSION="${XCODE_VERSION_LINE/Xcode /}" # drop the prefix.
  209. IOS_SIMULATOR_NAME="Simulator"
  210. case "${XCODE_VERSION}" in
  211. 6.* )
  212. echo "ERROR: Xcode 6.3/6.4 no longer supported for building, please use 7.0 or higher." 1>&2
  213. exit 10
  214. ;;
  215. 7.1* )
  216. XCODEBUILD_TEST_BASE_IOS+=(
  217. -destination "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
  218. -destination "platform=iOS Simulator,name=iPhone 6,OS=9.0" # 64bit
  219. -destination "platform=iOS Simulator,name=iPad 2,OS=8.1" # 32bit
  220. -destination "platform=iOS Simulator,name=iPad Air,OS=9.0" # 64bit
  221. )
  222. ;;
  223. 7.2* )
  224. XCODEBUILD_TEST_BASE_IOS+=(
  225. -destination "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
  226. -destination "platform=iOS Simulator,name=iPhone 6,OS=9.2" # 64bit
  227. -destination "platform=iOS Simulator,name=iPad 2,OS=8.1" # 32bit
  228. -destination "platform=iOS Simulator,name=iPad Air,OS=9.2" # 64bit
  229. )
  230. ;;
  231. 7.3* )
  232. XCODEBUILD_TEST_BASE_IOS+=(
  233. -destination "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
  234. -destination "platform=iOS Simulator,name=iPhone 6,OS=9.3" # 64bit
  235. -destination "platform=iOS Simulator,name=iPad 2,OS=8.1" # 32bit
  236. -destination "platform=iOS Simulator,name=iPad Air,OS=9.3" # 64bit
  237. )
  238. ;;
  239. * )
  240. echo "Time to update the simulator targets for Xcode ${XCODE_VERSION}"
  241. exit 2
  242. ;;
  243. esac
  244. if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
  245. header "Doing Xcode iOS build/tests - Debug"
  246. "${XCODEBUILD_TEST_BASE_IOS[@]}" -configuration Debug test
  247. fi
  248. if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
  249. header "Doing Xcode iOS build/tests - Release"
  250. "${XCODEBUILD_TEST_BASE_IOS[@]}" -configuration Release test
  251. fi
  252. # Don't leave the simulator in the developer's face.
  253. killall "${IOS_SIMULATOR_NAME}"
  254. fi
  255. if [[ "${DO_XCODE_OSX_TESTS}" == "yes" ]] ; then
  256. XCODEBUILD_TEST_BASE_OSX=(
  257. xcodebuild
  258. -project objectivec/ProtocolBuffers_OSX.xcodeproj
  259. -scheme ProtocolBuffers
  260. # Since the ObjC 2.0 Runtime is required, 32bit OS X isn't supported.
  261. -destination "platform=OS X,arch=x86_64" # 64bit
  262. )
  263. if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
  264. header "Doing Xcode OS X build/tests - Debug"
  265. "${XCODEBUILD_TEST_BASE_OSX[@]}" -configuration Debug test
  266. fi
  267. if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
  268. header "Doing Xcode OS X build/tests - Release"
  269. "${XCODEBUILD_TEST_BASE_OSX[@]}" -configuration Release test
  270. fi
  271. fi
  272. if [[ "${DO_OBJC_CONFORMANCE_TESTS}" == "yes" ]] ; then
  273. header "Running ObjC Conformance Tests"
  274. cd conformance
  275. wrapped_make -j "${NUM_MAKE_JOBS}" test_objc
  276. cd ..
  277. fi