blob: 73be5c1d47854384a80c28b1497c32c7768384e6 [file] [log] [blame]
Austin Schuh40c16522018-10-28 20:27:54 -07001#!/bin/bash
2#
3# Build and runs tests for the protobuf project. We use this script to run
4# tests on kokoro (Ubuntu and MacOS). It can run locally as well but you
5# will need to make sure the required compilers/tools are available.
6
7# For when some other test needs the C++ main build, including protoc and
8# libprotobuf.
9internal_build_cpp() {
10 if [ -f src/protoc ]; then
11 # Already built.
12 return
13 fi
14
15 # Initialize any submodules.
16 git submodule update --init --recursive
17
18 ./autogen.sh
19 ./configure CXXFLAGS="-fPIC" # -fPIC is needed for python cpp test.
20 # See python/setup.py for more details
21 make -j2
22}
23
24build_cpp() {
25 internal_build_cpp
26 make check -j2 || (cat src/test-suite.log; false)
27 cd conformance && make test_cpp && cd ..
28
29 # The benchmark code depends on cmake, so test if it is installed before
30 # trying to do the build.
31 if [[ $(type cmake 2>/dev/null) ]]; then
32 # Verify benchmarking code can build successfully.
33 cd benchmarks && make cpp-benchmark && cd ..
34 else
35 echo ""
36 echo "WARNING: Skipping validation of the bench marking code, cmake isn't installed."
37 echo ""
38 fi
39}
40
41build_cpp_distcheck() {
42 # Initialize any submodules.
43 git submodule update --init --recursive
44 ./autogen.sh
45 ./configure
46 make dist
47
48 # List all files that should be included in the distribution package.
49 git ls-files | grep "^\(java\|python\|objectivec\|csharp\|js\|ruby\|php\|cmake\|examples\|src/google/protobuf/.*\.proto\)" |\
50 grep -v ".gitignore" | grep -v "java/compatibility_tests" |\
51 grep -v "python/compatibility_tests" | grep -v "csharp/compatibility_tests" > dist.lst
52 # Unzip the dist tar file.
53 DIST=`ls *.tar.gz`
54 tar -xf $DIST
55 cd ${DIST//.tar.gz}
56 # Check if every file exists in the dist tar file.
57 FILES_MISSING=""
58 for FILE in $(<../dist.lst); do
59 if ! file $FILE &>/dev/null; then
60 echo "$FILE is not found!"
61 FILES_MISSING="$FILE $FILES_MISSING"
62 fi
63 done
64 cd ..
65 if [ ! -z "$FILES_MISSING" ]; then
66 echo "Missing files in EXTRA_DIST: $FILES_MISSING"
67 exit 1
68 fi
69
70 # Do the regular dist-check for C++.
71 make distcheck -j2
72}
73
74build_csharp() {
75 # Required for conformance tests and to regenerate protos.
76 internal_build_cpp
77 NUGET=/usr/local/bin/nuget.exe
78
79 # Perform "dotnet new" once to get the setup preprocessing out of the
80 # way. That spews a lot of output (including backspaces) into logs
81 # otherwise, and can cause problems. It doesn't matter if this step
82 # is performed multiple times; it's cheap after the first time anyway.
83 # (It also doesn't matter if it's unnecessary, which it will be on some
84 # systems. It's necessary on Jenkins in order to avoid unprintable
85 # characters appearing in the JUnit output.)
86 mkdir dotnettmp
87 (cd dotnettmp; dotnet new > /dev/null)
88 rm -rf dotnettmp
89
90 # Check that the protos haven't broken C# codegen.
91 # TODO(jonskeet): Fail if regenerating creates any changes.
92 csharp/generate_protos.sh
93
94 csharp/buildall.sh
95 cd conformance && make test_csharp && cd ..
96
97 # Run csharp compatibility test between 3.0.0 and the current version.
98 csharp/compatibility_tests/v3.0.0/test.sh 3.0.0
99}
100
101build_golang() {
102 # Go build needs `protoc`.
103 internal_build_cpp
104 # Add protoc to the path so that the examples build finds it.
105 export PATH="`pwd`/src:$PATH"
106
107 export GOPATH="$HOME/gocode"
108 mkdir -p "$GOPATH/src/github.com/google"
109 rm -f "$GOPATH/src/github.com/google/protobuf"
110 ln -s "`pwd`" "$GOPATH/src/github.com/google/protobuf"
111 export PATH="$GOPATH/bin:$PATH"
112 go get github.com/golang/protobuf/protoc-gen-go
113
114 cd examples && PROTO_PATH="-I../src -I." make gotest && cd ..
115}
116
117use_java() {
118 version=$1
119 case "$version" in
120 jdk7)
121 export PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH
122 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
123 ;;
124 oracle7)
125 export PATH=/usr/lib/jvm/java-7-oracle/bin:$PATH
126 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
127 ;;
128 esac
129
130 MAVEN_LOCAL_REPOSITORY=/var/maven_local_repository
131 MVN="$MVN -e -X --offline -Dmaven.repo.local=$MAVEN_LOCAL_REPOSITORY"
132
133 which java
134 java -version
135 $MVN -version
136}
137
138# --batch-mode supresses download progress output that spams the logs.
139MVN="mvn --batch-mode"
140
141build_java() {
142 version=$1
143 dir=java_$version
144 # Java build needs `protoc`.
145 internal_build_cpp
146 cp -r java $dir
147 cd $dir && $MVN clean && $MVN test
148 cd ../..
149}
150
151# The conformance tests are hard-coded to work with the $ROOT/java directory.
152# So this can't run in parallel with two different sets of tests.
153build_java_with_conformance_tests() {
154 # Java build needs `protoc`.
155 internal_build_cpp
156 cd java && $MVN test && $MVN install
157 cd util && $MVN package assembly:single
158 cd ../..
159 cd conformance && make test_java && cd ..
160}
161
162build_java_jdk7() {
163 use_java jdk7
164 build_java_with_conformance_tests
165}
166build_java_oracle7() {
167 use_java oracle7
168 build_java oracle7
169}
170build_java_compatibility() {
171 use_java jdk7
172 internal_build_cpp
173 # Use the unit-tests extraced from 2.5.0 to test the compatibilty between
174 # 3.0.0-beta-4 and the current version.
175 cd java/compatibility_tests/v2.5.0
176 ./test.sh 3.0.0-beta-4
177}
178
179build_objectivec_ios() {
180 # Reused the build script that takes care of configuring and ensuring things
181 # are up to date. The OS X test runs the objc conformance test, so skip it
182 # here.
183 # Note: travis has xctool installed, and we've looked at using it in the past
184 # but it has ended up proving unreliable (bugs), an they are removing build
185 # support in favor of xcbuild (or just xcodebuild).
186 objectivec/DevTools/full_mac_build.sh \
187 --core-only --skip-xcode-osx --skip-objc-conformance "$@"
188}
189
190build_objectivec_ios_debug() {
191 build_objectivec_ios --skip-xcode-release
192}
193
194build_objectivec_ios_release() {
195 build_objectivec_ios --skip-xcode-debug
196}
197
198build_objectivec_osx() {
199 # Reused the build script that takes care of configuring and ensuring things
200 # are up to date.
201 objectivec/DevTools/full_mac_build.sh \
202 --core-only --skip-xcode-ios
203}
204
205build_objectivec_cocoapods_integration() {
206 # Update pod to the latest version.
207 gem install cocoapods --no-ri --no-rdoc
208 objectivec/Tests/CocoaPods/run_tests.sh
209}
210
211build_python() {
212 internal_build_cpp
213 cd python
214 if [ $(uname -s) == "Linux" ]; then
215 envlist=py\{27,33,34,35,36\}-python
216 else
217 envlist=py27-python
218 fi
219 tox -e $envlist
220 cd ..
221}
222
223build_python_cpp() {
224 internal_build_cpp
225 export LD_LIBRARY_PATH=../src/.libs # for Linux
226 export DYLD_LIBRARY_PATH=../src/.libs # for OS X
227 cd python
228 if [ $(uname -s) == "Linux" ]; then
229 envlist=py\{27,33,34,35,36\}-cpp
230 else
231 envlist=py27-cpp
232 fi
233 tox -e $envlist
234 cd ..
235}
236
237build_python_compatibility() {
238 internal_build_cpp
239 # Use the unit-tests extraced from 2.5.0 to test the compatibilty.
240 cd python/compatibility_tests/v2.5.0
241 # Test between 2.5.0 and the current version.
242 ./test.sh 2.5.0
243 # Test between 3.0.0-beta-1 and the current version.
244 ./test.sh 3.0.0-beta-1
245}
246
247build_ruby21() {
248 internal_build_cpp # For conformance tests.
249 cd ruby && bash travis-test.sh ruby-2.1 && cd ..
250}
251build_ruby22() {
252 internal_build_cpp # For conformance tests.
253 cd ruby && bash travis-test.sh ruby-2.2 && cd ..
254}
255build_ruby23() {
256 internal_build_cpp # For conformance tests.
257 cd ruby && bash travis-test.sh ruby-2.3 && cd ..
258}
259build_ruby24() {
260 internal_build_cpp # For conformance tests.
261 cd ruby && bash travis-test.sh ruby-2.4 && cd ..
262}
263build_ruby25() {
264 internal_build_cpp # For conformance tests.
265 cd ruby && bash travis-test.sh ruby-2.5.0 && cd ..
266}
267build_ruby_all() {
268 build_ruby21
269 build_ruby22
270 build_ruby23
271 build_ruby24
272 build_ruby25
273}
274
275build_javascript() {
276 internal_build_cpp
277 cd js && npm install && npm test && cd ..
278 cd conformance && make test_nodejs && cd ..
279}
280
281generate_php_test_proto() {
282 internal_build_cpp
283 pushd php/tests
284 # Generate test file
285 rm -rf generated
286 mkdir generated
287 ../../src/protoc --php_out=generated \
288 proto/empty/echo.proto \
289 proto/test.proto \
290 proto/test_include.proto \
291 proto/test_no_namespace.proto \
292 proto/test_prefix.proto \
293 proto/test_php_namespace.proto \
294 proto/test_empty_php_namespace.proto \
295 proto/test_reserved_enum_lower.proto \
296 proto/test_reserved_enum_upper.proto \
297 proto/test_reserved_enum_value_lower.proto \
298 proto/test_reserved_enum_value_upper.proto \
299 proto/test_reserved_message_lower.proto \
300 proto/test_reserved_message_upper.proto \
301 proto/test_service.proto \
302 proto/test_service_namespace.proto \
303 proto/test_descriptors.proto
304 pushd ../../src
305 ./protoc --php_out=../php/tests/generated -I../php/tests -I. \
306 ../php/tests/proto/test_import_descriptor_proto.proto
307 popd
308 popd
309}
310
311use_php() {
312 VERSION=$1
313 PHP=`which php`
314 PHP_CONFIG=`which php-config`
315 PHPIZE=`which phpize`
316 ln -sfn "/usr/local/php-${VERSION}/bin/php" $PHP
317 ln -sfn "/usr/local/php-${VERSION}/bin/php-config" $PHP_CONFIG
318 ln -sfn "/usr/local/php-${VERSION}/bin/phpize" $PHPIZE
319 generate_php_test_proto
320}
321
322use_php_zts() {
323 VERSION=$1
324 PHP=`which php`
325 PHP_CONFIG=`which php-config`
326 PHPIZE=`which phpize`
327 ln -sfn "/usr/local/php-${VERSION}-zts/bin/php" $PHP
328 ln -sfn "/usr/local/php-${VERSION}-zts/bin/php-config" $PHP_CONFIG
329 ln -sfn "/usr/local/php-${VERSION}-zts/bin/phpize" $PHPIZE
330 generate_php_test_proto
331}
332
333use_php_bc() {
334 VERSION=$1
335 PHP=`which php`
336 PHP_CONFIG=`which php-config`
337 PHPIZE=`which phpize`
338 ln -sfn "/usr/local/php-${VERSION}-bc/bin/php" $PHP
339 ln -sfn "/usr/local/php-${VERSION}-bc/bin/php-config" $PHP_CONFIG
340 ln -sfn "/usr/local/php-${VERSION}-bc/bin/phpize" $PHPIZE
341 generate_php_test_proto
342}
343
344build_php5.5() {
345 use_php 5.5
346
347 pushd php
348 rm -rf vendor
349 cp -r /usr/local/vendor-5.5 vendor
350 wget https://phar.phpunit.de/phpunit-4.8.0.phar -O /usr/bin/phpunit
351 phpunit
352 popd
353 pushd conformance
354 make test_php
355 popd
356}
357
358build_php5.5_c() {
359 use_php 5.5
360 wget https://phar.phpunit.de/phpunit-4.8.0.phar -O /usr/bin/phpunit
361 pushd php/tests
362 /bin/bash ./test.sh 5.5
363 popd
364 # TODO(teboring): Add it back
365 # pushd conformance
366 # make test_php_c
367 # popd
368}
369
370build_php5.5_zts_c() {
371 use_php_zts 5.5
372 wget https://phar.phpunit.de/phpunit-4.8.0.phar -O /usr/bin/phpunit
373 cd php/tests && /bin/bash ./test.sh 5.5-zts && cd ../..
374 # TODO(teboring): Add it back
375 # pushd conformance
376 # make test_php_zts_c
377 # popd
378}
379
380build_php5.6() {
381 use_php 5.6
382 pushd php
383 rm -rf vendor
384 cp -r /usr/local/vendor-5.6 vendor
385 wget https://phar.phpunit.de/phpunit-5.7.0.phar -O /usr/bin/phpunit
386 phpunit
387 popd
388 pushd conformance
389 make test_php
390 popd
391}
392
393build_php5.6_c() {
394 use_php 5.6
395 wget https://phar.phpunit.de/phpunit-5.7.0.phar -O /usr/bin/phpunit
396 cd php/tests && /bin/bash ./test.sh 5.6 && cd ../..
397 # TODO(teboring): Add it back
398 # pushd conformance
399 # make test_php_c
400 # popd
401}
402
403build_php5.6_zts_c() {
404 use_php_zts 5.6
405 wget https://phar.phpunit.de/phpunit-5.7.0.phar -O /usr/bin/phpunit
406 cd php/tests && /bin/bash ./test.sh 5.6-zts && cd ../..
407 # TODO(teboring): Add it back
408 # pushd conformance
409 # make test_php_zts_c
410 # popd
411}
412
413build_php5.6_mac() {
414 generate_php_test_proto
415 # Install PHP
416 curl -s https://php-osx.liip.ch/install.sh | bash -s 5.6
417 PHP_FOLDER=`find /usr/local -type d -name "php5-5.6*"` # The folder name may change upon time
418 export PATH="$PHP_FOLDER/bin:$PATH"
419
420 # Install phpunit
421 curl https://phar.phpunit.de/phpunit-5.6.10.phar -L -o phpunit.phar
422 chmod +x phpunit.phar
423 sudo mv phpunit.phar /usr/local/bin/phpunit
424
425 # Install valgrind
426 echo "#! /bin/bash" > valgrind
427 chmod ug+x valgrind
428 sudo mv valgrind /usr/local/bin/valgrind
429
430 # Test
431 cd php/tests && /bin/bash ./test.sh && cd ../..
432 # TODO(teboring): Add it back
433 # pushd conformance
434 # make test_php_c
435 # popd
436}
437
438build_php7.0() {
439 use_php 7.0
440 pushd php
441 rm -rf vendor
442 cp -r /usr/local/vendor-7.0 vendor
443 wget https://phar.phpunit.de/phpunit-5.6.0.phar -O /usr/bin/phpunit
444 phpunit
445 popd
446 pushd conformance
447 make test_php
448 popd
449}
450
451build_php7.0_c() {
452 use_php 7.0
453 wget https://phar.phpunit.de/phpunit-5.6.0.phar -O /usr/bin/phpunit
454 cd php/tests && /bin/bash ./test.sh 7.0 && cd ../..
455 # TODO(teboring): Add it back
456 # pushd conformance
457 # make test_php_c
458 # popd
459}
460
461build_php7.0_zts_c() {
462 use_php_zts 7.0
463 wget https://phar.phpunit.de/phpunit-5.6.0.phar -O /usr/bin/phpunit
464 cd php/tests && /bin/bash ./test.sh 7.0-zts && cd ../..
465 # TODO(teboring): Add it back.
466 # pushd conformance
467 # make test_php_zts_c
468 # popd
469}
470
471build_php7.0_mac() {
472 generate_php_test_proto
473 # Install PHP
474 curl -s https://php-osx.liip.ch/install.sh | bash -s 7.0
475 PHP_FOLDER=`find /usr/local -type d -name "php7-7.0*"` # The folder name may change upon time
476 export PATH="$PHP_FOLDER/bin:$PATH"
477
478 # Install phpunit
479 curl https://phar.phpunit.de/phpunit-5.6.0.phar -L -o phpunit.phar
480 chmod +x phpunit.phar
481 sudo mv phpunit.phar /usr/local/bin/phpunit
482
483 # Install valgrind
484 echo "#! /bin/bash" > valgrind
485 chmod ug+x valgrind
486 sudo mv valgrind /usr/local/bin/valgrind
487
488 # Test
489 cd php/tests && /bin/bash ./test.sh && cd ../..
490 # TODO(teboring): Add it back
491 # pushd conformance
492 # make test_php_c
493 # popd
494}
495
496build_php_compatibility() {
497 internal_build_cpp
498 php/tests/compatibility_test.sh
499}
500
501build_php7.1() {
502 use_php 7.1
503 pushd php
504 rm -rf vendor
505 cp -r /usr/local/vendor-7.1 vendor
506 wget https://phar.phpunit.de/phpunit-5.6.0.phar -O /usr/bin/phpunit
507 phpunit
508 popd
509 pushd conformance
510 # TODO(teboring): Add it back
511 # make test_php
512 popd
513}
514
515build_php7.1_c() {
516 use_php 7.1
517 wget https://phar.phpunit.de/phpunit-5.6.0.phar -O /usr/bin/phpunit
518 cd php/tests && /bin/bash ./test.sh 7.1 && cd ../..
519 pushd conformance
520 # make test_php_c
521 popd
522}
523
524build_php7.1_zts_c() {
525 use_php_zts 7.1
526 wget https://phar.phpunit.de/phpunit-5.6.0.phar -O /usr/bin/phpunit
527 cd php/tests && /bin/bash ./test.sh 7.1-zts && cd ../..
528 pushd conformance
529 # make test_php_c
530 popd
531}
532
533build_php_all_32() {
534 build_php5.5
535 build_php5.6
536 build_php7.0
537 build_php7.1
538 build_php5.5_c
539 build_php5.6_c
540 build_php7.0_c
541 build_php7.1_c
542 build_php5.5_zts_c
543 build_php5.6_zts_c
544 build_php7.0_zts_c
545 build_php7.1_zts_c
546}
547
548build_php_all() {
549 build_php_all_32
550 build_php_compatibility
551}
552
553# -------- main --------
554
555if [ "$#" -ne 1 ]; then
556 echo "
557Usage: $0 { cpp |
558 cpp_distcheck |
559 csharp |
560 java_jdk7 |
561 java_oracle7 |
562 java_compatibility |
563 objectivec_ios |
564 objectivec_ios_debug |
565 objectivec_ios_release |
566 objectivec_osx |
567 objectivec_cocoapods_integration |
568 python |
569 python_cpp |
570 python_compatibility |
571 ruby21 |
572 ruby22 |
573 jruby |
574 ruby_all |
575 php5.5 |
576 php5.5_c |
577 php5.6 |
578 php5.6_c |
579 php7.0 |
580 php7.0_c |
581 php_compatibility |
582 php7.1 |
583 php7.1_c |
584 php_all)
585"
586 exit 1
587fi
588
589set -e # exit immediately on error
590set -x # display all commands
591cd $(dirname $0)
592eval "build_$1"