travis.sh 8.3 KB

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