travis.sh 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. #!/usr/bin/env bash
  2. # Note: travis currently does not support testing more than one language so the
  3. # .travis.yml cheats and claims to only be cpp. If they add multiple language
  4. # support, this should probably get updated to install steps and/or
  5. # rvm/gemfile/jdk/etc. entries rather than manually doing the work.
  6. # .travis.yml uses matrix.exclude to block the cases where app-get can't be
  7. # use to install things.
  8. # For when some other test needs the C++ main build, including protoc and
  9. # libprotobuf.
  10. internal_build_cpp() {
  11. ./autogen.sh
  12. ./configure
  13. make -j2
  14. }
  15. build_cpp() {
  16. internal_build_cpp
  17. make check -j2
  18. cd conformance && make test_cpp && cd ..
  19. }
  20. build_cpp_distcheck() {
  21. ./autogen.sh
  22. ./configure
  23. make distcheck -j2
  24. }
  25. build_csharp() {
  26. # Just for the conformance tests. We don't currently
  27. # need to really build protoc, but it's simplest to keep with the
  28. # conventions of the other builds.
  29. internal_build_cpp
  30. # Install latest version of Mono
  31. sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
  32. echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
  33. echo "deb http://download.mono-project.com/repo/debian wheezy-libtiff-compat main" | sudo tee -a /etc/apt/sources.list.d/mono-xamarin.list
  34. sudo apt-get update -qq
  35. sudo apt-get install -qq mono-devel referenceassemblies-pcl nunit
  36. wget www.nuget.org/NuGet.exe -O nuget.exe
  37. (cd csharp/src; mono ../../nuget.exe restore)
  38. csharp/buildall.sh
  39. cd conformance && make test_csharp && cd ..
  40. }
  41. use_java() {
  42. version=$1
  43. case "$version" in
  44. jdk6)
  45. sudo apt-get install openjdk-6-jdk
  46. export PATH=/usr/lib/jvm/java-6-openjdk-amd64/bin:$PATH
  47. ;;
  48. jdk7)
  49. sudo apt-get install openjdk-7-jdk
  50. export PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH
  51. ;;
  52. oracle7)
  53. sudo apt-get install python-software-properties # for apt-add-repository
  54. echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 select true" | \
  55. sudo debconf-set-selections
  56. yes | sudo apt-add-repository ppa:webupd8team/java
  57. yes | sudo apt-get install oracle-java7-installer
  58. export PATH=/usr/lib/jvm/java-7-oracle/bin:$PATH
  59. ;;
  60. esac
  61. which java
  62. java -version
  63. }
  64. build_java() {
  65. # Java build needs `protoc`.
  66. internal_build_cpp
  67. cd java && mvn test && cd ..
  68. cd conformance && make test_java && cd ..
  69. }
  70. build_javanano() {
  71. # Java build needs `protoc`.
  72. internal_build_cpp
  73. cd javanano && mvn test && cd ..
  74. }
  75. build_java_jdk6() {
  76. use_java jdk6
  77. build_java
  78. }
  79. build_java_jdk7() {
  80. use_java jdk7
  81. build_java
  82. }
  83. build_java_oracle7() {
  84. use_java oracle7
  85. build_java
  86. }
  87. build_javanano_jdk6() {
  88. use_java jdk6
  89. build_javanano
  90. }
  91. build_javanano_jdk7() {
  92. use_java jdk7
  93. build_javanano
  94. }
  95. build_javanano_oracle7() {
  96. use_java oracle7
  97. build_javanano
  98. }
  99. internal_install_python_deps() {
  100. # Install tox (OS X doesn't have pip).
  101. if [ $(uname -s) == "Darwin" ]; then
  102. sudo easy_install tox
  103. else
  104. sudo pip install tox
  105. fi
  106. # Only install Python2.6/3.x on Linux.
  107. if [ $(uname -s) == "Linux" ]; then
  108. sudo apt-get install -y python-software-properties # for apt-add-repository
  109. sudo apt-add-repository -y ppa:fkrull/deadsnakes
  110. sudo apt-get update -qq
  111. sudo apt-get install -y python2.6 python2.6-dev
  112. sudo apt-get install -y python3.3 python3.3-dev
  113. sudo apt-get install -y python3.4 python3.4-dev
  114. fi
  115. }
  116. internal_objectivec_common () {
  117. # Make sure xctool is up to date. Adapted from
  118. # http://docs.travis-ci.com/user/osx-ci-environment/
  119. # We don't use a before_install because we test multiple OSes.
  120. brew update
  121. brew outdated xctool || brew upgrade xctool
  122. # Reused the build script that takes care of configuring and ensuring things
  123. # are up to date. Xcode and conformance tests will be directly invoked.
  124. objectivec/DevTools/full_mac_build.sh \
  125. --core-only --skip-xcode --skip-objc-conformance
  126. }
  127. internal_xctool_debug_and_release() {
  128. xctool -configuration Debug "$@"
  129. xctool -configuration Release "$@"
  130. }
  131. build_objectivec_ios() {
  132. internal_objectivec_common
  133. # https://github.com/facebook/xctool/issues/509 - unlike xcodebuild, xctool
  134. # doesn't support >1 destination, so we have to build first and then run the
  135. # tests one destination at a time.
  136. internal_xctool_debug_and_release \
  137. -project objectivec/ProtocolBuffers_iOS.xcodeproj \
  138. -scheme ProtocolBuffers \
  139. -sdk iphonesimulator \
  140. build-tests
  141. IOS_DESTINATIONS=(
  142. "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
  143. "platform=iOS Simulator,name=iPhone 6,OS=9.1" # 64bit
  144. "platform=iOS Simulator,name=iPad 2,OS=8.1" # 32bit
  145. "platform=iOS Simulator,name=iPad Air,OS=9.1" # 64bit
  146. )
  147. for i in "${IOS_DESTINATIONS[@]}" ; do
  148. internal_xctool_debug_and_release \
  149. -project objectivec/ProtocolBuffers_iOS.xcodeproj \
  150. -scheme ProtocolBuffers \
  151. -sdk iphonesimulator \
  152. -destination "${i}" \
  153. run-tests
  154. done
  155. }
  156. build_objectivec_osx() {
  157. internal_objectivec_common
  158. internal_xctool_debug_and_release \
  159. -project objectivec/ProtocolBuffers_OSX.xcodeproj \
  160. -scheme ProtocolBuffers \
  161. -destination "platform=OS X,arch=x86_64" \
  162. test
  163. cd conformance && make test_objc && cd ..
  164. }
  165. build_python() {
  166. internal_build_cpp
  167. internal_install_python_deps
  168. cd python
  169. # Only test Python 2.6/3.x on Linux
  170. if [ $(uname -s) == "Linux" ]; then
  171. envlist=py\{26,27,33,34\}-python
  172. else
  173. envlist=py27-python
  174. fi
  175. tox -e $envlist
  176. cd ..
  177. }
  178. build_python_cpp() {
  179. internal_build_cpp
  180. internal_install_python_deps
  181. export LD_LIBRARY_PATH=../src/.libs # for Linux
  182. export DYLD_LIBRARY_PATH=../src/.libs # for OS X
  183. cd python
  184. # Only test Python 2.6/3.x on Linux
  185. if [ $(uname -s) == "Linux" ]; then
  186. # py26 is currently disabled due to json_format
  187. envlist=py\{27,33,34\}-cpp
  188. else
  189. envlist=py27-cpp
  190. fi
  191. tox -e $envlist
  192. cd ..
  193. }
  194. build_ruby19() {
  195. internal_build_cpp # For conformance tests.
  196. cd ruby && bash travis-test.sh ruby-1.9 && cd ..
  197. }
  198. build_ruby20() {
  199. internal_build_cpp # For conformance tests.
  200. cd ruby && bash travis-test.sh ruby-2.0 && cd ..
  201. }
  202. build_ruby21() {
  203. internal_build_cpp # For conformance tests.
  204. cd ruby && bash travis-test.sh ruby-2.1 && cd ..
  205. }
  206. build_ruby22() {
  207. internal_build_cpp # For conformance tests.
  208. cd ruby && bash travis-test.sh ruby-2.2 && cd ..
  209. }
  210. build_jruby() {
  211. internal_build_cpp # For conformance tests.
  212. cd ruby && bash travis-test.sh jruby && cd ..
  213. }
  214. # -------- main --------
  215. if [ "$#" -ne 1 ]; then
  216. echo "
  217. Usage: $0 { cpp |
  218. csharp |
  219. java_jdk6 |
  220. java_jdk7 |
  221. java_oracle7 |
  222. javanano_jdk6 |
  223. javanano_jdk7 |
  224. javanano_oracle7 |
  225. objectivec_ios |
  226. objectivec_osx |
  227. python |
  228. python_cpp |
  229. ruby_19 |
  230. ruby_20 |
  231. ruby_21 |
  232. ruby_22 |
  233. jruby }
  234. "
  235. exit 1
  236. fi
  237. set -e # exit immediately on error
  238. set -x # display all commands
  239. eval "build_$1"