• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2#
3# android_run_skia: starts the correct skia program on the device, prints the
4# output, and kills the app if interrupted.
5
6SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
7source $SCRIPT_DIR/utils/android_setup.sh
8source $SCRIPT_DIR/utils/setup_adb.sh
9
10if [ ! -f "${SKIA_OUT}/${APP_ARGS[0]}" ];
11then
12  echo "Unable to find ${APP_ARGS[0]} executable"
13  exit 1
14fi
15
16verbose "pushing binaries onto the device..."
17adb_push_if_needed "${SKIA_OUT}/${APP_ARGS[0]}" /data/local/tmp
18if [[ -n $RESOURCE_PATH ]]; then
19  verbose "pushing resources onto the device..."
20  adb_push_if_needed "${SCRIPT_DIR}/../../../resources" $RESOURCE_PATH
21fi
22
23if [ $LOGCAT ]; then
24   verbose "clearing the device logs..."
25  $ADB $DEVICE_SERIAL logcat -c;
26fi
27STATUS_FILENAME="/data/local/tmp/.skia_tmp_$(date +%s%N)"
28CMD_FILENAME=".skia_cmd_tmp_$(date +%s%N)"
29echo "/data/local/tmp/${APP_ARGS[*]}; \
30     echo \$? > ${STATUS_FILENAME}" > ${CMD_FILENAME}
31chmod +x ${CMD_FILENAME}
32verbose "======== To reproduce this run: ========"
33verbose "android_run_skia ${APP_ARGS[*]}"
34verbose "========================================"
35verbose "pushing command file onto the device..."
36$ADB ${DEVICE_SERIAL} push ${CMD_FILENAME} /data/local/tmp
37rm ${CMD_FILENAME}
38verbose "preparing to run ${APP_ARGS[0]} on the device..."
39$ADB ${DEVICE_SERIAL} shell sh /data/local/tmp/${CMD_FILENAME}
40
41if [ -z "$($ADB $DEVICE_SERIAL shell 'if [ -f $STATUS_FILENAME ]; then echo exists; fi')" ]; then
42  if [ $LOGCAT ]; then $ADB $DEVICE_SERIAL logcat -d; fi
43  echo "***********************************************************************"
44  echo "The application terminated unexpectedly and did not produce an exit code"
45  echo "***********************************************************************"
46  exit 1
47fi
48
49EXIT_CODE=`$ADB ${DEVICE_SERIAL} shell cat ${STATUS_FILENAME}`
50$ADB ${DEVICE_SERIAL} shell rm -f ${STATUS_FILENAME} ${CMD_FILENAME}
51
52# check to see if the 'cat' command failed and print errors accordingly
53if [[ ${EXIT_CODE} == *${STATUS_FILENAME}* ]]; then
54  if [ $LOGCAT ]; then $ADB $DEVICE_SERIAL logcat -d; fi
55  echo "***********************************************************************"
56  echo "ADB failed to retrieve the application's exit code"
57  echo "***********************************************************************"
58  exit 1
59fi
60
61echo "EXIT_CODE is ${EXIT_CODE}"
62if [[ "${EXIT_CODE}" != 0* ]]; then
63  if [ $LOGCAT ]; then $ADB $DEVICE_SERIAL logcat -d; fi
64  exit 1
65fi
66exit 0
67