blob: c28a5daaad685e4f9c4d5053118363dfdc71ca31 [file] [log] [blame]
Josh Haberman738393b2016-02-18 20:10:23 -08001#!/bin/bash
Thomas Van Lentenc4d36382015-06-09 13:35:41 -04002
Josh Haberman0f8c25d2016-02-19 09:11:38 -08003on_travis() {
4 if [ "$TRAVIS" == "true" ]; then
5 "$@"
6 fi
7}
8
Josh Haberman181c7f22015-07-15 11:05:10 -07009# For when some other test needs the C++ main build, including protoc and
10# libprotobuf.
11internal_build_cpp() {
Josh Haberman738393b2016-02-18 20:10:23 -080012 if [ -f src/protoc ]; then
13 # Already built.
14 return
15 fi
16
Josh Habermand33e93b2016-02-18 19:13:07 -080017 if [[ $(uname -s) == "Linux" && "$TRAVIS" == "true" ]]; then
Feng Xiao91258632015-12-21 03:34:28 -080018 # Install GCC 4.8 to replace the default GCC 4.6. We need 4.8 for more
19 # decent C++ 11 support in order to compile conformance tests.
20 sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
21 sudo apt-get update -qq
22 sudo apt-get install -qq g++-4.8
23 export CXX="g++-4.8" CC="gcc-4.8"
24 fi
Feng Xiao1e2fece2015-12-18 15:16:07 -080025
Chris Fallin20e94b22015-05-13 16:43:48 -070026 ./autogen.sh
27 ./configure
Josh Habermand33e93b2016-02-18 19:13:07 -080028 make $PARALLELISM
Josh Haberman181c7f22015-07-15 11:05:10 -070029}
30
31build_cpp() {
32 internal_build_cpp
Josh Habermand33e93b2016-02-18 19:13:07 -080033 make check $PARALLELISM
Chris Fallin20e94b22015-05-13 16:43:48 -070034 cd conformance && make test_cpp && cd ..
35}
36
37build_cpp_distcheck() {
38 ./autogen.sh
39 ./configure
Josh Habermand33e93b2016-02-18 19:13:07 -080040 make distcheck $PARALLELISM
Chris Fallin20e94b22015-05-13 16:43:48 -070041}
42
Jan Tattermuschddb36ef2015-05-18 17:34:02 -070043build_csharp() {
Jon Skeetb6defa72015-08-04 10:01:40 +010044 # Just for the conformance tests. We don't currently
45 # need to really build protoc, but it's simplest to keep with the
46 # conventions of the other builds.
47 internal_build_cpp
Josh Habermanffc81182016-02-22 15:39:29 -080048 NUGET=/usr/local/bin/nuget.exe
Jon Skeetb6defa72015-08-04 10:01:40 +010049
Josh Habermanffc81182016-02-22 15:39:29 -080050 if [ "$TRAVIS" == "true" ]; then
51 # Install latest version of Mono
52 sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
53 echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
54 echo "deb http://download.mono-project.com/repo/debian wheezy-libtiff-compat main" | sudo tee -a /etc/apt/sources.list.d/mono-xamarin.list
55 sudo apt-get update -qq
56 sudo apt-get install -qq mono-devel referenceassemblies-pcl nunit
57 wget www.nuget.org/NuGet.exe -O nuget.exe
58 NUGET=../../nuget.exe
59 fi
Jan Tattermuschddb36ef2015-05-18 17:34:02 -070060
Josh Habermanffc81182016-02-22 15:39:29 -080061 (cd csharp/src; mono $NUGET restore)
Jan Tattermuschddb36ef2015-05-18 17:34:02 -070062 csharp/buildall.sh
Josh Habermane891c292015-12-30 16:03:49 -080063 cd conformance && make test_csharp && cd ..
Jan Tattermuschddb36ef2015-05-18 17:34:02 -070064}
65
Tim Swast7e31c4d2015-11-20 15:32:53 -080066build_golang() {
67 # Go build needs `protoc`.
68 internal_build_cpp
69 # Add protoc to the path so that the examples build finds it.
70 export PATH="`pwd`/src:$PATH"
71
72 # Install Go and the Go protobuf compiler plugin.
73 sudo apt-get update -qq
74 sudo apt-get install -qq golang
75 export GOPATH="$HOME/gocode"
76 mkdir -p "$GOPATH/src/github.com/google"
77 ln -s "`pwd`" "$GOPATH/src/github.com/google/protobuf"
78 export PATH="$GOPATH/bin:$PATH"
79 go get github.com/golang/protobuf/protoc-gen-go
80
81 cd examples && make gotest && cd ..
82}
83
Chris Fallin20e94b22015-05-13 16:43:48 -070084use_java() {
Chris Fallin20e94b22015-05-13 16:43:48 -070085 version=$1
86 case "$version" in
87 jdk6)
Josh Haberman0f8c25d2016-02-19 09:11:38 -080088 on_travis sudo apt-get install openjdk-6-jdk
Chris Fallin20e94b22015-05-13 16:43:48 -070089 export PATH=/usr/lib/jvm/java-6-openjdk-amd64/bin:$PATH
90 ;;
91 jdk7)
Josh Haberman0f8c25d2016-02-19 09:11:38 -080092 on_travis sudo apt-get install openjdk-7-jdk
Chris Fallin20e94b22015-05-13 16:43:48 -070093 export PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH
94 ;;
95 oracle7)
Josh Habermanffc81182016-02-22 15:39:29 -080096 if [ "$TRAVIS" == "true" ]; then
97 sudo apt-get install python-software-properties # for apt-add-repository
98 echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 select true" | \
99 sudo debconf-set-selections
100 yes | sudo apt-add-repository ppa:webupd8team/java
101 yes | sudo apt-get install oracle-java7-installer
102 fi;
Chris Fallin20e94b22015-05-13 16:43:48 -0700103 export PATH=/usr/lib/jvm/java-7-oracle/bin:$PATH
104 ;;
105 esac
106
Josh Haberman1ee0fda2016-03-03 16:02:55 -0800107 if [ "$TRAVIS" != "true" ]; then
108 MAVEN_LOCAL_REPOSITORY=/var/maven_local_repository
109 MVN="$MVN -e -X --offline -Dmaven.repo.local=$MAVEN_LOCAL_REPOSITORY"
110 fi;
111
Chris Fallin20e94b22015-05-13 16:43:48 -0700112 which java
113 java -version
114}
115
Josh Habermand08c39c2016-02-20 12:03:39 -0800116# --batch-mode supresses download progress output that spams the logs.
Josh Habermanb28b3f62016-02-20 12:17:10 -0800117MVN="mvn --batch-mode"
Josh Habermand08c39c2016-02-20 12:03:39 -0800118
Chris Fallin20e94b22015-05-13 16:43:48 -0700119build_java() {
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800120 version=$1
121 dir=java_$version
Chris Fallin20e94b22015-05-13 16:43:48 -0700122 # Java build needs `protoc`.
Josh Haberman181c7f22015-07-15 11:05:10 -0700123 internal_build_cpp
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800124 cp -r java $dir
125 cd $dir && $MVN clean && $MVN test
Feng Xiao9e5fb552015-12-21 11:08:18 -0800126 cd ../..
127}
128
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800129# The conformance tests are hard-coded to work with the $ROOT/java directory.
130# So this can't run in parallel with two different sets of tests.
Feng Xiao9e5fb552015-12-21 11:08:18 -0800131build_java_with_conformance_tests() {
132 # Java build needs `protoc`.
133 internal_build_cpp
Josh Habermand08c39c2016-02-20 12:03:39 -0800134 cd java && $MVN test && $MVN install
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800135 cd util && $MVN package assembly:single
Feng Xiaoaf81dcf2015-12-21 03:25:59 -0800136 cd ../..
Chris Fallin20e94b22015-05-13 16:43:48 -0700137 cd conformance && make test_java && cd ..
138}
139
140build_javanano() {
141 # Java build needs `protoc`.
Josh Haberman181c7f22015-07-15 11:05:10 -0700142 internal_build_cpp
Josh Habermanb28b3f62016-02-20 12:17:10 -0800143 cd javanano && $MVN test && cd ..
Chris Fallin20e94b22015-05-13 16:43:48 -0700144}
145
146build_java_jdk6() {
147 use_java jdk6
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800148 build_java jdk6
Chris Fallin20e94b22015-05-13 16:43:48 -0700149}
150build_java_jdk7() {
151 use_java jdk7
Feng Xiao9e5fb552015-12-21 11:08:18 -0800152 build_java_with_conformance_tests
Chris Fallin20e94b22015-05-13 16:43:48 -0700153}
154build_java_oracle7() {
155 use_java oracle7
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800156 build_java oracle7
Chris Fallin20e94b22015-05-13 16:43:48 -0700157}
158
159build_javanano_jdk6() {
160 use_java jdk6
161 build_javanano
162}
163build_javanano_jdk7() {
164 use_java jdk7
165 build_javanano
166}
167build_javanano_oracle7() {
168 use_java oracle7
169 build_javanano
170}
171
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400172internal_install_python_deps() {
Josh Haberman483533d2016-02-19 12:48:33 -0800173 if [ "$TRAVIS" != "true" ]; then
174 return;
175 fi
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400176 # Install tox (OS X doesn't have pip).
177 if [ $(uname -s) == "Darwin" ]; then
178 sudo easy_install tox
179 else
180 sudo pip install tox
181 fi
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400182 # Only install Python2.6/3.x on Linux.
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400183 if [ $(uname -s) == "Linux" ]; then
184 sudo apt-get install -y python-software-properties # for apt-add-repository
185 sudo apt-add-repository -y ppa:fkrull/deadsnakes
186 sudo apt-get update -qq
187 sudo apt-get install -y python2.6 python2.6-dev
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400188 sudo apt-get install -y python3.3 python3.3-dev
189 sudo apt-get install -y python3.4 python3.4-dev
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400190 fi
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400191}
192
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500193internal_objectivec_common () {
194 # Make sure xctool is up to date. Adapted from
195 # http://docs.travis-ci.com/user/osx-ci-environment/
196 # We don't use a before_install because we test multiple OSes.
197 brew update
Thomas Van Lenten8c784502016-02-18 11:08:30 -0500198 # xctool 0.2.8 seems to have a bug where it randomly kills tests saying
199 # they failed. Disabling the updates, but letting it report about being
200 # updates as a hint that this needs to eventually get re-enabled.
201 # https://github.com/facebook/xctool/issues/619
202 # https://github.com/google/protobuf/issues/1232
203 brew outdated xctool || true
204 #brew outdated xctool || brew upgrade xctool
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500205 # Reused the build script that takes care of configuring and ensuring things
Thomas Van Lenten1745f7e2015-11-17 10:18:49 -0500206 # are up to date. Xcode and conformance tests will be directly invoked.
207 objectivec/DevTools/full_mac_build.sh \
208 --core-only --skip-xcode --skip-objc-conformance
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500209}
210
211internal_xctool_debug_and_release() {
Thomas Van Lentenefca3682016-02-16 15:10:14 -0500212 # Always use -reporter plain to avoid escape codes in output (makes travis
213 # logs easier to read).
214 xctool -reporter plain -configuration Debug "$@"
215 xctool -reporter plain -configuration Release "$@"
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400216}
217
218build_objectivec_ios() {
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500219 internal_objectivec_common
220 # https://github.com/facebook/xctool/issues/509 - unlike xcodebuild, xctool
221 # doesn't support >1 destination, so we have to build first and then run the
222 # tests one destination at a time.
223 internal_xctool_debug_and_release \
224 -project objectivec/ProtocolBuffers_iOS.xcodeproj \
225 -scheme ProtocolBuffers \
226 -sdk iphonesimulator \
227 build-tests
228 IOS_DESTINATIONS=(
229 "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
Thomas Van Lenten13241192016-02-16 09:19:50 -0500230 "platform=iOS Simulator,name=iPhone 6,OS=9.2" # 64bit
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500231 "platform=iOS Simulator,name=iPad 2,OS=8.1" # 32bit
Thomas Van Lenten13241192016-02-16 09:19:50 -0500232 "platform=iOS Simulator,name=iPad Air,OS=9.2" # 64bit
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500233 )
234 for i in "${IOS_DESTINATIONS[@]}" ; do
235 internal_xctool_debug_and_release \
236 -project objectivec/ProtocolBuffers_iOS.xcodeproj \
237 -scheme ProtocolBuffers \
238 -sdk iphonesimulator \
239 -destination "${i}" \
Thomas Van Lenten8c784502016-02-18 11:08:30 -0500240 run-tests
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500241 done
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400242}
243
244build_objectivec_osx() {
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500245 internal_objectivec_common
246 internal_xctool_debug_and_release \
247 -project objectivec/ProtocolBuffers_OSX.xcodeproj \
248 -scheme ProtocolBuffers \
249 -destination "platform=OS X,arch=x86_64" \
250 test
Thomas Van Lenten1745f7e2015-11-17 10:18:49 -0500251 cd conformance && make test_objc && cd ..
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400252}
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400253
Chris Fallin20e94b22015-05-13 16:43:48 -0700254build_python() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700255 internal_build_cpp
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400256 internal_install_python_deps
Chris Fallin20e94b22015-05-13 16:43:48 -0700257 cd python
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400258 # Only test Python 2.6/3.x on Linux
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400259 if [ $(uname -s) == "Linux" ]; then
Jie Luo2850a982015-10-09 17:07:03 -0700260 envlist=py\{26,27,33,34\}-python
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400261 else
262 envlist=py27-python
263 fi
264 tox -e $envlist
Chris Fallin20e94b22015-05-13 16:43:48 -0700265 cd ..
266}
267
268build_python_cpp() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700269 internal_build_cpp
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400270 internal_install_python_deps
271 export LD_LIBRARY_PATH=../src/.libs # for Linux
Tamir Dubersteinc91d9ab2015-05-14 21:32:39 -0400272 export DYLD_LIBRARY_PATH=../src/.libs # for OS X
Chris Fallin20e94b22015-05-13 16:43:48 -0700273 cd python
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400274 # Only test Python 2.6/3.x on Linux
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400275 if [ $(uname -s) == "Linux" ]; then
Jisi Liu72bd9c92015-10-06 10:48:57 -0700276 # py26 is currently disabled due to json_format
277 envlist=py\{27,33,34\}-cpp
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400278 else
279 envlist=py27-cpp
280 fi
281 tox -e $envlist
Chris Fallin20e94b22015-05-13 16:43:48 -0700282 cd ..
283}
284
285build_ruby19() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700286 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700287 cd ruby && bash travis-test.sh ruby-1.9 && cd ..
288}
289build_ruby20() {
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-2.0 && cd ..
292}
293build_ruby21() {
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.1 && cd ..
296}
297build_ruby22() {
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.2 && cd ..
300}
301build_jruby() {
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 jruby && cd ..
304}
305
Josh Habermane9cf31e2015-12-21 15:18:17 -0800306build_javascript() {
307 internal_build_cpp
Josh Haberman0d2d8bc2015-12-28 06:43:42 -0800308 cd js && npm install && npm test && cd ..
Josh Habermane9cf31e2015-12-21 15:18:17 -0800309}
310
Josh Haberman738393b2016-02-18 20:10:23 -0800311[ -n "${PARALLELISM}" ] && PARALLELISM=-j8
312
313# Note: travis currently does not support testing more than one language so the
314# .travis.yml cheats and claims to only be cpp. If they add multiple language
315# support, this should probably get updated to install steps and/or
316# rvm/gemfile/jdk/etc. entries rather than manually doing the work.
317
318# .travis.yml uses matrix.exclude to block the cases where app-get can't be
319# use to install things.
320
321# -------- main --------
322
323# Set value used in tests.sh.
324PARALLELISM=-j2
325
326if [ "$#" -ne 1 ]; then
327 echo "
328Usage: $0 { cpp |
329 csharp |
330 java_jdk6 |
331 java_jdk7 |
332 java_oracle7 |
333 javanano_jdk6 |
334 javanano_jdk7 |
335 javanano_oracle7 |
336 objectivec_ios |
337 objectivec_osx |
338 python |
339 python_cpp |
Josh Habermanffc81182016-02-22 15:39:29 -0800340 ruby19 |
341 ruby20 |
342 ruby21 |
343 ruby22 |
Josh Haberman738393b2016-02-18 20:10:23 -0800344 jruby }
345"
346 exit 1
347fi
348
349set -e # exit immediately on error
350set -x # display all commands
351eval "build_$1"