blob: 2ea5f6c4a804bbbf5cd3c363955ad4bef541ad03 [file] [log] [blame]
Josh Haberman738393b2016-02-18 20:10:23 -08001#!/bin/bash
Josh Haberman67c727c2016-03-04 14:21:18 -08002#
Feng Xiao9de4e642018-07-13 16:55:32 -07003# 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.
Josh Haberman0f8c25d2016-02-19 09:11:38 -08006
Josh Haberman181c7f22015-07-15 11:05:10 -07007# For when some other test needs the C++ main build, including protoc and
8# libprotobuf.
9internal_build_cpp() {
Josh Haberman738393b2016-02-18 20:10:23 -080010 if [ -f src/protoc ]; then
11 # Already built.
12 return
13 fi
14
Carlos O'Ryan3c5442a2018-03-26 16:54:32 -040015 # Initialize any submodules.
16 git submodule update --init --recursive
17
Chris Fallin20e94b22015-05-13 16:43:48 -070018 ./autogen.sh
Ben Wolsieffer56b40a82018-10-04 20:25:10 -040019 ./configure CXXFLAGS="-fPIC -std=c++11" # -fPIC is needed for python cpp test.
20 # See python/setup.py for more details
Joshua Habermanf5e8ee42019-03-06 12:04:17 -080021 make -j$(nproc)
Josh Haberman181c7f22015-07-15 11:05:10 -070022}
23
24build_cpp() {
25 internal_build_cpp
Joshua Habermanf5e8ee42019-03-06 12:04:17 -080026 make check -j$(nproc) || (cat src/test-suite.log; false)
Bo Yangfd332d12016-09-30 00:07:47 +000027 cd conformance && make test_cpp && cd ..
Josh Habermancb36bde2016-04-29 09:52:20 -070028
Thomas Van Lentenbc9d0772016-12-08 16:19:58 -050029 # The benchmark code depends on cmake, so test if it is installed before
30 # trying to do the build.
Thomas Van Lentenbc9d0772016-12-08 16:19:58 -050031 if [[ $(type cmake 2>/dev/null) ]]; then
32 # Verify benchmarking code can build successfully.
Yilun Chong34843ed2017-12-13 14:34:52 -080033 cd benchmarks && make cpp-benchmark && cd ..
Thomas Van Lentenbc9d0772016-12-08 16:19:58 -050034 else
35 echo ""
36 echo "WARNING: Skipping validation of the bench marking code, cmake isn't installed."
37 echo ""
38 fi
Chris Fallin20e94b22015-05-13 16:43:48 -070039}
40
Hao Nguyen4f8a6352019-01-23 10:02:51 -080041build_cpp_tcmalloc() {
42 internal_build_cpp
43 ./configure LIBS=-ltcmalloc && make clean && make \
44 PTHREAD_CFLAGS='-pthread -DGOOGLE_PROTOBUF_HEAP_CHECK_DRACONIAN' \
45 check
46 cd src
Adam Cozzetted135f072019-01-25 10:28:52 -080047 PPROF_PATH=/usr/bin/google-pprof HEAPCHECK=strict ./protobuf-test
Hao Nguyen4f8a6352019-01-23 10:02:51 -080048}
49
Chris Fallin20e94b22015-05-13 16:43:48 -070050build_cpp_distcheck() {
Adam Cozzette45aba802019-03-11 14:39:49 -070051 grep -q -- "-Og" src/Makefile.am &&
52 echo "The -Og flag is incompatible with Clang versions older than 4.0." &&
53 exit 1
54
Carlos O'Ryan3c5442a2018-03-26 16:54:32 -040055 # Initialize any submodules.
56 git submodule update --init --recursive
Chris Fallin20e94b22015-05-13 16:43:48 -070057 ./autogen.sh
58 ./configure
Feng Xiaoa4f68b12016-07-19 17:20:31 -070059 make dist
60
61 # List all files that should be included in the distribution package.
Jisi Liu55fdbe52017-08-23 11:35:48 -070062 git ls-files | grep "^\(java\|python\|objectivec\|csharp\|js\|ruby\|php\|cmake\|examples\|src/google/protobuf/.*\.proto\)" |\
Jie Luoea511492017-01-23 15:11:00 -080063 grep -v ".gitignore" | grep -v "java/compatibility_tests" |\
Jie Luo72886892017-02-09 16:49:52 -080064 grep -v "python/compatibility_tests" | grep -v "csharp/compatibility_tests" > dist.lst
Feng Xiaoa4f68b12016-07-19 17:20:31 -070065 # Unzip the dist tar file.
66 DIST=`ls *.tar.gz`
67 tar -xf $DIST
68 cd ${DIST//.tar.gz}
69 # Check if every file exists in the dist tar file.
70 FILES_MISSING=""
71 for FILE in $(<../dist.lst); do
Feng Xiaoacd5b052018-08-09 21:21:01 -070072 [ -f "$FILE" ] || {
Feng Xiaoa4f68b12016-07-19 17:20:31 -070073 echo "$FILE is not found!"
74 FILES_MISSING="$FILE $FILES_MISSING"
Feng Xiaoacd5b052018-08-09 21:21:01 -070075 }
Feng Xiaoa4f68b12016-07-19 17:20:31 -070076 done
77 cd ..
78 if [ ! -z "$FILES_MISSING" ]; then
79 echo "Missing files in EXTRA_DIST: $FILES_MISSING"
80 exit 1
81 fi
82
83 # Do the regular dist-check for C++.
Joshua Habermanf5e8ee42019-03-06 12:04:17 -080084 make distcheck -j$(nproc)
Chris Fallin20e94b22015-05-13 16:43:48 -070085}
86
Hao Nguyenf85c8232019-03-07 14:34:28 -080087build_dist_install() {
88 # Initialize any submodules.
89 git submodule update --init --recursive
90 ./autogen.sh
91 ./configure
92 make dist
93
94 # Unzip the dist tar file and install it.
95 DIST=`ls *.tar.gz`
96 tar -xf $DIST
97 pushd ${DIST//.tar.gz}
98 ./configure && make check -j4 && make install
99
100 export LD_LIBRARY_PATH=/usr/local/lib
101
102 # Try to install Java
103 pushd java
104 use_java jdk7
105 $MVN install
106 popd
107
108 # Try to install Python
109 virtualenv --no-site-packages venv
110 source venv/bin/activate
111 pushd python
112 python setup.py clean build sdist
113 pip install dist/protobuf-*.tar.gz
114 popd
115 deactivate
116 rm -rf python/venv
117}
118
Jan Tattermuschddb36ef2015-05-18 17:34:02 -0700119build_csharp() {
Jon Skeet9a9a66e2017-10-25 08:03:50 +0100120 # Required for conformance tests and to regenerate protos.
Jon Skeetb6defa72015-08-04 10:01:40 +0100121 internal_build_cpp
Josh Habermanffc81182016-02-22 15:39:29 -0800122 NUGET=/usr/local/bin/nuget.exe
Jon Skeetb6defa72015-08-04 10:01:40 +0100123
Jan Tattermusch67fee072019-03-12 04:48:10 -0400124 # Disable some unwanted dotnet options
125 export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true
126 export DOTNET_CLI_TELEMETRY_OPTOUT=true
127
128 # TODO(jtattermusch): is this still needed with "first time experience"
129 # disabled?
Jon Skeet10a8fb42016-07-14 22:01:47 +0100130 # Perform "dotnet new" once to get the setup preprocessing out of the
131 # way. That spews a lot of output (including backspaces) into logs
132 # otherwise, and can cause problems. It doesn't matter if this step
133 # is performed multiple times; it's cheap after the first time anyway.
Jon Skeetf26e8c22017-05-04 08:51:46 +0100134 # (It also doesn't matter if it's unnecessary, which it will be on some
135 # systems. It's necessary on Jenkins in order to avoid unprintable
136 # characters appearing in the JUnit output.)
Jon Skeet10a8fb42016-07-14 22:01:47 +0100137 mkdir dotnettmp
138 (cd dotnettmp; dotnet new > /dev/null)
139 rm -rf dotnettmp
140
Jon Skeet9a9a66e2017-10-25 08:03:50 +0100141 # Check that the protos haven't broken C# codegen.
142 # TODO(jonskeet): Fail if regenerating creates any changes.
143 csharp/generate_protos.sh
Brent Shaffer67379542018-05-23 16:43:30 -0700144
Jan Tattermuschddb36ef2015-05-18 17:34:02 -0700145 csharp/buildall.sh
Josh Habermane891c292015-12-30 16:03:49 -0800146 cd conformance && make test_csharp && cd ..
Jie Luo72886892017-02-09 16:49:52 -0800147
148 # Run csharp compatibility test between 3.0.0 and the current version.
149 csharp/compatibility_tests/v3.0.0/test.sh 3.0.0
Jan Tattermuschddb36ef2015-05-18 17:34:02 -0700150}
151
Tim Swast7e31c4d2015-11-20 15:32:53 -0800152build_golang() {
153 # Go build needs `protoc`.
154 internal_build_cpp
155 # Add protoc to the path so that the examples build finds it.
156 export PATH="`pwd`/src:$PATH"
157
Tim Swast7e31c4d2015-11-20 15:32:53 -0800158 export GOPATH="$HOME/gocode"
Feng Xiaoa0a17e22018-08-23 15:35:52 -0700159 mkdir -p "$GOPATH/src/github.com/protocolbuffers"
Feng Xiaoafe98de2018-08-22 11:55:30 -0700160 rm -f "$GOPATH/src/github.com/protocolbuffers/protobuf"
161 ln -s "`pwd`" "$GOPATH/src/github.com/protocolbuffers/protobuf"
Tim Swast7e31c4d2015-11-20 15:32:53 -0800162 export PATH="$GOPATH/bin:$PATH"
163 go get github.com/golang/protobuf/protoc-gen-go
164
Feng Xiao8136ccb2017-09-12 12:00:20 -0700165 cd examples && PROTO_PATH="-I../src -I." make gotest && cd ..
Tim Swast7e31c4d2015-11-20 15:32:53 -0800166}
167
Chris Fallin20e94b22015-05-13 16:43:48 -0700168use_java() {
Chris Fallin20e94b22015-05-13 16:43:48 -0700169 version=$1
170 case "$version" in
Chris Fallin20e94b22015-05-13 16:43:48 -0700171 jdk7)
Chris Fallin20e94b22015-05-13 16:43:48 -0700172 export PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH
Feng Xiaoad49ed72016-07-21 11:37:46 -0700173 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
Chris Fallin20e94b22015-05-13 16:43:48 -0700174 ;;
175 oracle7)
Chris Fallin20e94b22015-05-13 16:43:48 -0700176 export PATH=/usr/lib/jvm/java-7-oracle/bin:$PATH
Feng Xiaoad49ed72016-07-21 11:37:46 -0700177 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
Chris Fallin20e94b22015-05-13 16:43:48 -0700178 ;;
179 esac
180
Feng Xiao9de4e642018-07-13 16:55:32 -0700181 MAVEN_LOCAL_REPOSITORY=/var/maven_local_repository
Yilun Chong2b7ee382018-09-23 17:07:02 -0700182 MVN="$MVN -e -X -Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$MAVEN_LOCAL_REPOSITORY"
Josh Haberman1ee0fda2016-03-03 16:02:55 -0800183
Chris Fallin20e94b22015-05-13 16:43:48 -0700184 which java
185 java -version
Feng Xiaoad49ed72016-07-21 11:37:46 -0700186 $MVN -version
Chris Fallin20e94b22015-05-13 16:43:48 -0700187}
188
Josh Habermand08c39c2016-02-20 12:03:39 -0800189# --batch-mode supresses download progress output that spams the logs.
Josh Habermanb28b3f62016-02-20 12:17:10 -0800190MVN="mvn --batch-mode"
Josh Habermand08c39c2016-02-20 12:03:39 -0800191
Chris Fallin20e94b22015-05-13 16:43:48 -0700192build_java() {
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800193 version=$1
194 dir=java_$version
Chris Fallin20e94b22015-05-13 16:43:48 -0700195 # Java build needs `protoc`.
Josh Haberman181c7f22015-07-15 11:05:10 -0700196 internal_build_cpp
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800197 cp -r java $dir
198 cd $dir && $MVN clean && $MVN test
Feng Xiao9e5fb552015-12-21 11:08:18 -0800199 cd ../..
200}
201
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800202# The conformance tests are hard-coded to work with the $ROOT/java directory.
203# So this can't run in parallel with two different sets of tests.
Feng Xiao9e5fb552015-12-21 11:08:18 -0800204build_java_with_conformance_tests() {
205 # Java build needs `protoc`.
206 internal_build_cpp
Josh Habermand08c39c2016-02-20 12:03:39 -0800207 cd java && $MVN test && $MVN install
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800208 cd util && $MVN package assembly:single
Feng Xiaoaf81dcf2015-12-21 03:25:59 -0800209 cd ../..
Chris Fallin20e94b22015-05-13 16:43:48 -0700210 cd conformance && make test_java && cd ..
211}
212
Chris Fallin20e94b22015-05-13 16:43:48 -0700213build_java_jdk7() {
214 use_java jdk7
Feng Xiao9e5fb552015-12-21 11:08:18 -0800215 build_java_with_conformance_tests
Chris Fallin20e94b22015-05-13 16:43:48 -0700216}
217build_java_oracle7() {
218 use_java oracle7
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800219 build_java oracle7
Chris Fallin20e94b22015-05-13 16:43:48 -0700220}
Feng Xiaobaa40232016-07-29 14:11:21 -0700221build_java_compatibility() {
222 use_java jdk7
223 internal_build_cpp
224 # Use the unit-tests extraced from 2.5.0 to test the compatibilty between
225 # 3.0.0-beta-4 and the current version.
226 cd java/compatibility_tests/v2.5.0
227 ./test.sh 3.0.0-beta-4
228}
Chris Fallin20e94b22015-05-13 16:43:48 -0700229
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400230build_objectivec_ios() {
Thomas Van Lenten368a2f42016-05-24 11:27:33 -0400231 # Reused the build script that takes care of configuring and ensuring things
232 # are up to date. The OS X test runs the objc conformance test, so skip it
233 # here.
Thomas Van Lenten368a2f42016-05-24 11:27:33 -0400234 objectivec/DevTools/full_mac_build.sh \
Thomas Van Lentenbd006712019-01-07 16:42:22 -0500235 --core-only --skip-xcode-osx --skip-xcode-tvos --skip-objc-conformance "$@"
Thomas Van Lenten368a2f42016-05-24 11:27:33 -0400236}
237
238build_objectivec_ios_debug() {
239 build_objectivec_ios --skip-xcode-release
240}
241
242build_objectivec_ios_release() {
243 build_objectivec_ios --skip-xcode-debug
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400244}
245
246build_objectivec_osx() {
Thomas Van Lenten368a2f42016-05-24 11:27:33 -0400247 # Reused the build script that takes care of configuring and ensuring things
248 # are up to date.
249 objectivec/DevTools/full_mac_build.sh \
Thomas Van Lentenbd006712019-01-07 16:42:22 -0500250 --core-only --skip-xcode-ios --skip-xcode-tvos
251}
252
253build_objectivec_tvos() {
254 # Reused the build script that takes care of configuring and ensuring things
255 # are up to date. The OS X test runs the objc conformance test, so skip it
256 # here.
257 objectivec/DevTools/full_mac_build.sh \
258 --core-only --skip-xcode-ios --skip-xcode-osx --skip-objc-conformance "$@"
259}
260
261build_objectivec_tvos_debug() {
262 build_objectivec_tvos --skip-xcode-release
263}
264
265build_objectivec_tvos_release() {
266 build_objectivec_tvos --skip-xcode-debug
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400267}
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400268
Sergio Campamáf0c14922016-06-14 11:26:01 -0700269build_objectivec_cocoapods_integration() {
Sergio Campamáf0c14922016-06-14 11:26:01 -0700270 # Update pod to the latest version.
Yilun Chong89b914f2019-02-26 12:52:06 -0800271 gem install cocoapods --no_document
Sergio Campamáf0c14922016-06-14 11:26:01 -0700272 objectivec/Tests/CocoaPods/run_tests.sh
273}
274
Chris Fallin20e94b22015-05-13 16:43:48 -0700275build_python() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700276 internal_build_cpp
Chris Fallin20e94b22015-05-13 16:43:48 -0700277 cd python
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400278 if [ $(uname -s) == "Linux" ]; then
Jie Luo610e4332017-08-22 16:23:21 -0700279 envlist=py\{27,33,34,35,36\}-python
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400280 else
281 envlist=py27-python
282 fi
283 tox -e $envlist
Chris Fallin20e94b22015-05-13 16:43:48 -0700284 cd ..
285}
286
Paul Yang4dec4f92018-12-18 18:07:24 -0800287build_python_version() {
288 internal_build_cpp
289 cd python
290 envlist=$1
291 tox -e $envlist
292 cd ..
293}
294
295build_python27() {
296 build_python_version py27-python
297}
298
299build_python33() {
300 build_python_version py33-python
301}
302
303build_python34() {
304 build_python_version py34-python
305}
306
307build_python35() {
308 build_python_version py35-python
309}
310
311build_python36() {
312 build_python_version py36-python
313}
314
315build_python37() {
316 build_python_version py37-python
317}
318
Chris Fallin20e94b22015-05-13 16:43:48 -0700319build_python_cpp() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700320 internal_build_cpp
Bo Yangfd332d12016-09-30 00:07:47 +0000321 export LD_LIBRARY_PATH=../src/.libs # for Linux
322 export DYLD_LIBRARY_PATH=../src/.libs # for OS X
Chris Fallin20e94b22015-05-13 16:43:48 -0700323 cd python
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400324 if [ $(uname -s) == "Linux" ]; then
Jie Luo610e4332017-08-22 16:23:21 -0700325 envlist=py\{27,33,34,35,36\}-cpp
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400326 else
327 envlist=py27-cpp
328 fi
329 tox -e $envlist
Chris Fallin20e94b22015-05-13 16:43:48 -0700330 cd ..
331}
332
Paul Yang4dec4f92018-12-18 18:07:24 -0800333build_python_cpp_version() {
334 internal_build_cpp
335 export LD_LIBRARY_PATH=../src/.libs # for Linux
336 export DYLD_LIBRARY_PATH=../src/.libs # for OS X
337 cd python
338 envlist=$1
339 tox -e $envlist
340 cd ..
341}
342
343build_python27_cpp() {
344 build_python_cpp_version py27-cpp
345}
346
347build_python33_cpp() {
348 build_python_cpp_version py33-cpp
349}
350
351build_python34_cpp() {
352 build_python_cpp_version py34-cpp
353}
354
355build_python35_cpp() {
356 build_python_cpp_version py35-cpp
357}
358
359build_python36_cpp() {
360 build_python_cpp_version py36-cpp
361}
362
363build_python37_cpp() {
364 build_python_cpp_version py37-cpp
365}
366
Jie Luoea511492017-01-23 15:11:00 -0800367build_python_compatibility() {
368 internal_build_cpp
369 # Use the unit-tests extraced from 2.5.0 to test the compatibilty.
370 cd python/compatibility_tests/v2.5.0
371 # Test between 2.5.0 and the current version.
372 ./test.sh 2.5.0
373 # Test between 3.0.0-beta-1 and the current version.
374 ./test.sh 3.0.0-beta-1
375}
376
Paul Yang78ba0212018-07-02 15:11:36 -0700377build_ruby23() {
378 internal_build_cpp # For conformance tests.
Paul Yang333b3ce2018-10-18 11:16:55 -0700379 cd ruby && bash travis-test.sh ruby-2.3.8 && cd ..
Paul Yang78ba0212018-07-02 15:11:36 -0700380}
381build_ruby24() {
382 internal_build_cpp # For conformance tests.
383 cd ruby && bash travis-test.sh ruby-2.4 && cd ..
384}
385build_ruby25() {
386 internal_build_cpp # For conformance tests.
Paul Yang333b3ce2018-10-18 11:16:55 -0700387 cd ruby && bash travis-test.sh ruby-2.5.1 && cd ..
Paul Yang78ba0212018-07-02 15:11:36 -0700388}
Paul Yangde9e1a02019-01-03 14:25:50 -0800389build_ruby26() {
390 internal_build_cpp # For conformance tests.
391 cd ruby && bash travis-test.sh ruby-2.6.0 && cd ..
Chris Fallin20e94b22015-05-13 16:43:48 -0700392}
393
Josh Habermane9cf31e2015-12-21 15:18:17 -0800394build_javascript() {
395 internal_build_cpp
Josh Haberman0d2d8bc2015-12-28 06:43:42 -0800396 cd js && npm install && npm test && cd ..
Josh Habermanf873d322016-06-08 12:38:15 -0700397 cd conformance && make test_nodejs && cd ..
Josh Habermane9cf31e2015-12-21 15:18:17 -0800398}
399
Paul Yang46ae90d2016-12-08 11:16:49 -0800400generate_php_test_proto() {
401 internal_build_cpp
402 pushd php/tests
403 # Generate test file
404 rm -rf generated
405 mkdir generated
Bo Yangf46a01d2017-09-12 15:04:34 -0700406 ../../src/protoc --php_out=generated \
michaelbausor6a51c032018-10-07 16:56:41 -0700407 -I../../src -I. \
Brent Shaffer67379542018-05-23 16:43:30 -0700408 proto/empty/echo.proto \
Bo Yangf46a01d2017-09-12 15:04:34 -0700409 proto/test.proto \
410 proto/test_include.proto \
411 proto/test_no_namespace.proto \
412 proto/test_prefix.proto \
413 proto/test_php_namespace.proto \
414 proto/test_empty_php_namespace.proto \
415 proto/test_reserved_enum_lower.proto \
416 proto/test_reserved_enum_upper.proto \
417 proto/test_reserved_enum_value_lower.proto \
418 proto/test_reserved_enum_value_upper.proto \
419 proto/test_reserved_message_lower.proto \
420 proto/test_reserved_message_upper.proto \
421 proto/test_service.proto \
422 proto/test_service_namespace.proto \
michaelbausor6a51c032018-10-07 16:56:41 -0700423 proto/test_wrapper_type_setters.proto \
Paul Yangc15a3262017-08-02 07:42:27 -0700424 proto/test_descriptors.proto
Paul Yang46ae90d2016-12-08 11:16:49 -0800425 pushd ../../src
Paul Yangbcda9192017-11-03 12:30:09 -0700426 ./protoc --php_out=../php/tests/generated -I../php/tests -I. \
427 ../php/tests/proto/test_import_descriptor_proto.proto
Paul Yang46ae90d2016-12-08 11:16:49 -0800428 popd
429 popd
430}
431
Bo Yangc8bd36e2016-09-30 19:07:33 +0000432use_php() {
433 VERSION=$1
Paul Yangd7c44092018-12-18 10:57:03 -0800434 export PATH=/usr/local/php-${VERSION}/bin:$PATH
435 export CPLUS_INCLUDE_PATH=/usr/local/php-${VERSION}/include/php/main:/usr/local/php-${VERSION}/include/php/:$CPLUS_INCLUDE_PATH
436 export C_INCLUDE_PATH=/usr/local/php-${VERSION}/include/php/main:/usr/local/php-${VERSION}/include/php/:$C_INCLUDE_PATH
Paul Yang46ae90d2016-12-08 11:16:49 -0800437 generate_php_test_proto
Bo Yangc8bd36e2016-09-30 19:07:33 +0000438}
439
Bo Yangc96dd662016-10-04 17:32:08 +0000440use_php_zts() {
441 VERSION=$1
Paul Yangd7c44092018-12-18 10:57:03 -0800442 export PATH=/usr/local/php-${VERSION}-zts/bin:$PATH
443 export CPLUS_INCLUDE_PATH=/usr/local/php-${VERSION}-zts/include/php/main:/usr/local/php-${VERSION}-zts/include/php/:$CPLUS_INCLUDE_PATH
444 export C_INCLUDE_PATH=/usr/local/php-${VERSION}-zts/include/php/main:/usr/local/php-${VERSION}-zts/include/php/:$C_INCLUDE_PATH
Paul Yang46ae90d2016-12-08 11:16:49 -0800445 generate_php_test_proto
Bo Yangc96dd662016-10-04 17:32:08 +0000446}
447
Paul Yang51c5ff82016-10-25 17:27:05 -0700448use_php_bc() {
449 VERSION=$1
Paul Yangd7c44092018-12-18 10:57:03 -0800450 export PATH=/usr/local/php-${VERSION}-bc/bin:$PATH
451 export CPLUS_INCLUDE_PATH=/usr/local/php-${VERSION}-bc/include/php/main:/usr/local/php-${VERSION}-bc/include/php/:$CPLUS_INCLUDE_PATH
452 export C_INCLUDE_PATH=/usr/local/php-${VERSION}-bc/include/php/main:/usr/local/php-${VERSION}-bc/include/php/:$C_INCLUDE_PATH
Paul Yang46ae90d2016-12-08 11:16:49 -0800453 generate_php_test_proto
Paul Yang51c5ff82016-10-25 17:27:05 -0700454}
455
Bo Yangfd332d12016-09-30 00:07:47 +0000456build_php5.5() {
Paul Yang190b5272017-04-19 16:23:51 -0700457 use_php 5.5
Paul Yangdd8d5f52017-03-08 14:31:34 -0800458
Paul Yange3e38b82016-12-08 14:39:20 -0800459 pushd php
Bo Yangfd332d12016-09-30 00:07:47 +0000460 rm -rf vendor
Paul Yangd7c44092018-12-18 10:57:03 -0800461 composer update
462 ./vendor/bin/phpunit
Paul Yange3e38b82016-12-08 14:39:20 -0800463 popd
Paul Yang39756642017-02-01 12:47:58 -0800464 pushd conformance
Paul Yangecca6ea2017-06-30 12:14:09 -0700465 make test_php
Paul Yang39756642017-02-01 12:47:58 -0800466 popd
Bo Yangfd332d12016-09-30 00:07:47 +0000467}
468
Bo Yang34cdaf42016-10-03 21:59:58 +0000469build_php5.5_c() {
Paul Yang190b5272017-04-19 16:23:51 -0700470 use_php 5.5
Paul Yangecca6ea2017-06-30 12:14:09 -0700471 pushd php/tests
Paul Yang51293f32018-01-25 11:31:05 -0800472 /bin/bash ./test.sh 5.5
Paul Yang39756642017-02-01 12:47:58 -0800473 popd
Paul Yangecca6ea2017-06-30 12:14:09 -0700474 # TODO(teboring): Add it back
475 # pushd conformance
476 # make test_php_c
477 # popd
Bo Yang34cdaf42016-10-03 21:59:58 +0000478}
Bo Yang34cdaf42016-10-03 21:59:58 +0000479
David Supplee93533f72019-03-12 21:30:06 -0700480build_php5.5_mixed() {
481 use_php 5.5
482 pushd php
483 rm -rf vendor
484 composer update
485 /bin/bash ./tests/compile_extension.sh ./ext/google/protobuf
486 php -dextension=./ext/google/protobuf/modules/protobuf.so ./vendor/bin/phpunit
487 popd
488}
489
Bo Yangc96dd662016-10-04 17:32:08 +0000490build_php5.5_zts_c() {
491 use_php_zts 5.5
Paul Yang51293f32018-01-25 11:31:05 -0800492 cd php/tests && /bin/bash ./test.sh 5.5-zts && cd ../..
Paul Yangecca6ea2017-06-30 12:14:09 -0700493 # TODO(teboring): Add it back
494 # pushd conformance
495 # make test_php_zts_c
496 # popd
Paul Yangdf839072016-11-10 11:20:50 -0800497}
498
Bo Yangfd332d12016-09-30 00:07:47 +0000499build_php5.6() {
Bo Yangc8bd36e2016-09-30 19:07:33 +0000500 use_php 5.6
Paul Yange3e38b82016-12-08 14:39:20 -0800501 pushd php
Bo Yangfd332d12016-09-30 00:07:47 +0000502 rm -rf vendor
Paul Yangd7c44092018-12-18 10:57:03 -0800503 composer update
504 ./vendor/bin/phpunit
Paul Yange3e38b82016-12-08 14:39:20 -0800505 popd
Paul Yang39756642017-02-01 12:47:58 -0800506 pushd conformance
Paul Yangecca6ea2017-06-30 12:14:09 -0700507 make test_php
Paul Yang39756642017-02-01 12:47:58 -0800508 popd
Bo Yangfd332d12016-09-30 00:07:47 +0000509}
510
Bo Yang34cdaf42016-10-03 21:59:58 +0000511build_php5.6_c() {
512 use_php 5.6
Paul Yang51293f32018-01-25 11:31:05 -0800513 cd php/tests && /bin/bash ./test.sh 5.6 && cd ../..
Paul Yangecca6ea2017-06-30 12:14:09 -0700514 # TODO(teboring): Add it back
515 # pushd conformance
Paul Yang190b5272017-04-19 16:23:51 -0700516 # make test_php_c
Paul Yangecca6ea2017-06-30 12:14:09 -0700517 # popd
Paul Yang190b5272017-04-19 16:23:51 -0700518}
519
David Supplee93533f72019-03-12 21:30:06 -0700520build_php5.6_mixed() {
521 use_php 5.6
522 pushd php
523 rm -rf vendor
524 composer update
525 /bin/bash ./tests/compile_extension.sh ./ext/google/protobuf
526 php -dextension=./ext/google/protobuf/modules/protobuf.so ./vendor/bin/phpunit
527 popd
528}
529
Paul Yang190b5272017-04-19 16:23:51 -0700530build_php5.6_zts_c() {
531 use_php_zts 5.6
Paul Yang51293f32018-01-25 11:31:05 -0800532 cd php/tests && /bin/bash ./test.sh 5.6-zts && cd ../..
Paul Yangecca6ea2017-06-30 12:14:09 -0700533 # TODO(teboring): Add it back
534 # pushd conformance
535 # make test_php_zts_c
536 # popd
Bo Yangfd332d12016-09-30 00:07:47 +0000537}
538
Bo Yang63448e62016-10-05 18:28:13 -0700539build_php5.6_mac() {
Paul Yang46ae90d2016-12-08 11:16:49 -0800540 generate_php_test_proto
Bo Yang63448e62016-10-05 18:28:13 -0700541 # Install PHP
542 curl -s https://php-osx.liip.ch/install.sh | bash -s 5.6
Paul Yang1f2dbc82016-11-08 11:38:34 -0800543 PHP_FOLDER=`find /usr/local -type d -name "php5-5.6*"` # The folder name may change upon time
544 export PATH="$PHP_FOLDER/bin:$PATH"
Bo Yang63448e62016-10-05 18:28:13 -0700545
546 # Install phpunit
Bo Yang8400e292019-01-28 20:58:58 +0000547 curl https://phar.phpunit.de/phpunit-5.6.8.phar -L -o phpunit.phar
Bo Yang63448e62016-10-05 18:28:13 -0700548 chmod +x phpunit.phar
549 sudo mv phpunit.phar /usr/local/bin/phpunit
550
551 # Install valgrind
552 echo "#! /bin/bash" > valgrind
553 chmod ug+x valgrind
554 sudo mv valgrind /usr/local/bin/valgrind
555
556 # Test
557 cd php/tests && /bin/bash ./test.sh && cd ../..
Paul Yangecca6ea2017-06-30 12:14:09 -0700558 # TODO(teboring): Add it back
559 # pushd conformance
Paul Yang190b5272017-04-19 16:23:51 -0700560 # make test_php_c
Paul Yangecca6ea2017-06-30 12:14:09 -0700561 # popd
Bo Yang63448e62016-10-05 18:28:13 -0700562}
563
Bo Yangfd332d12016-09-30 00:07:47 +0000564build_php7.0() {
Bo Yangc8bd36e2016-09-30 19:07:33 +0000565 use_php 7.0
Paul Yange3e38b82016-12-08 14:39:20 -0800566 pushd php
Bo Yangfd332d12016-09-30 00:07:47 +0000567 rm -rf vendor
Paul Yangd7c44092018-12-18 10:57:03 -0800568 composer update
569 ./vendor/bin/phpunit
Paul Yange3e38b82016-12-08 14:39:20 -0800570 popd
Paul Yang39756642017-02-01 12:47:58 -0800571 pushd conformance
Paul Yangecca6ea2017-06-30 12:14:09 -0700572 make test_php
Paul Yang39756642017-02-01 12:47:58 -0800573 popd
Bo Yangfd332d12016-09-30 00:07:47 +0000574}
575
Bo Yang34cdaf42016-10-03 21:59:58 +0000576build_php7.0_c() {
577 use_php 7.0
Paul Yang51293f32018-01-25 11:31:05 -0800578 cd php/tests && /bin/bash ./test.sh 7.0 && cd ../..
Paul Yangecca6ea2017-06-30 12:14:09 -0700579 # TODO(teboring): Add it back
580 # pushd conformance
Paul Yang190b5272017-04-19 16:23:51 -0700581 # make test_php_c
Paul Yangecca6ea2017-06-30 12:14:09 -0700582 # popd
Paul Yang190b5272017-04-19 16:23:51 -0700583}
584
David Supplee93533f72019-03-12 21:30:06 -0700585build_php7.0_mixed() {
586 use_php 7.0
587 pushd php
588 rm -rf vendor
589 composer update
590 /bin/bash ./tests/compile_extension.sh ./ext/google/protobuf
591 php -dextension=./ext/google/protobuf/modules/protobuf.so ./vendor/bin/phpunit
592 popd
593}
594
Paul Yang190b5272017-04-19 16:23:51 -0700595build_php7.0_zts_c() {
596 use_php_zts 7.0
Paul Yang51293f32018-01-25 11:31:05 -0800597 cd php/tests && /bin/bash ./test.sh 7.0-zts && cd ../..
Paul Yangecca6ea2017-06-30 12:14:09 -0700598 # TODO(teboring): Add it back.
599 # pushd conformance
600 # make test_php_zts_c
601 # popd
Paul Yang190b5272017-04-19 16:23:51 -0700602}
603
604build_php7.0_mac() {
605 generate_php_test_proto
606 # Install PHP
607 curl -s https://php-osx.liip.ch/install.sh | bash -s 7.0
608 PHP_FOLDER=`find /usr/local -type d -name "php7-7.0*"` # The folder name may change upon time
609 export PATH="$PHP_FOLDER/bin:$PATH"
610
611 # Install phpunit
612 curl https://phar.phpunit.de/phpunit-5.6.0.phar -L -o phpunit.phar
613 chmod +x phpunit.phar
614 sudo mv phpunit.phar /usr/local/bin/phpunit
615
616 # Install valgrind
617 echo "#! /bin/bash" > valgrind
618 chmod ug+x valgrind
619 sudo mv valgrind /usr/local/bin/valgrind
620
621 # Test
622 cd php/tests && /bin/bash ./test.sh && cd ../..
Paul Yangecca6ea2017-06-30 12:14:09 -0700623 # TODO(teboring): Add it back
624 # pushd conformance
Paul Yang190b5272017-04-19 16:23:51 -0700625 # make test_php_c
Paul Yangecca6ea2017-06-30 12:14:09 -0700626 # popd
Bo Yang34cdaf42016-10-03 21:59:58 +0000627}
628
Paul Yang25abd7b2017-05-05 11:14:11 -0700629build_php_compatibility() {
630 internal_build_cpp
631 php/tests/compatibility_test.sh
632}
633
Paul Yang22319312017-05-10 15:59:59 -0700634build_php7.1() {
635 use_php 7.1
636 pushd php
637 rm -rf vendor
Paul Yangd7c44092018-12-18 10:57:03 -0800638 composer update
639 ./vendor/bin/phpunit
Paul Yang22319312017-05-10 15:59:59 -0700640 popd
641 pushd conformance
Paul Yangbdcbcab2018-07-26 13:52:22 -0700642 make test_php
Paul Yang22319312017-05-10 15:59:59 -0700643 popd
644}
645
646build_php7.1_c() {
Paul Yangbdcbcab2018-07-26 13:52:22 -0700647 ENABLE_CONFORMANCE_TEST=$1
Paul Yang22319312017-05-10 15:59:59 -0700648 use_php 7.1
Paul Yang51293f32018-01-25 11:31:05 -0800649 cd php/tests && /bin/bash ./test.sh 7.1 && cd ../..
Paul Yangbdcbcab2018-07-26 13:52:22 -0700650 if [ "$ENABLE_CONFORMANCE_TEST" = "true" ]
651 then
652 pushd conformance
653 make test_php_c
654 popd
655 fi
Paul Yang22319312017-05-10 15:59:59 -0700656}
657
David Supplee93533f72019-03-12 21:30:06 -0700658build_php7.1_mixed() {
659 use_php 7.1
660 pushd php
661 rm -rf vendor
662 composer update
663 /bin/bash ./tests/compile_extension.sh ./ext/google/protobuf
664 php -dextension=./ext/google/protobuf/modules/protobuf.so ./vendor/bin/phpunit
665 popd
666}
667
Paul Yang22319312017-05-10 15:59:59 -0700668build_php7.1_zts_c() {
669 use_php_zts 7.1
Paul Yang51293f32018-01-25 11:31:05 -0800670 cd php/tests && /bin/bash ./test.sh 7.1-zts && cd ../..
Paul Yang22319312017-05-10 15:59:59 -0700671 pushd conformance
672 # make test_php_c
673 popd
674}
675
Paul Yang25abd7b2017-05-05 11:14:11 -0700676build_php_all_32() {
Bo Yangc8bd36e2016-09-30 19:07:33 +0000677 build_php5.5
678 build_php5.6
679 build_php7.0
Paul Yang22319312017-05-10 15:59:59 -0700680 build_php7.1
Bo Yangc8bd36e2016-09-30 19:07:33 +0000681 build_php5.5_c
682 build_php5.6_c
Paul Yang190b5272017-04-19 16:23:51 -0700683 build_php7.0_c
Paul Yangbdcbcab2018-07-26 13:52:22 -0700684 build_php7.1_c $1
David Supplee93533f72019-03-12 21:30:06 -0700685 build_php5.5_mixed
686 build_php5.6_mixed
687 build_php7.0_mixed
688 build_php7.1_mixed
Bo Yangc96dd662016-10-04 17:32:08 +0000689 build_php5.5_zts_c
Paul Yang190b5272017-04-19 16:23:51 -0700690 build_php5.6_zts_c
691 build_php7.0_zts_c
Paul Yang22319312017-05-10 15:59:59 -0700692 build_php7.1_zts_c
Paul Yang51c5ff82016-10-25 17:27:05 -0700693}
694
Paul Yang25abd7b2017-05-05 11:14:11 -0700695build_php_all() {
Paul Yangbdcbcab2018-07-26 13:52:22 -0700696 build_php_all_32 true
Paul Yang25abd7b2017-05-05 11:14:11 -0700697 build_php_compatibility
698}
699
Yilun Chong6adc3d72018-12-18 16:20:23 -0800700build_benchmark() {
Yilun Chong152c8302018-12-20 17:15:51 -0800701 use_php 7.2
Yilun Chong6adc3d72018-12-18 16:20:23 -0800702 cd kokoro/linux/benchmark && ./run.sh
703}
704
Josh Haberman738393b2016-02-18 20:10:23 -0800705# -------- main --------
706
Josh Haberman738393b2016-02-18 20:10:23 -0800707if [ "$#" -ne 1 ]; then
708 echo "
709Usage: $0 { cpp |
Feng Xiaoa4f68b12016-07-19 17:20:31 -0700710 cpp_distcheck |
Josh Haberman738393b2016-02-18 20:10:23 -0800711 csharp |
Josh Haberman738393b2016-02-18 20:10:23 -0800712 java_jdk7 |
713 java_oracle7 |
Feng Xiaobaa40232016-07-29 14:11:21 -0700714 java_compatibility |
Josh Haberman738393b2016-02-18 20:10:23 -0800715 objectivec_ios |
Thomas Van Lenten368a2f42016-05-24 11:27:33 -0400716 objectivec_ios_debug |
717 objectivec_ios_release |
Josh Haberman738393b2016-02-18 20:10:23 -0800718 objectivec_osx |
Thomas Van Lentenbd006712019-01-07 16:42:22 -0500719 objectivec_tvos |
720 objectivec_tvos_debug |
721 objectivec_tvos_release |
Sergio Campamáf0c14922016-06-14 11:26:01 -0700722 objectivec_cocoapods_integration |
Josh Haberman738393b2016-02-18 20:10:23 -0800723 python |
724 python_cpp |
Jie Luoea511492017-01-23 15:11:00 -0800725 python_compatibility |
Paul Yang39df66e2018-10-12 12:36:33 -0700726 ruby23 |
727 ruby24 |
728 ruby25 |
Paul Yangde9e1a02019-01-03 14:25:50 -0800729 ruby26 |
Feng Xiao20fbb352016-07-21 18:04:56 -0700730 jruby |
Bo Yangfd332d12016-09-30 00:07:47 +0000731 ruby_all |
732 php5.5 |
733 php5.5_c |
734 php5.6 |
735 php5.6_c |
736 php7.0 |
Bo Yangc8bd36e2016-09-30 19:07:33 +0000737 php7.0_c |
Paul Yang25abd7b2017-05-05 11:14:11 -0700738 php_compatibility |
Paul Yang22319312017-05-10 15:59:59 -0700739 php7.1 |
740 php7.1_c |
Yilun Chong6adc3d72018-12-18 16:20:23 -0800741 php_all |
Hao Nguyenf85c8232019-03-07 14:34:28 -0800742 dist_install |
Yilun Chong152c8302018-12-20 17:15:51 -0800743 benchmark)
Josh Haberman738393b2016-02-18 20:10:23 -0800744"
745 exit 1
746fi
747
748set -e # exit immediately on error
749set -x # display all commands
Feng Xiao9de4e642018-07-13 16:55:32 -0700750cd $(dirname $0)
Josh Haberman738393b2016-02-18 20:10:23 -0800751eval "build_$1"