full_mac_build.sh 7.9 KB

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