blob: d1127508956b15d79b8f21dc3b1719318a1c81ac [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
Chris Fallin20e94b22015-05-13 16:43:48 -0700130 jdk7)
Josh Haberman0f8c25d2016-02-19 09:11:38 -0800131 on_travis sudo apt-get install openjdk-7-jdk
Chris Fallin20e94b22015-05-13 16:43:48 -0700132 export PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH
Feng Xiaoad49ed72016-07-21 11:37:46 -0700133 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
Chris Fallin20e94b22015-05-13 16:43:48 -0700134 ;;
135 oracle7)
Josh Habermanffc81182016-02-22 15:39:29 -0800136 if [ "$TRAVIS" == "true" ]; then
137 sudo apt-get install python-software-properties # for apt-add-repository
138 echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 select true" | \
139 sudo debconf-set-selections
140 yes | sudo apt-add-repository ppa:webupd8team/java
141 yes | sudo apt-get install oracle-java7-installer
142 fi;
Chris Fallin20e94b22015-05-13 16:43:48 -0700143 export PATH=/usr/lib/jvm/java-7-oracle/bin:$PATH
Feng Xiaoad49ed72016-07-21 11:37:46 -0700144 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
Chris Fallin20e94b22015-05-13 16:43:48 -0700145 ;;
146 esac
147
Josh Haberman1ee0fda2016-03-03 16:02:55 -0800148 if [ "$TRAVIS" != "true" ]; then
149 MAVEN_LOCAL_REPOSITORY=/var/maven_local_repository
150 MVN="$MVN -e -X --offline -Dmaven.repo.local=$MAVEN_LOCAL_REPOSITORY"
151 fi;
152
Chris Fallin20e94b22015-05-13 16:43:48 -0700153 which java
154 java -version
Feng Xiaoad49ed72016-07-21 11:37:46 -0700155 $MVN -version
Chris Fallin20e94b22015-05-13 16:43:48 -0700156}
157
Josh Habermand08c39c2016-02-20 12:03:39 -0800158# --batch-mode supresses download progress output that spams the logs.
Josh Habermanb28b3f62016-02-20 12:17:10 -0800159MVN="mvn --batch-mode"
Josh Habermand08c39c2016-02-20 12:03:39 -0800160
Chris Fallin20e94b22015-05-13 16:43:48 -0700161build_java() {
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800162 version=$1
163 dir=java_$version
Chris Fallin20e94b22015-05-13 16:43:48 -0700164 # Java build needs `protoc`.
Josh Haberman181c7f22015-07-15 11:05:10 -0700165 internal_build_cpp
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800166 cp -r java $dir
167 cd $dir && $MVN clean && $MVN test
Feng Xiao9e5fb552015-12-21 11:08:18 -0800168 cd ../..
169}
170
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800171# The conformance tests are hard-coded to work with the $ROOT/java directory.
172# So this can't run in parallel with two different sets of tests.
Feng Xiao9e5fb552015-12-21 11:08:18 -0800173build_java_with_conformance_tests() {
174 # Java build needs `protoc`.
175 internal_build_cpp
Josh Habermand08c39c2016-02-20 12:03:39 -0800176 cd java && $MVN test && $MVN install
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800177 cd util && $MVN package assembly:single
Feng Xiaoaf81dcf2015-12-21 03:25:59 -0800178 cd ../..
Chris Fallin20e94b22015-05-13 16:43:48 -0700179 cd conformance && make test_java && cd ..
180}
181
182build_javanano() {
183 # Java build needs `protoc`.
Josh Haberman181c7f22015-07-15 11:05:10 -0700184 internal_build_cpp
Josh Habermanb28b3f62016-02-20 12:17:10 -0800185 cd javanano && $MVN test && cd ..
Chris Fallin20e94b22015-05-13 16:43:48 -0700186}
187
Chris Fallin20e94b22015-05-13 16:43:48 -0700188build_java_jdk7() {
189 use_java jdk7
Feng Xiao9e5fb552015-12-21 11:08:18 -0800190 build_java_with_conformance_tests
Chris Fallin20e94b22015-05-13 16:43:48 -0700191}
192build_java_oracle7() {
193 use_java oracle7
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800194 build_java oracle7
Chris Fallin20e94b22015-05-13 16:43:48 -0700195}
196
Chris Fallin20e94b22015-05-13 16:43:48 -0700197build_javanano_jdk7() {
198 use_java jdk7
199 build_javanano
200}
201build_javanano_oracle7() {
202 use_java oracle7
203 build_javanano
204}
205
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400206internal_install_python_deps() {
Josh Haberman483533d2016-02-19 12:48:33 -0800207 if [ "$TRAVIS" != "true" ]; then
208 return;
209 fi
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400210 # Install tox (OS X doesn't have pip).
211 if [ $(uname -s) == "Darwin" ]; then
212 sudo easy_install tox
213 else
214 sudo pip install tox
215 fi
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400216 # Only install Python2.6/3.x on Linux.
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400217 if [ $(uname -s) == "Linux" ]; then
218 sudo apt-get install -y python-software-properties # for apt-add-repository
219 sudo apt-add-repository -y ppa:fkrull/deadsnakes
220 sudo apt-get update -qq
221 sudo apt-get install -y python2.6 python2.6-dev
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400222 sudo apt-get install -y python3.3 python3.3-dev
223 sudo apt-get install -y python3.4 python3.4-dev
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400224 fi
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400225}
226
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400227build_objectivec_ios() {
Thomas Van Lenten368a2f42016-05-24 11:27:33 -0400228 # Reused the build script that takes care of configuring and ensuring things
229 # are up to date. The OS X test runs the objc conformance test, so skip it
230 # here.
231 # Note: travis has xctool installed, and we've looked at using it in the past
232 # but it has ended up proving unreliable (bugs), an they are removing build
233 # support in favor of xcbuild (or just xcodebuild).
234 objectivec/DevTools/full_mac_build.sh \
235 --core-only --skip-xcode-osx --skip-objc-conformance "$@"
236}
237
238build_objectivec_ios_debug() {
239 build_objectivec_ios --skip-xcode-release
240}
241
242build_objectivec_ios_release() {
243 build_objectivec_ios --skip-xcode-debug
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400244}
245
246build_objectivec_osx() {
Thomas Van Lenten368a2f42016-05-24 11:27:33 -0400247 # Reused the build script that takes care of configuring and ensuring things
248 # are up to date.
249 objectivec/DevTools/full_mac_build.sh \
250 --core-only --skip-xcode-ios
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400251}
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400252
Sergio Campamáf0c14922016-06-14 11:26:01 -0700253build_objectivec_cocoapods_integration() {
254 # First, load the RVM environment in bash, needed to update ruby.
255 source ~/.rvm/scripts/rvm
Sergio Campamáf6d1d1a2016-07-15 13:59:09 -0700256 # Update rvm to the latest version. This is needed to solve
257 # https://github.com/google/protobuf/issues/1786 and may not be needed in the
258 # future when Travis updates the default version of rvm.
259 rvm get head
Sergio Campamáf0c14922016-06-14 11:26:01 -0700260 # Update ruby to 2.2.3 as the default one crashes with segmentation faults
261 # when using pod.
262 rvm use 2.2.3 --install --binary --fuzzy
263 # Update pod to the latest version.
264 gem install cocoapods --no-ri --no-rdoc
265 objectivec/Tests/CocoaPods/run_tests.sh
266}
267
Chris Fallin20e94b22015-05-13 16:43:48 -0700268build_python() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700269 internal_build_cpp
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400270 internal_install_python_deps
Chris Fallin20e94b22015-05-13 16:43:48 -0700271 cd python
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400272 # Only test Python 2.6/3.x on Linux
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400273 if [ $(uname -s) == "Linux" ]; then
Jie Luo2850a982015-10-09 17:07:03 -0700274 envlist=py\{26,27,33,34\}-python
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400275 else
276 envlist=py27-python
277 fi
278 tox -e $envlist
Chris Fallin20e94b22015-05-13 16:43:48 -0700279 cd ..
280}
281
282build_python_cpp() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700283 internal_build_cpp
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400284 internal_install_python_deps
285 export LD_LIBRARY_PATH=../src/.libs # for Linux
Tamir Dubersteinc91d9ab2015-05-14 21:32:39 -0400286 export DYLD_LIBRARY_PATH=../src/.libs # for OS X
Chris Fallin20e94b22015-05-13 16:43:48 -0700287 cd python
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400288 # Only test Python 2.6/3.x on Linux
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400289 if [ $(uname -s) == "Linux" ]; then
Jisi Liu72bd9c92015-10-06 10:48:57 -0700290 # py26 is currently disabled due to json_format
291 envlist=py\{27,33,34\}-cpp
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400292 else
293 envlist=py27-cpp
294 fi
295 tox -e $envlist
Chris Fallin20e94b22015-05-13 16:43:48 -0700296 cd ..
297}
298
299build_ruby19() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700300 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700301 cd ruby && bash travis-test.sh ruby-1.9 && cd ..
302}
303build_ruby20() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700304 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700305 cd ruby && bash travis-test.sh ruby-2.0 && cd ..
306}
307build_ruby21() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700308 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700309 cd ruby && bash travis-test.sh ruby-2.1 && cd ..
310}
311build_ruby22() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700312 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700313 cd ruby && bash travis-test.sh ruby-2.2 && cd ..
314}
315build_jruby() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700316 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700317 cd ruby && bash travis-test.sh jruby && cd ..
318}
319
Josh Habermane9cf31e2015-12-21 15:18:17 -0800320build_javascript() {
321 internal_build_cpp
Josh Haberman0d2d8bc2015-12-28 06:43:42 -0800322 cd js && npm install && npm test && cd ..
Josh Habermane9cf31e2015-12-21 15:18:17 -0800323}
324
Josh Haberman738393b2016-02-18 20:10:23 -0800325# Note: travis currently does not support testing more than one language so the
326# .travis.yml cheats and claims to only be cpp. If they add multiple language
327# support, this should probably get updated to install steps and/or
328# rvm/gemfile/jdk/etc. entries rather than manually doing the work.
329
330# .travis.yml uses matrix.exclude to block the cases where app-get can't be
331# use to install things.
332
333# -------- main --------
334
Josh Haberman738393b2016-02-18 20:10:23 -0800335if [ "$#" -ne 1 ]; then
336 echo "
337Usage: $0 { cpp |
Feng Xiaoa4f68b12016-07-19 17:20:31 -0700338 cpp_distcheck |
Josh Haberman738393b2016-02-18 20:10:23 -0800339 csharp |
Josh Haberman738393b2016-02-18 20:10:23 -0800340 java_jdk7 |
341 java_oracle7 |
Josh Haberman738393b2016-02-18 20:10:23 -0800342 javanano_jdk7 |
343 javanano_oracle7 |
344 objectivec_ios |
Thomas Van Lenten368a2f42016-05-24 11:27:33 -0400345 objectivec_ios_debug |
346 objectivec_ios_release |
Josh Haberman738393b2016-02-18 20:10:23 -0800347 objectivec_osx |
Sergio Campamáf0c14922016-06-14 11:26:01 -0700348 objectivec_cocoapods_integration |
Josh Haberman738393b2016-02-18 20:10:23 -0800349 python |
350 python_cpp |
Josh Habermanffc81182016-02-22 15:39:29 -0800351 ruby19 |
352 ruby20 |
353 ruby21 |
354 ruby22 |
Josh Haberman738393b2016-02-18 20:10:23 -0800355 jruby }
356"
357 exit 1
358fi
359
360set -e # exit immediately on error
361set -x # display all commands
362eval "build_$1"