blob: 6295336b4d470e73bdaf89dc91f8156de51d197b [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
Tim Swast7e31c4d2015-11-20 15:32:53 -080050build_golang() {
51 # Go build needs `protoc`.
52 internal_build_cpp
53 # Add protoc to the path so that the examples build finds it.
54 export PATH="`pwd`/src:$PATH"
55
56 # Install Go and the Go protobuf compiler plugin.
57 sudo apt-get update -qq
58 sudo apt-get install -qq golang
59 export GOPATH="$HOME/gocode"
60 mkdir -p "$GOPATH/src/github.com/google"
61 ln -s "`pwd`" "$GOPATH/src/github.com/google/protobuf"
62 export PATH="$GOPATH/bin:$PATH"
63 go get github.com/golang/protobuf/protoc-gen-go
64
65 cd examples && make gotest && cd ..
66}
67
Chris Fallin20e94b22015-05-13 16:43:48 -070068use_java() {
Chris Fallin20e94b22015-05-13 16:43:48 -070069 version=$1
70 case "$version" in
71 jdk6)
72 sudo apt-get install openjdk-6-jdk
73 export PATH=/usr/lib/jvm/java-6-openjdk-amd64/bin:$PATH
74 ;;
75 jdk7)
76 sudo apt-get install openjdk-7-jdk
77 export PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH
78 ;;
79 oracle7)
80 sudo apt-get install python-software-properties # for apt-add-repository
81 echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 select true" | \
82 sudo debconf-set-selections
83 yes | sudo apt-add-repository ppa:webupd8team/java
84 yes | sudo apt-get install oracle-java7-installer
85 export PATH=/usr/lib/jvm/java-7-oracle/bin:$PATH
86 ;;
87 esac
88
89 which java
90 java -version
91}
92
93build_java() {
94 # Java build needs `protoc`.
Josh Haberman181c7f22015-07-15 11:05:10 -070095 internal_build_cpp
Chris Fallin20e94b22015-05-13 16:43:48 -070096 cd java && mvn test && cd ..
97 cd conformance && make test_java && cd ..
98}
99
100build_javanano() {
101 # Java build needs `protoc`.
Josh Haberman181c7f22015-07-15 11:05:10 -0700102 internal_build_cpp
Chris Fallin20e94b22015-05-13 16:43:48 -0700103 cd javanano && mvn test && cd ..
104}
105
106build_java_jdk6() {
107 use_java jdk6
108 build_java
109}
110build_java_jdk7() {
111 use_java jdk7
112 build_java
113}
114build_java_oracle7() {
115 use_java oracle7
116 build_java
117}
118
119build_javanano_jdk6() {
120 use_java jdk6
121 build_javanano
122}
123build_javanano_jdk7() {
124 use_java jdk7
125 build_javanano
126}
127build_javanano_oracle7() {
128 use_java oracle7
129 build_javanano
130}
131
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400132internal_install_python_deps() {
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400133 # Install tox (OS X doesn't have pip).
134 if [ $(uname -s) == "Darwin" ]; then
135 sudo easy_install tox
136 else
137 sudo pip install tox
138 fi
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400139 # Only install Python2.6/3.x on Linux.
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400140 if [ $(uname -s) == "Linux" ]; then
141 sudo apt-get install -y python-software-properties # for apt-add-repository
142 sudo apt-add-repository -y ppa:fkrull/deadsnakes
143 sudo apt-get update -qq
144 sudo apt-get install -y python2.6 python2.6-dev
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400145 sudo apt-get install -y python3.3 python3.3-dev
146 sudo apt-get install -y python3.4 python3.4-dev
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400147 fi
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400148}
149
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500150internal_objectivec_common () {
151 # Make sure xctool is up to date. Adapted from
152 # http://docs.travis-ci.com/user/osx-ci-environment/
153 # We don't use a before_install because we test multiple OSes.
154 brew update
155 brew outdated xctool || brew upgrade xctool
156 # Reused the build script that takes care of configuring and ensuring things
Thomas Van Lenten1745f7e2015-11-17 10:18:49 -0500157 # are up to date. Xcode and conformance tests will be directly invoked.
158 objectivec/DevTools/full_mac_build.sh \
159 --core-only --skip-xcode --skip-objc-conformance
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500160}
161
162internal_xctool_debug_and_release() {
163 xctool -configuration Debug "$@"
164 xctool -configuration Release "$@"
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400165}
166
167build_objectivec_ios() {
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500168 internal_objectivec_common
169 # https://github.com/facebook/xctool/issues/509 - unlike xcodebuild, xctool
170 # doesn't support >1 destination, so we have to build first and then run the
171 # tests one destination at a time.
172 internal_xctool_debug_and_release \
173 -project objectivec/ProtocolBuffers_iOS.xcodeproj \
174 -scheme ProtocolBuffers \
175 -sdk iphonesimulator \
176 build-tests
177 IOS_DESTINATIONS=(
178 "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
179 "platform=iOS Simulator,name=iPhone 6,OS=9.1" # 64bit
180 "platform=iOS Simulator,name=iPad 2,OS=8.1" # 32bit
181 "platform=iOS Simulator,name=iPad Air,OS=9.1" # 64bit
182 )
183 for i in "${IOS_DESTINATIONS[@]}" ; do
184 internal_xctool_debug_and_release \
185 -project objectivec/ProtocolBuffers_iOS.xcodeproj \
186 -scheme ProtocolBuffers \
187 -sdk iphonesimulator \
188 -destination "${i}" \
189 run-tests
190 done
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400191}
192
193build_objectivec_osx() {
Thomas Van Lenten76b61382015-11-09 14:21:51 -0500194 internal_objectivec_common
195 internal_xctool_debug_and_release \
196 -project objectivec/ProtocolBuffers_OSX.xcodeproj \
197 -scheme ProtocolBuffers \
198 -destination "platform=OS X,arch=x86_64" \
199 test
Thomas Van Lenten1745f7e2015-11-17 10:18:49 -0500200 cd conformance && make test_objc && cd ..
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400201}
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400202
Chris Fallin20e94b22015-05-13 16:43:48 -0700203build_python() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700204 internal_build_cpp
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400205 internal_install_python_deps
Chris Fallin20e94b22015-05-13 16:43:48 -0700206 cd python
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400207 # Only test Python 2.6/3.x on Linux
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400208 if [ $(uname -s) == "Linux" ]; then
Jie Luo2850a982015-10-09 17:07:03 -0700209 envlist=py\{26,27,33,34\}-python
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400210 else
211 envlist=py27-python
212 fi
213 tox -e $envlist
Chris Fallin20e94b22015-05-13 16:43:48 -0700214 cd ..
215}
216
217build_python_cpp() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700218 internal_build_cpp
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400219 internal_install_python_deps
220 export LD_LIBRARY_PATH=../src/.libs # for Linux
Tamir Dubersteinc91d9ab2015-05-14 21:32:39 -0400221 export DYLD_LIBRARY_PATH=../src/.libs # for OS X
Chris Fallin20e94b22015-05-13 16:43:48 -0700222 cd python
Dan O'Reillyd9598ca2015-08-26 20:30:41 -0400223 # Only test Python 2.6/3.x on Linux
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400224 if [ $(uname -s) == "Linux" ]; then
Jisi Liu72bd9c92015-10-06 10:48:57 -0700225 # py26 is currently disabled due to json_format
226 envlist=py\{27,33,34\}-cpp
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400227 else
228 envlist=py27-cpp
229 fi
230 tox -e $envlist
Chris Fallin20e94b22015-05-13 16:43:48 -0700231 cd ..
232}
233
234build_ruby19() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700235 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700236 cd ruby && bash travis-test.sh ruby-1.9 && cd ..
237}
238build_ruby20() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700239 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700240 cd ruby && bash travis-test.sh ruby-2.0 && cd ..
241}
242build_ruby21() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700243 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700244 cd ruby && bash travis-test.sh ruby-2.1 && cd ..
245}
246build_ruby22() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700247 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700248 cd ruby && bash travis-test.sh ruby-2.2 && cd ..
249}
250build_jruby() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700251 internal_build_cpp # For conformance tests.
Chris Fallin20e94b22015-05-13 16:43:48 -0700252 cd ruby && bash travis-test.sh jruby && cd ..
253}
254
255# -------- main --------
256
257if [ "$#" -ne 1 ]; then
258 echo "
259Usage: $0 { cpp |
Jan Tattermuschddb36ef2015-05-18 17:34:02 -0700260 csharp |
Chris Fallin20e94b22015-05-13 16:43:48 -0700261 java_jdk6 |
262 java_jdk7 |
263 java_oracle7 |
264 javanano_jdk6 |
265 javanano_jdk7 |
266 javanano_oracle7 |
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400267 objectivec_ios |
268 objectivec_osx |
Chris Fallin20e94b22015-05-13 16:43:48 -0700269 python |
270 python_cpp |
271 ruby_19 |
272 ruby_20 |
273 ruby_21 |
274 ruby_22 |
275 jruby }
276"
277 exit 1
278fi
279
280set -e # exit immediately on error
281set -x # display all commands
282eval "build_$1"