blob: 718d6de9dfcb62d04ef5c1c6322f76bae0f79543 [file] [log] [blame]
Josh Haberman738393b2016-02-18 20:10:23 -08001#!/bin/bash
Thomas Van Lentenc4d36382015-06-09 13:35:41 -04002
Josh Haberman181c7f22015-07-15 11:05:10 -07003# For when some other test needs the C++ main build, including protoc and
4# libprotobuf.
5internal_build_cpp() {
Josh Haberman738393b2016-02-18 20:10:23 -08006 if [ -f src/protoc ]; then
7 # Already built.
8 return
9 fi
10
Josh Habermand33e93b2016-02-18 19:13:07 -080011 if [[ $(uname -s) == "Linux" && "$TRAVIS" == "true" ]]; then
Feng Xiao91258632015-12-21 03:34:28 -080012 # Install GCC 4.8 to replace the default GCC 4.6. We need 4.8 for more
13 # decent C++ 11 support in order to compile conformance tests.
14 sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
15 sudo apt-get update -qq
16 sudo apt-get install -qq g++-4.8
17 export CXX="g++-4.8" CC="gcc-4.8"
18 fi
Feng Xiao1e2fece2015-12-18 15:16:07 -080019
Chris Fallin20e94b22015-05-13 16:43:48 -070020 ./autogen.sh
21 ./configure
Josh Habermand33e93b2016-02-18 19:13:07 -080022 make $PARALLELISM
Josh Haberman181c7f22015-07-15 11:05:10 -070023}
24
25build_cpp() {
26 internal_build_cpp
Josh Habermand33e93b2016-02-18 19:13:07 -080027 make check $PARALLELISM
Chris Fallin20e94b22015-05-13 16:43:48 -070028 cd conformance && make test_cpp && cd ..
29}
30
31build_cpp_distcheck() {
32 ./autogen.sh
33 ./configure
Josh Habermand33e93b2016-02-18 19:13:07 -080034 make distcheck $PARALLELISM
Chris Fallin20e94b22015-05-13 16:43:48 -070035}
36
Jan Tattermuschddb36ef2015-05-18 17:34:02 -070037build_csharp() {
Jon Skeetb6defa72015-08-04 10:01:40 +010038 # Just for the conformance tests. We don't currently
39 # need to really build protoc, but it's simplest to keep with the
40 # conventions of the other builds.
41 internal_build_cpp
42
Jan Tattermuschddb36ef2015-05-18 17:34:02 -070043 # Install latest version of Mono
44 sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
45 echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
46 echo "deb http://download.mono-project.com/repo/debian wheezy-libtiff-compat main" | sudo tee -a /etc/apt/sources.list.d/mono-xamarin.list
47 sudo apt-get update -qq
48 sudo apt-get install -qq mono-devel referenceassemblies-pcl nunit
49 wget www.nuget.org/NuGet.exe -O nuget.exe
50
51 (cd csharp/src; mono ../../nuget.exe restore)
52 csharp/buildall.sh
Josh Habermane891c292015-12-30 16:03:49 -080053 cd conformance && make test_csharp && cd ..
Jan Tattermuschddb36ef2015-05-18 17:34:02 -070054}
55
Tim Swast7e31c4d2015-11-20 15:32:53 -080056build_golang() {
57 # Go build needs `protoc`.
58 internal_build_cpp
59 # Add protoc to the path so that the examples build finds it.
60 export PATH="`pwd`/src:$PATH"
61
62 # Install Go and the Go protobuf compiler plugin.
63 sudo apt-get update -qq
64 sudo apt-get install -qq golang
65 export GOPATH="$HOME/gocode"
66 mkdir -p "$GOPATH/src/github.com/google"
67 ln -s "`pwd`" "$GOPATH/src/github.com/google/protobuf"
68 export PATH="$GOPATH/bin:$PATH"
69 go get github.com/golang/protobuf/protoc-gen-go
70
71 cd examples && make gotest && cd ..
72}
73
Chris Fallin20e94b22015-05-13 16:43:48 -070074use_java() {
Chris Fallin20e94b22015-05-13 16:43:48 -070075 version=$1
76 case "$version" in
77 jdk6)
78 sudo apt-get install openjdk-6-jdk
79 export PATH=/usr/lib/jvm/java-6-openjdk-amd64/bin:$PATH
80 ;;
81 jdk7)
82 sudo apt-get install openjdk-7-jdk
83 export PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH
84 ;;
85 oracle7)
86 sudo apt-get install python-software-properties # for apt-add-repository
87 echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 select true" | \
88 sudo debconf-set-selections
89 yes | sudo apt-add-repository ppa:webupd8team/java
90 yes | sudo apt-get install oracle-java7-installer
91 export PATH=/usr/lib/jvm/java-7-oracle/bin:$PATH
92 ;;
93 esac
94
95 which java
96 java -version
97}
98
99build_java() {
100 # Java build needs `protoc`.
Josh Haberman181c7f22015-07-15 11:05:10 -0700101 internal_build_cpp
Feng Xiaoaf81dcf2015-12-21 03:25:59 -0800102 cd java && mvn test && mvn install
Feng Xiao9e5fb552015-12-21 11:08:18 -0800103 cd util && mvn test
104 cd ../..
105}
106
107build_java_with_conformance_tests() {
108 # Java build needs `protoc`.
109 internal_build_cpp
110 cd java && mvn test && mvn install
Feng Xiaoaf81dcf2015-12-21 03:25:59 -0800111 cd util && mvn test && mvn assembly:single
112 cd ../..
Chris Fallin20e94b22015-05-13 16:43:48 -0700113 cd conformance && make test_java && cd ..
114}
115
116build_javanano() {
117 # Java build needs `protoc`.
Josh Haberman181c7f22015-07-15 11:05:10 -0700118 internal_build_cpp
Chris Fallin20e94b22015-05-13 16:43:48 -0700119 cd javanano && mvn test && cd ..
120}
121
122build_java_jdk6() {
123 use_java jdk6
124 build_java
125}
126build_java_jdk7() {
127 use_java jdk7
Feng Xiao9e5fb552015-12-21 11:08:18 -0800128 build_java_with_conformance_tests
Chris Fallin20e94b22015-05-13 16:43:48 -0700129}
130build_java_oracle7() {
131 use_java oracle7
132 build_java
133}
134
135build_javanano_jdk6() {
136 use_java jdk6
137 build_javanano
138}
139build_javanano_jdk7() {
140 use_java jdk7
141 build_javanano
142}
143build_javanano_oracle7() {
144 use_java oracle7
145 build_javanano
146}
147
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400148internal_install_python_deps() {
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400149 # Install tox (OS X doesn't have pip).
150 if [ $(uname -s) == "Darwin" ]; then
151 sudo easy_install tox
152 else
153 sudo pip install tox
154 fi
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400155 # Only install Python2.6/3.x on Linux.
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400156 if [ $(uname -s) == "Linux" ]; then
157 sudo apt-get install -y python-software-properties # for apt-add-repository
158 sudo apt-add-repository -y ppa:fkrull/deadsnakes
159 sudo apt-get update -qq
160 sudo apt-get install -y python2.6 python2.6-dev
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400161 sudo apt-get install -y python3.3 python3.3-dev
162 sudo apt-get install -y python3.4 python3.4-dev
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400163 fi
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400164}
165
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500166internal_objectivec_common () {
167 # Make sure xctool is up to date. Adapted from
168 # http://docs.travis-ci.com/user/osx-ci-environment/
169 # We don't use a before_install because we test multiple OSes.
170 brew update
Thomas Van Lenten8c784502016-02-18 11:08:30 -0500171 # xctool 0.2.8 seems to have a bug where it randomly kills tests saying
172 # they failed. Disabling the updates, but letting it report about being
173 # updates as a hint that this needs to eventually get re-enabled.
174 # https://github.com/facebook/xctool/issues/619
175 # https://github.com/google/protobuf/issues/1232
176 brew outdated xctool || true
177 #brew outdated xctool || brew upgrade xctool
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500178 # Reused the build script that takes care of configuring and ensuring things
Thomas Van Lenten1745f7e2015-11-17 10:18:49 -0500179 # are up to date. Xcode and conformance tests will be directly invoked.
180 objectivec/DevTools/full_mac_build.sh \
181 --core-only --skip-xcode --skip-objc-conformance
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500182}
183
184internal_xctool_debug_and_release() {
Thomas Van Lentenefca3682016-02-16 15:10:14 -0500185 # Always use -reporter plain to avoid escape codes in output (makes travis
186 # logs easier to read).
187 xctool -reporter plain -configuration Debug "$@"
188 xctool -reporter plain -configuration Release "$@"
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400189}
190
191build_objectivec_ios() {
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500192 internal_objectivec_common
193 # https://github.com/facebook/xctool/issues/509 - unlike xcodebuild, xctool
194 # doesn't support >1 destination, so we have to build first and then run the
195 # tests one destination at a time.
196 internal_xctool_debug_and_release \
197 -project objectivec/ProtocolBuffers_iOS.xcodeproj \
198 -scheme ProtocolBuffers \
199 -sdk iphonesimulator \
200 build-tests
201 IOS_DESTINATIONS=(
202 "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
Thomas Van Lenten13241192016-02-16 09:19:50 -0500203 "platform=iOS Simulator,name=iPhone 6,OS=9.2" # 64bit
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500204 "platform=iOS Simulator,name=iPad 2,OS=8.1" # 32bit
Thomas Van Lenten13241192016-02-16 09:19:50 -0500205 "platform=iOS Simulator,name=iPad Air,OS=9.2" # 64bit
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500206 )
207 for i in "${IOS_DESTINATIONS[@]}" ; do
208 internal_xctool_debug_and_release \
209 -project objectivec/ProtocolBuffers_iOS.xcodeproj \
210 -scheme ProtocolBuffers \
211 -sdk iphonesimulator \
212 -destination "${i}" \
Thomas Van Lenten8c784502016-02-18 11:08:30 -0500213 run-tests
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500214 done
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400215}
216
217build_objectivec_osx() {
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500218 internal_objectivec_common
219 internal_xctool_debug_and_release \
220 -project objectivec/ProtocolBuffers_OSX.xcodeproj \
221 -scheme ProtocolBuffers \
222 -destination "platform=OS X,arch=x86_64" \
223 test
Thomas Van Lenten1745f7e2015-11-17 10:18:49 -0500224 cd conformance && make test_objc && cd ..
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400225}
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400226
Chris Fallin20e94b22015-05-13 16:43:48 -0700227build_python() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700228 internal_build_cpp
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400229 internal_install_python_deps
Chris Fallin20e94b22015-05-13 16:43:48 -0700230 cd python
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400231 # Only test Python 2.6/3.x on Linux
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400232 if [ $(uname -s) == "Linux" ]; then
Jie Luo2850a982015-10-09 17:07:03 -0700233 envlist=py\{26,27,33,34\}-python
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400234 else
235 envlist=py27-python
236 fi
237 tox -e $envlist
Chris Fallin20e94b22015-05-13 16:43:48 -0700238 cd ..
239}
240
241build_python_cpp() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700242 internal_build_cpp
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400243 internal_install_python_deps
244 export LD_LIBRARY_PATH=../src/.libs # for Linux
Tamir Dubersteinc91d9ab2015-05-14 21:32:39 -0400245 export DYLD_LIBRARY_PATH=../src/.libs # for OS X
Chris Fallin20e94b22015-05-13 16:43:48 -0700246 cd python
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400247 # Only test Python 2.6/3.x on Linux
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400248 if [ $(uname -s) == "Linux" ]; then
Jisi Liu72bd9c92015-10-06 10:48:57 -0700249 # py26 is currently disabled due to json_format
250 envlist=py\{27,33,34\}-cpp
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400251 else
252 envlist=py27-cpp
253 fi
254 tox -e $envlist
Chris Fallin20e94b22015-05-13 16:43:48 -0700255 cd ..
256}
257
258build_ruby19() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700259 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700260 cd ruby && bash travis-test.sh ruby-1.9 && cd ..
261}
262build_ruby20() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700263 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700264 cd ruby && bash travis-test.sh ruby-2.0 && cd ..
265}
266build_ruby21() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700267 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700268 cd ruby && bash travis-test.sh ruby-2.1 && cd ..
269}
270build_ruby22() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700271 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700272 cd ruby && bash travis-test.sh ruby-2.2 && cd ..
273}
274build_jruby() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700275 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700276 cd ruby && bash travis-test.sh jruby && cd ..
277}
278
Josh Habermane9cf31e2015-12-21 15:18:17 -0800279build_javascript() {
280 internal_build_cpp
Josh Haberman0d2d8bc2015-12-28 06:43:42 -0800281 cd js && npm install && npm test && cd ..
Josh Habermane9cf31e2015-12-21 15:18:17 -0800282}
283
Josh Haberman738393b2016-02-18 20:10:23 -0800284[ -n "${PARALLELISM}" ] && PARALLELISM=-j8
285
286# Note: travis currently does not support testing more than one language so the
287# .travis.yml cheats and claims to only be cpp. If they add multiple language
288# support, this should probably get updated to install steps and/or
289# rvm/gemfile/jdk/etc. entries rather than manually doing the work.
290
291# .travis.yml uses matrix.exclude to block the cases where app-get can't be
292# use to install things.
293
294# -------- main --------
295
296# Set value used in tests.sh.
297PARALLELISM=-j2
298
299if [ "$#" -ne 1 ]; then
300 echo "
301Usage: $0 { cpp |
302 csharp |
303 java_jdk6 |
304 java_jdk7 |
305 java_oracle7 |
306 javanano_jdk6 |
307 javanano_jdk7 |
308 javanano_oracle7 |
309 objectivec_ios |
310 objectivec_osx |
311 python |
312 python_cpp |
313 ruby_19 |
314 ruby_20 |
315 ruby_21 |
316 ruby_22 |
317 jruby }
318"
319 exit 1
320fi
321
322set -e # exit immediately on error
323set -x # display all commands
324eval "build_$1"