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/android_setup.sh 8source $SCRIPT_DIR/utils/setup_adb.sh 9 10if [ ! -f "${SKIA_OUT}/$BUILDTYPE/lib/lib${APP_ARGS[0]}.so" ]; 11then 12 echo "Unable to find $BUILDTYPE ${APP_ARGS[0]} library" 13 exit 1 14fi 15 16adb_push_if_needed "${SKIA_OUT}/$BUILDTYPE/skia_launcher" /data/local/tmp 17if [ -f "${SKIA_OUT}/$BUILDTYPE/lib/libskia_android.so" ]; then 18 # Does not exist for builds with static skia. 19 adb_push_if_needed "${SKIA_OUT}/$BUILDTYPE/lib/libskia_android.so" /data/local/tmp 20fi 21adb_push_if_needed "${SKIA_OUT}/$BUILDTYPE/lib/lib${APP_ARGS[0]}.so" /data/local/tmp 22if [[ -n $RESOURCE_PATH ]]; then 23 adb_push_if_needed "${SKIA_SRC_DIR}/resources" $RESOURCE_PATH 24fi 25 26if [ $LOGCAT ]; then $ADB $DEVICE_SERIAL logcat -c; fi 27STATUS_FILENAME="/data/local/tmp/.skia_tmp_$(date +%s%N)" 28CMD_FILENAME=".skia_cmd_tmp_$(date +%s%N)" 29echo "LD_LIBRARY_PATH=/data/local/tmp:$LD_LIBRARY_PATH \ 30 /data/local/tmp/skia_launcher ${APP_ARGS[*]}; \ 31 echo \$? > ${STATUS_FILENAME}" > ${CMD_FILENAME} 32chmod +x ${CMD_FILENAME} 33$ADB ${DEVICE_SERIAL} push ${CMD_FILENAME} /data/local/tmp 34rm ${CMD_FILENAME} 35$ADB ${DEVICE_SERIAL} shell sh /data/local/tmp/${CMD_FILENAME} 36 37if [ -z "$($ADB $DEVICE_SERIAL shell 'if [ -f $STATUS_FILENAME ]; then echo exists; fi')" ]; then 38 if [ $LOGCAT ]; then $ADB $DEVICE_SERIAL logcat -d; fi 39 echo "***********************************************************************" 40 echo "The application terminated unexpectedly and did not produce an exit code" 41 echo "***********************************************************************" 42 exit 1 43fi 44 45EXIT_CODE=`$ADB ${DEVICE_SERIAL} shell cat ${STATUS_FILENAME}` 46$ADB ${DEVICE_SERIAL} shell rm -f ${STATUS_FILENAME} ${CMD_FILENAME} 47 48# check to see if the 'cat' command failed and print errors accordingly 49if [[ ${EXIT_CODE} == *${STATUS_FILENAME}* ]]; then 50 if [ $LOGCAT ]; then $ADB $DEVICE_SERIAL logcat -d; fi 51 echo "***********************************************************************" 52 echo "ADB failed to retrieve the application's exit code" 53 echo "***********************************************************************" 54 exit 1 55fi 56 57echo "EXIT_CODE is ${EXIT_CODE}" 58if [ $'0\r' != "${EXIT_CODE}" ]; then 59 if [ $LOGCAT ]; then $ADB $DEVICE_SERIAL logcat -d; fi 60 exit 1 61fi 62exit 0 63