1#!/bin/bash
2
3# This script builds Skia for ChromeOS by mounting the Skia checkout inside a
4# chroot contained within an existing ChromeOS checkout, entering the chroot,
5# and running the build_skia_in_chroot script.
6
7SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
8
9if [ $(uname) != "Linux" ]; then
10    echo "ERROR: Can only build for ChromeOS on Linux."
11    exit 1
12fi
13
14
15makeVars=""
16deviceID=""
17
18while (( "$#" )); do
19
20  if [[ $(echo "$1" | grep "^-d$") != "" ]];
21  then 
22    deviceID="$2"
23    shift
24  else
25    makeVars="$makeVars $1"
26  fi
27
28shift
29done
30
31if [[ -z "${deviceID}" ]]; then
32  echo "You must provide a deviceID with -d."
33  exit 1
34fi
35
36CHROMEOS_CHROOT="${SCRIPT_DIR}/../toolchain"
37
38# Get the required SDK version.
39# TODO(borenet): Should we instead get the latest from GS?
40#SDK_VERSION=$(gsutil cat gs://chromeos-image-archive/${deviceID}-release/LATEST-master)
41#SDK_VERSION=${SDK_VERSION:4}
42SDK_VERSION="4279.0.0"
43mkdir -p "${CHROMEOS_CHROOT}/src/chromeos"
44echo -n ${SDK_VERSION} > "${CHROMEOS_CHROOT}/src/chromeos/CHROMEOS_LKGM"
45
46# Download the toolchain tarball if needed.
47# TODO(borenet): Let chrome-sdk take care of this once it works with external
48# boards.
49if ! [[ -d "${CHROMEOS_CHROOT}/.cros_cache" ]]; then
50  TARBALL="cros_toolchain.tgz"
51  gsutil cp gs://chromium-skia-gm/chromeos-toolchains/${TARBALL} ${CHROMEOS_CHROOT}
52  if [ "$?" != "0" ]
53  then
54    exit 1;
55  fi
56  pushd "${CHROMEOS_CHROOT}" > /dev/null
57  tar -zxvf ${TARBALL}
58  popd > /dev/null
59  rm ${CHROMEOS_CHROOT}/${TARBALL}
60fi
61
62# Put a fake .gclient file in the toolchain directory so that the cros tool
63# thinks we're in a Chrome checkout.
64echo "Delete me!" > "${CHROMEOS_CHROOT}/.gclient"
65
66# Where the Skia code will pretend to live inside the chroot.
67SKIA_TOP_DIR="${SCRIPT_DIR}/../../.."
68
69pushd ${CHROMEOS_CHROOT}
70cros chrome-sdk --nogoma --board ${deviceID} --debug -- /bin/sh -c "cd ${SKIA_TOP_DIR}; platform_tools/chromeos/bin/build_skia_in_chroot ${makeVars}"
71popd > /dev/null
72
73# Clean up
74rm ${CHROMEOS_CHROOT}/.gclient
75
76if [ -f .cros_build_successful ]; then
77  rm -rf .cros_build_successful
78  exit 0
79fi
80
81exit 1