full_mac_build.sh 7.8 KB

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