blob: 6a9439a5515bcc9982e4d8427d18418580bc4023 [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
Colin Cross11fb7ae2018-11-04 17:34:26 -080031 ./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
Bo Yangfd332d12016-09-30 00:07:47 +000038 cd conformance && make test_cpp && cd ..
Josh Habermancb36bde2016-04-29 09:52:20 -070039
Colin Cross11fb7ae2018-11-04 17:34:26 -080040 # Verify benchmarking code can build successfully.
41 cd benchmarks && make && ./generate-datasets && cd ..
Chris Fallin20e94b22015-05-13 16:43:48 -070042}
43
44build_cpp_distcheck() {
45 ./autogen.sh
46 ./configure
Josh Haberman67c727c2016-03-04 14:21:18 -080047 make distcheck -j2
Chris Fallin20e94b22015-05-13 16:43:48 -070048}
49
Jan Tattermuschddb36ef2015-05-18 17:34:02 -070050build_csharp() {
Jon Skeetb6defa72015-08-04 10:01:40 +010051 # Just for the conformance tests. We don't currently
52 # need to really build protoc, but it's simplest to keep with the
53 # conventions of the other builds.
54 internal_build_cpp
Josh Habermanffc81182016-02-22 15:39:29 -080055 NUGET=/usr/local/bin/nuget.exe
Jon Skeetb6defa72015-08-04 10:01:40 +010056
Colin Cross11fb7ae2018-11-04 17:34:26 -080057 if [ "$TRAVIS" == "true" ]; then
58 # Install latest version of Mono
59 sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
60 echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
61 echo "deb http://download.mono-project.com/repo/debian wheezy-libtiff-compat main" | sudo tee -a /etc/apt/sources.list.d/mono-xamarin.list
62 sudo apt-get update -qq
63 sudo apt-get install -qq mono-devel referenceassemblies-pcl nunit
64 wget www.nuget.org/NuGet.exe -O nuget.exe
65 NUGET=../../nuget.exe
66 fi
Jon Skeet10a8fb42016-07-14 22:01:47 +010067
Colin Cross11fb7ae2018-11-04 17:34:26 -080068 (cd csharp/src; mono $NUGET restore)
Jan Tattermuschddb36ef2015-05-18 17:34:02 -070069 csharp/buildall.sh
Josh Habermane891c292015-12-30 16:03:49 -080070 cd conformance && make test_csharp && cd ..
Jan Tattermuschddb36ef2015-05-18 17:34:02 -070071}
72
Tim Swast7e31c4d2015-11-20 15:32:53 -080073build_golang() {
74 # Go build needs `protoc`.
75 internal_build_cpp
76 # Add protoc to the path so that the examples build finds it.
77 export PATH="`pwd`/src:$PATH"
78
79 # Install Go and the Go protobuf compiler plugin.
Colin Cross11fb7ae2018-11-04 17:34:26 -080080 sudo apt-get update -qq
81 sudo apt-get install -qq golang
Tim Swast7e31c4d2015-11-20 15:32:53 -080082 export GOPATH="$HOME/gocode"
83 mkdir -p "$GOPATH/src/github.com/google"
Tim Swast7e31c4d2015-11-20 15:32:53 -080084 ln -s "`pwd`" "$GOPATH/src/github.com/google/protobuf"
85 export PATH="$GOPATH/bin:$PATH"
86 go get github.com/golang/protobuf/protoc-gen-go
87
Colin Cross11fb7ae2018-11-04 17:34:26 -080088 cd examples && make gotest && cd ..
Tim Swast7e31c4d2015-11-20 15:32:53 -080089}
90
Chris Fallin20e94b22015-05-13 16:43:48 -070091use_java() {
Chris Fallin20e94b22015-05-13 16:43:48 -070092 version=$1
93 case "$version" in
Colin Cross11fb7ae2018-11-04 17:34:26 -080094 jdk6)
95 on_travis sudo apt-get install openjdk-6-jdk
96 export PATH=/usr/lib/jvm/java-6-openjdk-amd64/bin:$PATH
97 ;;
Chris Fallin20e94b22015-05-13 16:43:48 -070098 jdk7)
Josh Haberman0f8c25d2016-02-19 09:11:38 -080099 on_travis sudo apt-get install openjdk-7-jdk
Chris Fallin20e94b22015-05-13 16:43:48 -0700100 export PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH
Chris Fallin20e94b22015-05-13 16:43:48 -0700101 ;;
102 oracle7)
Josh Habermanffc81182016-02-22 15:39:29 -0800103 if [ "$TRAVIS" == "true" ]; then
104 sudo apt-get install python-software-properties # for apt-add-repository
105 echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 select true" | \
106 sudo debconf-set-selections
107 yes | sudo apt-add-repository ppa:webupd8team/java
108 yes | sudo apt-get install oracle-java7-installer
109 fi;
Chris Fallin20e94b22015-05-13 16:43:48 -0700110 export PATH=/usr/lib/jvm/java-7-oracle/bin:$PATH
Chris Fallin20e94b22015-05-13 16:43:48 -0700111 ;;
112 esac
113
Josh Haberman1ee0fda2016-03-03 16:02:55 -0800114 if [ "$TRAVIS" != "true" ]; then
115 MAVEN_LOCAL_REPOSITORY=/var/maven_local_repository
116 MVN="$MVN -e -X --offline -Dmaven.repo.local=$MAVEN_LOCAL_REPOSITORY"
117 fi;
118
Chris Fallin20e94b22015-05-13 16:43:48 -0700119 which java
120 java -version
Chris Fallin20e94b22015-05-13 16:43:48 -0700121}
122
Josh Habermand08c39c2016-02-20 12:03:39 -0800123# --batch-mode supresses download progress output that spams the logs.
Josh Habermanb28b3f62016-02-20 12:17:10 -0800124MVN="mvn --batch-mode"
Josh Habermand08c39c2016-02-20 12:03:39 -0800125
Chris Fallin20e94b22015-05-13 16:43:48 -0700126build_java() {
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800127 version=$1
128 dir=java_$version
Chris Fallin20e94b22015-05-13 16:43:48 -0700129 # Java build needs `protoc`.
Josh Haberman181c7f22015-07-15 11:05:10 -0700130 internal_build_cpp
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800131 cp -r java $dir
132 cd $dir && $MVN clean && $MVN test
Feng Xiao9e5fb552015-12-21 11:08:18 -0800133 cd ../..
134}
135
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800136# The conformance tests are hard-coded to work with the $ROOT/java directory.
137# So this can't run in parallel with two different sets of tests.
Feng Xiao9e5fb552015-12-21 11:08:18 -0800138build_java_with_conformance_tests() {
139 # Java build needs `protoc`.
140 internal_build_cpp
Josh Habermand08c39c2016-02-20 12:03:39 -0800141 cd java && $MVN test && $MVN install
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800142 cd util && $MVN package assembly:single
Feng Xiaoaf81dcf2015-12-21 03:25:59 -0800143 cd ../..
Chris Fallin20e94b22015-05-13 16:43:48 -0700144 cd conformance && make test_java && cd ..
145}
146
147build_javanano() {
148 # Java build needs `protoc`.
Josh Haberman181c7f22015-07-15 11:05:10 -0700149 internal_build_cpp
Josh Habermanb28b3f62016-02-20 12:17:10 -0800150 cd javanano && $MVN test && cd ..
Chris Fallin20e94b22015-05-13 16:43:48 -0700151}
152
Colin Cross11fb7ae2018-11-04 17:34:26 -0800153build_java_jdk6() {
154 use_java jdk6
155 build_java jdk6
156}
Chris Fallin20e94b22015-05-13 16:43:48 -0700157build_java_jdk7() {
158 use_java jdk7
Feng Xiao9e5fb552015-12-21 11:08:18 -0800159 build_java_with_conformance_tests
Chris Fallin20e94b22015-05-13 16:43:48 -0700160}
161build_java_oracle7() {
162 use_java oracle7
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800163 build_java oracle7
Chris Fallin20e94b22015-05-13 16:43:48 -0700164}
Chris Fallin20e94b22015-05-13 16:43:48 -0700165
Colin Cross11fb7ae2018-11-04 17:34:26 -0800166build_javanano_jdk6() {
167 use_java jdk6
168 build_javanano
169}
Chris Fallin20e94b22015-05-13 16:43:48 -0700170build_javanano_jdk7() {
171 use_java jdk7
172 build_javanano
173}
174build_javanano_oracle7() {
175 use_java oracle7
176 build_javanano
177}
178
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400179internal_install_python_deps() {
Josh Haberman483533d2016-02-19 12:48:33 -0800180 if [ "$TRAVIS" != "true" ]; then
181 return;
182 fi
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400183 # Install tox (OS X doesn't have pip).
184 if [ $(uname -s) == "Darwin" ]; then
185 sudo easy_install tox
186 else
187 sudo pip install tox
188 fi
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400189 # Only install Python2.6/3.x on Linux.
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400190 if [ $(uname -s) == "Linux" ]; then
191 sudo apt-get install -y python-software-properties # for apt-add-repository
192 sudo apt-add-repository -y ppa:fkrull/deadsnakes
193 sudo apt-get update -qq
Colin Cross11fb7ae2018-11-04 17:34:26 -0800194 sudo apt-get install -y python2.6 python2.6-dev
Jie Luoc2aa26e2017-08-18 13:15:06 -0700195 sudo apt-get install -y python3.3 python3.3-dev
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400196 sudo apt-get install -y python3.4 python3.4-dev
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400197 fi
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400198}
199
Colin Cross11fb7ae2018-11-04 17:34:26 -0800200internal_objectivec_common () {
201 # Make sure xctool is up to date. Adapted from
202 # http://docs.travis-ci.com/user/osx-ci-environment/
203 # We don't use a before_install because we test multiple OSes.
204 brew update
205 brew outdated xctool || brew upgrade xctool
Thomas Van Lenten368a2f42016-05-24 11:27:33 -0400206 # Reused the build script that takes care of configuring and ensuring things
Colin Cross11fb7ae2018-11-04 17:34:26 -0800207 # are up to date. Xcode and conformance tests will be directly invoked.
Thomas Van Lenten368a2f42016-05-24 11:27:33 -0400208 objectivec/DevTools/full_mac_build.sh \
Colin Cross11fb7ae2018-11-04 17:34:26 -0800209 --core-only --skip-xcode --skip-objc-conformance
Thomas Van Lenten368a2f42016-05-24 11:27:33 -0400210}
211
Colin Cross11fb7ae2018-11-04 17:34:26 -0800212internal_xctool_debug_and_release() {
213 # Always use -reporter plain to avoid escape codes in output (makes travis
214 # logs easier to read).
215 xctool -reporter plain -configuration Debug "$@"
216 xctool -reporter plain -configuration Release "$@"
Thomas Van Lenten368a2f42016-05-24 11:27:33 -0400217}
218
Colin Cross11fb7ae2018-11-04 17:34:26 -0800219build_objectivec_ios() {
220 internal_objectivec_common
221 # https://github.com/facebook/xctool/issues/509 - unlike xcodebuild, xctool
222 # doesn't support >1 destination, so we have to build first and then run the
223 # tests one destination at a time.
224 internal_xctool_debug_and_release \
225 -project objectivec/ProtocolBuffers_iOS.xcodeproj \
226 -scheme ProtocolBuffers \
227 -sdk iphonesimulator \
228 build-tests
229 IOS_DESTINATIONS=(
230 "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
231 "platform=iOS Simulator,name=iPhone 6,OS=9.2" # 64bit
232 "platform=iOS Simulator,name=iPad 2,OS=8.1" # 32bit
233 "platform=iOS Simulator,name=iPad Air,OS=9.2" # 64bit
234 )
235 for i in "${IOS_DESTINATIONS[@]}" ; do
236 internal_xctool_debug_and_release \
237 -project objectivec/ProtocolBuffers_iOS.xcodeproj \
238 -scheme ProtocolBuffers \
239 -sdk iphonesimulator \
240 -destination "${i}" \
241 run-tests
242 done
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400243}
244
245build_objectivec_osx() {
Colin Cross11fb7ae2018-11-04 17:34:26 -0800246 internal_objectivec_common
247 internal_xctool_debug_and_release \
248 -project objectivec/ProtocolBuffers_OSX.xcodeproj \
249 -scheme ProtocolBuffers \
250 -destination "platform=OS X,arch=x86_64" \
251 test
252 cd conformance && make test_objc && cd ..
Sergio Campamáf0c14922016-06-14 11:26:01 -0700253}
254
Chris Fallin20e94b22015-05-13 16:43:48 -0700255build_python() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700256 internal_build_cpp
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400257 internal_install_python_deps
Chris Fallin20e94b22015-05-13 16:43:48 -0700258 cd python
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400259 # Only test Python 2.6/3.x on Linux
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400260 if [ $(uname -s) == "Linux" ]; then
Colin Cross11fb7ae2018-11-04 17:34:26 -0800261 envlist=py\{26,27,33,34\}-python
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400262 else
263 envlist=py27-python
264 fi
265 tox -e $envlist
Chris Fallin20e94b22015-05-13 16:43:48 -0700266 cd ..
267}
268
269build_python_cpp() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700270 internal_build_cpp
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400271 internal_install_python_deps
Bo Yangfd332d12016-09-30 00:07:47 +0000272 export LD_LIBRARY_PATH=../src/.libs # for Linux
273 export DYLD_LIBRARY_PATH=../src/.libs # for OS X
Chris Fallin20e94b22015-05-13 16:43:48 -0700274 cd python
Colin Cross11fb7ae2018-11-04 17:34:26 -0800275 # Only test Python 2.6/3.x on Linux
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400276 if [ $(uname -s) == "Linux" ]; then
Colin Cross11fb7ae2018-11-04 17:34:26 -0800277 # py26 is currently disabled due to json_format
278 envlist=py\{27,33,34\}-cpp
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400279 else
280 envlist=py27-cpp
281 fi
282 tox -e $envlist
Chris Fallin20e94b22015-05-13 16:43:48 -0700283 cd ..
284}
285
Colin Cross11fb7ae2018-11-04 17:34:26 -0800286build_ruby19() {
287 internal_build_cpp # For conformance tests.
288 cd ruby && bash travis-test.sh ruby-1.9 && cd ..
Jie Luoea511492017-01-23 15:11:00 -0800289}
Colin Cross11fb7ae2018-11-04 17:34:26 -0800290build_ruby20() {
291 internal_build_cpp # For conformance tests.
292 cd ruby && bash travis-test.sh ruby-2.0 && cd ..
293}
Chris Fallin20e94b22015-05-13 16:43:48 -0700294build_ruby21() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700295 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700296 cd ruby && bash travis-test.sh ruby-2.1 && cd ..
297}
298build_ruby22() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700299 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700300 cd ruby && bash travis-test.sh ruby-2.2 && cd ..
301}
302build_jruby() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700303 internal_build_cpp # For conformance tests.
Colin Cross11fb7ae2018-11-04 17:34:26 -0800304 cd ruby && bash travis-test.sh jruby && cd ..
Chris Fallin20e94b22015-05-13 16:43:48 -0700305}
306
Josh Habermane9cf31e2015-12-21 15:18:17 -0800307build_javascript() {
308 internal_build_cpp
Josh Haberman0d2d8bc2015-12-28 06:43:42 -0800309 cd js && npm install && npm test && cd ..
Paul Yang25abd7b2017-05-05 11:14:11 -0700310}
311
Josh Haberman738393b2016-02-18 20:10:23 -0800312# Note: travis currently does not support testing more than one language so the
313# .travis.yml cheats and claims to only be cpp. If they add multiple language
314# support, this should probably get updated to install steps and/or
315# rvm/gemfile/jdk/etc. entries rather than manually doing the work.
316
317# .travis.yml uses matrix.exclude to block the cases where app-get can't be
318# use to install things.
319
320# -------- main --------
321
Josh Haberman738393b2016-02-18 20:10:23 -0800322if [ "$#" -ne 1 ]; then
323 echo "
324Usage: $0 { cpp |
Josh Haberman738393b2016-02-18 20:10:23 -0800325 csharp |
Colin Cross11fb7ae2018-11-04 17:34:26 -0800326 java_jdk6 |
Josh Haberman738393b2016-02-18 20:10:23 -0800327 java_jdk7 |
328 java_oracle7 |
Colin Cross11fb7ae2018-11-04 17:34:26 -0800329 javanano_jdk6 |
Josh Haberman738393b2016-02-18 20:10:23 -0800330 javanano_jdk7 |
331 javanano_oracle7 |
332 objectivec_ios |
Josh Haberman738393b2016-02-18 20:10:23 -0800333 objectivec_osx |
Josh Haberman738393b2016-02-18 20:10:23 -0800334 python |
335 python_cpp |
Colin Cross11fb7ae2018-11-04 17:34:26 -0800336 ruby19 |
337 ruby20 |
Josh Habermanffc81182016-02-22 15:39:29 -0800338 ruby21 |
339 ruby22 |
Colin Cross11fb7ae2018-11-04 17:34:26 -0800340 jruby }
Josh Haberman738393b2016-02-18 20:10:23 -0800341"
342 exit 1
343fi
344
345set -e # exit immediately on error
346set -x # display all commands
347eval "build_$1"