full_mac_build.sh 6.7 KB

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