blob: 317bef4e0c37ee640845dfd37269f5d85c9fcf0b [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 Xiao1e2fece2015-12-18 15:16:07 -080014 # Install GCC 4.8 to replace the default GCC 4.6. We need 4.8 for more
15 # decent C++ 11 support in order to compile conformance tests.
16 sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
17 sudo apt-get update -qq
18 sudo apt-get install -qq g++-4.8
19 export CXX="g++-4.8" CC="gcc-4.8"
20
Chris Fallin20e94b22015-05-13 16:43:48 -070021 ./autogen.sh
22 ./configure
23 make -j2
Josh Haberman181c7f22015-07-15 11:05:10 -070024}
25
26build_cpp() {
27 internal_build_cpp
Chris Fallin20e94b22015-05-13 16:43:48 -070028 make check -j2
29 cd conformance && make test_cpp && cd ..
30}
31
32build_cpp_distcheck() {
33 ./autogen.sh
34 ./configure
35 make distcheck -j2
36}
37
Jan Tattermuschddb36ef2015-05-18 17:34:02 -070038build_csharp() {
Jon Skeetb6defa72015-08-04 10:01:40 +010039 # Just for the conformance tests. We don't currently
40 # need to really build protoc, but it's simplest to keep with the
41 # conventions of the other builds.
42 internal_build_cpp
43
Jan Tattermuschddb36ef2015-05-18 17:34:02 -070044 # Install latest version of Mono
45 sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
46 echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
47 echo "deb http://download.mono-project.com/repo/debian wheezy-libtiff-compat main" | sudo tee -a /etc/apt/sources.list.d/mono-xamarin.list
48 sudo apt-get update -qq
49 sudo apt-get install -qq mono-devel referenceassemblies-pcl nunit
50 wget www.nuget.org/NuGet.exe -O nuget.exe
51
52 (cd csharp/src; mono ../../nuget.exe restore)
53 csharp/buildall.sh
Jon Skeetb6defa72015-08-04 10:01:40 +010054 cd conformance && make test_csharp && cd ..
Jan Tattermuschddb36ef2015-05-18 17:34:02 -070055}
56
Tim Swast7e31c4d2015-11-20 15:32:53 -080057build_golang() {
58 # Go build needs `protoc`.
59 internal_build_cpp
60 # Add protoc to the path so that the examples build finds it.
61 export PATH="`pwd`/src:$PATH"
62
63 # Install Go and the Go protobuf compiler plugin.
64 sudo apt-get update -qq
65 sudo apt-get install -qq golang
66 export GOPATH="$HOME/gocode"
67 mkdir -p "$GOPATH/src/github.com/google"
68 ln -s "`pwd`" "$GOPATH/src/github.com/google/protobuf"
69 export PATH="$GOPATH/bin:$PATH"
70 go get github.com/golang/protobuf/protoc-gen-go
71
72 cd examples && make gotest && cd ..
73}
74
Chris Fallin20e94b22015-05-13 16:43:48 -070075use_java() {
Chris Fallin20e94b22015-05-13 16:43:48 -070076 version=$1
77 case "$version" in
78 jdk6)
79 sudo apt-get install openjdk-6-jdk
80 export PATH=/usr/lib/jvm/java-6-openjdk-amd64/bin:$PATH
81 ;;
82 jdk7)
83 sudo apt-get install openjdk-7-jdk
84 export PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH
85 ;;
86 oracle7)
87 sudo apt-get install python-software-properties # for apt-add-repository
88 echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 select true" | \
89 sudo debconf-set-selections
90 yes | sudo apt-add-repository ppa:webupd8team/java
91 yes | sudo apt-get install oracle-java7-installer
92 export PATH=/usr/lib/jvm/java-7-oracle/bin:$PATH
93 ;;
94 esac
95
96 which java
97 java -version
98}
99
100build_java() {
101 # Java build needs `protoc`.
Josh Haberman181c7f22015-07-15 11:05:10 -0700102 internal_build_cpp
Feng Xiaoa0cecfd2015-12-14 18:33:38 -0800103 cd java && mvn test && cd util && mvn test && mvn assembly:single && cd ../..
Chris Fallin20e94b22015-05-13 16:43:48 -0700104 cd conformance && make test_java && cd ..
105}
106
107build_javanano() {
108 # Java build needs `protoc`.
Josh Haberman181c7f22015-07-15 11:05:10 -0700109 internal_build_cpp
Chris Fallin20e94b22015-05-13 16:43:48 -0700110 cd javanano && mvn test && cd ..
111}
112
113build_java_jdk6() {
114 use_java jdk6
115 build_java
116}
117build_java_jdk7() {
118 use_java jdk7
119 build_java
120}
121build_java_oracle7() {
122 use_java oracle7
123 build_java
124}
125
126build_javanano_jdk6() {
127 use_java jdk6
128 build_javanano
129}
130build_javanano_jdk7() {
131 use_java jdk7
132 build_javanano
133}
134build_javanano_oracle7() {
135 use_java oracle7
136 build_javanano
137}
138
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400139internal_install_python_deps() {
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400140 # Install tox (OS X doesn't have pip).
141 if [ $(uname -s) == "Darwin" ]; then
142 sudo easy_install tox
143 else
144 sudo pip install tox
145 fi
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400146 # Only install Python2.6/3.x on Linux.
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400147 if [ $(uname -s) == "Linux" ]; then
148 sudo apt-get install -y python-software-properties # for apt-add-repository
149 sudo apt-add-repository -y ppa:fkrull/deadsnakes
150 sudo apt-get update -qq
151 sudo apt-get install -y python2.6 python2.6-dev
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400152 sudo apt-get install -y python3.3 python3.3-dev
153 sudo apt-get install -y python3.4 python3.4-dev
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400154 fi
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400155}
156
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500157internal_objectivec_common () {
158 # Make sure xctool is up to date. Adapted from
159 # http://docs.travis-ci.com/user/osx-ci-environment/
160 # We don't use a before_install because we test multiple OSes.
161 brew update
162 brew outdated xctool || brew upgrade xctool
163 # Reused the build script that takes care of configuring and ensuring things
Thomas Van Lenten1745f7e2015-11-17 10:18:49 -0500164 # are up to date. Xcode and conformance tests will be directly invoked.
165 objectivec/DevTools/full_mac_build.sh \
166 --core-only --skip-xcode --skip-objc-conformance
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500167}
168
169internal_xctool_debug_and_release() {
170 xctool -configuration Debug "$@"
171 xctool -configuration Release "$@"
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400172}
173
174build_objectivec_ios() {
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500175 internal_objectivec_common
176 # https://github.com/facebook/xctool/issues/509 - unlike xcodebuild, xctool
177 # doesn't support >1 destination, so we have to build first and then run the
178 # tests one destination at a time.
179 internal_xctool_debug_and_release \
180 -project objectivec/ProtocolBuffers_iOS.xcodeproj \
181 -scheme ProtocolBuffers \
182 -sdk iphonesimulator \
183 build-tests
184 IOS_DESTINATIONS=(
185 "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
186 "platform=iOS Simulator,name=iPhone 6,OS=9.1" # 64bit
187 "platform=iOS Simulator,name=iPad 2,OS=8.1" # 32bit
188 "platform=iOS Simulator,name=iPad Air,OS=9.1" # 64bit
189 )
190 for i in "${IOS_DESTINATIONS[@]}" ; do
191 internal_xctool_debug_and_release \
192 -project objectivec/ProtocolBuffers_iOS.xcodeproj \
193 -scheme ProtocolBuffers \
194 -sdk iphonesimulator \
195 -destination "${i}" \
196 run-tests
197 done
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400198}
199
200build_objectivec_osx() {
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500201 internal_objectivec_common
202 internal_xctool_debug_and_release \
203 -project objectivec/ProtocolBuffers_OSX.xcodeproj \
204 -scheme ProtocolBuffers \
205 -destination "platform=OS X,arch=x86_64" \
206 test
Thomas Van Lenten1745f7e2015-11-17 10:18:49 -0500207 cd conformance && make test_objc && cd ..
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400208}
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400209
Chris Fallin20e94b22015-05-13 16:43:48 -0700210build_python() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700211 internal_build_cpp
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400212 internal_install_python_deps
Chris Fallin20e94b22015-05-13 16:43:48 -0700213 cd python
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400214 # Only test Python 2.6/3.x on Linux
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400215 if [ $(uname -s) == "Linux" ]; then
Jie Luo2850a982015-10-09 17:07:03 -0700216 envlist=py\{26,27,33,34\}-python
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400217 else
218 envlist=py27-python
219 fi
220 tox -e $envlist
Chris Fallin20e94b22015-05-13 16:43:48 -0700221 cd ..
222}
223
224build_python_cpp() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700225 internal_build_cpp
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400226 internal_install_python_deps
227 export LD_LIBRARY_PATH=../src/.libs # for Linux
Tamir Dubersteinc91d9ab2015-05-14 21:32:39 -0400228 export DYLD_LIBRARY_PATH=../src/.libs # for OS X
Chris Fallin20e94b22015-05-13 16:43:48 -0700229 cd python
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400230 # Only test Python 2.6/3.x on Linux
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400231 if [ $(uname -s) == "Linux" ]; then
Jisi Liu72bd9c92015-10-06 10:48:57 -0700232 # py26 is currently disabled due to json_format
233 envlist=py\{27,33,34\}-cpp
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400234 else
235 envlist=py27-cpp
236 fi
237 tox -e $envlist
Chris Fallin20e94b22015-05-13 16:43:48 -0700238 cd ..
239}
240
241build_ruby19() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700242 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700243 cd ruby && bash travis-test.sh ruby-1.9 && cd ..
244}
245build_ruby20() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700246 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700247 cd ruby && bash travis-test.sh ruby-2.0 && cd ..
248}
249build_ruby21() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700250 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700251 cd ruby && bash travis-test.sh ruby-2.1 && cd ..
252}
253build_ruby22() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700254 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700255 cd ruby && bash travis-test.sh ruby-2.2 && cd ..
256}
257build_jruby() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700258 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700259 cd ruby && bash travis-test.sh jruby && cd ..
260}
261
262# -------- main --------
263
264if [ "$#" -ne 1 ]; then
265 echo "
266Usage: $0 { cpp |
Jan Tattermuschddb36ef2015-05-18 17:34:02 -0700267 csharp |
Chris Fallin20e94b22015-05-13 16:43:48 -0700268 java_jdk6 |
269 java_jdk7 |
270 java_oracle7 |
271 javanano_jdk6 |
272 javanano_jdk7 |
273 javanano_oracle7 |
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400274 objectivec_ios |
275 objectivec_osx |
Chris Fallin20e94b22015-05-13 16:43:48 -0700276 python |
277 python_cpp |
278 ruby_19 |
279 ruby_20 |
280 ruby_21 |
281 ruby_22 |
282 jruby }
283"
284 exit 1
285fi
286
287set -e # exit immediately on error
288set -x # display all commands
289eval "build_$1"