blob: a4624c0c9e8c63f81aa3abca834138d42ff3372b [file] [log] [blame]
Josh Haberman738393b2016-02-18 20:10:23 -08001#!/bin/bash
Josh Haberman67c727c2016-03-04 14:21:18 -08002#
3# Build and runs tests for the protobuf project. The tests as written here are
4# used by both Jenkins and Travis, though some specialized logic is required to
5# handle the differences between them.
Thomas Van Lentenc4d36382015-06-09 13:35:41 -04006
Josh Haberman0f8c25d2016-02-19 09:11:38 -08007on_travis() {
8 if [ "$TRAVIS" == "true" ]; then
9 "$@"
10 fi
11}
12
Josh Haberman181c7f22015-07-15 11:05:10 -070013# For when some other test needs the C++ main build, including protoc and
14# libprotobuf.
15internal_build_cpp() {
Josh Haberman738393b2016-02-18 20:10:23 -080016 if [ -f src/protoc ]; then
17 # Already built.
18 return
19 fi
20
Josh Habermand33e93b2016-02-18 19:13:07 -080021 if [[ $(uname -s) == "Linux" && "$TRAVIS" == "true" ]]; then
Feng Xiao91258632015-12-21 03:34:28 -080022 # Install GCC 4.8 to replace the default GCC 4.6. We need 4.8 for more
23 # decent C++ 11 support in order to compile conformance tests.
24 sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
25 sudo apt-get update -qq
26 sudo apt-get install -qq g++-4.8
27 export CXX="g++-4.8" CC="gcc-4.8"
28 fi
Feng Xiao1e2fece2015-12-18 15:16:07 -080029
Chris Fallin20e94b22015-05-13 16:43:48 -070030 ./autogen.sh
31 ./configure
Josh Haberman67c727c2016-03-04 14:21:18 -080032 make -j2
Josh Haberman181c7f22015-07-15 11:05:10 -070033}
34
35build_cpp() {
36 internal_build_cpp
Josh Haberman67c727c2016-03-04 14:21:18 -080037 make check -j2
Chris Fallin20e94b22015-05-13 16:43:48 -070038 cd conformance && make test_cpp && cd ..
39}
40
41build_cpp_distcheck() {
42 ./autogen.sh
43 ./configure
Josh Haberman67c727c2016-03-04 14:21:18 -080044 make distcheck -j2
Chris Fallin20e94b22015-05-13 16:43:48 -070045}
46
Jan Tattermuschddb36ef2015-05-18 17:34:02 -070047build_csharp() {
Jon Skeetb6defa72015-08-04 10:01:40 +010048 # Just for the conformance tests. We don't currently
49 # need to really build protoc, but it's simplest to keep with the
50 # conventions of the other builds.
51 internal_build_cpp
Josh Habermanffc81182016-02-22 15:39:29 -080052 NUGET=/usr/local/bin/nuget.exe
Jon Skeetb6defa72015-08-04 10:01:40 +010053
Josh Habermanffc81182016-02-22 15:39:29 -080054 if [ "$TRAVIS" == "true" ]; then
55 # Install latest version of Mono
56 sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
57 echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
58 echo "deb http://download.mono-project.com/repo/debian wheezy-libtiff-compat main" | sudo tee -a /etc/apt/sources.list.d/mono-xamarin.list
59 sudo apt-get update -qq
60 sudo apt-get install -qq mono-devel referenceassemblies-pcl nunit
61 wget www.nuget.org/NuGet.exe -O nuget.exe
62 NUGET=../../nuget.exe
63 fi
Jan Tattermuschddb36ef2015-05-18 17:34:02 -070064
Josh Habermanffc81182016-02-22 15:39:29 -080065 (cd csharp/src; mono $NUGET restore)
Jan Tattermuschddb36ef2015-05-18 17:34:02 -070066 csharp/buildall.sh
Josh Habermane891c292015-12-30 16:03:49 -080067 cd conformance && make test_csharp && cd ..
Jan Tattermuschddb36ef2015-05-18 17:34:02 -070068}
69
Tim Swast7e31c4d2015-11-20 15:32:53 -080070build_golang() {
71 # Go build needs `protoc`.
72 internal_build_cpp
73 # Add protoc to the path so that the examples build finds it.
74 export PATH="`pwd`/src:$PATH"
75
76 # Install Go and the Go protobuf compiler plugin.
77 sudo apt-get update -qq
78 sudo apt-get install -qq golang
79 export GOPATH="$HOME/gocode"
80 mkdir -p "$GOPATH/src/github.com/google"
81 ln -s "`pwd`" "$GOPATH/src/github.com/google/protobuf"
82 export PATH="$GOPATH/bin:$PATH"
83 go get github.com/golang/protobuf/protoc-gen-go
84
85 cd examples && make gotest && cd ..
86}
87
Chris Fallin20e94b22015-05-13 16:43:48 -070088use_java() {
Chris Fallin20e94b22015-05-13 16:43:48 -070089 version=$1
90 case "$version" in
91 jdk6)
Josh Haberman0f8c25d2016-02-19 09:11:38 -080092 on_travis sudo apt-get install openjdk-6-jdk
Chris Fallin20e94b22015-05-13 16:43:48 -070093 export PATH=/usr/lib/jvm/java-6-openjdk-amd64/bin:$PATH
94 ;;
95 jdk7)
Josh Haberman0f8c25d2016-02-19 09:11:38 -080096 on_travis sudo apt-get install openjdk-7-jdk
Chris Fallin20e94b22015-05-13 16:43:48 -070097 export PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH
98 ;;
99 oracle7)
Josh Habermanffc81182016-02-22 15:39:29 -0800100 if [ "$TRAVIS" == "true" ]; then
101 sudo apt-get install python-software-properties # for apt-add-repository
102 echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 select true" | \
103 sudo debconf-set-selections
104 yes | sudo apt-add-repository ppa:webupd8team/java
105 yes | sudo apt-get install oracle-java7-installer
106 fi;
Chris Fallin20e94b22015-05-13 16:43:48 -0700107 export PATH=/usr/lib/jvm/java-7-oracle/bin:$PATH
108 ;;
109 esac
110
Josh Haberman1ee0fda2016-03-03 16:02:55 -0800111 if [ "$TRAVIS" != "true" ]; then
112 MAVEN_LOCAL_REPOSITORY=/var/maven_local_repository
113 MVN="$MVN -e -X --offline -Dmaven.repo.local=$MAVEN_LOCAL_REPOSITORY"
114 fi;
115
Chris Fallin20e94b22015-05-13 16:43:48 -0700116 which java
117 java -version
118}
119
Josh Habermand08c39c2016-02-20 12:03:39 -0800120# --batch-mode supresses download progress output that spams the logs.
Josh Habermanb28b3f62016-02-20 12:17:10 -0800121MVN="mvn --batch-mode"
Josh Habermand08c39c2016-02-20 12:03:39 -0800122
Chris Fallin20e94b22015-05-13 16:43:48 -0700123build_java() {
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800124 version=$1
125 dir=java_$version
Chris Fallin20e94b22015-05-13 16:43:48 -0700126 # Java build needs `protoc`.
Josh Haberman181c7f22015-07-15 11:05:10 -0700127 internal_build_cpp
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800128 cp -r java $dir
129 cd $dir && $MVN clean && $MVN test
Feng Xiao9e5fb552015-12-21 11:08:18 -0800130 cd ../..
131}
132
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800133# The conformance tests are hard-coded to work with the $ROOT/java directory.
134# So this can't run in parallel with two different sets of tests.
Feng Xiao9e5fb552015-12-21 11:08:18 -0800135build_java_with_conformance_tests() {
136 # Java build needs `protoc`.
137 internal_build_cpp
Josh Habermand08c39c2016-02-20 12:03:39 -0800138 cd java && $MVN test && $MVN install
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800139 cd util && $MVN package assembly:single
Feng Xiaoaf81dcf2015-12-21 03:25:59 -0800140 cd ../..
Chris Fallin20e94b22015-05-13 16:43:48 -0700141 cd conformance && make test_java && cd ..
142}
143
144build_javanano() {
145 # Java build needs `protoc`.
Josh Haberman181c7f22015-07-15 11:05:10 -0700146 internal_build_cpp
Josh Habermanb28b3f62016-02-20 12:17:10 -0800147 cd javanano && $MVN test && cd ..
Chris Fallin20e94b22015-05-13 16:43:48 -0700148}
149
150build_java_jdk6() {
151 use_java jdk6
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800152 build_java jdk6
Chris Fallin20e94b22015-05-13 16:43:48 -0700153}
154build_java_jdk7() {
155 use_java jdk7
Feng Xiao9e5fb552015-12-21 11:08:18 -0800156 build_java_with_conformance_tests
Chris Fallin20e94b22015-05-13 16:43:48 -0700157}
158build_java_oracle7() {
159 use_java oracle7
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800160 build_java oracle7
Chris Fallin20e94b22015-05-13 16:43:48 -0700161}
162
163build_javanano_jdk6() {
164 use_java jdk6
165 build_javanano
166}
167build_javanano_jdk7() {
168 use_java jdk7
169 build_javanano
170}
171build_javanano_oracle7() {
172 use_java oracle7
173 build_javanano
174}
175
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400176internal_install_python_deps() {
Josh Haberman483533d2016-02-19 12:48:33 -0800177 if [ "$TRAVIS" != "true" ]; then
178 return;
179 fi
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400180 # Install tox (OS X doesn't have pip).
181 if [ $(uname -s) == "Darwin" ]; then
182 sudo easy_install tox
183 else
184 sudo pip install tox
185 fi
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400186 # Only install Python2.6/3.x on Linux.
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400187 if [ $(uname -s) == "Linux" ]; then
188 sudo apt-get install -y python-software-properties # for apt-add-repository
189 sudo apt-add-repository -y ppa:fkrull/deadsnakes
190 sudo apt-get update -qq
191 sudo apt-get install -y python2.6 python2.6-dev
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400192 sudo apt-get install -y python3.3 python3.3-dev
193 sudo apt-get install -y python3.4 python3.4-dev
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400194 fi
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400195}
196
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500197internal_objectivec_common () {
198 # Make sure xctool is up to date. Adapted from
199 # http://docs.travis-ci.com/user/osx-ci-environment/
200 # We don't use a before_install because we test multiple OSes.
201 brew update
Thomas Van Lenten8c784502016-02-18 11:08:30 -0500202 # xctool 0.2.8 seems to have a bug where it randomly kills tests saying
203 # they failed. Disabling the updates, but letting it report about being
204 # updates as a hint that this needs to eventually get re-enabled.
205 # https://github.com/facebook/xctool/issues/619
206 # https://github.com/google/protobuf/issues/1232
207 brew outdated xctool || true
208 #brew outdated xctool || brew upgrade xctool
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500209 # Reused the build script that takes care of configuring and ensuring things
Thomas Van Lenten1745f7e2015-11-17 10:18:49 -0500210 # are up to date. Xcode and conformance tests will be directly invoked.
211 objectivec/DevTools/full_mac_build.sh \
212 --core-only --skip-xcode --skip-objc-conformance
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500213}
214
215internal_xctool_debug_and_release() {
Thomas Van Lentenefca3682016-02-16 15:10:14 -0500216 # Always use -reporter plain to avoid escape codes in output (makes travis
217 # logs easier to read).
218 xctool -reporter plain -configuration Debug "$@"
219 xctool -reporter plain -configuration Release "$@"
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400220}
221
222build_objectivec_ios() {
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500223 internal_objectivec_common
224 # https://github.com/facebook/xctool/issues/509 - unlike xcodebuild, xctool
225 # doesn't support >1 destination, so we have to build first and then run the
226 # tests one destination at a time.
227 internal_xctool_debug_and_release \
228 -project objectivec/ProtocolBuffers_iOS.xcodeproj \
229 -scheme ProtocolBuffers \
230 -sdk iphonesimulator \
231 build-tests
232 IOS_DESTINATIONS=(
233 "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
Thomas Van Lenten13241192016-02-16 09:19:50 -0500234 "platform=iOS Simulator,name=iPhone 6,OS=9.2" # 64bit
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500235 "platform=iOS Simulator,name=iPad 2,OS=8.1" # 32bit
Thomas Van Lenten13241192016-02-16 09:19:50 -0500236 "platform=iOS Simulator,name=iPad Air,OS=9.2" # 64bit
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500237 )
238 for i in "${IOS_DESTINATIONS[@]}" ; do
239 internal_xctool_debug_and_release \
240 -project objectivec/ProtocolBuffers_iOS.xcodeproj \
241 -scheme ProtocolBuffers \
242 -sdk iphonesimulator \
243 -destination "${i}" \
Thomas Van Lenten8c784502016-02-18 11:08:30 -0500244 run-tests
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500245 done
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400246}
247
248build_objectivec_osx() {
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500249 internal_objectivec_common
250 internal_xctool_debug_and_release \
251 -project objectivec/ProtocolBuffers_OSX.xcodeproj \
252 -scheme ProtocolBuffers \
253 -destination "platform=OS X,arch=x86_64" \
254 test
Thomas Van Lenten1745f7e2015-11-17 10:18:49 -0500255 cd conformance && make test_objc && cd ..
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400256}
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400257
Chris Fallin20e94b22015-05-13 16:43:48 -0700258build_python() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700259 internal_build_cpp
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400260 internal_install_python_deps
Chris Fallin20e94b22015-05-13 16:43:48 -0700261 cd python
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400262 # Only test Python 2.6/3.x on Linux
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400263 if [ $(uname -s) == "Linux" ]; then
Jie Luo2850a982015-10-09 17:07:03 -0700264 envlist=py\{26,27,33,34\}-python
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400265 else
266 envlist=py27-python
267 fi
268 tox -e $envlist
Chris Fallin20e94b22015-05-13 16:43:48 -0700269 cd ..
270}
271
272build_python_cpp() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700273 internal_build_cpp
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400274 internal_install_python_deps
275 export LD_LIBRARY_PATH=../src/.libs # for Linux
Tamir Dubersteinc91d9ab2015-05-14 21:32:39 -0400276 export DYLD_LIBRARY_PATH=../src/.libs # for OS X
Chris Fallin20e94b22015-05-13 16:43:48 -0700277 cd python
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400278 # Only test Python 2.6/3.x on Linux
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400279 if [ $(uname -s) == "Linux" ]; then
Jisi Liu72bd9c92015-10-06 10:48:57 -0700280 # py26 is currently disabled due to json_format
281 envlist=py\{27,33,34\}-cpp
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400282 else
283 envlist=py27-cpp
284 fi
285 tox -e $envlist
Chris Fallin20e94b22015-05-13 16:43:48 -0700286 cd ..
287}
288
289build_ruby19() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700290 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700291 cd ruby && bash travis-test.sh ruby-1.9 && cd ..
292}
293build_ruby20() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700294 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700295 cd ruby && bash travis-test.sh ruby-2.0 && cd ..
296}
297build_ruby21() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700298 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700299 cd ruby && bash travis-test.sh ruby-2.1 && cd ..
300}
301build_ruby22() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700302 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700303 cd ruby && bash travis-test.sh ruby-2.2 && cd ..
304}
305build_jruby() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700306 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700307 cd ruby && bash travis-test.sh jruby && cd ..
308}
309
Josh Habermane9cf31e2015-12-21 15:18:17 -0800310build_javascript() {
311 internal_build_cpp
Josh Haberman0d2d8bc2015-12-28 06:43:42 -0800312 cd js && npm install && npm test && cd ..
Josh Habermane9cf31e2015-12-21 15:18:17 -0800313}
314
Josh Haberman738393b2016-02-18 20:10:23 -0800315# Note: travis currently does not support testing more than one language so the
316# .travis.yml cheats and claims to only be cpp. If they add multiple language
317# support, this should probably get updated to install steps and/or
318# rvm/gemfile/jdk/etc. entries rather than manually doing the work.
319
320# .travis.yml uses matrix.exclude to block the cases where app-get can't be
321# use to install things.
322
323# -------- main --------
324
Josh Haberman738393b2016-02-18 20:10:23 -0800325if [ "$#" -ne 1 ]; then
326 echo "
327Usage: $0 { cpp |
328 csharp |
329 java_jdk6 |
330 java_jdk7 |
331 java_oracle7 |
332 javanano_jdk6 |
333 javanano_jdk7 |
334 javanano_oracle7 |
335 objectivec_ios |
336 objectivec_osx |
337 python |
338 python_cpp |
Josh Habermanffc81182016-02-22 15:39:29 -0800339 ruby19 |
340 ruby20 |
341 ruby21 |
342 ruby22 |
Josh Haberman738393b2016-02-18 20:10:23 -0800343 jruby }
344"
345 exit 1
346fi
347
348set -e # exit immediately on error
349set -x # display all commands
350eval "build_$1"