blob: 459f83f5f8e34400549636dd4665b9174e0cc302 [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() {
Chris Fallin20e94b22015-05-13 16:43:48 -070014 ./autogen.sh
15 ./configure
16 make -j2
Josh Haberman181c7f22015-07-15 11:05:10 -070017}
18
19build_cpp() {
20 internal_build_cpp
Chris Fallin20e94b22015-05-13 16:43:48 -070021 make check -j2
22 cd conformance && make test_cpp && cd ..
23}
24
25build_cpp_distcheck() {
26 ./autogen.sh
27 ./configure
28 make distcheck -j2
29}
30
Jan Tattermuschddb36ef2015-05-18 17:34:02 -070031build_csharp() {
Jon Skeetb6defa72015-08-04 10:01:40 +010032 # Just for the conformance tests. We don't currently
33 # need to really build protoc, but it's simplest to keep with the
34 # conventions of the other builds.
35 internal_build_cpp
36
Jan Tattermuschddb36ef2015-05-18 17:34:02 -070037 # Install latest version of Mono
38 sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
39 echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
40 echo "deb http://download.mono-project.com/repo/debian wheezy-libtiff-compat main" | sudo tee -a /etc/apt/sources.list.d/mono-xamarin.list
41 sudo apt-get update -qq
42 sudo apt-get install -qq mono-devel referenceassemblies-pcl nunit
43 wget www.nuget.org/NuGet.exe -O nuget.exe
44
45 (cd csharp/src; mono ../../nuget.exe restore)
46 csharp/buildall.sh
Jon Skeetb6defa72015-08-04 10:01:40 +010047 cd conformance && make test_csharp && cd ..
Jan Tattermuschddb36ef2015-05-18 17:34:02 -070048}
49
Chris Fallin20e94b22015-05-13 16:43:48 -070050use_java() {
Chris Fallin20e94b22015-05-13 16:43:48 -070051 version=$1
52 case "$version" in
53 jdk6)
54 sudo apt-get install openjdk-6-jdk
55 export PATH=/usr/lib/jvm/java-6-openjdk-amd64/bin:$PATH
56 ;;
57 jdk7)
58 sudo apt-get install openjdk-7-jdk
59 export PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH
60 ;;
61 oracle7)
62 sudo apt-get install python-software-properties # for apt-add-repository
63 echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 select true" | \
64 sudo debconf-set-selections
65 yes | sudo apt-add-repository ppa:webupd8team/java
66 yes | sudo apt-get install oracle-java7-installer
67 export PATH=/usr/lib/jvm/java-7-oracle/bin:$PATH
68 ;;
69 esac
70
71 which java
72 java -version
73}
74
75build_java() {
76 # Java build needs `protoc`.
Josh Haberman181c7f22015-07-15 11:05:10 -070077 internal_build_cpp
Chris Fallin20e94b22015-05-13 16:43:48 -070078 cd java && mvn test && cd ..
79 cd conformance && make test_java && cd ..
80}
81
82build_javanano() {
83 # Java build needs `protoc`.
Josh Haberman181c7f22015-07-15 11:05:10 -070084 internal_build_cpp
Chris Fallin20e94b22015-05-13 16:43:48 -070085 cd javanano && mvn test && cd ..
86}
87
88build_java_jdk6() {
89 use_java jdk6
90 build_java
91}
92build_java_jdk7() {
93 use_java jdk7
94 build_java
95}
96build_java_oracle7() {
97 use_java oracle7
98 build_java
99}
100
101build_javanano_jdk6() {
102 use_java jdk6
103 build_javanano
104}
105build_javanano_jdk7() {
106 use_java jdk7
107 build_javanano
108}
109build_javanano_oracle7() {
110 use_java oracle7
111 build_javanano
112}
113
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400114internal_install_python_deps() {
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400115 # Install tox (OS X doesn't have pip).
116 if [ $(uname -s) == "Darwin" ]; then
117 sudo easy_install tox
118 else
119 sudo pip install tox
120 fi
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400121 # Only install Python2.6/3.x on Linux.
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400122 if [ $(uname -s) == "Linux" ]; then
123 sudo apt-get install -y python-software-properties # for apt-add-repository
124 sudo apt-add-repository -y ppa:fkrull/deadsnakes
125 sudo apt-get update -qq
126 sudo apt-get install -y python2.6 python2.6-dev
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400127 sudo apt-get install -y python3.3 python3.3-dev
128 sudo apt-get install -y python3.4 python3.4-dev
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400129 fi
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400130}
131
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500132internal_objectivec_common () {
133 # Make sure xctool is up to date. Adapted from
134 # http://docs.travis-ci.com/user/osx-ci-environment/
135 # We don't use a before_install because we test multiple OSes.
136 brew update
137 brew outdated xctool || brew upgrade xctool
138 # Reused the build script that takes care of configuring and ensuring things
Thomas Van Lenten1745f7e2015-11-17 10:18:49 -0500139 # are up to date. Xcode and conformance tests will be directly invoked.
140 objectivec/DevTools/full_mac_build.sh \
141 --core-only --skip-xcode --skip-objc-conformance
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500142}
143
144internal_xctool_debug_and_release() {
145 xctool -configuration Debug "$@"
146 xctool -configuration Release "$@"
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400147}
148
149build_objectivec_ios() {
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500150 internal_objectivec_common
151 # https://github.com/facebook/xctool/issues/509 - unlike xcodebuild, xctool
152 # doesn't support >1 destination, so we have to build first and then run the
153 # tests one destination at a time.
154 internal_xctool_debug_and_release \
155 -project objectivec/ProtocolBuffers_iOS.xcodeproj \
156 -scheme ProtocolBuffers \
157 -sdk iphonesimulator \
158 build-tests
159 IOS_DESTINATIONS=(
160 "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
161 "platform=iOS Simulator,name=iPhone 6,OS=9.1" # 64bit
162 "platform=iOS Simulator,name=iPad 2,OS=8.1" # 32bit
163 "platform=iOS Simulator,name=iPad Air,OS=9.1" # 64bit
164 )
165 for i in "${IOS_DESTINATIONS[@]}" ; do
166 internal_xctool_debug_and_release \
167 -project objectivec/ProtocolBuffers_iOS.xcodeproj \
168 -scheme ProtocolBuffers \
169 -sdk iphonesimulator \
170 -destination "${i}" \
171 run-tests
172 done
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400173}
174
175build_objectivec_osx() {
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500176 internal_objectivec_common
177 internal_xctool_debug_and_release \
178 -project objectivec/ProtocolBuffers_OSX.xcodeproj \
179 -scheme ProtocolBuffers \
180 -destination "platform=OS X,arch=x86_64" \
181 test
Thomas Van Lenten1745f7e2015-11-17 10:18:49 -0500182 cd conformance && make test_objc && cd ..
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400183}
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400184
Chris Fallin20e94b22015-05-13 16:43:48 -0700185build_python() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700186 internal_build_cpp
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400187 internal_install_python_deps
Chris Fallin20e94b22015-05-13 16:43:48 -0700188 cd python
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400189 # Only test Python 2.6/3.x on Linux
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400190 if [ $(uname -s) == "Linux" ]; then
Jie Luo2850a982015-10-09 17:07:03 -0700191 envlist=py\{26,27,33,34\}-python
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400192 else
193 envlist=py27-python
194 fi
195 tox -e $envlist
Chris Fallin20e94b22015-05-13 16:43:48 -0700196 cd ..
197}
198
199build_python_cpp() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700200 internal_build_cpp
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400201 internal_install_python_deps
202 export LD_LIBRARY_PATH=../src/.libs # for Linux
Tamir Dubersteinc91d9ab2015-05-14 21:32:39 -0400203 export DYLD_LIBRARY_PATH=../src/.libs # for OS X
Chris Fallin20e94b22015-05-13 16:43:48 -0700204 cd python
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400205 # Only test Python 2.6/3.x on Linux
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400206 if [ $(uname -s) == "Linux" ]; then
Jisi Liu72bd9c92015-10-06 10:48:57 -0700207 # py26 is currently disabled due to json_format
208 envlist=py\{27,33,34\}-cpp
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400209 else
210 envlist=py27-cpp
211 fi
212 tox -e $envlist
Chris Fallin20e94b22015-05-13 16:43:48 -0700213 cd ..
214}
215
216build_ruby19() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700217 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700218 cd ruby && bash travis-test.sh ruby-1.9 && cd ..
219}
220build_ruby20() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700221 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700222 cd ruby && bash travis-test.sh ruby-2.0 && cd ..
223}
224build_ruby21() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700225 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700226 cd ruby && bash travis-test.sh ruby-2.1 && cd ..
227}
228build_ruby22() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700229 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700230 cd ruby && bash travis-test.sh ruby-2.2 && cd ..
231}
232build_jruby() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700233 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700234 cd ruby && bash travis-test.sh jruby && cd ..
235}
236
237# -------- main --------
238
239if [ "$#" -ne 1 ]; then
240 echo "
241Usage: $0 { cpp |
Jan Tattermuschddb36ef2015-05-18 17:34:02 -0700242 csharp |
Chris Fallin20e94b22015-05-13 16:43:48 -0700243 java_jdk6 |
244 java_jdk7 |
245 java_oracle7 |
246 javanano_jdk6 |
247 javanano_jdk7 |
248 javanano_oracle7 |
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400249 objectivec_ios |
250 objectivec_osx |
Chris Fallin20e94b22015-05-13 16:43:48 -0700251 python |
252 python_cpp |
253 ruby_19 |
254 ruby_20 |
255 ruby_21 |
256 ruby_22 |
257 jruby }
258"
259 exit 1
260fi
261
262set -e # exit immediately on error
263set -x # display all commands
264eval "build_$1"