xref: /aosp_15_r20/external/protobuf/kokoro/linux/aarch64/test_php_aarch64.sh (revision 1b3f573f81763fcece89efc2b6a5209149e44ab8)
1#!/bin/bash
2
3set -ex
4
5# go to the repo root
6cd $(dirname $0)/../../..
7
8# there is no php testing docker image readily available, so we build
9# our own. It's a aarch64 image, but that's fine since qemu will
10# automatically be used to run the commands in the dockerfile.
11docker build -t testimage_protobuf_php_arm64v8 kokoro/linux/aarch64/testimage_protobuf_php_arm64v8
12
13if [[ -t 0 ]]; then
14  DOCKER_TTY_ARGS="-it"
15else
16  # The input device on kokoro is not a TTY, so -it does not work.
17  DOCKER_TTY_ARGS=
18fi
19
20# crosscompile protoc as we will later need it for the php build.
21# we build it under the dockcross/manylinux2014-aarch64 image so that the resulting protoc binary is compatible
22# with a wide range of linux distros (including any docker images we will use later to build and test php)
23kokoro/linux/aarch64/dockcross_helpers/run_dockcross_manylinux2014_aarch64.sh kokoro/linux/aarch64/protoc_crosscompile_aarch64.sh
24
25# use an actual aarch64 docker image (with a real aarch64 php) to run build & test protobuf php under an emulator
26# * mount the protobuf root as /work to be able to access the crosscompiled files
27# * to avoid running the process inside docker as root (which can pollute the workspace with files owned by root), we force
28#   running under current user's UID and GID. To be able to do that, we need to provide a home directory for the user
29#   otherwise the UID would be homeless under the docker container and pip install wouldn't work. For simplicity,
30#   we just run map the user's home to a throwaway temporary directory
31docker run $DOCKER_TTY_ARGS --rm --user "$(id -u):$(id -g)" -e "HOME=/home/fake-user" -v "$(mktemp -d):/home/fake-user" -v "$(pwd)":/work -w /work testimage_protobuf_php_arm64v8 kokoro/linux/aarch64/php_build_and_run_tests_with_qemu_aarch64.sh
32