• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
26create_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
35download_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
49set -ex
50
51SCRIPT_DIR=$(realpath "$(dirname "$0")")
52SKQP_PATCH_DIR="${SCRIPT_DIR}"
53BASE_ARGS_GN_FILE="${SCRIPT_DIR}/build-skqp_base.gn"
54
55SKQP_ARCH=${SKQP_ARCH:-x64}
56SKIA_DIR=${SKIA_DIR:-$(mktemp -d)}
57SKQP_OUT_DIR=${SKIA_DIR}/out/${SKQP_ARCH}
58SKQP_INSTALL_DIR=/skqp
59SKQP_ASSETS_DIR="${SKQP_INSTALL_DIR}/assets"
60SKQP_BINARIES=(skqp)
61
62download_skia_source
63
64pushd "${SKIA_DIR}"
65
66# Apply all skqp patches for Mesa CI
67cat "${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.
73python tools/git-sync-deps
74
75mkdir -p "${SKQP_OUT_DIR}"
76mkdir -p "${SKQP_INSTALL_DIR}"
77
78create_gn_args
79
80# Build and install skqp binaries
81bin/gn gen "${SKQP_OUT_DIR}"
82
83for BINARY in "${SKQP_BINARIES[@]}"
84do
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}"
89done
90
91# Move assets to the target directory, which will reside in rootfs.
92mv platform_tools/android/apps/skqp/src/main/assets/ "${SKQP_ASSETS_DIR}"
93
94popd
95rm -Rf "${SKIA_DIR}"
96
97set +ex
98