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