travis.sh 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. build_golang() {
  42. # Go build needs `protoc`.
  43. internal_build_cpp
  44. # Add protoc to the path so that the examples build finds it.
  45. export PATH="`pwd`/src:$PATH"
  46. # Install Go and the Go protobuf compiler plugin.
  47. sudo apt-get update -qq
  48. sudo apt-get install -qq golang
  49. export GOPATH="$HOME/gocode"
  50. mkdir -p "$GOPATH/src/github.com/google"
  51. ln -s "`pwd`" "$GOPATH/src/github.com/google/protobuf"
  52. export PATH="$GOPATH/bin:$PATH"
  53. go get github.com/golang/protobuf/protoc-gen-go
  54. cd examples && make gotest && cd ..
  55. }
  56. use_java() {
  57. version=$1
  58. case "$version" in
  59. jdk6)
  60. sudo apt-get install openjdk-6-jdk
  61. export PATH=/usr/lib/jvm/java-6-openjdk-amd64/bin:$PATH
  62. ;;
  63. jdk7)
  64. sudo apt-get install openjdk-7-jdk
  65. export PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH
  66. ;;
  67. oracle7)
  68. sudo apt-get install python-software-properties # for apt-add-repository
  69. echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 select true" | \
  70. sudo debconf-set-selections
  71. yes | sudo apt-add-repository ppa:webupd8team/java
  72. yes | sudo apt-get install oracle-java7-installer
  73. export PATH=/usr/lib/jvm/java-7-oracle/bin:$PATH
  74. ;;
  75. esac
  76. which java
  77. java -version
  78. }
  79. build_java() {
  80. # Java build needs `protoc`.
  81. internal_build_cpp
  82. cd java && mvn test && cd ..
  83. cd conformance && make test_java && cd ..
  84. }
  85. build_javanano() {
  86. # Java build needs `protoc`.
  87. internal_build_cpp
  88. cd javanano && mvn test && cd ..
  89. }
  90. build_java_jdk6() {
  91. use_java jdk6
  92. build_java
  93. }
  94. build_java_jdk7() {
  95. use_java jdk7
  96. build_java
  97. }
  98. build_java_oracle7() {
  99. use_java oracle7
  100. build_java
  101. }
  102. build_javanano_jdk6() {
  103. use_java jdk6
  104. build_javanano
  105. }
  106. build_javanano_jdk7() {
  107. use_java jdk7
  108. build_javanano
  109. }
  110. build_javanano_oracle7() {
  111. use_java oracle7
  112. build_javanano
  113. }
  114. internal_install_python_deps() {
  115. # Install tox (OS X doesn't have pip).
  116. if [ $(uname -s) == "Darwin" ]; then
  117. sudo easy_install tox
  118. else
  119. sudo pip install tox
  120. fi
  121. # Only install Python2.6/3.x on Linux.
  122. if [ $(uname -s) == "Linux" ]; then
  123. sudo apt-get install -y python-software-properties # for apt-add-repository
  124. sudo apt-add-repository -y ppa:fkrull/deadsnakes
  125. sudo apt-get update -qq
  126. sudo apt-get install -y python2.6 python2.6-dev
  127. sudo apt-get install -y python3.3 python3.3-dev
  128. sudo apt-get install -y python3.4 python3.4-dev
  129. fi
  130. }
  131. internal_objectivec_common () {
  132. # Make sure xctool is up to date. Adapted from
  133. # http://docs.travis-ci.com/user/osx-ci-environment/
  134. # We don't use a before_install because we test multiple OSes.
  135. brew update
  136. brew outdated xctool || brew upgrade xctool
  137. # Reused the build script that takes care of configuring and ensuring things
  138. # are up to date. Xcode and conformance tests will be directly invoked.
  139. objectivec/DevTools/full_mac_build.sh \
  140. --core-only --skip-xcode --skip-objc-conformance
  141. }
  142. internal_xctool_debug_and_release() {
  143. xctool -configuration Debug "$@"
  144. xctool -configuration Release "$@"
  145. }
  146. build_objectivec_ios() {
  147. internal_objectivec_common
  148. # https://github.com/facebook/xctool/issues/509 - unlike xcodebuild, xctool
  149. # doesn't support >1 destination, so we have to build first and then run the
  150. # tests one destination at a time.
  151. internal_xctool_debug_and_release \
  152. -project objectivec/ProtocolBuffers_iOS.xcodeproj \
  153. -scheme ProtocolBuffers \
  154. -sdk iphonesimulator \
  155. build-tests
  156. IOS_DESTINATIONS=(
  157. "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
  158. "platform=iOS Simulator,name=iPhone 6,OS=9.1" # 64bit
  159. "platform=iOS Simulator,name=iPad 2,OS=8.1" # 32bit
  160. "platform=iOS Simulator,name=iPad Air,OS=9.1" # 64bit
  161. )
  162. for i in "${IOS_DESTINATIONS[@]}" ; do
  163. internal_xctool_debug_and_release \
  164. -project objectivec/ProtocolBuffers_iOS.xcodeproj \
  165. -scheme ProtocolBuffers \
  166. -sdk iphonesimulator \
  167. -destination "${i}" \
  168. run-tests
  169. done
  170. }
  171. build_objectivec_osx() {
  172. internal_objectivec_common
  173. internal_xctool_debug_and_release \
  174. -project objectivec/ProtocolBuffers_OSX.xcodeproj \
  175. -scheme ProtocolBuffers \
  176. -destination "platform=OS X,arch=x86_64" \
  177. test
  178. cd conformance && make test_objc && cd ..
  179. }
  180. build_python() {
  181. internal_build_cpp
  182. internal_install_python_deps
  183. cd python
  184. # Only test Python 2.6/3.x on Linux
  185. if [ $(uname -s) == "Linux" ]; then
  186. envlist=py\{26,27,33,34\}-python
  187. else
  188. envlist=py27-python
  189. fi
  190. tox -e $envlist
  191. cd ..
  192. }
  193. build_python_cpp() {
  194. internal_build_cpp
  195. internal_install_python_deps
  196. export LD_LIBRARY_PATH=../src/.libs # for Linux
  197. export DYLD_LIBRARY_PATH=../src/.libs # for OS X
  198. cd python
  199. # Only test Python 2.6/3.x on Linux
  200. if [ $(uname -s) == "Linux" ]; then
  201. # py26 is currently disabled due to json_format
  202. envlist=py\{27,33,34\}-cpp
  203. else
  204. envlist=py27-cpp
  205. fi
  206. tox -e $envlist
  207. cd ..
  208. }
  209. build_ruby19() {
  210. internal_build_cpp # For conformance tests.
  211. cd ruby && bash travis-test.sh ruby-1.9 && cd ..
  212. }
  213. build_ruby20() {
  214. internal_build_cpp # For conformance tests.
  215. cd ruby && bash travis-test.sh ruby-2.0 && cd ..
  216. }
  217. build_ruby21() {
  218. internal_build_cpp # For conformance tests.
  219. cd ruby && bash travis-test.sh ruby-2.1 && cd ..
  220. }
  221. build_ruby22() {
  222. internal_build_cpp # For conformance tests.
  223. cd ruby && bash travis-test.sh ruby-2.2 && cd ..
  224. }
  225. build_jruby() {
  226. internal_build_cpp # For conformance tests.
  227. cd ruby && bash travis-test.sh jruby && cd ..
  228. }
  229. # -------- main --------
  230. if [ "$#" -ne 1 ]; then
  231. echo "
  232. Usage: $0 { cpp |
  233. csharp |
  234. java_jdk6 |
  235. java_jdk7 |
  236. java_oracle7 |
  237. javanano_jdk6 |
  238. javanano_jdk7 |
  239. javanano_oracle7 |
  240. objectivec_ios |
  241. objectivec_osx |
  242. python |
  243. python_cpp |
  244. ruby_19 |
  245. ruby_20 |
  246. ruby_21 |
  247. ruby_22 |
  248. jruby }
  249. "
  250. exit 1
  251. fi
  252. set -e # exit immediately on error
  253. set -x # display all commands
  254. eval "build_$1"