blob: c973ec6cb42c335ebca88b6ae5103a5b44dd291f [file] [log] [blame]
Tamir Dubersteine54c1452015-05-06 20:24:58 -04001#!/usr/bin/env bash
Chris Fallin20e94b22015-05-13 16:43:48 -07002
Thomas Van Lentenc4d36382015-06-09 13:35:41 -04003# Note: travis currently does not support testing more than one language so the
4# .travis.yml cheats and claims to only be cpp. If they add multiple language
5# support, this should probably get updated to install steps and/or
6# rvm/gemfile/jdk/etc. entries rather than manually doing the work.
7
8# .travis.yml uses matrix.exclude to block the cases where app-get can't be
9# use to install things.
10
Josh Haberman181c7f22015-07-15 11:05:10 -070011# For when some other test needs the C++ main build, including protoc and
12# libprotobuf.
13internal_build_cpp() {
Feng Xiao91258632015-12-21 03:34:28 -080014 if [ $(uname -s) == "Linux" ]; then
15 # Install GCC 4.8 to replace the default GCC 4.6. We need 4.8 for more
16 # decent C++ 11 support in order to compile conformance tests.
17 sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
18 sudo apt-get update -qq
19 sudo apt-get install -qq g++-4.8
20 export CXX="g++-4.8" CC="gcc-4.8"
21 fi
Feng Xiao1e2fece2015-12-18 15:16:07 -080022
Chris Fallin20e94b22015-05-13 16:43:48 -070023 ./autogen.sh
24 ./configure
25 make -j2
Josh Haberman181c7f22015-07-15 11:05:10 -070026}
27
28build_cpp() {
29 internal_build_cpp
Chris Fallin20e94b22015-05-13 16:43:48 -070030 make check -j2
31 cd conformance && make test_cpp && cd ..
32}
33
34build_cpp_distcheck() {
35 ./autogen.sh
36 ./configure
37 make distcheck -j2
38}
39
Jan Tattermuschddb36ef2015-05-18 17:34:02 -070040build_csharp() {
Jon Skeetb6defa72015-08-04 10:01:40 +010041 # Just for the conformance tests. We don't currently
42 # need to really build protoc, but it's simplest to keep with the
43 # conventions of the other builds.
44 internal_build_cpp
45
Jan Tattermuschddb36ef2015-05-18 17:34:02 -070046 # Install latest version of Mono
47 sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
48 echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
49 echo "deb http://download.mono-project.com/repo/debian wheezy-libtiff-compat main" | sudo tee -a /etc/apt/sources.list.d/mono-xamarin.list
50 sudo apt-get update -qq
51 sudo apt-get install -qq mono-devel referenceassemblies-pcl nunit
52 wget www.nuget.org/NuGet.exe -O nuget.exe
53
54 (cd csharp/src; mono ../../nuget.exe restore)
55 csharp/buildall.sh
Josh Habermane891c292015-12-30 16:03:49 -080056 cd conformance && make test_csharp && cd ..
Jan Tattermuschddb36ef2015-05-18 17:34:02 -070057}
58
Tim Swast7e31c4d2015-11-20 15:32:53 -080059build_golang() {
60 # Go build needs `protoc`.
61 internal_build_cpp
62 # Add protoc to the path so that the examples build finds it.
63 export PATH="`pwd`/src:$PATH"
64
65 # Install Go and the Go protobuf compiler plugin.
66 sudo apt-get update -qq
67 sudo apt-get install -qq golang
68 export GOPATH="$HOME/gocode"
69 mkdir -p "$GOPATH/src/github.com/google"
70 ln -s "`pwd`" "$GOPATH/src/github.com/google/protobuf"
71 export PATH="$GOPATH/bin:$PATH"
72 go get github.com/golang/protobuf/protoc-gen-go
73
74 cd examples && make gotest && cd ..
75}
76
Chris Fallin20e94b22015-05-13 16:43:48 -070077use_java() {
Chris Fallin20e94b22015-05-13 16:43:48 -070078 version=$1
79 case "$version" in
80 jdk6)
81 sudo apt-get install openjdk-6-jdk
82 export PATH=/usr/lib/jvm/java-6-openjdk-amd64/bin:$PATH
83 ;;
84 jdk7)
85 sudo apt-get install openjdk-7-jdk
86 export PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH
87 ;;
88 oracle7)
89 sudo apt-get install python-software-properties # for apt-add-repository
90 echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 select true" | \
91 sudo debconf-set-selections
92 yes | sudo apt-add-repository ppa:webupd8team/java
93 yes | sudo apt-get install oracle-java7-installer
94 export PATH=/usr/lib/jvm/java-7-oracle/bin:$PATH
95 ;;
96 esac
97
98 which java
99 java -version
100}
101
102build_java() {
103 # Java build needs `protoc`.
Josh Haberman181c7f22015-07-15 11:05:10 -0700104 internal_build_cpp
Feng Xiaoaf81dcf2015-12-21 03:25:59 -0800105 cd java && mvn test && mvn install
Feng Xiao9e5fb552015-12-21 11:08:18 -0800106 cd util && mvn test
107 cd ../..
108}
109
110build_java_with_conformance_tests() {
111 # Java build needs `protoc`.
112 internal_build_cpp
113 cd java && mvn test && mvn install
Feng Xiaoaf81dcf2015-12-21 03:25:59 -0800114 cd util && mvn test && mvn assembly:single
115 cd ../..
Chris Fallin20e94b22015-05-13 16:43:48 -0700116 cd conformance && make test_java && cd ..
117}
118
119build_javanano() {
120 # Java build needs `protoc`.
Josh Haberman181c7f22015-07-15 11:05:10 -0700121 internal_build_cpp
Chris Fallin20e94b22015-05-13 16:43:48 -0700122 cd javanano && mvn test && cd ..
123}
124
125build_java_jdk6() {
126 use_java jdk6
127 build_java
128}
129build_java_jdk7() {
130 use_java jdk7
Feng Xiao9e5fb552015-12-21 11:08:18 -0800131 build_java_with_conformance_tests
Chris Fallin20e94b22015-05-13 16:43:48 -0700132}
133build_java_oracle7() {
134 use_java oracle7
135 build_java
136}
137
138build_javanano_jdk6() {
139 use_java jdk6
140 build_javanano
141}
142build_javanano_jdk7() {
143 use_java jdk7
144 build_javanano
145}
146build_javanano_oracle7() {
147 use_java oracle7
148 build_javanano
149}
150
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400151internal_install_python_deps() {
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400152 # Install tox (OS X doesn't have pip).
153 if [ $(uname -s) == "Darwin" ]; then
154 sudo easy_install tox
155 else
156 sudo pip install tox
157 fi
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400158 # Only install Python2.6/3.x on Linux.
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400159 if [ $(uname -s) == "Linux" ]; then
160 sudo apt-get install -y python-software-properties # for apt-add-repository
161 sudo apt-add-repository -y ppa:fkrull/deadsnakes
162 sudo apt-get update -qq
163 sudo apt-get install -y python2.6 python2.6-dev
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400164 sudo apt-get install -y python3.3 python3.3-dev
165 sudo apt-get install -y python3.4 python3.4-dev
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400166 fi
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400167}
168
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500169internal_objectivec_common () {
170 # Make sure xctool is up to date. Adapted from
171 # http://docs.travis-ci.com/user/osx-ci-environment/
172 # We don't use a before_install because we test multiple OSes.
173 brew update
174 brew outdated xctool || brew upgrade xctool
175 # Reused the build script that takes care of configuring and ensuring things
Thomas Van Lenten1745f7e2015-11-17 10:18:49 -0500176 # are up to date. Xcode and conformance tests will be directly invoked.
177 objectivec/DevTools/full_mac_build.sh \
178 --core-only --skip-xcode --skip-objc-conformance
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500179}
180
181internal_xctool_debug_and_release() {
Thomas Van Lentenefca3682016-02-16 15:10:14 -0500182 # Always use -reporter plain to avoid escape codes in output (makes travis
183 # logs easier to read).
184 xctool -reporter plain -configuration Debug "$@"
185 xctool -reporter plain -configuration Release "$@"
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400186}
187
188build_objectivec_ios() {
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500189 internal_objectivec_common
190 # https://github.com/facebook/xctool/issues/509 - unlike xcodebuild, xctool
191 # doesn't support >1 destination, so we have to build first and then run the
192 # tests one destination at a time.
193 internal_xctool_debug_and_release \
194 -project objectivec/ProtocolBuffers_iOS.xcodeproj \
195 -scheme ProtocolBuffers \
196 -sdk iphonesimulator \
197 build-tests
198 IOS_DESTINATIONS=(
199 "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
Thomas Van Lenten13241192016-02-16 09:19:50 -0500200 "platform=iOS Simulator,name=iPhone 6,OS=9.2" # 64bit
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500201 "platform=iOS Simulator,name=iPad 2,OS=8.1" # 32bit
Thomas Van Lenten13241192016-02-16 09:19:50 -0500202 "platform=iOS Simulator,name=iPad Air,OS=9.2" # 64bit
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500203 )
204 for i in "${IOS_DESTINATIONS[@]}" ; do
Thomas Van Lenten30e645b2016-02-16 11:16:42 -0500205 # Throw -newSimulatorInstance in incase it helps with the flake that
206 # started happening after xctool 0.2.8 got released.
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500207 internal_xctool_debug_and_release \
208 -project objectivec/ProtocolBuffers_iOS.xcodeproj \
209 -scheme ProtocolBuffers \
210 -sdk iphonesimulator \
211 -destination "${i}" \
Thomas Van Lenten30e645b2016-02-16 11:16:42 -0500212 run-tests \
213 -newSimulatorInstance
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
Chris Fallin20e94b22015-05-13 16:43:48 -0700284# -------- main --------
285
286if [ "$#" -ne 1 ]; then
287 echo "
288Usage: $0 { cpp |
Jan Tattermuschddb36ef2015-05-18 17:34:02 -0700289 csharp |
Chris Fallin20e94b22015-05-13 16:43:48 -0700290 java_jdk6 |
291 java_jdk7 |
292 java_oracle7 |
293 javanano_jdk6 |
294 javanano_jdk7 |
295 javanano_oracle7 |
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400296 objectivec_ios |
297 objectivec_osx |
Chris Fallin20e94b22015-05-13 16:43:48 -0700298 python |
299 python_cpp |
300 ruby_19 |
301 ruby_20 |
302 ruby_21 |
303 ruby_22 |
304 jruby }
305"
306 exit 1
307fi
308
309set -e # exit immediately on error
310set -x # display all commands
311eval "build_$1"