Some more updates to PHP testing infrastructure (#8576)
* WIP.
* Added build config for all of the tests.
* Use ../src/protoc if it is available, for cases where Bazel isn't available.
* Added test_php.sh.
* Fix for the broken macOS tests.
* Move all jobs to use php80 instead of lots of separate jobs.
* Only pass -t flag if we are running in a terminal.
* Updated php_all job to use new Docker stuff.
diff --git a/kokoro/linux/php80/build.sh b/kokoro/linux/php80/build.sh
index f17aec1..ba269e5 100755
--- a/kokoro/linux/php80/build.sh
+++ b/kokoro/linux/php80/build.sh
@@ -1,18 +1,17 @@
#!/bin/bash
#
-# This is the top-level script we give to Kokoro as the entry point for
-# running the "pull request" project:
-#
-# This script selects a specific Dockerfile (for building a Docker image) and
-# a script to run inside that image. Then we delegate to the general
-# build_and_run_docker.sh script.
+# This is the entry point for kicking off a Kokoro job. This path is referenced
+# from the .cfg files in this directory.
-# Change to repo root
-cd $(dirname $0)/../../..
+set -ex
-export DOCKERHUB_ORGANIZATION=protobuftesting
-export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/php80
-export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh
-export OUTPUT_DIR=testoutput
-export TEST_SET="php8.0_all"
-./kokoro/linux/build_and_run_docker.sh
+cd $(dirname $0)
+
+# Most of our tests use a debug build of PHP, but we do one build against an opt
+# php just in case that surfaces anything unexpected.
+../test_php.sh gcr.io/protobuf-build/php/linux:8.0.5-14a06550010c0649bf69b6c9b803c1ca609bbb6d
+
+../test_php.sh gcr.io/protobuf-build/php/linux:7.0.33-dbg-14a06550010c0649bf69b6c9b803c1ca609bbb6d
+../test_php.sh gcr.io/protobuf-build/php/linux:7.3.28-dbg-14a06550010c0649bf69b6c9b803c1ca609bbb6d
+../test_php.sh gcr.io/protobuf-build/php/linux:7.4.18-dbg-14a06550010c0649bf69b6c9b803c1ca609bbb6d
+../test_php.sh gcr.io/protobuf-build/php/linux:8.0.5-dbg-14a06550010c0649bf69b6c9b803c1ca609bbb6d
diff --git a/kokoro/linux/php80/continuous.cfg b/kokoro/linux/php80/continuous.cfg
index 8426318..6d67a8c 100644
--- a/kokoro/linux/php80/continuous.cfg
+++ b/kokoro/linux/php80/continuous.cfg
@@ -2,10 +2,4 @@
# Location of the build script in repository
build_file: "protobuf/kokoro/linux/php80/build.sh"
-timeout_mins: 120
-
-action {
- define_artifacts {
- regex: "**/sponge_log.xml"
- }
-}
+timeout_mins: 20
diff --git a/kokoro/linux/php80/presubmit.cfg b/kokoro/linux/php80/presubmit.cfg
index 8426318..6d67a8c 100644
--- a/kokoro/linux/php80/presubmit.cfg
+++ b/kokoro/linux/php80/presubmit.cfg
@@ -2,10 +2,4 @@
# Location of the build script in repository
build_file: "protobuf/kokoro/linux/php80/build.sh"
-timeout_mins: 120
-
-action {
- define_artifacts {
- regex: "**/sponge_log.xml"
- }
-}
+timeout_mins: 20
diff --git a/kokoro/linux/php_all/build.sh b/kokoro/linux/php_all/build.sh
index 23468a7..ba269e5 100755
--- a/kokoro/linux/php_all/build.sh
+++ b/kokoro/linux/php_all/build.sh
@@ -1,18 +1,17 @@
#!/bin/bash
#
-# This is the top-level script we give to Kokoro as the entry point for
-# running the "pull request" project:
-#
-# This script selects a specific Dockerfile (for building a Docker image) and
-# a script to run inside that image. Then we delegate to the general
-# build_and_run_docker.sh script.
+# This is the entry point for kicking off a Kokoro job. This path is referenced
+# from the .cfg files in this directory.
-# Change to repo root
-cd $(dirname $0)/../../..
+set -ex
-export DOCKERHUB_ORGANIZATION=protobuftesting
-export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/php
-export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh
-export OUTPUT_DIR=testoutput
-export TEST_SET="php_all"
-./kokoro/linux/build_and_run_docker.sh
+cd $(dirname $0)
+
+# Most of our tests use a debug build of PHP, but we do one build against an opt
+# php just in case that surfaces anything unexpected.
+../test_php.sh gcr.io/protobuf-build/php/linux:8.0.5-14a06550010c0649bf69b6c9b803c1ca609bbb6d
+
+../test_php.sh gcr.io/protobuf-build/php/linux:7.0.33-dbg-14a06550010c0649bf69b6c9b803c1ca609bbb6d
+../test_php.sh gcr.io/protobuf-build/php/linux:7.3.28-dbg-14a06550010c0649bf69b6c9b803c1ca609bbb6d
+../test_php.sh gcr.io/protobuf-build/php/linux:7.4.18-dbg-14a06550010c0649bf69b6c9b803c1ca609bbb6d
+../test_php.sh gcr.io/protobuf-build/php/linux:8.0.5-dbg-14a06550010c0649bf69b6c9b803c1ca609bbb6d
diff --git a/kokoro/linux/test_php.sh b/kokoro/linux/test_php.sh
new file mode 100755
index 0000000..918dd6d
--- /dev/null
+++ b/kokoro/linux/test_php.sh
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+set -ex
+
+test -t 1 && USE_TTY="-it"
+docker run ${USE_TTY} -v$(realpath $(dirname $0)/../..):/workspace $1 "composer test && composer test_c"
diff --git a/kokoro/macos/prepare_build_macos_rc b/kokoro/macos/prepare_build_macos_rc
index d94dd54..dcd17f3 100755
--- a/kokoro/macos/prepare_build_macos_rc
+++ b/kokoro/macos/prepare_build_macos_rc
@@ -45,6 +45,11 @@
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow
+# This is needed to fix a conflict between the ilmbase and imath packages,
+# which seem to conflict with each other by both trying to install
+# libImath.dylib.
+brew unlink ilmbase
+
brew update
brew upgrade
diff --git a/php/generate_test_protos.sh b/php/generate_test_protos.sh
index 0aa4bdb..e86ca07 100755
--- a/php/generate_test_protos.sh
+++ b/php/generate_test_protos.sh
@@ -4,7 +4,17 @@
cd `dirname $0`
-if [[ -d tmp && -z $(find tests/proto ../src/protoc -newer tmp) ]]; then
+./prepare_c_extension.sh
+
+if ../src/protoc --help > /dev/null; then
+ PROTOC=src/protoc
+else
+ (cd .. && bazel build -c opt :protoc)
+ PROTOC=bazel-bin/protoc
+fi
+
+
+if [[ -d tmp && -z $(find tests/proto ../$PROTOC -newer tmp) ]]; then
# Generated protos are already present and up to date, so we can skip protoc.
#
# Protoc is very fast, but sometimes it is not available (like if we haven't
@@ -16,12 +26,13 @@
rm -rf tmp
mkdir -p tmp
-find tests/proto -type f -name "*.proto"| xargs ../src/protoc --php_out=tmp -I../src -Itests
+cd ..
+find php/tests/proto -type f -name "*.proto"| xargs $PROTOC --php_out=php/tmp -Isrc -Iphp/tests
if [ "$1" = "--aggregate_metadata" ]; then
# Overwrite some of the files to use aggregation.
AGGREGATED_FILES="tests/proto/test.proto tests/proto/test_include.proto tests/proto/test_import_descriptor_proto.proto"
- ../src/protoc --php_out=aggregate_metadata=foo#bar:tmp -I../src -Itests $AGGREGATED_FILES
+ $PROTOC --php_out=aggregate_metadata=foo#bar:php/tmp -Isrc -Iphp/tests $AGGREGATED_FILES
fi
echo "Generated test protos from tests/proto -> tmp"
diff --git a/php/prepare_c_extension.sh b/php/prepare_c_extension.sh
index 84cd1aa..1b6b9f1 100755
--- a/php/prepare_c_extension.sh
+++ b/php/prepare_c_extension.sh
@@ -1,6 +1,20 @@
+cd $(dirname $0)
+
+if [[ -f ext/google/protobuf/third_party/wyhash/wyhash.h && -z $(find ../third_party/wyhash -newer ext/google/protobuf/third_party) ]]; then
+ # Generated protos are already present and up to date, so we can skip protoc.
+ #
+ # Protoc is very fast, but sometimes it is not available (like if we haven't
+ # built it in Docker). Skipping it helps us proceed in this case.
+ echo "wyhash is up to date, skipping."
+ exit 0
+fi
+
# wyhash has to live in the base third_party directory.
# We copy it into the ext/google/protobuf directory for the build
# (and for the release to PECL).
-mkdir -p ../ext/google/protobuf/third_party/wyhash
-cp ../../third_party/wyhash/* ../ext/google/protobuf/third_party/wyhash
+rm -rf ext/google/protobuf/third_party
+mkdir -p ext/google/protobuf/third_party/wyhash
+cp ../third_party/wyhash/* ext/google/protobuf/third_party/wyhash
+
+echo "Copied wyhash from ../third_party -> ext/google/protobuf/third_party"
diff --git a/php/tests/compile_extension.sh b/php/tests/compile_extension.sh
index d26fcb4..fe77bbc 100755
--- a/php/tests/compile_extension.sh
+++ b/php/tests/compile_extension.sh
@@ -13,13 +13,16 @@
CONFIGURE_OPTIONS+=("CFLAGS=-g -O0 -Wall")
fi
+FINGERPRINT="$(sha256sum $(which php)) ${CONFIGURE_OPTIONS[@]}"
+
# If the PHP interpreter we are building against or the arguments
# have changed, we must regenerated the Makefile.
-if [[ ! -f Makefile ]] || [[ "$(grep ' \$ ./configure' config.log)" != " $ ${CONFIGURE_OPTIONS[@]}" ]]; then
+if [[ ! -f BUILD_STAMP ]] || [[ "$(cat BUILD_STAMP)" != "$FINGERPRINT" ]]; then
phpize --clean
rm -f configure.in configure.ac
phpize
"${CONFIGURE_OPTIONS[@]}"
+ echo "$FINGERPRINT" > BUILD_STAMP
fi
make