forked from protocolbuffers/protobuf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.sh
executable file
·332 lines (295 loc) · 8.87 KB
/
tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#!/bin/bash
#
# Build and runs tests for the protobuf project. The tests as written here are
# used by both Jenkins and Travis, though some specialized logic is required to
# handle the differences between them.
on_travis() {
if [ "$TRAVIS" == "true" ]; then
"$@"
fi
}
# For when some other test needs the C++ main build, including protoc and
# libprotobuf.
internal_build_cpp() {
if [ -f src/protoc ]; then
# Already built.
return
fi
if [[ $(uname -s) == "Linux" && "$TRAVIS" == "true" ]]; then
# Install GCC 4.8 to replace the default GCC 4.6. We need 4.8 for more
# decent C++ 11 support in order to compile conformance tests.
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
sudo apt-get update -qq
sudo apt-get install -qq g++-4.8
export CXX="g++-4.8" CC="gcc-4.8"
fi
./autogen.sh
./configure
make -j2
}
build_cpp() {
internal_build_cpp
make check -j2
cd conformance && make test_cpp && cd ..
# Verify benchmarking code can build successfully.
cd benchmarks && make && ./generate-datasets && cd ..
}
build_cpp_distcheck() {
./autogen.sh
./configure
make distcheck -j2
}
build_csharp() {
# Just for the conformance tests. We don't currently
# need to really build protoc, but it's simplest to keep with the
# conventions of the other builds.
internal_build_cpp
NUGET=/usr/local/bin/nuget.exe
if [ "$TRAVIS" == "true" ]; then
# Install latest version of Mono
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
echo "deb http://download.mono-project.com/repo/debian wheezy-libtiff-compat main" | sudo tee -a /etc/apt/sources.list.d/mono-xamarin.list
sudo apt-get update -qq
sudo apt-get install -qq mono-devel referenceassemblies-pcl nunit
wget www.nuget.org/NuGet.exe -O nuget.exe
NUGET=../../nuget.exe
fi
(cd csharp/src; mono $NUGET restore)
csharp/buildall.sh
cd conformance && make test_csharp && cd ..
}
build_golang() {
# Go build needs `protoc`.
internal_build_cpp
# Add protoc to the path so that the examples build finds it.
export PATH="`pwd`/src:$PATH"
# Install Go and the Go protobuf compiler plugin.
sudo apt-get update -qq
sudo apt-get install -qq golang
export GOPATH="$HOME/gocode"
mkdir -p "$GOPATH/src/github.com/google"
ln -s "`pwd`" "$GOPATH/src/github.com/google/protobuf"
export PATH="$GOPATH/bin:$PATH"
go get github.com/golang/protobuf/protoc-gen-go
cd examples && make gotest && cd ..
}
use_java() {
version=$1
case "$version" in
jdk6)
on_travis sudo apt-get install openjdk-6-jdk
export PATH=/usr/lib/jvm/java-6-openjdk-amd64/bin:$PATH
;;
jdk7)
on_travis sudo apt-get install openjdk-7-jdk
export PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH
;;
oracle7)
if [ "$TRAVIS" == "true" ]; then
sudo apt-get install python-software-properties # for apt-add-repository
echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 select true" | \
sudo debconf-set-selections
yes | sudo apt-add-repository ppa:webupd8team/java
yes | sudo apt-get install oracle-java7-installer
fi;
export PATH=/usr/lib/jvm/java-7-oracle/bin:$PATH
;;
esac
if [ "$TRAVIS" != "true" ]; then
MAVEN_LOCAL_REPOSITORY=/var/maven_local_repository
MVN="$MVN -e -X --offline -Dmaven.repo.local=$MAVEN_LOCAL_REPOSITORY"
fi;
which java
java -version
}
# --batch-mode supresses download progress output that spams the logs.
MVN="mvn --batch-mode"
build_java() {
version=$1
dir=java_$version
# Java build needs `protoc`.
internal_build_cpp
cp -r java $dir
cd $dir && $MVN clean && $MVN test
cd ../..
}
# The conformance tests are hard-coded to work with the $ROOT/java directory.
# So this can't run in parallel with two different sets of tests.
build_java_with_conformance_tests() {
# Java build needs `protoc`.
internal_build_cpp
cd java && $MVN test && $MVN install
cd util && $MVN package assembly:single
cd ../..
cd conformance && make test_java && cd ..
}
build_javanano() {
# Java build needs `protoc`.
internal_build_cpp
cd javanano && $MVN test && cd ..
}
build_java_jdk6() {
use_java jdk6
build_java jdk6
}
build_java_jdk7() {
use_java jdk7
build_java_with_conformance_tests
}
build_java_oracle7() {
use_java oracle7
build_java oracle7
}
build_javanano_jdk6() {
use_java jdk6
build_javanano
}
build_javanano_jdk7() {
use_java jdk7
build_javanano
}
build_javanano_oracle7() {
use_java oracle7
build_javanano
}
internal_install_python_deps() {
if [ "$TRAVIS" != "true" ]; then
return;
fi
# Install tox (OS X doesn't have pip).
if [ $(uname -s) == "Darwin" ]; then
sudo easy_install tox
else
sudo pip install tox
fi
# Only install Python2.6/3.x on Linux.
if [ $(uname -s) == "Linux" ]; then
sudo apt-get install -y python-software-properties # for apt-add-repository
sudo apt-add-repository -y ppa:fkrull/deadsnakes
sudo apt-get update -qq
sudo apt-get install -y python2.6 python2.6-dev
sudo apt-get install -y python3.3 python3.3-dev
sudo apt-get install -y python3.4 python3.4-dev
fi
}
build_objectivec_ios() {
# Reused the build script that takes care of configuring and ensuring things
# are up to date. The OS X test runs the objc conformance test, so skip it
# here.
# Note: travis has xctool installed, and we've looked at using it in the past
# but it has ended up proving unreliable (bugs), an they are removing build
# support in favor of xcbuild (or just xcodebuild).
objectivec/DevTools/full_mac_build.sh \
--core-only --skip-xcode-osx --skip-objc-conformance "$@"
}
build_objectivec_ios_debug() {
build_objectivec_ios --skip-xcode-release
}
build_objectivec_ios_release() {
build_objectivec_ios --skip-xcode-debug
}
build_objectivec_osx() {
# Reused the build script that takes care of configuring and ensuring things
# are up to date.
objectivec/DevTools/full_mac_build.sh \
--core-only --skip-xcode-ios
}
build_objectivec_cocoapods_integration() {
# First, load the RVM environment in bash, needed to update ruby.
source ~/.rvm/scripts/rvm
# Update ruby to 2.2.3 as the default one crashes with segmentation faults
# when using pod.
rvm use 2.2.3 --install --binary --fuzzy
# Update pod to the latest version.
gem install cocoapods --no-ri --no-rdoc
objectivec/Tests/CocoaPods/run_tests.sh
}
build_python() {
internal_build_cpp
internal_install_python_deps
cd python
# Only test Python 2.6/3.x on Linux
if [ $(uname -s) == "Linux" ]; then
envlist=py\{26,27,33,34\}-python
else
envlist=py27-python
fi
tox -e $envlist
cd ..
}
build_python_cpp() {
internal_build_cpp
internal_install_python_deps
export LD_LIBRARY_PATH=../src/.libs # for Linux
export DYLD_LIBRARY_PATH=../src/.libs # for OS X
cd python
# Only test Python 2.6/3.x on Linux
if [ $(uname -s) == "Linux" ]; then
# py26 is currently disabled due to json_format
envlist=py\{27,33,34\}-cpp
else
envlist=py27-cpp
fi
tox -e $envlist
cd ..
}
build_ruby19() {
internal_build_cpp # For conformance tests.
cd ruby && bash travis-test.sh ruby-1.9 && cd ..
}
build_ruby20() {
internal_build_cpp # For conformance tests.
cd ruby && bash travis-test.sh ruby-2.0 && cd ..
}
build_ruby21() {
internal_build_cpp # For conformance tests.
cd ruby && bash travis-test.sh ruby-2.1 && cd ..
}
build_ruby22() {
internal_build_cpp # For conformance tests.
cd ruby && bash travis-test.sh ruby-2.2 && cd ..
}
build_jruby() {
internal_build_cpp # For conformance tests.
cd ruby && bash travis-test.sh jruby && cd ..
}
build_javascript() {
internal_build_cpp
cd js && npm install && npm test && cd ..
}
# Note: travis currently does not support testing more than one language so the
# .travis.yml cheats and claims to only be cpp. If they add multiple language
# support, this should probably get updated to install steps and/or
# rvm/gemfile/jdk/etc. entries rather than manually doing the work.
# .travis.yml uses matrix.exclude to block the cases where app-get can't be
# use to install things.
# -------- main --------
if [ "$#" -ne 1 ]; then
echo "
Usage: $0 { cpp |
csharp |
java_jdk6 |
java_jdk7 |
java_oracle7 |
javanano_jdk6 |
javanano_jdk7 |
javanano_oracle7 |
objectivec_ios |
objectivec_ios_debug |
objectivec_ios_release |
objectivec_osx |
objectivec_cocoapods_integration |
python |
python_cpp |
ruby19 |
ruby20 |
ruby21 |
ruby22 |
jruby }
"
exit 1
fi
set -e # exit immediately on error
set -x # display all commands
eval "build_$1"