blob: 771575978c1cd071a5e8f45c530ec9e5dd3bb4aa [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.
Jie Luod1eeb852019-07-31 17:49:26 -07009LAST_RELEASED=3.9.0
10
Josh Haberman181c7f22015-07-15 11:05:10 -070011internal_build_cpp() {
Josh Haberman738393b2016-02-18 20:10:23 -080012 if [ -f src/protoc ]; then
13 # Already built.
14 return
15 fi
16
Carlos O'Ryan3c5442a2018-03-26 16:54:32 -040017 # Initialize any submodules.
18 git submodule update --init --recursive
19
Chris Fallin20e94b22015-05-13 16:43:48 -070020 ./autogen.sh
Ben Wolsieffer56b40a82018-10-04 20:25:10 -040021 ./configure CXXFLAGS="-fPIC -std=c++11" # -fPIC is needed for python cpp test.
22 # See python/setup.py for more details
Joshua Habermanf5e8ee42019-03-06 12:04:17 -080023 make -j$(nproc)
Josh Haberman181c7f22015-07-15 11:05:10 -070024}
25
26build_cpp() {
27 internal_build_cpp
Joshua Habermanf5e8ee42019-03-06 12:04:17 -080028 make check -j$(nproc) || (cat src/test-suite.log; false)
Bo Yangfd332d12016-09-30 00:07:47 +000029 cd conformance && make test_cpp && cd ..
Josh Habermancb36bde2016-04-29 09:52:20 -070030
Thomas Van Lentenbc9d0772016-12-08 16:19:58 -050031 # The benchmark code depends on cmake, so test if it is installed before
32 # trying to do the build.
Thomas Van Lentenbc9d0772016-12-08 16:19:58 -050033 if [[ $(type cmake 2>/dev/null) ]]; then
34 # Verify benchmarking code can build successfully.
Yilun Chong34843ed2017-12-13 14:34:52 -080035 cd benchmarks && make cpp-benchmark && cd ..
Thomas Van Lentenbc9d0772016-12-08 16:19:58 -050036 else
37 echo ""
38 echo "WARNING: Skipping validation of the bench marking code, cmake isn't installed."
39 echo ""
40 fi
Chris Fallin20e94b22015-05-13 16:43:48 -070041}
42
Hao Nguyen4f8a6352019-01-23 10:02:51 -080043build_cpp_tcmalloc() {
44 internal_build_cpp
45 ./configure LIBS=-ltcmalloc && make clean && make \
46 PTHREAD_CFLAGS='-pthread -DGOOGLE_PROTOBUF_HEAP_CHECK_DRACONIAN' \
47 check
48 cd src
Adam Cozzetted135f072019-01-25 10:28:52 -080049 PPROF_PATH=/usr/bin/google-pprof HEAPCHECK=strict ./protobuf-test
Hao Nguyen4f8a6352019-01-23 10:02:51 -080050}
51
Chris Fallin20e94b22015-05-13 16:43:48 -070052build_cpp_distcheck() {
Adam Cozzette45aba802019-03-11 14:39:49 -070053 grep -q -- "-Og" src/Makefile.am &&
54 echo "The -Og flag is incompatible with Clang versions older than 4.0." &&
55 exit 1
56
Carlos O'Ryan3c5442a2018-03-26 16:54:32 -040057 # Initialize any submodules.
58 git submodule update --init --recursive
Chris Fallin20e94b22015-05-13 16:43:48 -070059 ./autogen.sh
60 ./configure
Feng Xiaoa4f68b12016-07-19 17:20:31 -070061 make dist
62
63 # List all files that should be included in the distribution package.
Jisi Liu55fdbe52017-08-23 11:35:48 -070064 git ls-files | grep "^\(java\|python\|objectivec\|csharp\|js\|ruby\|php\|cmake\|examples\|src/google/protobuf/.*\.proto\)" |\
Jie Luoea511492017-01-23 15:11:00 -080065 grep -v ".gitignore" | grep -v "java/compatibility_tests" |\
Jie Luo72886892017-02-09 16:49:52 -080066 grep -v "python/compatibility_tests" | grep -v "csharp/compatibility_tests" > dist.lst
Feng Xiaoa4f68b12016-07-19 17:20:31 -070067 # Unzip the dist tar file.
68 DIST=`ls *.tar.gz`
69 tar -xf $DIST
70 cd ${DIST//.tar.gz}
71 # Check if every file exists in the dist tar file.
72 FILES_MISSING=""
73 for FILE in $(<../dist.lst); do
Feng Xiaoacd5b052018-08-09 21:21:01 -070074 [ -f "$FILE" ] || {
Feng Xiaoa4f68b12016-07-19 17:20:31 -070075 echo "$FILE is not found!"
76 FILES_MISSING="$FILE $FILES_MISSING"
Feng Xiaoacd5b052018-08-09 21:21:01 -070077 }
Feng Xiaoa4f68b12016-07-19 17:20:31 -070078 done
79 cd ..
80 if [ ! -z "$FILES_MISSING" ]; then
81 echo "Missing files in EXTRA_DIST: $FILES_MISSING"
82 exit 1
83 fi
84
85 # Do the regular dist-check for C++.
Joshua Habermanf5e8ee42019-03-06 12:04:17 -080086 make distcheck -j$(nproc)
Chris Fallin20e94b22015-05-13 16:43:48 -070087}
88
Hao Nguyenf85c8232019-03-07 14:34:28 -080089build_dist_install() {
90 # Initialize any submodules.
91 git submodule update --init --recursive
92 ./autogen.sh
93 ./configure
94 make dist
95
96 # Unzip the dist tar file and install it.
97 DIST=`ls *.tar.gz`
98 tar -xf $DIST
99 pushd ${DIST//.tar.gz}
100 ./configure && make check -j4 && make install
101
102 export LD_LIBRARY_PATH=/usr/local/lib
103
104 # Try to install Java
105 pushd java
106 use_java jdk7
107 $MVN install
108 popd
109
110 # Try to install Python
111 virtualenv --no-site-packages venv
112 source venv/bin/activate
113 pushd python
114 python setup.py clean build sdist
115 pip install dist/protobuf-*.tar.gz
116 popd
117 deactivate
118 rm -rf python/venv
119}
120
Jan Tattermuschddb36ef2015-05-18 17:34:02 -0700121build_csharp() {
Jon Skeet9a9a66e2017-10-25 08:03:50 +0100122 # Required for conformance tests and to regenerate protos.
Jon Skeetb6defa72015-08-04 10:01:40 +0100123 internal_build_cpp
Josh Habermanffc81182016-02-22 15:39:29 -0800124 NUGET=/usr/local/bin/nuget.exe
Jon Skeetb6defa72015-08-04 10:01:40 +0100125
Jan Tattermusch67fee072019-03-12 04:48:10 -0400126 # Disable some unwanted dotnet options
127 export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true
128 export DOTNET_CLI_TELEMETRY_OPTOUT=true
129
130 # TODO(jtattermusch): is this still needed with "first time experience"
131 # disabled?
Jon Skeet10a8fb42016-07-14 22:01:47 +0100132 # Perform "dotnet new" once to get the setup preprocessing out of the
133 # way. That spews a lot of output (including backspaces) into logs
134 # otherwise, and can cause problems. It doesn't matter if this step
135 # is performed multiple times; it's cheap after the first time anyway.
Jon Skeetf26e8c22017-05-04 08:51:46 +0100136 # (It also doesn't matter if it's unnecessary, which it will be on some
137 # systems. It's necessary on Jenkins in order to avoid unprintable
138 # characters appearing in the JUnit output.)
Jon Skeet10a8fb42016-07-14 22:01:47 +0100139 mkdir dotnettmp
140 (cd dotnettmp; dotnet new > /dev/null)
141 rm -rf dotnettmp
142
Jon Skeet9a9a66e2017-10-25 08:03:50 +0100143 # Check that the protos haven't broken C# codegen.
144 # TODO(jonskeet): Fail if regenerating creates any changes.
145 csharp/generate_protos.sh
Brent Shaffer67379542018-05-23 16:43:30 -0700146
Jan Tattermuschddb36ef2015-05-18 17:34:02 -0700147 csharp/buildall.sh
Josh Habermane891c292015-12-30 16:03:49 -0800148 cd conformance && make test_csharp && cd ..
Jie Luo72886892017-02-09 16:49:52 -0800149
150 # Run csharp compatibility test between 3.0.0 and the current version.
151 csharp/compatibility_tests/v3.0.0/test.sh 3.0.0
Jie Luoe3993082019-07-25 14:31:00 -0700152
Jie Luoe3993082019-07-25 14:31:00 -0700153 # Run csharp compatibility test between last released and the current version.
154 csharp/compatibility_tests/v3.0.0/test.sh $LAST_RELEASED
Jan Tattermuschddb36ef2015-05-18 17:34:02 -0700155}
156
Tim Swast7e31c4d2015-11-20 15:32:53 -0800157build_golang() {
158 # Go build needs `protoc`.
159 internal_build_cpp
160 # Add protoc to the path so that the examples build finds it.
161 export PATH="`pwd`/src:$PATH"
162
Tim Swast7e31c4d2015-11-20 15:32:53 -0800163 export GOPATH="$HOME/gocode"
Feng Xiaoa0a17e22018-08-23 15:35:52 -0700164 mkdir -p "$GOPATH/src/github.com/protocolbuffers"
Feng Xiaoafe98de2018-08-22 11:55:30 -0700165 rm -f "$GOPATH/src/github.com/protocolbuffers/protobuf"
166 ln -s "`pwd`" "$GOPATH/src/github.com/protocolbuffers/protobuf"
Tim Swast7e31c4d2015-11-20 15:32:53 -0800167 export PATH="$GOPATH/bin:$PATH"
168 go get github.com/golang/protobuf/protoc-gen-go
169
Feng Xiao8136ccb2017-09-12 12:00:20 -0700170 cd examples && PROTO_PATH="-I../src -I." make gotest && cd ..
Tim Swast7e31c4d2015-11-20 15:32:53 -0800171}
172
Chris Fallin20e94b22015-05-13 16:43:48 -0700173use_java() {
Chris Fallin20e94b22015-05-13 16:43:48 -0700174 version=$1
175 case "$version" in
Tomo Suzuki70517252019-06-26 15:28:49 -0400176 jdk8)
177 export PATH=/usr/lib/jvm/java-8-openjdk-amd64/bin:$PATH
178 export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
179 ;;
Chris Fallin20e94b22015-05-13 16:43:48 -0700180 jdk7)
Chris Fallin20e94b22015-05-13 16:43:48 -0700181 export PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH
Feng Xiaoad49ed72016-07-21 11:37:46 -0700182 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
Chris Fallin20e94b22015-05-13 16:43:48 -0700183 ;;
184 oracle7)
Chris Fallin20e94b22015-05-13 16:43:48 -0700185 export PATH=/usr/lib/jvm/java-7-oracle/bin:$PATH
Feng Xiaoad49ed72016-07-21 11:37:46 -0700186 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
Chris Fallin20e94b22015-05-13 16:43:48 -0700187 ;;
188 esac
189
Feng Xiao9de4e642018-07-13 16:55:32 -0700190 MAVEN_LOCAL_REPOSITORY=/var/maven_local_repository
Yilun Chong2b7ee382018-09-23 17:07:02 -0700191 MVN="$MVN -e -X -Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$MAVEN_LOCAL_REPOSITORY"
Josh Haberman1ee0fda2016-03-03 16:02:55 -0800192
Chris Fallin20e94b22015-05-13 16:43:48 -0700193 which java
194 java -version
Feng Xiaoad49ed72016-07-21 11:37:46 -0700195 $MVN -version
Chris Fallin20e94b22015-05-13 16:43:48 -0700196}
197
Josh Habermand08c39c2016-02-20 12:03:39 -0800198# --batch-mode supresses download progress output that spams the logs.
Josh Habermanb28b3f62016-02-20 12:17:10 -0800199MVN="mvn --batch-mode"
Josh Habermand08c39c2016-02-20 12:03:39 -0800200
Chris Fallin20e94b22015-05-13 16:43:48 -0700201build_java() {
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800202 version=$1
203 dir=java_$version
Chris Fallin20e94b22015-05-13 16:43:48 -0700204 # Java build needs `protoc`.
Josh Haberman181c7f22015-07-15 11:05:10 -0700205 internal_build_cpp
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800206 cp -r java $dir
207 cd $dir && $MVN clean && $MVN test
Feng Xiao9e5fb552015-12-21 11:08:18 -0800208 cd ../..
209}
210
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800211# The conformance tests are hard-coded to work with the $ROOT/java directory.
212# So this can't run in parallel with two different sets of tests.
Feng Xiao9e5fb552015-12-21 11:08:18 -0800213build_java_with_conformance_tests() {
214 # Java build needs `protoc`.
215 internal_build_cpp
Tomo Suzukica25bad2019-10-22 13:42:35 -0400216 # This local installation avoids the problem caused by a new version not yet in Maven Central
217 cd java/bom && $MVN install
218 cd ../..
Josh Habermand08c39c2016-02-20 12:03:39 -0800219 cd java && $MVN test && $MVN install
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800220 cd util && $MVN package assembly:single
Feng Xiaoaf81dcf2015-12-21 03:25:59 -0800221 cd ../..
Chris Fallin20e94b22015-05-13 16:43:48 -0700222 cd conformance && make test_java && cd ..
223}
224
Chris Fallin20e94b22015-05-13 16:43:48 -0700225build_java_jdk7() {
226 use_java jdk7
Feng Xiao9e5fb552015-12-21 11:08:18 -0800227 build_java_with_conformance_tests
Chris Fallin20e94b22015-05-13 16:43:48 -0700228}
229build_java_oracle7() {
230 use_java oracle7
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800231 build_java oracle7
Chris Fallin20e94b22015-05-13 16:43:48 -0700232}
Feng Xiaobaa40232016-07-29 14:11:21 -0700233build_java_compatibility() {
234 use_java jdk7
235 internal_build_cpp
236 # Use the unit-tests extraced from 2.5.0 to test the compatibilty between
237 # 3.0.0-beta-4 and the current version.
238 cd java/compatibility_tests/v2.5.0
239 ./test.sh 3.0.0-beta-4
Jie Luod1eeb852019-07-31 17:49:26 -0700240
241 # Test the last released and current version.
242 ./test.sh $LAST_RELEASED
Feng Xiaobaa40232016-07-29 14:11:21 -0700243}
Tomo Suzuki70517252019-06-26 15:28:49 -0400244build_java_linkage_monitor() {
Tomo Suzukibedef1e2019-07-01 17:03:04 -0400245 # Linkage Monitor checks compatibility with other Google libraries
246 # https://github.com/GoogleCloudPlatform/cloud-opensource-java/tree/master/linkage-monitor
247
Tomo Suzuki70517252019-06-26 15:28:49 -0400248 use_java jdk8
Tomo Suzukibedef1e2019-07-01 17:03:04 -0400249 internal_build_cpp
250
251 # Linkage Monitor uses $HOME/.m2 local repository
252 MVN="mvn -e -B -Dhttps.protocols=TLSv1.2"
253 cd java
254 # Sets java artifact version with SNAPSHOT, as Linkage Monitor looks for SNAPSHOT versions.
255 # Example: "3.9.0" (without 'rc')
256 VERSION=`grep '<version>' pom.xml |head -1 |perl -nle 'print $1 if m/<version>(\d+\.\d+.\d+)/'`
257 cd bom
Tomo Suzukif460c172019-09-06 09:53:44 -0400258 # This local installation avoids the problem caused by a new version not yet in Maven Central
259 # https://github.com/protocolbuffers/protobuf/issues/6627
Tomo Suzukic1a04652019-09-06 09:56:55 -0400260 $MVN install
Tomo Suzukibedef1e2019-07-01 17:03:04 -0400261 $MVN versions:set -DnewVersion=${VERSION}-SNAPSHOT
262 cd ..
263 $MVN versions:set -DnewVersion=${VERSION}-SNAPSHOT
264 # Installs the snapshot version locally
265 $MVN install -Dmaven.test.skip=true
266
267 # Linkage Monitor uses the snapshot versions installed in $HOME/.m2 to verify compatibility
268 JAR=linkage-monitor-latest-all-deps.jar
269 curl -v -O "https://storage.googleapis.com/cloud-opensource-java-linkage-monitor/${JAR}"
270 # Fails if there's new linkage errors compared with baseline
271 java -jar $JAR com.google.cloud:libraries-bom
Tomo Suzuki70517252019-06-26 15:28:49 -0400272}
Chris Fallin20e94b22015-05-13 16:43:48 -0700273
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400274build_objectivec_ios() {
Thomas Van Lenten368a2f42016-05-24 11:27:33 -0400275 # Reused the build script that takes care of configuring and ensuring things
276 # are up to date. The OS X test runs the objc conformance test, so skip it
277 # here.
Thomas Van Lenten368a2f42016-05-24 11:27:33 -0400278 objectivec/DevTools/full_mac_build.sh \
Thomas Van Lentenbd006712019-01-07 16:42:22 -0500279 --core-only --skip-xcode-osx --skip-xcode-tvos --skip-objc-conformance "$@"
Thomas Van Lenten368a2f42016-05-24 11:27:33 -0400280}
281
282build_objectivec_ios_debug() {
283 build_objectivec_ios --skip-xcode-release
284}
285
286build_objectivec_ios_release() {
287 build_objectivec_ios --skip-xcode-debug
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400288}
289
290build_objectivec_osx() {
Thomas Van Lenten368a2f42016-05-24 11:27:33 -0400291 # Reused the build script that takes care of configuring and ensuring things
292 # are up to date.
293 objectivec/DevTools/full_mac_build.sh \
Thomas Van Lentenbd006712019-01-07 16:42:22 -0500294 --core-only --skip-xcode-ios --skip-xcode-tvos
295}
296
297build_objectivec_tvos() {
298 # Reused the build script that takes care of configuring and ensuring things
299 # are up to date. The OS X test runs the objc conformance test, so skip it
300 # here.
301 objectivec/DevTools/full_mac_build.sh \
302 --core-only --skip-xcode-ios --skip-xcode-osx --skip-objc-conformance "$@"
303}
304
305build_objectivec_tvos_debug() {
306 build_objectivec_tvos --skip-xcode-release
307}
308
309build_objectivec_tvos_release() {
310 build_objectivec_tvos --skip-xcode-debug
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400311}
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400312
Sergio Campamáf0c14922016-06-14 11:26:01 -0700313build_objectivec_cocoapods_integration() {
Sergio Campamáf0c14922016-06-14 11:26:01 -0700314 # Update pod to the latest version.
Yilun Chong89b914f2019-02-26 12:52:06 -0800315 gem install cocoapods --no_document
Sergio Campamáf0c14922016-06-14 11:26:01 -0700316 objectivec/Tests/CocoaPods/run_tests.sh
317}
318
Chris Fallin20e94b22015-05-13 16:43:48 -0700319build_python() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700320 internal_build_cpp
Chris Fallin20e94b22015-05-13 16:43:48 -0700321 cd python
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400322 if [ $(uname -s) == "Linux" ]; then
Jie Luo610e4332017-08-22 16:23:21 -0700323 envlist=py\{27,33,34,35,36\}-python
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400324 else
325 envlist=py27-python
326 fi
327 tox -e $envlist
Chris Fallin20e94b22015-05-13 16:43:48 -0700328 cd ..
329}
330
Paul Yang4dec4f92018-12-18 18:07:24 -0800331build_python_version() {
332 internal_build_cpp
333 cd python
334 envlist=$1
335 tox -e $envlist
336 cd ..
337}
338
339build_python27() {
340 build_python_version py27-python
341}
342
343build_python33() {
344 build_python_version py33-python
345}
346
347build_python34() {
348 build_python_version py34-python
349}
350
351build_python35() {
352 build_python_version py35-python
353}
354
355build_python36() {
356 build_python_version py36-python
357}
358
359build_python37() {
360 build_python_version py37-python
361}
362
Chris Fallin20e94b22015-05-13 16:43:48 -0700363build_python_cpp() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700364 internal_build_cpp
Bo Yangfd332d12016-09-30 00:07:47 +0000365 export LD_LIBRARY_PATH=../src/.libs # for Linux
366 export DYLD_LIBRARY_PATH=../src/.libs # for OS X
Chris Fallin20e94b22015-05-13 16:43:48 -0700367 cd python
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400368 if [ $(uname -s) == "Linux" ]; then
Jie Luo610e4332017-08-22 16:23:21 -0700369 envlist=py\{27,33,34,35,36\}-cpp
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400370 else
371 envlist=py27-cpp
372 fi
373 tox -e $envlist
Chris Fallin20e94b22015-05-13 16:43:48 -0700374 cd ..
375}
376
Paul Yang4dec4f92018-12-18 18:07:24 -0800377build_python_cpp_version() {
378 internal_build_cpp
379 export LD_LIBRARY_PATH=../src/.libs # for Linux
380 export DYLD_LIBRARY_PATH=../src/.libs # for OS X
381 cd python
382 envlist=$1
383 tox -e $envlist
384 cd ..
385}
386
387build_python27_cpp() {
388 build_python_cpp_version py27-cpp
389}
390
391build_python33_cpp() {
392 build_python_cpp_version py33-cpp
393}
394
395build_python34_cpp() {
396 build_python_cpp_version py34-cpp
397}
398
399build_python35_cpp() {
400 build_python_cpp_version py35-cpp
401}
402
403build_python36_cpp() {
404 build_python_cpp_version py36-cpp
405}
406
407build_python37_cpp() {
408 build_python_cpp_version py37-cpp
409}
410
Jie Luoea511492017-01-23 15:11:00 -0800411build_python_compatibility() {
412 internal_build_cpp
413 # Use the unit-tests extraced from 2.5.0 to test the compatibilty.
414 cd python/compatibility_tests/v2.5.0
415 # Test between 2.5.0 and the current version.
416 ./test.sh 2.5.0
417 # Test between 3.0.0-beta-1 and the current version.
418 ./test.sh 3.0.0-beta-1
Jie Luod1eeb852019-07-31 17:49:26 -0700419
420 # Test between last released and current version.
421 ./test.sh $LAST_RELEASED
Jie Luoea511492017-01-23 15:11:00 -0800422}
423
Paul Yang78ba0212018-07-02 15:11:36 -0700424build_ruby23() {
425 internal_build_cpp # For conformance tests.
Paul Yang333b3ce2018-10-18 11:16:55 -0700426 cd ruby && bash travis-test.sh ruby-2.3.8 && cd ..
Paul Yang78ba0212018-07-02 15:11:36 -0700427}
428build_ruby24() {
429 internal_build_cpp # For conformance tests.
430 cd ruby && bash travis-test.sh ruby-2.4 && cd ..
431}
432build_ruby25() {
433 internal_build_cpp # For conformance tests.
Paul Yang333b3ce2018-10-18 11:16:55 -0700434 cd ruby && bash travis-test.sh ruby-2.5.1 && cd ..
Paul Yang78ba0212018-07-02 15:11:36 -0700435}
Paul Yangde9e1a02019-01-03 14:25:50 -0800436build_ruby26() {
437 internal_build_cpp # For conformance tests.
438 cd ruby && bash travis-test.sh ruby-2.6.0 && cd ..
Chris Fallin20e94b22015-05-13 16:43:48 -0700439}
440
Josh Habermane9cf31e2015-12-21 15:18:17 -0800441build_javascript() {
442 internal_build_cpp
Josh Haberman0d2d8bc2015-12-28 06:43:42 -0800443 cd js && npm install && npm test && cd ..
Josh Habermanf873d322016-06-08 12:38:15 -0700444 cd conformance && make test_nodejs && cd ..
Josh Habermane9cf31e2015-12-21 15:18:17 -0800445}
446
Paul Yang46ae90d2016-12-08 11:16:49 -0800447generate_php_test_proto() {
448 internal_build_cpp
449 pushd php/tests
450 # Generate test file
451 rm -rf generated
452 mkdir generated
Bo Yangf46a01d2017-09-12 15:04:34 -0700453 ../../src/protoc --php_out=generated \
michaelbausor6a51c032018-10-07 16:56:41 -0700454 -I../../src -I. \
Brent Shaffer67379542018-05-23 16:43:30 -0700455 proto/empty/echo.proto \
Bo Yangf46a01d2017-09-12 15:04:34 -0700456 proto/test.proto \
457 proto/test_include.proto \
458 proto/test_no_namespace.proto \
459 proto/test_prefix.proto \
460 proto/test_php_namespace.proto \
461 proto/test_empty_php_namespace.proto \
462 proto/test_reserved_enum_lower.proto \
463 proto/test_reserved_enum_upper.proto \
464 proto/test_reserved_enum_value_lower.proto \
465 proto/test_reserved_enum_value_upper.proto \
466 proto/test_reserved_message_lower.proto \
467 proto/test_reserved_message_upper.proto \
468 proto/test_service.proto \
469 proto/test_service_namespace.proto \
michaelbausor6a51c032018-10-07 16:56:41 -0700470 proto/test_wrapper_type_setters.proto \
Paul Yangc15a3262017-08-02 07:42:27 -0700471 proto/test_descriptors.proto
Paul Yang46ae90d2016-12-08 11:16:49 -0800472 pushd ../../src
Paul Yangbcda9192017-11-03 12:30:09 -0700473 ./protoc --php_out=../php/tests/generated -I../php/tests -I. \
474 ../php/tests/proto/test_import_descriptor_proto.proto
Paul Yang46ae90d2016-12-08 11:16:49 -0800475 popd
476 popd
477}
478
Bo Yangc8bd36e2016-09-30 19:07:33 +0000479use_php() {
480 VERSION=$1
Paul Yangd7c44092018-12-18 10:57:03 -0800481 export PATH=/usr/local/php-${VERSION}/bin:$PATH
482 export CPLUS_INCLUDE_PATH=/usr/local/php-${VERSION}/include/php/main:/usr/local/php-${VERSION}/include/php/:$CPLUS_INCLUDE_PATH
483 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 -0800484 generate_php_test_proto
Bo Yangc8bd36e2016-09-30 19:07:33 +0000485}
486
Bo Yangc96dd662016-10-04 17:32:08 +0000487use_php_zts() {
488 VERSION=$1
Paul Yangd7c44092018-12-18 10:57:03 -0800489 export PATH=/usr/local/php-${VERSION}-zts/bin:$PATH
490 export CPLUS_INCLUDE_PATH=/usr/local/php-${VERSION}-zts/include/php/main:/usr/local/php-${VERSION}-zts/include/php/:$CPLUS_INCLUDE_PATH
491 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 -0800492 generate_php_test_proto
Bo Yangc96dd662016-10-04 17:32:08 +0000493}
494
Paul Yang51c5ff82016-10-25 17:27:05 -0700495use_php_bc() {
496 VERSION=$1
Paul Yangd7c44092018-12-18 10:57:03 -0800497 export PATH=/usr/local/php-${VERSION}-bc/bin:$PATH
498 export CPLUS_INCLUDE_PATH=/usr/local/php-${VERSION}-bc/include/php/main:/usr/local/php-${VERSION}-bc/include/php/:$CPLUS_INCLUDE_PATH
499 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 -0800500 generate_php_test_proto
Paul Yang51c5ff82016-10-25 17:27:05 -0700501}
502
Bo Yangfd332d12016-09-30 00:07:47 +0000503build_php5.5() {
Paul Yang190b5272017-04-19 16:23:51 -0700504 use_php 5.5
Paul Yangdd8d5f52017-03-08 14:31:34 -0800505
Paul Yange3e38b82016-12-08 14:39:20 -0800506 pushd php
Bo Yangfd332d12016-09-30 00:07:47 +0000507 rm -rf vendor
Paul Yangd7c44092018-12-18 10:57:03 -0800508 composer update
509 ./vendor/bin/phpunit
Paul Yange3e38b82016-12-08 14:39:20 -0800510 popd
Paul Yang39756642017-02-01 12:47:58 -0800511 pushd conformance
Paul Yangecca6ea2017-06-30 12:14:09 -0700512 make test_php
Paul Yang39756642017-02-01 12:47:58 -0800513 popd
Bo Yangfd332d12016-09-30 00:07:47 +0000514}
515
Bo Yang34cdaf42016-10-03 21:59:58 +0000516build_php5.5_c() {
Paul Yang190b5272017-04-19 16:23:51 -0700517 use_php 5.5
Paul Yangecca6ea2017-06-30 12:14:09 -0700518 pushd php/tests
Paul Yang51293f32018-01-25 11:31:05 -0800519 /bin/bash ./test.sh 5.5
Paul Yang39756642017-02-01 12:47:58 -0800520 popd
Paul Yangecca6ea2017-06-30 12:14:09 -0700521 # TODO(teboring): Add it back
522 # pushd conformance
523 # make test_php_c
524 # popd
Bo Yang34cdaf42016-10-03 21:59:58 +0000525}
Bo Yang34cdaf42016-10-03 21:59:58 +0000526
David Supplee93533f72019-03-12 21:30:06 -0700527build_php5.5_mixed() {
528 use_php 5.5
529 pushd php
530 rm -rf vendor
531 composer update
532 /bin/bash ./tests/compile_extension.sh ./ext/google/protobuf
533 php -dextension=./ext/google/protobuf/modules/protobuf.so ./vendor/bin/phpunit
534 popd
535}
536
Bo Yangc96dd662016-10-04 17:32:08 +0000537build_php5.5_zts_c() {
538 use_php_zts 5.5
Paul Yang51293f32018-01-25 11:31:05 -0800539 cd php/tests && /bin/bash ./test.sh 5.5-zts && cd ../..
Paul Yangecca6ea2017-06-30 12:14:09 -0700540 # TODO(teboring): Add it back
541 # pushd conformance
542 # make test_php_zts_c
543 # popd
Paul Yangdf839072016-11-10 11:20:50 -0800544}
545
Bo Yangfd332d12016-09-30 00:07:47 +0000546build_php5.6() {
Bo Yangc8bd36e2016-09-30 19:07:33 +0000547 use_php 5.6
Paul Yange3e38b82016-12-08 14:39:20 -0800548 pushd php
Bo Yangfd332d12016-09-30 00:07:47 +0000549 rm -rf vendor
Paul Yangd7c44092018-12-18 10:57:03 -0800550 composer update
551 ./vendor/bin/phpunit
Paul Yange3e38b82016-12-08 14:39:20 -0800552 popd
Paul Yang39756642017-02-01 12:47:58 -0800553 pushd conformance
Paul Yangecca6ea2017-06-30 12:14:09 -0700554 make test_php
Paul Yang39756642017-02-01 12:47:58 -0800555 popd
Bo Yangfd332d12016-09-30 00:07:47 +0000556}
557
Bo Yang34cdaf42016-10-03 21:59:58 +0000558build_php5.6_c() {
559 use_php 5.6
Paul Yang51293f32018-01-25 11:31:05 -0800560 cd php/tests && /bin/bash ./test.sh 5.6 && cd ../..
Paul Yangecca6ea2017-06-30 12:14:09 -0700561 # TODO(teboring): Add it back
562 # pushd conformance
Paul Yang190b5272017-04-19 16:23:51 -0700563 # make test_php_c
Paul Yangecca6ea2017-06-30 12:14:09 -0700564 # popd
Paul Yang190b5272017-04-19 16:23:51 -0700565}
566
David Supplee93533f72019-03-12 21:30:06 -0700567build_php5.6_mixed() {
568 use_php 5.6
569 pushd php
570 rm -rf vendor
571 composer update
572 /bin/bash ./tests/compile_extension.sh ./ext/google/protobuf
573 php -dextension=./ext/google/protobuf/modules/protobuf.so ./vendor/bin/phpunit
574 popd
575}
576
Paul Yang190b5272017-04-19 16:23:51 -0700577build_php5.6_zts_c() {
578 use_php_zts 5.6
Paul Yang51293f32018-01-25 11:31:05 -0800579 cd php/tests && /bin/bash ./test.sh 5.6-zts && cd ../..
Paul Yangecca6ea2017-06-30 12:14:09 -0700580 # TODO(teboring): Add it back
581 # pushd conformance
582 # make test_php_zts_c
583 # popd
Bo Yangfd332d12016-09-30 00:07:47 +0000584}
585
Bo Yang63448e62016-10-05 18:28:13 -0700586build_php5.6_mac() {
Paul Yang46ae90d2016-12-08 11:16:49 -0800587 generate_php_test_proto
Bo Yang63448e62016-10-05 18:28:13 -0700588 # Install PHP
589 curl -s https://php-osx.liip.ch/install.sh | bash -s 5.6
Paul Yang1f2dbc82016-11-08 11:38:34 -0800590 PHP_FOLDER=`find /usr/local -type d -name "php5-5.6*"` # The folder name may change upon time
591 export PATH="$PHP_FOLDER/bin:$PATH"
Bo Yang63448e62016-10-05 18:28:13 -0700592
593 # Install phpunit
Bo Yang8400e292019-01-28 20:58:58 +0000594 curl https://phar.phpunit.de/phpunit-5.6.8.phar -L -o phpunit.phar
Bo Yang63448e62016-10-05 18:28:13 -0700595 chmod +x phpunit.phar
596 sudo mv phpunit.phar /usr/local/bin/phpunit
597
598 # Install valgrind
599 echo "#! /bin/bash" > valgrind
600 chmod ug+x valgrind
601 sudo mv valgrind /usr/local/bin/valgrind
602
603 # Test
604 cd php/tests && /bin/bash ./test.sh && cd ../..
Paul Yangecca6ea2017-06-30 12:14:09 -0700605 # TODO(teboring): Add it back
606 # pushd conformance
Paul Yang190b5272017-04-19 16:23:51 -0700607 # make test_php_c
Paul Yangecca6ea2017-06-30 12:14:09 -0700608 # popd
Bo Yang63448e62016-10-05 18:28:13 -0700609}
610
Bo Yangfd332d12016-09-30 00:07:47 +0000611build_php7.0() {
Bo Yangc8bd36e2016-09-30 19:07:33 +0000612 use_php 7.0
Paul Yange3e38b82016-12-08 14:39:20 -0800613 pushd php
Bo Yangfd332d12016-09-30 00:07:47 +0000614 rm -rf vendor
Paul Yangd7c44092018-12-18 10:57:03 -0800615 composer update
616 ./vendor/bin/phpunit
Paul Yange3e38b82016-12-08 14:39:20 -0800617 popd
Paul Yang39756642017-02-01 12:47:58 -0800618 pushd conformance
Paul Yangecca6ea2017-06-30 12:14:09 -0700619 make test_php
Paul Yang39756642017-02-01 12:47:58 -0800620 popd
Bo Yangfd332d12016-09-30 00:07:47 +0000621}
622
Bo Yang34cdaf42016-10-03 21:59:58 +0000623build_php7.0_c() {
624 use_php 7.0
Paul Yang51293f32018-01-25 11:31:05 -0800625 cd php/tests && /bin/bash ./test.sh 7.0 && cd ../..
Paul Yangecca6ea2017-06-30 12:14:09 -0700626 # TODO(teboring): Add it back
627 # pushd conformance
Paul Yang190b5272017-04-19 16:23:51 -0700628 # make test_php_c
Paul Yangecca6ea2017-06-30 12:14:09 -0700629 # popd
Paul Yang190b5272017-04-19 16:23:51 -0700630}
631
David Supplee93533f72019-03-12 21:30:06 -0700632build_php7.0_mixed() {
633 use_php 7.0
634 pushd php
635 rm -rf vendor
636 composer update
637 /bin/bash ./tests/compile_extension.sh ./ext/google/protobuf
638 php -dextension=./ext/google/protobuf/modules/protobuf.so ./vendor/bin/phpunit
639 popd
640}
641
Paul Yang190b5272017-04-19 16:23:51 -0700642build_php7.0_zts_c() {
643 use_php_zts 7.0
Paul Yang51293f32018-01-25 11:31:05 -0800644 cd php/tests && /bin/bash ./test.sh 7.0-zts && cd ../..
Paul Yangecca6ea2017-06-30 12:14:09 -0700645 # TODO(teboring): Add it back.
646 # pushd conformance
647 # make test_php_zts_c
648 # popd
Paul Yang190b5272017-04-19 16:23:51 -0700649}
650
651build_php7.0_mac() {
652 generate_php_test_proto
653 # Install PHP
654 curl -s https://php-osx.liip.ch/install.sh | bash -s 7.0
655 PHP_FOLDER=`find /usr/local -type d -name "php7-7.0*"` # The folder name may change upon time
656 export PATH="$PHP_FOLDER/bin:$PATH"
657
658 # Install phpunit
659 curl https://phar.phpunit.de/phpunit-5.6.0.phar -L -o phpunit.phar
660 chmod +x phpunit.phar
661 sudo mv phpunit.phar /usr/local/bin/phpunit
662
663 # Install valgrind
664 echo "#! /bin/bash" > valgrind
665 chmod ug+x valgrind
666 sudo mv valgrind /usr/local/bin/valgrind
667
668 # Test
669 cd php/tests && /bin/bash ./test.sh && cd ../..
Paul Yangecca6ea2017-06-30 12:14:09 -0700670 # TODO(teboring): Add it back
671 # pushd conformance
Paul Yang190b5272017-04-19 16:23:51 -0700672 # make test_php_c
Paul Yangecca6ea2017-06-30 12:14:09 -0700673 # popd
Bo Yang34cdaf42016-10-03 21:59:58 +0000674}
675
Paul Yang25abd7b2017-05-05 11:14:11 -0700676build_php_compatibility() {
677 internal_build_cpp
Jie Luod1eeb852019-07-31 17:49:26 -0700678 php/tests/compatibility_test.sh $LAST_RELEASED
Paul Yang25abd7b2017-05-05 11:14:11 -0700679}
680
Paul Yang22319312017-05-10 15:59:59 -0700681build_php7.1() {
682 use_php 7.1
683 pushd php
684 rm -rf vendor
Paul Yangd7c44092018-12-18 10:57:03 -0800685 composer update
686 ./vendor/bin/phpunit
Paul Yang22319312017-05-10 15:59:59 -0700687 popd
688 pushd conformance
Paul Yangbdcbcab2018-07-26 13:52:22 -0700689 make test_php
Paul Yang22319312017-05-10 15:59:59 -0700690 popd
691}
692
693build_php7.1_c() {
Paul Yangbdcbcab2018-07-26 13:52:22 -0700694 ENABLE_CONFORMANCE_TEST=$1
Paul Yang22319312017-05-10 15:59:59 -0700695 use_php 7.1
Paul Yang51293f32018-01-25 11:31:05 -0800696 cd php/tests && /bin/bash ./test.sh 7.1 && cd ../..
Paul Yangbdcbcab2018-07-26 13:52:22 -0700697 if [ "$ENABLE_CONFORMANCE_TEST" = "true" ]
698 then
699 pushd conformance
700 make test_php_c
701 popd
702 fi
Paul Yang22319312017-05-10 15:59:59 -0700703}
704
David Supplee93533f72019-03-12 21:30:06 -0700705build_php7.1_mixed() {
706 use_php 7.1
707 pushd php
708 rm -rf vendor
709 composer update
710 /bin/bash ./tests/compile_extension.sh ./ext/google/protobuf
711 php -dextension=./ext/google/protobuf/modules/protobuf.so ./vendor/bin/phpunit
712 popd
713}
714
Paul Yang22319312017-05-10 15:59:59 -0700715build_php7.1_zts_c() {
716 use_php_zts 7.1
Paul Yang51293f32018-01-25 11:31:05 -0800717 cd php/tests && /bin/bash ./test.sh 7.1-zts && cd ../..
Paul Yang22319312017-05-10 15:59:59 -0700718 pushd conformance
719 # make test_php_c
720 popd
721}
722
Paul Yang25abd7b2017-05-05 11:14:11 -0700723build_php_all_32() {
Bo Yangc8bd36e2016-09-30 19:07:33 +0000724 build_php5.5
725 build_php5.6
726 build_php7.0
Paul Yang22319312017-05-10 15:59:59 -0700727 build_php7.1
Bo Yangc8bd36e2016-09-30 19:07:33 +0000728 build_php5.5_c
729 build_php5.6_c
Paul Yang190b5272017-04-19 16:23:51 -0700730 build_php7.0_c
Paul Yangbdcbcab2018-07-26 13:52:22 -0700731 build_php7.1_c $1
David Supplee93533f72019-03-12 21:30:06 -0700732 build_php5.5_mixed
733 build_php5.6_mixed
734 build_php7.0_mixed
735 build_php7.1_mixed
Bo Yangc96dd662016-10-04 17:32:08 +0000736 build_php5.5_zts_c
Paul Yang190b5272017-04-19 16:23:51 -0700737 build_php5.6_zts_c
738 build_php7.0_zts_c
Paul Yang22319312017-05-10 15:59:59 -0700739 build_php7.1_zts_c
Paul Yang51c5ff82016-10-25 17:27:05 -0700740}
741
Paul Yang25abd7b2017-05-05 11:14:11 -0700742build_php_all() {
Paul Yangbdcbcab2018-07-26 13:52:22 -0700743 build_php_all_32 true
Paul Yang25abd7b2017-05-05 11:14:11 -0700744 build_php_compatibility
745}
746
Yilun Chong6adc3d72018-12-18 16:20:23 -0800747build_benchmark() {
Yilun Chong152c8302018-12-20 17:15:51 -0800748 use_php 7.2
Yilun Chong6adc3d72018-12-18 16:20:23 -0800749 cd kokoro/linux/benchmark && ./run.sh
750}
751
Josh Haberman738393b2016-02-18 20:10:23 -0800752# -------- main --------
753
Josh Haberman738393b2016-02-18 20:10:23 -0800754if [ "$#" -ne 1 ]; then
755 echo "
756Usage: $0 { cpp |
Feng Xiaoa4f68b12016-07-19 17:20:31 -0700757 cpp_distcheck |
Josh Haberman738393b2016-02-18 20:10:23 -0800758 csharp |
Josh Haberman738393b2016-02-18 20:10:23 -0800759 java_jdk7 |
760 java_oracle7 |
Feng Xiaobaa40232016-07-29 14:11:21 -0700761 java_compatibility |
Tomo Suzuki70517252019-06-26 15:28:49 -0400762 java_linkage_monitor |
Josh Haberman738393b2016-02-18 20:10:23 -0800763 objectivec_ios |
Thomas Van Lenten368a2f42016-05-24 11:27:33 -0400764 objectivec_ios_debug |
765 objectivec_ios_release |
Josh Haberman738393b2016-02-18 20:10:23 -0800766 objectivec_osx |
Thomas Van Lentenbd006712019-01-07 16:42:22 -0500767 objectivec_tvos |
768 objectivec_tvos_debug |
769 objectivec_tvos_release |
Sergio Campamáf0c14922016-06-14 11:26:01 -0700770 objectivec_cocoapods_integration |
Josh Haberman738393b2016-02-18 20:10:23 -0800771 python |
772 python_cpp |
Jie Luoea511492017-01-23 15:11:00 -0800773 python_compatibility |
Paul Yang39df66e2018-10-12 12:36:33 -0700774 ruby23 |
775 ruby24 |
776 ruby25 |
Paul Yangde9e1a02019-01-03 14:25:50 -0800777 ruby26 |
Feng Xiao20fbb352016-07-21 18:04:56 -0700778 jruby |
Bo Yangfd332d12016-09-30 00:07:47 +0000779 ruby_all |
780 php5.5 |
781 php5.5_c |
782 php5.6 |
783 php5.6_c |
784 php7.0 |
Bo Yangc8bd36e2016-09-30 19:07:33 +0000785 php7.0_c |
Paul Yang25abd7b2017-05-05 11:14:11 -0700786 php_compatibility |
Paul Yang22319312017-05-10 15:59:59 -0700787 php7.1 |
788 php7.1_c |
Yilun Chong6adc3d72018-12-18 16:20:23 -0800789 php_all |
Hao Nguyenf85c8232019-03-07 14:34:28 -0800790 dist_install |
Yilun Chong152c8302018-12-20 17:15:51 -0800791 benchmark)
Josh Haberman738393b2016-02-18 20:10:23 -0800792"
793 exit 1
794fi
795
796set -e # exit immediately on error
797set -x # display all commands
Feng Xiao9de4e642018-07-13 16:55:32 -0700798cd $(dirname $0)
Josh Haberman738393b2016-02-18 20:10:23 -0800799eval "build_$1"