blob: 4b8ef2f6bc3733a51c7334d2a2d32feb69f0febd [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 ..
Josh Habermancb36bde2016-04-29 09:52:20 -070039
40 # Verify benchmarking code can build successfully.
Josh Haberman49a89182016-04-29 10:19:03 -070041 cd benchmarks && make && ./generate-datasets && cd ..
Chris Fallin20e94b22015-05-13 16:43:48 -070042}
43
44build_cpp_distcheck() {
45 ./autogen.sh
46 ./configure
Feng Xiaoa4f68b12016-07-19 17:20:31 -070047 make dist
48
49 # List all files that should be included in the distribution package.
50 git ls-files | grep "^\(java\|python\|objectivec\|csharp\|js\|ruby\|cmake\|examples\)" |\
51 grep -v ".gitignore" | grep -v "java/compatibility_tests" > dist.lst
52 # Unzip the dist tar file.
53 DIST=`ls *.tar.gz`
54 tar -xf $DIST
55 cd ${DIST//.tar.gz}
56 # Check if every file exists in the dist tar file.
57 FILES_MISSING=""
58 for FILE in $(<../dist.lst); do
59 if ! file $FILE &>/dev/null; then
60 echo "$FILE is not found!"
61 FILES_MISSING="$FILE $FILES_MISSING"
62 fi
63 done
64 cd ..
65 if [ ! -z "$FILES_MISSING" ]; then
66 echo "Missing files in EXTRA_DIST: $FILES_MISSING"
67 exit 1
68 fi
69
70 # Do the regular dist-check for C++.
Josh Haberman67c727c2016-03-04 14:21:18 -080071 make distcheck -j2
Chris Fallin20e94b22015-05-13 16:43:48 -070072}
73
Jan Tattermuschddb36ef2015-05-18 17:34:02 -070074build_csharp() {
Jon Skeetb6defa72015-08-04 10:01:40 +010075 # Just for the conformance tests. We don't currently
76 # need to really build protoc, but it's simplest to keep with the
77 # conventions of the other builds.
78 internal_build_cpp
Josh Habermanffc81182016-02-22 15:39:29 -080079 NUGET=/usr/local/bin/nuget.exe
Jon Skeetb6defa72015-08-04 10:01:40 +010080
Josh Habermanffc81182016-02-22 15:39:29 -080081 if [ "$TRAVIS" == "true" ]; then
82 # Install latest version of Mono
83 sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
Jon Skeet10a8fb42016-07-14 22:01:47 +010084 sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 1397BC53640DB551
Josh Habermanffc81182016-02-22 15:39:29 -080085 echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
Josh Habermanffc81182016-02-22 15:39:29 -080086 sudo apt-get update -qq
87 sudo apt-get install -qq mono-devel referenceassemblies-pcl nunit
Jon Skeet10a8fb42016-07-14 22:01:47 +010088
89 # Then install the dotnet SDK as per Ubuntu 14.04 instructions on dot.net.
Jon Skeetdeaea212016-07-19 17:57:46 -070090 sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ trusty main" > /etc/apt/sources.list.d/dotnetdev.list'
Jon Skeet10a8fb42016-07-14 22:01:47 +010091 sudo apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893
92 sudo apt-get update -qq
93 sudo apt-get install -qq dotnet-dev-1.0.0-preview2-003121
Josh Habermanffc81182016-02-22 15:39:29 -080094 fi
Jan Tattermuschddb36ef2015-05-18 17:34:02 -070095
Jon Skeet10a8fb42016-07-14 22:01:47 +010096 # Perform "dotnet new" once to get the setup preprocessing out of the
97 # way. That spews a lot of output (including backspaces) into logs
98 # otherwise, and can cause problems. It doesn't matter if this step
99 # is performed multiple times; it's cheap after the first time anyway.
100 mkdir dotnettmp
101 (cd dotnettmp; dotnet new > /dev/null)
102 rm -rf dotnettmp
103
104 (cd csharp/src; dotnet restore)
Jan Tattermuschddb36ef2015-05-18 17:34:02 -0700105 csharp/buildall.sh
Josh Habermane891c292015-12-30 16:03:49 -0800106 cd conformance && make test_csharp && cd ..
Jan Tattermuschddb36ef2015-05-18 17:34:02 -0700107}
108
Tim Swast7e31c4d2015-11-20 15:32:53 -0800109build_golang() {
110 # Go build needs `protoc`.
111 internal_build_cpp
112 # Add protoc to the path so that the examples build finds it.
113 export PATH="`pwd`/src:$PATH"
114
115 # Install Go and the Go protobuf compiler plugin.
116 sudo apt-get update -qq
117 sudo apt-get install -qq golang
118 export GOPATH="$HOME/gocode"
119 mkdir -p "$GOPATH/src/github.com/google"
120 ln -s "`pwd`" "$GOPATH/src/github.com/google/protobuf"
121 export PATH="$GOPATH/bin:$PATH"
122 go get github.com/golang/protobuf/protoc-gen-go
123
124 cd examples && make gotest && cd ..
125}
126
Chris Fallin20e94b22015-05-13 16:43:48 -0700127use_java() {
Chris Fallin20e94b22015-05-13 16:43:48 -0700128 version=$1
129 case "$version" in
130 jdk6)
Josh Haberman0f8c25d2016-02-19 09:11:38 -0800131 on_travis sudo apt-get install openjdk-6-jdk
Chris Fallin20e94b22015-05-13 16:43:48 -0700132 export PATH=/usr/lib/jvm/java-6-openjdk-amd64/bin:$PATH
133 ;;
134 jdk7)
Josh Haberman0f8c25d2016-02-19 09:11:38 -0800135 on_travis sudo apt-get install openjdk-7-jdk
Chris Fallin20e94b22015-05-13 16:43:48 -0700136 export PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH
137 ;;
138 oracle7)
Josh Habermanffc81182016-02-22 15:39:29 -0800139 if [ "$TRAVIS" == "true" ]; then
140 sudo apt-get install python-software-properties # for apt-add-repository
141 echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 select true" | \
142 sudo debconf-set-selections
143 yes | sudo apt-add-repository ppa:webupd8team/java
144 yes | sudo apt-get install oracle-java7-installer
145 fi;
Chris Fallin20e94b22015-05-13 16:43:48 -0700146 export PATH=/usr/lib/jvm/java-7-oracle/bin:$PATH
147 ;;
148 esac
149
Josh Haberman1ee0fda2016-03-03 16:02:55 -0800150 if [ "$TRAVIS" != "true" ]; then
151 MAVEN_LOCAL_REPOSITORY=/var/maven_local_repository
152 MVN="$MVN -e -X --offline -Dmaven.repo.local=$MAVEN_LOCAL_REPOSITORY"
153 fi;
154
Chris Fallin20e94b22015-05-13 16:43:48 -0700155 which java
156 java -version
157}
158
Josh Habermand08c39c2016-02-20 12:03:39 -0800159# --batch-mode supresses download progress output that spams the logs.
Josh Habermanb28b3f62016-02-20 12:17:10 -0800160MVN="mvn --batch-mode"
Josh Habermand08c39c2016-02-20 12:03:39 -0800161
Chris Fallin20e94b22015-05-13 16:43:48 -0700162build_java() {
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800163 version=$1
164 dir=java_$version
Chris Fallin20e94b22015-05-13 16:43:48 -0700165 # Java build needs `protoc`.
Josh Haberman181c7f22015-07-15 11:05:10 -0700166 internal_build_cpp
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800167 cp -r java $dir
168 cd $dir && $MVN clean && $MVN test
Feng Xiao9e5fb552015-12-21 11:08:18 -0800169 cd ../..
170}
171
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800172# The conformance tests are hard-coded to work with the $ROOT/java directory.
173# So this can't run in parallel with two different sets of tests.
Feng Xiao9e5fb552015-12-21 11:08:18 -0800174build_java_with_conformance_tests() {
175 # Java build needs `protoc`.
176 internal_build_cpp
Josh Habermand08c39c2016-02-20 12:03:39 -0800177 cd java && $MVN test && $MVN install
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800178 cd util && $MVN package assembly:single
Feng Xiaoaf81dcf2015-12-21 03:25:59 -0800179 cd ../..
Chris Fallin20e94b22015-05-13 16:43:48 -0700180 cd conformance && make test_java && cd ..
181}
182
183build_javanano() {
184 # Java build needs `protoc`.
Josh Haberman181c7f22015-07-15 11:05:10 -0700185 internal_build_cpp
Josh Habermanb28b3f62016-02-20 12:17:10 -0800186 cd javanano && $MVN test && cd ..
Chris Fallin20e94b22015-05-13 16:43:48 -0700187}
188
189build_java_jdk6() {
190 use_java jdk6
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800191 build_java jdk6
Chris Fallin20e94b22015-05-13 16:43:48 -0700192}
193build_java_jdk7() {
194 use_java jdk7
Feng Xiao9e5fb552015-12-21 11:08:18 -0800195 build_java_with_conformance_tests
Chris Fallin20e94b22015-05-13 16:43:48 -0700196}
197build_java_oracle7() {
198 use_java oracle7
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800199 build_java oracle7
Chris Fallin20e94b22015-05-13 16:43:48 -0700200}
201
202build_javanano_jdk6() {
203 use_java jdk6
204 build_javanano
205}
206build_javanano_jdk7() {
207 use_java jdk7
208 build_javanano
209}
210build_javanano_oracle7() {
211 use_java oracle7
212 build_javanano
213}
214
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400215internal_install_python_deps() {
Josh Haberman483533d2016-02-19 12:48:33 -0800216 if [ "$TRAVIS" != "true" ]; then
217 return;
218 fi
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400219 # Install tox (OS X doesn't have pip).
220 if [ $(uname -s) == "Darwin" ]; then
221 sudo easy_install tox
222 else
223 sudo pip install tox
224 fi
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400225 # Only install Python2.6/3.x on Linux.
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400226 if [ $(uname -s) == "Linux" ]; then
227 sudo apt-get install -y python-software-properties # for apt-add-repository
228 sudo apt-add-repository -y ppa:fkrull/deadsnakes
229 sudo apt-get update -qq
230 sudo apt-get install -y python2.6 python2.6-dev
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400231 sudo apt-get install -y python3.3 python3.3-dev
232 sudo apt-get install -y python3.4 python3.4-dev
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400233 fi
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400234}
235
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400236build_objectivec_ios() {
Thomas Van Lenten368a2f42016-05-24 11:27:33 -0400237 # Reused the build script that takes care of configuring and ensuring things
238 # are up to date. The OS X test runs the objc conformance test, so skip it
239 # here.
240 # Note: travis has xctool installed, and we've looked at using it in the past
241 # but it has ended up proving unreliable (bugs), an they are removing build
242 # support in favor of xcbuild (or just xcodebuild).
243 objectivec/DevTools/full_mac_build.sh \
244 --core-only --skip-xcode-osx --skip-objc-conformance "$@"
245}
246
247build_objectivec_ios_debug() {
248 build_objectivec_ios --skip-xcode-release
249}
250
251build_objectivec_ios_release() {
252 build_objectivec_ios --skip-xcode-debug
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400253}
254
255build_objectivec_osx() {
Thomas Van Lenten368a2f42016-05-24 11:27:33 -0400256 # Reused the build script that takes care of configuring and ensuring things
257 # are up to date.
258 objectivec/DevTools/full_mac_build.sh \
259 --core-only --skip-xcode-ios
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400260}
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400261
Sergio Campamáf0c14922016-06-14 11:26:01 -0700262build_objectivec_cocoapods_integration() {
263 # First, load the RVM environment in bash, needed to update ruby.
264 source ~/.rvm/scripts/rvm
Sergio Campamáf6d1d1a2016-07-15 13:59:09 -0700265 # Update rvm to the latest version. This is needed to solve
266 # https://github.com/google/protobuf/issues/1786 and may not be needed in the
267 # future when Travis updates the default version of rvm.
268 rvm get head
Sergio Campamáf0c14922016-06-14 11:26:01 -0700269 # Update ruby to 2.2.3 as the default one crashes with segmentation faults
270 # when using pod.
271 rvm use 2.2.3 --install --binary --fuzzy
272 # Update pod to the latest version.
273 gem install cocoapods --no-ri --no-rdoc
274 objectivec/Tests/CocoaPods/run_tests.sh
275}
276
Chris Fallin20e94b22015-05-13 16:43:48 -0700277build_python() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700278 internal_build_cpp
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400279 internal_install_python_deps
Chris Fallin20e94b22015-05-13 16:43:48 -0700280 cd python
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400281 # Only test Python 2.6/3.x on Linux
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400282 if [ $(uname -s) == "Linux" ]; then
Jie Luo2850a982015-10-09 17:07:03 -0700283 envlist=py\{26,27,33,34\}-python
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400284 else
285 envlist=py27-python
286 fi
287 tox -e $envlist
Chris Fallin20e94b22015-05-13 16:43:48 -0700288 cd ..
289}
290
291build_python_cpp() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700292 internal_build_cpp
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400293 internal_install_python_deps
294 export LD_LIBRARY_PATH=../src/.libs # for Linux
Tamir Dubersteinc91d9ab2015-05-14 21:32:39 -0400295 export DYLD_LIBRARY_PATH=../src/.libs # for OS X
Chris Fallin20e94b22015-05-13 16:43:48 -0700296 cd python
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400297 # Only test Python 2.6/3.x on Linux
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400298 if [ $(uname -s) == "Linux" ]; then
Jisi Liu72bd9c92015-10-06 10:48:57 -0700299 # py26 is currently disabled due to json_format
300 envlist=py\{27,33,34\}-cpp
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400301 else
302 envlist=py27-cpp
303 fi
304 tox -e $envlist
Chris Fallin20e94b22015-05-13 16:43:48 -0700305 cd ..
306}
307
308build_ruby19() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700309 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700310 cd ruby && bash travis-test.sh ruby-1.9 && cd ..
311}
312build_ruby20() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700313 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700314 cd ruby && bash travis-test.sh ruby-2.0 && cd ..
315}
316build_ruby21() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700317 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700318 cd ruby && bash travis-test.sh ruby-2.1 && cd ..
319}
320build_ruby22() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700321 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700322 cd ruby && bash travis-test.sh ruby-2.2 && cd ..
323}
324build_jruby() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700325 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700326 cd ruby && bash travis-test.sh jruby && cd ..
327}
328
Josh Habermane9cf31e2015-12-21 15:18:17 -0800329build_javascript() {
330 internal_build_cpp
Josh Haberman0d2d8bc2015-12-28 06:43:42 -0800331 cd js && npm install && npm test && cd ..
Josh Habermane9cf31e2015-12-21 15:18:17 -0800332}
333
Josh Haberman738393b2016-02-18 20:10:23 -0800334# Note: travis currently does not support testing more than one language so the
335# .travis.yml cheats and claims to only be cpp. If they add multiple language
336# support, this should probably get updated to install steps and/or
337# rvm/gemfile/jdk/etc. entries rather than manually doing the work.
338
339# .travis.yml uses matrix.exclude to block the cases where app-get can't be
340# use to install things.
341
342# -------- main --------
343
Josh Haberman738393b2016-02-18 20:10:23 -0800344if [ "$#" -ne 1 ]; then
345 echo "
346Usage: $0 { cpp |
Feng Xiaoa4f68b12016-07-19 17:20:31 -0700347 cpp_distcheck |
Josh Haberman738393b2016-02-18 20:10:23 -0800348 csharp |
349 java_jdk6 |
350 java_jdk7 |
351 java_oracle7 |
352 javanano_jdk6 |
353 javanano_jdk7 |
354 javanano_oracle7 |
355 objectivec_ios |
Thomas Van Lenten368a2f42016-05-24 11:27:33 -0400356 objectivec_ios_debug |
357 objectivec_ios_release |
Josh Haberman738393b2016-02-18 20:10:23 -0800358 objectivec_osx |
Sergio Campamáf0c14922016-06-14 11:26:01 -0700359 objectivec_cocoapods_integration |
Josh Haberman738393b2016-02-18 20:10:23 -0800360 python |
361 python_cpp |
Josh Habermanffc81182016-02-22 15:39:29 -0800362 ruby19 |
363 ruby20 |
364 ruby21 |
365 ruby22 |
Josh Haberman738393b2016-02-18 20:10:23 -0800366 jruby }
367"
368 exit 1
369fi
370
371set -e # exit immediately on error
372set -x # display all commands
373eval "build_$1"