kokoro: Switch over to using the radial docker image

Has a recent version of CMake and a selection of compiler toolchains released in the last few years.

Bug: b/157730274
Change-Id: Id7aac194366bc076df01391fc5fb1ce0804a8319
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/61348
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Tested-by: Ben Clayton <bclayton@google.com>
Kokoro-Result: Ben Clayton <bclayton@google.com>
diff --git a/tests/kokoro/gcp_ubuntu/build.sh b/tests/kokoro/gcp_ubuntu/build.sh
new file mode 100755
index 0000000..93c2467
--- /dev/null
+++ b/tests/kokoro/gcp_ubuntu/build.sh
@@ -0,0 +1,45 @@
+#!/bin/bash
+
+# Copyright 2022 The SwiftShader Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -e # Fail on any error.
+
+SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )"
+ROOT_DIR="$( cd "${SCRIPT_DIR}/../../.." >/dev/null 2>&1 && pwd )"
+
+# Inside the docker VM, we clone the project to a new directory.
+# We do this so that the docker script can be tested in a local development
+# checkout, without having the build litter the local checkout with artifacts.
+# This directory is mapped to the host temporary directory.
+# Kokoro uses a '/tmpfs' root, where as most linux enviroments just have '/tmp'
+if [ -d "/tmpfs" ]; then
+    TMP_DIR=/tmpfs
+else
+    TMP_DIR=/tmp
+fi
+
+# --privileged is required for some sanitizer builds, as they seem to require PTRACE privileges
+docker run --rm -i \
+  --privileged \
+  --volume "${ROOT_DIR}:${ROOT_DIR}" \
+  --volume "${TMP_DIR}:/src" \
+  --volume "${KOKORO_ARTIFACTS_DIR}:/mnt/artifacts" \
+  --workdir "${ROOT_DIR}" \
+  --env SRC_DIR="/src/swiftshader" \
+  --env BUILD_TYPE=$BUILD_TYPE \
+  --env REACTOR_BACKEND=$REACTOR_BACKEND \
+  --env LLVM_VERSION=$LLVM_VERSION \
+  --entrypoint "${SCRIPT_DIR}/docker.sh" \
+  "gcr.io/shaderc-build/radial-build:latest"
diff --git a/tests/kokoro/gcp_ubuntu/continuous.sh b/tests/kokoro/gcp_ubuntu/continuous.sh
deleted file mode 100755
index bfa5d8d..0000000
--- a/tests/kokoro/gcp_ubuntu/continuous.sh
+++ /dev/null
@@ -1,79 +0,0 @@
-#!/bin/bash
-
-cd git/SwiftShader
-
-set -e # Fail on any error.
-set -x # Display commands being run.
-
-# Update CMake
-sudo aptitude purge -yq cmake
-wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | sudo apt-key add -
-sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ xenial main'
-sudo aptitude update -yq
-sudo aptitude install -yq cmake
-cmake --version
-
-# Specify we want to build with GCC 9
-sudo add-apt-repository ppa:ubuntu-toolchain-r/test
-sudo aptitude update -yq
-sudo aptitude install -yq gcc-9 g++-9
-sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 100 --slave /usr/bin/g++ g++ /usr/bin/g++-9
-sudo update-alternatives --set gcc "/usr/bin/gcc-9"
-
-# Install libxcb-shm0-dev
-sudo aptitude install -yq libxcb-shm0-dev
-
-mkdir -p build && cd build
-
-if [[ -z "${REACTOR_BACKEND}" ]]; then
-  REACTOR_BACKEND="LLVM"
-fi
-
-# Lower the amount of debug info, to reduce Kokoro build times.
-SWIFTSHADER_LESS_DEBUG_INFO=1
-
-cmake .. \
-    "-DCMAKE_BUILD_TYPE=${BUILD_TYPE}" \
-    "-DREACTOR_BACKEND=${REACTOR_BACKEND}" \
-    "-DSWIFTSHADER_LLVM_VERSION=${LLVM_VERSION}" \
-    "-DREACTOR_VERIFY_LLVM_IR=1" \
-    "-DSWIFTSHADER_LESS_DEBUG_INFO=${SWIFTSHADER_LESS_DEBUG_INFO}"
-cmake --build . -- -j $(nproc)
-
-# Run unit tests
-
-cd .. # Some tests must be run from project root
-
-build/ReactorUnitTests
-build/system-unittests
-build/vk-unittests
-
-# Incrementally build and run rr::Print unit tests
-cd build
-cmake .. "-DREACTOR_ENABLE_PRINT=1"
-cmake --build . --target ReactorUnitTests -- -j $(nproc)
-cmake .. "-DREACTOR_ENABLE_PRINT=0"
-cd ..
-build/ReactorUnitTests --gtest_filter=ReactorUnitTests.Print*
-
-# Incrementally build with REACTOR_EMIT_ASM_FILE and run unit test
-cd build
-cmake .. "-DREACTOR_EMIT_ASM_FILE=1"
-cmake --build . --target ReactorUnitTests -- -j $(nproc)
-cmake .. "-DREACTOR_EMIT_ASM_FILE=0"
-cd ..
-build/ReactorUnitTests --gtest_filter=ReactorUnitTests.EmitAsm
-
-# Incrementally build with REACTOR_EMIT_DEBUG_INFO to ensure it builds
-cd build
-cmake .. "-DREACTOR_EMIT_DEBUG_INFO=1"
-cmake --build . --target ReactorUnitTests -- -j $(nproc)
-cmake .. "-DREACTOR_EMIT_DEBUG_INFO=0"
-cd ..
-
-# Incrementally build with REACTOR_EMIT_PRINT_LOCATION to ensure it builds
-cd build
-cmake .. "-DREACTOR_EMIT_PRINT_LOCATION=1"
-cmake --build . --target ReactorUnitTests -- -j $(nproc)
-cmake .. "-DREACTOR_EMIT_PRINT_LOCATION=0"
-cd ..
diff --git a/tests/kokoro/gcp_ubuntu/docker.sh b/tests/kokoro/gcp_ubuntu/docker.sh
new file mode 100755
index 0000000..8dcf5d1
--- /dev/null
+++ b/tests/kokoro/gcp_ubuntu/docker.sh
@@ -0,0 +1,117 @@
+#!/bin/bash
+
+# Copyright 2022 The SwiftShader Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -e # Fail on any error.
+
+function show_cmds { set -x; }
+function hide_cmds { { set +x; } 2>/dev/null; }
+function task_begin {
+    TASK_NAME="$@"
+    SECONDS=0
+}
+function print_last_task_duration {
+    if [ ! -z "${TASK_NAME}" ]; then
+        echo "${TASK_NAME} completed in $(($SECONDS / 3600))h$((($SECONDS / 60) % 60))m$(($SECONDS % 60))s"
+    fi
+}
+function status {
+    echo ""
+    echo ""
+    print_last_task_duration
+    echo ""
+    echo "*****************************************************************"
+    echo "* $@"
+    echo "*****************************************************************"
+    echo ""
+    task_begin $@
+}
+
+CLONE_SRC_DIR="$(pwd)"
+
+. /bin/using.sh # Declare the bash `using` function for configuring toolchains.
+
+using cmake-3.17.2
+using gcc-9
+
+status "Cloning to clean source directory at '${SRC_DIR}'"
+
+mkdir -p ${SRC_DIR}
+cd ${SRC_DIR}
+git clone ${CLONE_SRC_DIR} .
+
+mkdir -p build && cd build
+
+if [[ -z "${REACTOR_BACKEND}" ]]; then
+  REACTOR_BACKEND="LLVM"
+fi
+
+# Lower the amount of debug info, to reduce Kokoro build times.
+SWIFTSHADER_LESS_DEBUG_INFO=1
+
+status "Generating CMake build files"
+cmake .. \
+    "-DCMAKE_BUILD_TYPE=${BUILD_TYPE}" \
+    "-DREACTOR_BACKEND=${REACTOR_BACKEND}" \
+    "-DSWIFTSHADER_LLVM_VERSION=${LLVM_VERSION}" \
+    "-DREACTOR_VERIFY_LLVM_IR=1" \
+    "-DSWIFTSHADER_LESS_DEBUG_INFO=${SWIFTSHADER_LESS_DEBUG_INFO}"
+
+status "Building"
+cmake --build . -- -j $(nproc)
+
+status "Running unit tests"
+
+cd .. # Some tests must be run from project root
+
+build/ReactorUnitTests
+build/system-unittests
+build/vk-unittests
+
+status "Building and running rr::Print unit tests"
+
+cd build
+cmake .. "-DREACTOR_ENABLE_PRINT=1"
+cmake --build . --target ReactorUnitTests -- -j $(nproc)
+cmake .. "-DREACTOR_ENABLE_PRINT=0"
+cd ..
+build/ReactorUnitTests --gtest_filter=ReactorUnitTests.Print*
+
+status "Building and testing with REACTOR_EMIT_ASM_FILE"
+
+cd build
+cmake .. "-DREACTOR_EMIT_ASM_FILE=1"
+cmake --build . --target ReactorUnitTests -- -j $(nproc)
+cmake .. "-DREACTOR_EMIT_ASM_FILE=0"
+cd ..
+build/ReactorUnitTests --gtest_filter=ReactorUnitTests.EmitAsm
+
+status "Building with REACTOR_EMIT_DEBUG_INFO"
+
+cd build
+cmake .. "-DREACTOR_EMIT_DEBUG_INFO=1"
+cmake --build . --target ReactorUnitTests -- -j $(nproc)
+cmake .. "-DREACTOR_EMIT_DEBUG_INFO=0"
+cd ..
+
+status "Building with REACTOR_EMIT_PRINT_LOCATION"
+
+cd build
+cmake .. "-DREACTOR_EMIT_PRINT_LOCATION=1"
+cmake --build . --target ReactorUnitTests -- -j $(nproc)
+cmake .. "-DREACTOR_EMIT_PRINT_LOCATION=0"
+cd ..
+
+status "Done"
diff --git a/tests/kokoro/gcp_ubuntu/reactor_llvm/10.0/debug/continuous.cfg b/tests/kokoro/gcp_ubuntu/reactor_llvm/10.0/debug/continuous.cfg
index a9e3edb..08156ee 100644
--- a/tests/kokoro/gcp_ubuntu/reactor_llvm/10.0/debug/continuous.cfg
+++ b/tests/kokoro/gcp_ubuntu/reactor_llvm/10.0/debug/continuous.cfg
@@ -1,7 +1,7 @@
 # Format: //devtools/kokoro/config/proto/build.proto
 
-# Location of the continuous bash script in Git.
-build_file: "SwiftShader/tests/kokoro/gcp_ubuntu/continuous.sh"
+# Location of the build bash script in Git.
+build_file: "SwiftShader/tests/kokoro/gcp_ubuntu/build.sh"
 
 env_vars {
   key: "REACTOR_BACKEND"
diff --git a/tests/kokoro/gcp_ubuntu/reactor_llvm/10.0/debug/presubmit.cfg b/tests/kokoro/gcp_ubuntu/reactor_llvm/10.0/debug/presubmit.cfg
index a9e3edb..08156ee 100644
--- a/tests/kokoro/gcp_ubuntu/reactor_llvm/10.0/debug/presubmit.cfg
+++ b/tests/kokoro/gcp_ubuntu/reactor_llvm/10.0/debug/presubmit.cfg
@@ -1,7 +1,7 @@
 # Format: //devtools/kokoro/config/proto/build.proto
 
-# Location of the continuous bash script in Git.
-build_file: "SwiftShader/tests/kokoro/gcp_ubuntu/continuous.sh"
+# Location of the build bash script in Git.
+build_file: "SwiftShader/tests/kokoro/gcp_ubuntu/build.sh"
 
 env_vars {
   key: "REACTOR_BACKEND"
diff --git a/tests/kokoro/gcp_ubuntu/reactor_llvm/10.0/release/continuous.cfg b/tests/kokoro/gcp_ubuntu/reactor_llvm/10.0/release/continuous.cfg
index 252b181..c41fd1c 100644
--- a/tests/kokoro/gcp_ubuntu/reactor_llvm/10.0/release/continuous.cfg
+++ b/tests/kokoro/gcp_ubuntu/reactor_llvm/10.0/release/continuous.cfg
@@ -1,7 +1,7 @@
 # Format: //devtools/kokoro/config/proto/build.proto
 
-# Location of the continuous bash script in Git.
-build_file: "SwiftShader/tests/kokoro/gcp_ubuntu/continuous.sh"
+# Location of the build bash script in Git.
+build_file: "SwiftShader/tests/kokoro/gcp_ubuntu/build.sh"
 
 env_vars {
   key: "REACTOR_BACKEND"
diff --git a/tests/kokoro/gcp_ubuntu/reactor_llvm/10.0/release/presubmit.cfg b/tests/kokoro/gcp_ubuntu/reactor_llvm/10.0/release/presubmit.cfg
index 252b181..c41fd1c 100644
--- a/tests/kokoro/gcp_ubuntu/reactor_llvm/10.0/release/presubmit.cfg
+++ b/tests/kokoro/gcp_ubuntu/reactor_llvm/10.0/release/presubmit.cfg
@@ -1,7 +1,7 @@
 # Format: //devtools/kokoro/config/proto/build.proto
 
-# Location of the continuous bash script in Git.
-build_file: "SwiftShader/tests/kokoro/gcp_ubuntu/continuous.sh"
+# Location of the build bash script in Git.
+build_file: "SwiftShader/tests/kokoro/gcp_ubuntu/build.sh"
 
 env_vars {
   key: "REACTOR_BACKEND"
diff --git a/tests/kokoro/gcp_ubuntu/reactor_subzero/debug/continuous.cfg b/tests/kokoro/gcp_ubuntu/reactor_subzero/debug/continuous.cfg
index 2bba348..76f6fdd 100644
--- a/tests/kokoro/gcp_ubuntu/reactor_subzero/debug/continuous.cfg
+++ b/tests/kokoro/gcp_ubuntu/reactor_subzero/debug/continuous.cfg
@@ -1,7 +1,7 @@
 # Format: //devtools/kokoro/config/proto/build.proto
 
-# Location of the continuous bash script in Git.
-build_file: "SwiftShader/tests/kokoro/gcp_ubuntu/continuous.sh"
+# Location of the build bash script in Git.
+build_file: "SwiftShader/tests/kokoro/gcp_ubuntu/build.sh"
 
 env_vars {
   key: "REACTOR_BACKEND"
diff --git a/tests/kokoro/gcp_ubuntu/reactor_subzero/debug/presubmit.cfg b/tests/kokoro/gcp_ubuntu/reactor_subzero/debug/presubmit.cfg
index 2bba348..76f6fdd 100644
--- a/tests/kokoro/gcp_ubuntu/reactor_subzero/debug/presubmit.cfg
+++ b/tests/kokoro/gcp_ubuntu/reactor_subzero/debug/presubmit.cfg
@@ -1,7 +1,7 @@
 # Format: //devtools/kokoro/config/proto/build.proto
 
-# Location of the continuous bash script in Git.
-build_file: "SwiftShader/tests/kokoro/gcp_ubuntu/continuous.sh"
+# Location of the build bash script in Git.
+build_file: "SwiftShader/tests/kokoro/gcp_ubuntu/build.sh"
 
 env_vars {
   key: "REACTOR_BACKEND"
diff --git a/tests/kokoro/gcp_ubuntu/reactor_subzero/release/continuous.cfg b/tests/kokoro/gcp_ubuntu/reactor_subzero/release/continuous.cfg
index 900f17a..64e7b11 100644
--- a/tests/kokoro/gcp_ubuntu/reactor_subzero/release/continuous.cfg
+++ b/tests/kokoro/gcp_ubuntu/reactor_subzero/release/continuous.cfg
@@ -1,7 +1,7 @@
 # Format: //devtools/kokoro/config/proto/build.proto
 
-# Location of the continuous bash script in Git.
-build_file: "SwiftShader/tests/kokoro/gcp_ubuntu/continuous.sh"
+# Location of the build bash script in Git.
+build_file: "SwiftShader/tests/kokoro/gcp_ubuntu/build.sh"
 
 env_vars {
   key: "REACTOR_BACKEND"
diff --git a/tests/kokoro/gcp_ubuntu/reactor_subzero/release/presubmit.cfg b/tests/kokoro/gcp_ubuntu/reactor_subzero/release/presubmit.cfg
index 900f17a..64e7b11 100644
--- a/tests/kokoro/gcp_ubuntu/reactor_subzero/release/presubmit.cfg
+++ b/tests/kokoro/gcp_ubuntu/reactor_subzero/release/presubmit.cfg
@@ -1,7 +1,7 @@
 # Format: //devtools/kokoro/config/proto/build.proto
 
-# Location of the continuous bash script in Git.
-build_file: "SwiftShader/tests/kokoro/gcp_ubuntu/continuous.sh"
+# Location of the build bash script in Git.
+build_file: "SwiftShader/tests/kokoro/gcp_ubuntu/build.sh"
 
 env_vars {
   key: "REACTOR_BACKEND"