travis.sh 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. if [ $(uname -s) == "Linux" ]; then
  12. # Install GCC 4.8 to replace the default GCC 4.6. We need 4.8 for more
  13. # decent C++ 11 support in order to compile conformance tests.
  14. sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
  15. sudo apt-get update -qq
  16. sudo apt-get install -qq g++-4.8
  17. export CXX="g++-4.8" CC="gcc-4.8"
  18. fi
  19. ./autogen.sh
  20. ./configure
  21. make -j2
  22. }
  23. build_cpp() {
  24. internal_build_cpp
  25. make check -j2
  26. cd conformance && make test_cpp && cd ..
  27. }
  28. build_cpp_distcheck() {
  29. ./autogen.sh
  30. ./configure
  31. make distcheck -j2
  32. }
  33. build_csharp() {
  34. # Just for the conformance tests. We don't currently
  35. # need to really build protoc, but it's simplest to keep with the
  36. # conventions of the other builds.
  37. internal_build_cpp
  38. # Install latest version of Mono
  39. sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
  40. echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
  41. echo "deb http://download.mono-project.com/repo/debian wheezy-libtiff-compat main" | sudo tee -a /etc/apt/sources.list.d/mono-xamarin.list
  42. sudo apt-get update -qq
  43. sudo apt-get install -qq mono-devel referenceassemblies-pcl nunit
  44. wget www.nuget.org/NuGet.exe -O nuget.exe
  45. (cd csharp/src; mono ../../nuget.exe restore)
  46. csharp/buildall.sh
  47. cd conformance && make test_csharp && cd ..
  48. }
  49. build_golang() {
  50. # Go build needs `protoc`.
  51. internal_build_cpp
  52. # Add protoc to the path so that the examples build finds it.
  53. export PATH="`pwd`/src:$PATH"
  54. # Install Go and the Go protobuf compiler plugin.
  55. sudo apt-get update -qq
  56. sudo apt-get install -qq golang
  57. export GOPATH="$HOME/gocode"
  58. mkdir -p "$GOPATH/src/github.com/google"
  59. ln -s "`pwd`" "$GOPATH/src/github.com/google/protobuf"
  60. export PATH="$GOPATH/bin:$PATH"
  61. go get github.com/golang/protobuf/protoc-gen-go
  62. cd examples && make gotest && cd ..
  63. }
  64. use_java() {
  65. version=$1
  66. case "$version" in
  67. jdk6)
  68. sudo apt-get install openjdk-6-jdk
  69. export PATH=/usr/lib/jvm/java-6-openjdk-amd64/bin:$PATH
  70. ;;
  71. jdk7)
  72. sudo apt-get install openjdk-7-jdk
  73. export PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH
  74. ;;
  75. oracle7)
  76. sudo apt-get install python-software-properties # for apt-add-repository
  77. echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 select true" | \
  78. sudo debconf-set-selections
  79. yes | sudo apt-add-repository ppa:webupd8team/java
  80. yes | sudo apt-get install oracle-java7-installer
  81. export PATH=/usr/lib/jvm/java-7-oracle/bin:$PATH
  82. ;;
  83. esac
  84. which java
  85. java -version
  86. }
  87. build_java() {
  88. # Java build needs `protoc`.
  89. internal_build_cpp
  90. cd java && mvn test && mvn install
  91. cd util && mvn test
  92. cd ../..
  93. }
  94. build_java_with_conformance_tests() {
  95. # Java build needs `protoc`.
  96. internal_build_cpp
  97. cd java && mvn test && mvn install
  98. cd util && mvn test && mvn assembly:single
  99. cd ../..
  100. cd conformance && make test_java && cd ..
  101. }
  102. build_javanano() {
  103. # Java build needs `protoc`.
  104. internal_build_cpp
  105. cd javanano && mvn test && cd ..
  106. }
  107. build_java_jdk6() {
  108. use_java jdk6
  109. build_java
  110. }
  111. build_java_jdk7() {
  112. use_java jdk7
  113. build_java_with_conformance_tests
  114. }
  115. build_java_oracle7() {
  116. use_java oracle7
  117. build_java
  118. }
  119. build_javanano_jdk6() {
  120. use_java jdk6
  121. build_javanano
  122. }
  123. build_javanano_jdk7() {
  124. use_java jdk7
  125. build_javanano
  126. }
  127. build_javanano_oracle7() {
  128. use_java oracle7
  129. build_javanano
  130. }
  131. internal_install_python_deps() {
  132. # Install tox (OS X doesn't have pip).
  133. if [ $(uname -s) == "Darwin" ]; then
  134. sudo easy_install tox
  135. else
  136. sudo pip install tox
  137. fi
  138. # Only install Python2.6/3.x on Linux.
  139. if [ $(uname -s) == "Linux" ]; then
  140. sudo apt-get install -y python-software-properties # for apt-add-repository
  141. sudo apt-add-repository -y ppa:fkrull/deadsnakes
  142. sudo apt-get update -qq
  143. sudo apt-get install -y python2.6 python2.6-dev
  144. sudo apt-get install -y python3.3 python3.3-dev
  145. sudo apt-get install -y python3.4 python3.4-dev
  146. fi
  147. }
  148. internal_objectivec_common () {
  149. # Make sure xctool is up to date. Adapted from
  150. # http://docs.travis-ci.com/user/osx-ci-environment/
  151. # We don't use a before_install because we test multiple OSes.
  152. brew update
  153. # xctool 0.2.8 seems to have a bug where it randomly kills tests saying
  154. # they failed. Disabling the updates, but letting it report about being
  155. # updates as a hint that this needs to eventually get re-enabled.
  156. # https://github.com/facebook/xctool/issues/619
  157. # https://github.com/google/protobuf/issues/1232
  158. brew outdated xctool || true
  159. #brew outdated xctool || brew upgrade xctool
  160. # Reused the build script that takes care of configuring and ensuring things
  161. # are up to date. Xcode and conformance tests will be directly invoked.
  162. objectivec/DevTools/full_mac_build.sh \
  163. --core-only --skip-xcode --skip-objc-conformance
  164. }
  165. internal_xctool_debug_and_release() {
  166. # Always use -reporter plain to avoid escape codes in output (makes travis
  167. # logs easier to read).
  168. xctool -reporter plain -configuration Debug "$@"
  169. xctool -reporter plain -configuration Release "$@"
  170. }
  171. build_objectivec_ios() {
  172. internal_objectivec_common
  173. # https://github.com/facebook/xctool/issues/509 - unlike xcodebuild, xctool
  174. # doesn't support >1 destination, so we have to build first and then run the
  175. # tests one destination at a time.
  176. internal_xctool_debug_and_release \
  177. -project objectivec/ProtocolBuffers_iOS.xcodeproj \
  178. -scheme ProtocolBuffers \
  179. -sdk iphonesimulator \
  180. build-tests
  181. IOS_DESTINATIONS=(
  182. "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
  183. "platform=iOS Simulator,name=iPhone 6,OS=9.2" # 64bit
  184. "platform=iOS Simulator,name=iPad 2,OS=8.1" # 32bit
  185. "platform=iOS Simulator,name=iPad Air,OS=9.2" # 64bit
  186. )
  187. for i in "${IOS_DESTINATIONS[@]}" ; do
  188. internal_xctool_debug_and_release \
  189. -project objectivec/ProtocolBuffers_iOS.xcodeproj \
  190. -scheme ProtocolBuffers \
  191. -sdk iphonesimulator \
  192. -destination "${i}" \
  193. run-tests
  194. done
  195. }
  196. build_objectivec_osx() {
  197. internal_objectivec_common
  198. internal_xctool_debug_and_release \
  199. -project objectivec/ProtocolBuffers_OSX.xcodeproj \
  200. -scheme ProtocolBuffers \
  201. -destination "platform=OS X,arch=x86_64" \
  202. test
  203. cd conformance && make test_objc && cd ..
  204. }
  205. build_python() {
  206. internal_build_cpp
  207. internal_install_python_deps
  208. cd python
  209. # Only test Python 2.6/3.x on Linux
  210. if [ $(uname -s) == "Linux" ]; then
  211. envlist=py\{26,27,33,34\}-python
  212. else
  213. envlist=py27-python
  214. fi
  215. tox -e $envlist
  216. cd ..
  217. }
  218. build_python_cpp() {
  219. internal_build_cpp
  220. internal_install_python_deps
  221. export LD_LIBRARY_PATH=../src/.libs # for Linux
  222. export DYLD_LIBRARY_PATH=../src/.libs # for OS X
  223. cd python
  224. # Only test Python 2.6/3.x on Linux
  225. if [ $(uname -s) == "Linux" ]; then
  226. # py26 is currently disabled due to json_format
  227. envlist=py\{27,33,34\}-cpp
  228. else
  229. envlist=py27-cpp
  230. fi
  231. tox -e $envlist
  232. cd ..
  233. }
  234. build_ruby19() {
  235. internal_build_cpp # For conformance tests.
  236. cd ruby && bash travis-test.sh ruby-1.9 && cd ..
  237. }
  238. build_ruby20() {
  239. internal_build_cpp # For conformance tests.
  240. cd ruby && bash travis-test.sh ruby-2.0 && cd ..
  241. }
  242. build_ruby21() {
  243. internal_build_cpp # For conformance tests.
  244. cd ruby && bash travis-test.sh ruby-2.1 && cd ..
  245. }
  246. build_ruby22() {
  247. internal_build_cpp # For conformance tests.
  248. cd ruby && bash travis-test.sh ruby-2.2 && cd ..
  249. }
  250. build_jruby() {
  251. internal_build_cpp # For conformance tests.
  252. cd ruby && bash travis-test.sh jruby && cd ..
  253. }
  254. build_javascript() {
  255. internal_build_cpp
  256. cd js && npm install && npm test && cd ..
  257. }
  258. # -------- main --------
  259. if [ "$#" -ne 1 ]; then
  260. echo "
  261. Usage: $0 { cpp |
  262. csharp |
  263. java_jdk6 |
  264. java_jdk7 |
  265. java_oracle7 |
  266. javanano_jdk6 |
  267. javanano_jdk7 |
  268. javanano_oracle7 |
  269. objectivec_ios |
  270. objectivec_osx |
  271. python |
  272. python_cpp |
  273. ruby_19 |
  274. ruby_20 |
  275. ruby_21 |
  276. ruby_22 |
  277. jruby }
  278. "
  279. exit 1
  280. fi
  281. set -e # exit immediately on error
  282. set -x # display all commands
  283. eval "build_$1"