travis.sh 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. brew outdated xctool || brew upgrade xctool
  154. # Reused the build script that takes care of configuring and ensuring things
  155. # are up to date. Xcode and conformance tests will be directly invoked.
  156. objectivec/DevTools/full_mac_build.sh \
  157. --core-only --skip-xcode --skip-objc-conformance
  158. }
  159. internal_xctool_debug_and_release() {
  160. xctool -configuration Debug "$@"
  161. xctool -configuration Release "$@"
  162. }
  163. build_objectivec_ios() {
  164. internal_objectivec_common
  165. # https://github.com/facebook/xctool/issues/509 - unlike xcodebuild, xctool
  166. # doesn't support >1 destination, so we have to build first and then run the
  167. # tests one destination at a time.
  168. internal_xctool_debug_and_release \
  169. -project objectivec/ProtocolBuffers_iOS.xcodeproj \
  170. -scheme ProtocolBuffers \
  171. -sdk iphonesimulator \
  172. build-tests
  173. IOS_DESTINATIONS=(
  174. "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
  175. "platform=iOS Simulator,name=iPhone 6,OS=9.1" # 64bit
  176. "platform=iOS Simulator,name=iPad 2,OS=8.1" # 32bit
  177. "platform=iOS Simulator,name=iPad Air,OS=9.1" # 64bit
  178. )
  179. for i in "${IOS_DESTINATIONS[@]}" ; do
  180. internal_xctool_debug_and_release \
  181. -project objectivec/ProtocolBuffers_iOS.xcodeproj \
  182. -scheme ProtocolBuffers \
  183. -sdk iphonesimulator \
  184. -destination "${i}" \
  185. run-tests
  186. done
  187. }
  188. build_objectivec_osx() {
  189. internal_objectivec_common
  190. internal_xctool_debug_and_release \
  191. -project objectivec/ProtocolBuffers_OSX.xcodeproj \
  192. -scheme ProtocolBuffers \
  193. -destination "platform=OS X,arch=x86_64" \
  194. test
  195. cd conformance && make test_objc && cd ..
  196. }
  197. build_python() {
  198. internal_build_cpp
  199. internal_install_python_deps
  200. cd python
  201. # Only test Python 2.6/3.x on Linux
  202. if [ $(uname -s) == "Linux" ]; then
  203. envlist=py\{26,27,33,34\}-python
  204. else
  205. envlist=py27-python
  206. fi
  207. tox -e $envlist
  208. cd ..
  209. }
  210. build_python_cpp() {
  211. internal_build_cpp
  212. internal_install_python_deps
  213. export LD_LIBRARY_PATH=../src/.libs # for Linux
  214. export DYLD_LIBRARY_PATH=../src/.libs # for OS X
  215. cd python
  216. # Only test Python 2.6/3.x on Linux
  217. if [ $(uname -s) == "Linux" ]; then
  218. # py26 is currently disabled due to json_format
  219. envlist=py\{27,33,34\}-cpp
  220. else
  221. envlist=py27-cpp
  222. fi
  223. tox -e $envlist
  224. cd ..
  225. }
  226. build_ruby19() {
  227. internal_build_cpp # For conformance tests.
  228. cd ruby && bash travis-test.sh ruby-1.9 && cd ..
  229. }
  230. build_ruby20() {
  231. internal_build_cpp # For conformance tests.
  232. cd ruby && bash travis-test.sh ruby-2.0 && cd ..
  233. }
  234. build_ruby21() {
  235. internal_build_cpp # For conformance tests.
  236. cd ruby && bash travis-test.sh ruby-2.1 && cd ..
  237. }
  238. build_ruby22() {
  239. internal_build_cpp # For conformance tests.
  240. cd ruby && bash travis-test.sh ruby-2.2 && cd ..
  241. }
  242. build_jruby() {
  243. internal_build_cpp # For conformance tests.
  244. cd ruby && bash travis-test.sh jruby && cd ..
  245. }
  246. build_javascript() {
  247. internal_build_cpp
  248. cd js && npm install && npm test && cd ..
  249. }
  250. # -------- main --------
  251. if [ "$#" -ne 1 ]; then
  252. echo "
  253. Usage: $0 { cpp |
  254. csharp |
  255. java_jdk6 |
  256. java_jdk7 |
  257. java_oracle7 |
  258. javanano_jdk6 |
  259. javanano_jdk7 |
  260. javanano_oracle7 |
  261. objectivec_ios |
  262. objectivec_osx |
  263. python |
  264. python_cpp |
  265. ruby_19 |
  266. ruby_20 |
  267. ruby_21 |
  268. ruby_22 |
  269. jruby }
  270. "
  271. exit 1
  272. fi
  273. set -e # exit immediately on error
  274. set -x # display all commands
  275. eval "build_$1"