c91dfda33bb8351c12fada0a2d4f8c774050cc26
[platform/upstream/mesa.git] / .gitlab-ci / container / build-skqp.sh
1 #!/bin/bash
2 #
3 # Copyright (C) 2022 Collabora Limited
4 # Author: Guilherme Gallo <guilherme.gallo@collabora.com>
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining a
7 # copy of this software and associated documentation files (the "Software"),
8 # to deal in the Software without restriction, including without limitation
9 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 # and/or sell copies of the Software, and to permit persons to whom the
11 # Software is furnished to do so, subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice (including the next
14 # paragraph) shall be included in all copies or substantial portions of the
15 # Software.
16 #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 # SOFTWARE.
24
25
26 create_gn_args() {
27     # gn can be configured to cross-compile skia and its tools
28     # It is important to set the target_cpu to guarantee the intended target
29     # machine
30     cp "${BASE_ARGS_GN_FILE}" "${SKQP_OUT_DIR}"/args.gn
31     echo "target_cpu = \"${SKQP_ARCH}\"" >> "${SKQP_OUT_DIR}"/args.gn
32 }
33
34
35 download_skia_source() {
36     if [ -z ${SKIA_DIR+x} ]
37     then
38         return 1
39     fi
40
41     # Skia cloned from https://android.googlesource.com/platform/external/skqp
42     # has all needed assets tracked on git-fs
43     SKQP_REPO=https://android.googlesource.com/platform/external/skqp
44     SKQP_BRANCH=android-cts-11.0_r7
45
46     git clone --branch "${SKQP_BRANCH}" --depth 1 "${SKQP_REPO}" "${SKIA_DIR}"
47 }
48
49 set -ex
50
51 SCRIPT_DIR=$(realpath "$(dirname "$0")")
52 SKQP_PATCH_DIR="${SCRIPT_DIR}"
53 BASE_ARGS_GN_FILE="${SCRIPT_DIR}/build-skqp_base.gn"
54
55 SKQP_ARCH=${SKQP_ARCH:-x64}
56 SKIA_DIR=${SKIA_DIR:-$(mktemp -d)}
57 SKQP_OUT_DIR=${SKIA_DIR}/out/${SKQP_ARCH}
58 SKQP_INSTALL_DIR=${SKQP_INSTALL_DIR:-/skqp}
59 SKQP_ASSETS_DIR="${SKQP_INSTALL_DIR}/assets"
60 SKQP_BINARIES=(skqp list_gpu_unit_tests list_gms)
61
62 download_skia_source
63
64 pushd "${SKIA_DIR}"
65
66 # Apply all skqp patches for Mesa CI
67 cat "${SKQP_PATCH_DIR}"/build-skqp_*.patch |
68     patch -p1
69
70 # Fetch some needed build tools needed to build skia/skqp.
71 # Basically, it clones repositories with commits SHAs from ${SKIA_DIR}/DEPS
72 # directory.
73 python tools/git-sync-deps
74
75 mkdir -p "${SKQP_OUT_DIR}"
76 mkdir -p "${SKQP_INSTALL_DIR}"
77
78 create_gn_args
79
80 # Build and install skqp binaries
81 bin/gn gen "${SKQP_OUT_DIR}"
82
83 for BINARY in "${SKQP_BINARIES[@]}"
84 do
85     /usr/bin/ninja -C "${SKQP_OUT_DIR}" "${BINARY}"
86     # Strip binary, since gn is not stripping it even when `is_debug == false`
87     ${STRIP_CMD:-strip} "${SKQP_OUT_DIR}/${BINARY}"
88     install -m 0755 "${SKQP_OUT_DIR}/${BINARY}" "${SKQP_INSTALL_DIR}"
89 done
90
91 # Move assets to the target directory, which will reside in rootfs.
92 mv platform_tools/android/apps/skqp/src/main/assets/ "${SKQP_ASSETS_DIR}"
93
94 popd
95 rm -Rf "${SKIA_DIR}"
96
97 set +ex