blob: 923201a8218ab28288b031fade2e7b8b29792ed7 [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\)" |\
Derek Perezd1b2eff2021-04-20 09:36:06 -070065 grep -v ".gitignore" | grep -v "java/lite/proguard.pgcfg" |\
David L. Jonesf1308272020-03-06 16:37:15 -080066 grep -v "python/compatibility_tests" | grep -v "python/docs" | grep -v "python/.repo-metadata.json" |\
David L. Jonesff06e232020-08-31 10:40:57 -070067 grep -v "python/protobuf_distutils" | grep -v "csharp/compatibility_tests" > dist.lst
Feng Xiaoa4f68b12016-07-19 17:20:31 -070068 # Unzip the dist tar file.
69 DIST=`ls *.tar.gz`
70 tar -xf $DIST
71 cd ${DIST//.tar.gz}
72 # Check if every file exists in the dist tar file.
73 FILES_MISSING=""
74 for FILE in $(<../dist.lst); do
Feng Xiaoacd5b052018-08-09 21:21:01 -070075 [ -f "$FILE" ] || {
Feng Xiaoa4f68b12016-07-19 17:20:31 -070076 echo "$FILE is not found!"
77 FILES_MISSING="$FILE $FILES_MISSING"
Feng Xiaoacd5b052018-08-09 21:21:01 -070078 }
Feng Xiaoa4f68b12016-07-19 17:20:31 -070079 done
80 cd ..
81 if [ ! -z "$FILES_MISSING" ]; then
82 echo "Missing files in EXTRA_DIST: $FILES_MISSING"
83 exit 1
84 fi
85
86 # Do the regular dist-check for C++.
Joshua Habermanf5e8ee42019-03-06 12:04:17 -080087 make distcheck -j$(nproc)
Chris Fallin20e94b22015-05-13 16:43:48 -070088}
89
Hao Nguyenf85c8232019-03-07 14:34:28 -080090build_dist_install() {
91 # Initialize any submodules.
92 git submodule update --init --recursive
93 ./autogen.sh
94 ./configure
95 make dist
96
97 # Unzip the dist tar file and install it.
98 DIST=`ls *.tar.gz`
99 tar -xf $DIST
100 pushd ${DIST//.tar.gz}
101 ./configure && make check -j4 && make install
102
103 export LD_LIBRARY_PATH=/usr/local/lib
104
105 # Try to install Java
106 pushd java
Adam Cozzetteca295502021-05-12 14:42:15 -0700107 use_java jdk8
Hao Nguyenf85c8232019-03-07 14:34:28 -0800108 $MVN install
109 popd
110
111 # Try to install Python
112 virtualenv --no-site-packages venv
113 source venv/bin/activate
114 pushd python
115 python setup.py clean build sdist
116 pip install dist/protobuf-*.tar.gz
117 popd
118 deactivate
119 rm -rf python/venv
120}
121
Jan Tattermuschddb36ef2015-05-18 17:34:02 -0700122build_csharp() {
Jon Skeet9a9a66e2017-10-25 08:03:50 +0100123 # Required for conformance tests and to regenerate protos.
Jon Skeetb6defa72015-08-04 10:01:40 +0100124 internal_build_cpp
Josh Habermanffc81182016-02-22 15:39:29 -0800125 NUGET=/usr/local/bin/nuget.exe
Jon Skeetb6defa72015-08-04 10:01:40 +0100126
Jan Tattermusch67fee072019-03-12 04:48:10 -0400127 # Disable some unwanted dotnet options
128 export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true
129 export DOTNET_CLI_TELEMETRY_OPTOUT=true
130
131 # TODO(jtattermusch): is this still needed with "first time experience"
132 # disabled?
Jon Skeet10a8fb42016-07-14 22:01:47 +0100133 # Perform "dotnet new" once to get the setup preprocessing out of the
134 # way. That spews a lot of output (including backspaces) into logs
135 # otherwise, and can cause problems. It doesn't matter if this step
136 # is performed multiple times; it's cheap after the first time anyway.
Jon Skeetf26e8c22017-05-04 08:51:46 +0100137 # (It also doesn't matter if it's unnecessary, which it will be on some
138 # systems. It's necessary on Jenkins in order to avoid unprintable
139 # characters appearing in the JUnit output.)
Jon Skeet10a8fb42016-07-14 22:01:47 +0100140 mkdir dotnettmp
141 (cd dotnettmp; dotnet new > /dev/null)
142 rm -rf dotnettmp
143
Jon Skeet9a9a66e2017-10-25 08:03:50 +0100144 # Check that the protos haven't broken C# codegen.
145 # TODO(jonskeet): Fail if regenerating creates any changes.
146 csharp/generate_protos.sh
Brent Shaffer67379542018-05-23 16:43:30 -0700147
Jan Tattermuschddb36ef2015-05-18 17:34:02 -0700148 csharp/buildall.sh
Josh Habermane891c292015-12-30 16:03:49 -0800149 cd conformance && make test_csharp && cd ..
Jie Luo72886892017-02-09 16:49:52 -0800150
151 # Run csharp compatibility test between 3.0.0 and the current version.
152 csharp/compatibility_tests/v3.0.0/test.sh 3.0.0
Jie Luoe3993082019-07-25 14:31:00 -0700153
Jie Luoe3993082019-07-25 14:31:00 -0700154 # Run csharp compatibility test between last released and the current version.
155 csharp/compatibility_tests/v3.0.0/test.sh $LAST_RELEASED
Jan Tattermuschddb36ef2015-05-18 17:34:02 -0700156}
157
Tim Swast7e31c4d2015-11-20 15:32:53 -0800158build_golang() {
159 # Go build needs `protoc`.
160 internal_build_cpp
161 # Add protoc to the path so that the examples build finds it.
162 export PATH="`pwd`/src:$PATH"
163
Tim Swast7e31c4d2015-11-20 15:32:53 -0800164 export GOPATH="$HOME/gocode"
Feng Xiaoa0a17e22018-08-23 15:35:52 -0700165 mkdir -p "$GOPATH/src/github.com/protocolbuffers"
Joe Tsai654edd82020-05-12 13:02:09 -0700166 mkdir -p "$GOPATH/src/github.com/golang"
Feng Xiaoafe98de2018-08-22 11:55:30 -0700167 rm -f "$GOPATH/src/github.com/protocolbuffers/protobuf"
Joe Tsai654edd82020-05-12 13:02:09 -0700168 rm -f "$GOPATH/src/github.com/golang/protobuf"
Feng Xiaoafe98de2018-08-22 11:55:30 -0700169 ln -s "`pwd`" "$GOPATH/src/github.com/protocolbuffers/protobuf"
Tim Swast7e31c4d2015-11-20 15:32:53 -0800170 export PATH="$GOPATH/bin:$PATH"
Joe Tsai654edd82020-05-12 13:02:09 -0700171 (cd $GOPATH/src/github.com/golang && git clone https://github.com/golang/protobuf.git && cd protobuf && git checkout v1.3.5)
172 go install github.com/golang/protobuf/protoc-gen-go
Tim Swast7e31c4d2015-11-20 15:32:53 -0800173
Feng Xiao8136ccb2017-09-12 12:00:20 -0700174 cd examples && PROTO_PATH="-I../src -I." make gotest && cd ..
Tim Swast7e31c4d2015-11-20 15:32:53 -0800175}
176
Chris Fallin20e94b22015-05-13 16:43:48 -0700177use_java() {
Chris Fallin20e94b22015-05-13 16:43:48 -0700178 version=$1
179 case "$version" in
Tomo Suzuki70517252019-06-26 15:28:49 -0400180 jdk8)
181 export PATH=/usr/lib/jvm/java-8-openjdk-amd64/bin:$PATH
182 export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
183 ;;
Chris Fallin20e94b22015-05-13 16:43:48 -0700184 jdk7)
Chris Fallin20e94b22015-05-13 16:43:48 -0700185 export PATH=/usr/lib/jvm/java-7-openjdk-amd64/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 oracle7)
Chris Fallin20e94b22015-05-13 16:43:48 -0700189 export PATH=/usr/lib/jvm/java-7-oracle/bin:$PATH
Feng Xiaoad49ed72016-07-21 11:37:46 -0700190 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
Chris Fallin20e94b22015-05-13 16:43:48 -0700191 ;;
192 esac
193
Feng Xiao9de4e642018-07-13 16:55:32 -0700194 MAVEN_LOCAL_REPOSITORY=/var/maven_local_repository
Yilun Chong2b7ee382018-09-23 17:07:02 -0700195 MVN="$MVN -e -X -Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$MAVEN_LOCAL_REPOSITORY"
Josh Haberman1ee0fda2016-03-03 16:02:55 -0800196
Chris Fallin20e94b22015-05-13 16:43:48 -0700197 which java
198 java -version
Feng Xiaoad49ed72016-07-21 11:37:46 -0700199 $MVN -version
Chris Fallin20e94b22015-05-13 16:43:48 -0700200}
201
Brian Wignalla104dff2020-01-08 13:18:20 -0500202# --batch-mode suppresses download progress output that spams the logs.
Josh Habermanb28b3f62016-02-20 12:17:10 -0800203MVN="mvn --batch-mode"
Josh Habermand08c39c2016-02-20 12:03:39 -0800204
Chris Fallin20e94b22015-05-13 16:43:48 -0700205build_java() {
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800206 version=$1
207 dir=java_$version
Chris Fallin20e94b22015-05-13 16:43:48 -0700208 # Java build needs `protoc`.
Josh Haberman181c7f22015-07-15 11:05:10 -0700209 internal_build_cpp
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800210 cp -r java $dir
Adam Cozzette5a9367a2021-05-11 12:07:45 -0700211 cd $dir && $MVN clean
212 # Skip the Kotlin tests on Oracle 7
213 if [ "$version" == "oracle7" ]; then
214 $MVN test -pl bom,lite,core,util
215 else
216 $MVN test
217 fi
Feng Xiao9e5fb552015-12-21 11:08:18 -0800218 cd ../..
219}
220
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800221# The conformance tests are hard-coded to work with the $ROOT/java directory.
222# So this can't run in parallel with two different sets of tests.
Feng Xiao9e5fb552015-12-21 11:08:18 -0800223build_java_with_conformance_tests() {
224 # Java build needs `protoc`.
225 internal_build_cpp
Tomo Suzukica25bad2019-10-22 13:42:35 -0400226 # This local installation avoids the problem caused by a new version not yet in Maven Central
227 cd java/bom && $MVN install
228 cd ../..
Josh Habermand08c39c2016-02-20 12:03:39 -0800229 cd java && $MVN test && $MVN install
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800230 cd util && $MVN package assembly:single
Feng Xiaoaf81dcf2015-12-21 03:25:59 -0800231 cd ../..
Chris Fallin20e94b22015-05-13 16:43:48 -0700232 cd conformance && make test_java && cd ..
233}
234
Chris Fallin20e94b22015-05-13 16:43:48 -0700235build_java_jdk7() {
236 use_java jdk7
Feng Xiao9e5fb552015-12-21 11:08:18 -0800237 build_java_with_conformance_tests
Chris Fallin20e94b22015-05-13 16:43:48 -0700238}
239build_java_oracle7() {
240 use_java oracle7
Josh Haberman2f3f1de2016-03-01 15:37:17 -0800241 build_java oracle7
Chris Fallin20e94b22015-05-13 16:43:48 -0700242}
Tomo Suzuki70517252019-06-26 15:28:49 -0400243build_java_linkage_monitor() {
Tomo Suzukibedef1e2019-07-01 17:03:04 -0400244 # Linkage Monitor checks compatibility with other Google libraries
245 # https://github.com/GoogleCloudPlatform/cloud-opensource-java/tree/master/linkage-monitor
246
Tomo Suzuki70517252019-06-26 15:28:49 -0400247 use_java jdk8
Tomo Suzukibedef1e2019-07-01 17:03:04 -0400248 internal_build_cpp
249
250 # Linkage Monitor uses $HOME/.m2 local repository
251 MVN="mvn -e -B -Dhttps.protocols=TLSv1.2"
252 cd java
Tomo Suzukibedef1e2019-07-01 17:03:04 -0400253 # Installs the snapshot version locally
254 $MVN install -Dmaven.test.skip=true
255
256 # Linkage Monitor uses the snapshot versions installed in $HOME/.m2 to verify compatibility
257 JAR=linkage-monitor-latest-all-deps.jar
258 curl -v -O "https://storage.googleapis.com/cloud-opensource-java-linkage-monitor/${JAR}"
259 # Fails if there's new linkage errors compared with baseline
260 java -jar $JAR com.google.cloud:libraries-bom
Tomo Suzuki70517252019-06-26 15:28:49 -0400261}
Chris Fallin20e94b22015-05-13 16:43:48 -0700262
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400263build_objectivec_ios() {
Thomas Van Lenten368a2f42016-05-24 11:27:33 -0400264 # Reused the build script that takes care of configuring and ensuring things
265 # are up to date. The OS X test runs the objc conformance test, so skip it
266 # here.
Thomas Van Lenten368a2f42016-05-24 11:27:33 -0400267 objectivec/DevTools/full_mac_build.sh \
Thomas Van Lentenbd006712019-01-07 16:42:22 -0500268 --core-only --skip-xcode-osx --skip-xcode-tvos --skip-objc-conformance "$@"
Thomas Van Lenten368a2f42016-05-24 11:27:33 -0400269}
270
271build_objectivec_ios_debug() {
272 build_objectivec_ios --skip-xcode-release
273}
274
275build_objectivec_ios_release() {
276 build_objectivec_ios --skip-xcode-debug
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400277}
278
279build_objectivec_osx() {
Thomas Van Lenten368a2f42016-05-24 11:27:33 -0400280 # Reused the build script that takes care of configuring and ensuring things
281 # are up to date.
282 objectivec/DevTools/full_mac_build.sh \
Thomas Van Lentenbd006712019-01-07 16:42:22 -0500283 --core-only --skip-xcode-ios --skip-xcode-tvos
284}
285
286build_objectivec_tvos() {
287 # Reused the build script that takes care of configuring and ensuring things
288 # are up to date. The OS X test runs the objc conformance test, so skip it
289 # here.
290 objectivec/DevTools/full_mac_build.sh \
291 --core-only --skip-xcode-ios --skip-xcode-osx --skip-objc-conformance "$@"
292}
293
294build_objectivec_tvos_debug() {
295 build_objectivec_tvos --skip-xcode-release
296}
297
298build_objectivec_tvos_release() {
299 build_objectivec_tvos --skip-xcode-debug
Thomas Van Lenten9642b822015-06-10 17:21:23 -0400300}
Dan O'Reilly5de2a812015-08-20 18:19:56 -0400301
Sergio Campamáf0c14922016-06-14 11:26:01 -0700302build_objectivec_cocoapods_integration() {
Sergio Campamáf0c14922016-06-14 11:26:01 -0700303 objectivec/Tests/CocoaPods/run_tests.sh
304}
305
Chris Fallin20e94b22015-05-13 16:43:48 -0700306build_python() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700307 internal_build_cpp
Chris Fallin20e94b22015-05-13 16:43:48 -0700308 cd python
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400309 if [ $(uname -s) == "Linux" ]; then
Jie Luo610e4332017-08-22 16:23:21 -0700310 envlist=py\{27,33,34,35,36\}-python
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400311 else
David L. Jones0f9ae072020-07-13 20:54:22 -0700312 envlist=py\{27,36\}-python
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400313 fi
David L. Jonesb774da02020-09-30 15:56:17 -0700314 python -m tox -e $envlist
Chris Fallin20e94b22015-05-13 16:43:48 -0700315 cd ..
316}
317
Paul Yang4dec4f92018-12-18 18:07:24 -0800318build_python_version() {
319 internal_build_cpp
320 cd python
321 envlist=$1
David L. Jonesb774da02020-09-30 15:56:17 -0700322 python -m tox -e $envlist
Paul Yang4dec4f92018-12-18 18:07:24 -0800323 cd ..
324}
325
326build_python27() {
327 build_python_version py27-python
328}
329
330build_python33() {
331 build_python_version py33-python
332}
333
334build_python34() {
335 build_python_version py34-python
336}
337
338build_python35() {
339 build_python_version py35-python
340}
341
342build_python36() {
343 build_python_version py36-python
344}
345
346build_python37() {
347 build_python_version py37-python
348}
349
Jie Luo7faab5e2019-12-13 15:49:18 -0800350build_python38() {
351 build_python_version py38-python
352}
353
Bu Sun Kim51c80ce2020-12-04 21:16:47 +0000354build_python39() {
Bu Sun Kim523b1092020-12-15 17:08:56 -0700355 build_python_version py39-python
Bu Sun Kim51c80ce2020-12-04 21:16:47 +0000356}
357
Chris Fallin20e94b22015-05-13 16:43:48 -0700358build_python_cpp() {
Josh Haberman181c7f22015-07-15 11:05:10 -0700359 internal_build_cpp
Bo Yangfd332d12016-09-30 00:07:47 +0000360 export LD_LIBRARY_PATH=../src/.libs # for Linux
361 export DYLD_LIBRARY_PATH=../src/.libs # for OS X
Chris Fallin20e94b22015-05-13 16:43:48 -0700362 cd python
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400363 if [ $(uname -s) == "Linux" ]; then
Jie Luo610e4332017-08-22 16:23:21 -0700364 envlist=py\{27,33,34,35,36\}-cpp
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400365 else
David L. Jones0f9ae072020-07-13 20:54:22 -0700366 envlist=py\{27,36\}-cpp
Dan O'Reilly76f8a3f2015-08-21 18:51:47 -0400367 fi
368 tox -e $envlist
Chris Fallin20e94b22015-05-13 16:43:48 -0700369 cd ..
370}
371
Paul Yang4dec4f92018-12-18 18:07:24 -0800372build_python_cpp_version() {
373 internal_build_cpp
374 export LD_LIBRARY_PATH=../src/.libs # for Linux
375 export DYLD_LIBRARY_PATH=../src/.libs # for OS X
376 cd python
377 envlist=$1
378 tox -e $envlist
379 cd ..
380}
381
382build_python27_cpp() {
383 build_python_cpp_version py27-cpp
384}
385
386build_python33_cpp() {
387 build_python_cpp_version py33-cpp
388}
389
390build_python34_cpp() {
391 build_python_cpp_version py34-cpp
392}
393
394build_python35_cpp() {
395 build_python_cpp_version py35-cpp
396}
397
398build_python36_cpp() {
399 build_python_cpp_version py36-cpp
400}
401
402build_python37_cpp() {
403 build_python_cpp_version py37-cpp
404}
405
Jie Luo7faab5e2019-12-13 15:49:18 -0800406build_python38_cpp() {
407 build_python_cpp_version py38-cpp
408}
409
Bu Sun Kim51c80ce2020-12-04 21:16:47 +0000410build_python39_cpp() {
Bu Sun Kim523b1092020-12-15 17:08:56 -0700411 build_python_cpp_version py39-cpp
Bu Sun Kim51c80ce2020-12-04 21:16:47 +0000412}
413
Paul Yang78ba0212018-07-02 15:11:36 -0700414build_ruby23() {
415 internal_build_cpp # For conformance tests.
Paul Yang333b3ce2018-10-18 11:16:55 -0700416 cd ruby && bash travis-test.sh ruby-2.3.8 && cd ..
Paul Yang78ba0212018-07-02 15:11:36 -0700417}
418build_ruby24() {
419 internal_build_cpp # For conformance tests.
420 cd ruby && bash travis-test.sh ruby-2.4 && cd ..
421}
422build_ruby25() {
423 internal_build_cpp # For conformance tests.
Paul Yang333b3ce2018-10-18 11:16:55 -0700424 cd ruby && bash travis-test.sh ruby-2.5.1 && cd ..
Paul Yang78ba0212018-07-02 15:11:36 -0700425}
Paul Yangde9e1a02019-01-03 14:25:50 -0800426build_ruby26() {
427 internal_build_cpp # For conformance tests.
428 cd ruby && bash travis-test.sh ruby-2.6.0 && cd ..
Chris Fallin20e94b22015-05-13 16:43:48 -0700429}
Eric Walker2c8364b2020-04-17 13:20:38 -0400430build_ruby27() {
431 internal_build_cpp # For conformance tests.
432 cd ruby && bash travis-test.sh ruby-2.7.0 && cd ..
433}
Joshua Haberman9abf6e22021-01-13 12:16:25 -0800434build_ruby30() {
435 internal_build_cpp # For conformance tests.
436 cd ruby && bash travis-test.sh ruby-3.0.0 && cd ..
437}
Chris Fallin20e94b22015-05-13 16:43:48 -0700438
Rob Widmer24b20942020-09-16 11:00:29 -0400439build_jruby() {
440 internal_build_cpp # For conformance tests.
441 cd ruby && bash travis-test.sh jruby-9.2.11.1 && cd ..
442}
443
Josh Habermane9cf31e2015-12-21 15:18:17 -0800444build_javascript() {
445 internal_build_cpp
Joshua Haberman79b1c3b2020-05-13 16:16:27 -0700446 NODE_VERSION=node-v12.16.3-darwin-x64
447 NODE_TGZ="$NODE_VERSION.tar.gz"
448 pushd /tmp
449 curl -OL https://nodejs.org/dist/v12.16.3/$NODE_TGZ
450 tar zxvf $NODE_TGZ
451 export PATH=$PATH:`pwd`/$NODE_VERSION/bin
452 popd
Josh Haberman0d2d8bc2015-12-28 06:43:42 -0800453 cd js && npm install && npm test && cd ..
Josh Habermanf873d322016-06-08 12:38:15 -0700454 cd conformance && make test_nodejs && cd ..
Josh Habermane9cf31e2015-12-21 15:18:17 -0800455}
456
Bo Yangc8bd36e2016-09-30 19:07:33 +0000457use_php() {
458 VERSION=$1
Paul Yangd7c44092018-12-18 10:57:03 -0800459 export PATH=/usr/local/php-${VERSION}/bin:$PATH
Joshua Habermanf1ce8662020-06-09 15:40:29 -0700460 internal_build_cpp
Bo Yangc8bd36e2016-09-30 19:07:33 +0000461}
462
Joshua Haberman8b870752021-05-04 10:19:22 -0700463build_php() {
464 use_php $1
Paul Yang525be942021-02-04 09:50:28 -0800465 pushd php
466 rm -rf vendor
467 composer update
468 composer test
469 popd
470 (cd conformance && make test_php)
471}
472
Joshua Haberman8b870752021-05-04 10:19:22 -0700473test_php_c() {
Paul Yange3e38b82016-12-08 14:39:20 -0800474 pushd php
Bo Yangfd332d12016-09-30 00:07:47 +0000475 rm -rf vendor
Paul Yangd7c44092018-12-18 10:57:03 -0800476 composer update
Joshua Haberman8b870752021-05-04 10:19:22 -0700477 composer test_c
Paul Yange3e38b82016-12-08 14:39:20 -0800478 popd
Joshua Haberman8b870752021-05-04 10:19:22 -0700479 (cd conformance && make test_php_c)
Bo Yangfd332d12016-09-30 00:07:47 +0000480}
481
Joshua Haberman8b870752021-05-04 10:19:22 -0700482build_php_c() {
483 use_php $1
484 test_php_c
Paul Yang190b5272017-04-19 16:23:51 -0700485}
486
487build_php7.0_mac() {
Joshua Habermanf1ce8662020-06-09 15:40:29 -0700488 internal_build_cpp
Paul Yang190b5272017-04-19 16:23:51 -0700489 # Install PHP
490 curl -s https://php-osx.liip.ch/install.sh | bash -s 7.0
Joshua Haberman27ba0c52020-05-13 15:36:21 -0700491 PHP_FOLDER=`find /usr/local -type d -name "php5-7.0*"` # The folder name may change upon time
492 test ! -z "$PHP_FOLDER"
Paul Yang190b5272017-04-19 16:23:51 -0700493 export PATH="$PHP_FOLDER/bin:$PATH"
494
Joshua Haberman8b870752021-05-04 10:19:22 -0700495 # Install Composer
496 wget https://getcomposer.org/download/2.0.13/composer.phar --progress=dot:mega -O /usr/local/bin/composer
497 chmod a+x /usr/local/bin/composer
498
Paul Yang190b5272017-04-19 16:23:51 -0700499 # Install valgrind
500 echo "#! /bin/bash" > valgrind
501 chmod ug+x valgrind
502 sudo mv valgrind /usr/local/bin/valgrind
503
504 # Test
Joshua Haberman8b870752021-05-04 10:19:22 -0700505 test_php_c
Bo Yang34cdaf42016-10-03 21:59:58 +0000506}
507
Joshua Haberman27ba0c52020-05-13 15:36:21 -0700508build_php7.3_mac() {
Joshua Habermanf1ce8662020-06-09 15:40:29 -0700509 internal_build_cpp
Paul Yang85219572020-01-30 12:45:47 -0800510 # Install PHP
Joshua Haberman27ba0c52020-05-13 15:36:21 -0700511 # We can't test PHP 7.4 with these binaries yet:
512 # https://github.com/liip/php-osx/issues/276
513 curl -s https://php-osx.liip.ch/install.sh | bash -s 7.3
514 PHP_FOLDER=`find /usr/local -type d -name "php5-7.3*"` # The folder name may change upon time
515 test ! -z "$PHP_FOLDER"
Paul Yang85219572020-01-30 12:45:47 -0800516 export PATH="$PHP_FOLDER/bin:$PATH"
517
Joshua Haberman8b870752021-05-04 10:19:22 -0700518 # Install Composer
519 wget https://getcomposer.org/download/2.0.13/composer.phar --progress=dot:mega -O /usr/local/bin/composer
520 chmod a+x /usr/local/bin/composer
521
Paul Yang85219572020-01-30 12:45:47 -0800522 # Install valgrind
523 echo "#! /bin/bash" > valgrind
524 chmod ug+x valgrind
525 sudo mv valgrind /usr/local/bin/valgrind
526
527 # Test
Joshua Haberman8b870752021-05-04 10:19:22 -0700528 test_php_c
Paul Yang85219572020-01-30 12:45:47 -0800529}
530
Paul Yang25abd7b2017-05-05 11:14:11 -0700531build_php_compatibility() {
532 internal_build_cpp
Jie Luod1eeb852019-07-31 17:49:26 -0700533 php/tests/compatibility_test.sh $LAST_RELEASED
Paul Yang25abd7b2017-05-05 11:14:11 -0700534}
535
Paul Yangfe1790c2019-12-12 13:59:51 -0800536build_php_multirequest() {
537 use_php 7.4
Joshua Haberman2cc68ef2020-05-28 19:24:08 -0700538 php/tests/multirequest.sh
Paul Yangfe1790c2019-12-12 13:59:51 -0800539}
540
Paul Yangd4ca9292020-08-11 19:30:46 -0700541build_php8.0_all() {
Joshua Haberman8b870752021-05-04 10:19:22 -0700542 build_php 8.0
543 build_php_c 8.0
Paul Yangd4ca9292020-08-11 19:30:46 -0700544}
545
Paul Yang25abd7b2017-05-05 11:14:11 -0700546build_php_all_32() {
Joshua Haberman8b870752021-05-04 10:19:22 -0700547 build_php 7.0
548 build_php 7.1
549 build_php 7.4
550 build_php_c 7.0
551 build_php_c 7.1
552 build_php_c 7.4
553 build_php_c 7.1-zts
554 build_php_c 7.2-zts
555 build_php_c 7.5-zts
Paul Yang51c5ff82016-10-25 17:27:05 -0700556}
557
Paul Yang25abd7b2017-05-05 11:14:11 -0700558build_php_all() {
Joshua Haberman8b870752021-05-04 10:19:22 -0700559 build_php_all_32
Paul Yangfe1790c2019-12-12 13:59:51 -0800560 build_php_multirequest
Paul Yang25abd7b2017-05-05 11:14:11 -0700561 build_php_compatibility
562}
563
Yilun Chong6adc3d72018-12-18 16:20:23 -0800564build_benchmark() {
Yilun Chong152c8302018-12-20 17:15:51 -0800565 use_php 7.2
Yilun Chong6adc3d72018-12-18 16:20:23 -0800566 cd kokoro/linux/benchmark && ./run.sh
567}
568
Josh Haberman738393b2016-02-18 20:10:23 -0800569# -------- main --------
570
Josh Haberman738393b2016-02-18 20:10:23 -0800571if [ "$#" -ne 1 ]; then
572 echo "
573Usage: $0 { cpp |
Feng Xiaoa4f68b12016-07-19 17:20:31 -0700574 cpp_distcheck |
Josh Haberman738393b2016-02-18 20:10:23 -0800575 csharp |
Josh Haberman738393b2016-02-18 20:10:23 -0800576 java_jdk7 |
577 java_oracle7 |
Tomo Suzuki70517252019-06-26 15:28:49 -0400578 java_linkage_monitor |
Josh Haberman738393b2016-02-18 20:10:23 -0800579 objectivec_ios |
Thomas Van Lenten368a2f42016-05-24 11:27:33 -0400580 objectivec_ios_debug |
581 objectivec_ios_release |
Josh Haberman738393b2016-02-18 20:10:23 -0800582 objectivec_osx |
Thomas Van Lentenbd006712019-01-07 16:42:22 -0500583 objectivec_tvos |
584 objectivec_tvos_debug |
585 objectivec_tvos_release |
Sergio Campamáf0c14922016-06-14 11:26:01 -0700586 objectivec_cocoapods_integration |
Josh Haberman738393b2016-02-18 20:10:23 -0800587 python |
588 python_cpp |
Jie Luoea511492017-01-23 15:11:00 -0800589 python_compatibility |
Paul Yang39df66e2018-10-12 12:36:33 -0700590 ruby23 |
591 ruby24 |
592 ruby25 |
Paul Yangde9e1a02019-01-03 14:25:50 -0800593 ruby26 |
Masaki Haraf494cb22020-04-25 01:50:27 +0900594 ruby27 |
Joshua Haberman9abf6e22021-01-13 12:16:25 -0800595 ruby30 |
Feng Xiao20fbb352016-07-21 18:04:56 -0700596 jruby |
Bo Yangfd332d12016-09-30 00:07:47 +0000597 ruby_all |
Yilun Chong6adc3d72018-12-18 16:20:23 -0800598 php_all |
Joshua Haberman8b870752021-05-04 10:19:22 -0700599 php_all_32 |
600 php7.0_mac |
601 php7.3_mac |
Hao Nguyenf85c8232019-03-07 14:34:28 -0800602 dist_install |
Yilun Chong152c8302018-12-20 17:15:51 -0800603 benchmark)
Josh Haberman738393b2016-02-18 20:10:23 -0800604"
605 exit 1
606fi
607
608set -e # exit immediately on error
609set -x # display all commands
Feng Xiao9de4e642018-07-13 16:55:32 -0700610cd $(dirname $0)
Josh Haberman738393b2016-02-18 20:10:23 -0800611eval "build_$1"