full_mac_build.sh 8.2 KB

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