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 16verbose "pushing binaries onto the device..." 17adb_push_if_needed "${SKIA_OUT}/$BUILDTYPE/skia_launcher" /data/local/tmp 18if [ -f "${SKIA_OUT}/$BUILDTYPE/lib/libskia_android.so" ]; then 19 # Does not exist for builds with static skia. 20 adb_push_if_needed "${SKIA_OUT}/$BUILDTYPE/lib/libskia_android.so" /data/local/tmp 21fi 22adb_push_if_needed "${SKIA_OUT}/$BUILDTYPE/lib/lib${APP_ARGS[0]}.so" /data/local/tmp 23if [[ -n $RESOURCE_PATH ]]; then 24 verbose "pushing resources onto the device..." 25 adb_push_if_needed "${SKIA_SRC_DIR}/resources" $RESOURCE_PATH 26fi 27 28if [ $LOGCAT ]; then 29 verbose "clearing the device logs..." 30 $ADB $DEVICE_SERIAL logcat -c; 31fi 32STATUS_FILENAME="/data/local/tmp/.skia_tmp_$(date +%s%N)" 33CMD_FILENAME=".skia_cmd_tmp_$(date +%s%N)" 34echo "LD_LIBRARY_PATH=/data/local/tmp:$LD_LIBRARY_PATH \ 35 /data/local/tmp/skia_launcher ${APP_ARGS[*]}; \ 36 echo \$? > ${STATUS_FILENAME}" > ${CMD_FILENAME} 37chmod +x ${CMD_FILENAME} 38verbose "======== To reproduce this run: ========" 39verbose "android_run_skia ${APP_ARGS[*]}" 40verbose "========================================" 41verbose "pushing command file onto the device..." 42$ADB ${DEVICE_SERIAL} push ${CMD_FILENAME} /data/local/tmp 43rm ${CMD_FILENAME} 44verbose "preparing to run ${APP_ARGS[0]} on the device..." 45$ADB ${DEVICE_SERIAL} shell sh /data/local/tmp/${CMD_FILENAME} 46 47if [ -z "$($ADB $DEVICE_SERIAL shell 'if [ -f $STATUS_FILENAME ]; then echo exists; fi')" ]; then 48 if [ $LOGCAT ]; then $ADB $DEVICE_SERIAL logcat -d; fi 49 echo "***********************************************************************" 50 echo "The application terminated unexpectedly and did not produce an exit code" 51 echo "***********************************************************************" 52 exit 1 53fi 54 55EXIT_CODE=`$ADB ${DEVICE_SERIAL} shell cat ${STATUS_FILENAME}` 56$ADB ${DEVICE_SERIAL} shell rm -f ${STATUS_FILENAME} ${CMD_FILENAME} 57 58# check to see if the 'cat' command failed and print errors accordingly 59if [[ ${EXIT_CODE} == *${STATUS_FILENAME}* ]]; then 60 if [ $LOGCAT ]; then $ADB $DEVICE_SERIAL logcat -d; fi 61 echo "***********************************************************************" 62 echo "ADB failed to retrieve the application's exit code" 63 echo "***********************************************************************" 64 exit 1 65fi 66 67echo "EXIT_CODE is ${EXIT_CODE}" 68if [ $'0\r' != "${EXIT_CODE}" ]; then 69 if [ $LOGCAT ]; then $ADB $DEVICE_SERIAL logcat -d; fi 70 exit 1 71fi 72exit 0 73