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 6 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 7 source $SCRIPT_DIR/android_setup.sh 8 source $SCRIPT_DIR/utils/setup_adb.sh 9 10 if [ ! -f "${SKIA_OUT}/$BUILDTYPE/lib/lib${APP_ARGS[0]}.so" ]; 11 then 12 echo "Unable to find $BUILDTYPE ${APP_ARGS[0]} library" 13 exit 1 14 fi 15 16 verbose "pushing binaries onto the device..." 17 adb_push_if_needed "${SKIA_OUT}/$BUILDTYPE/skia_launcher" /data/local/tmp 18 if [ -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 21 fi 22 adb_push_if_needed "${SKIA_OUT}/$BUILDTYPE/lib/lib${APP_ARGS[0]}.so" /data/local/tmp 23 if [[ -n $RESOURCE_PATH ]]; then 24 verbose "pushing resources onto the device..." 25 adb_push_if_needed "${SKIA_SRC_DIR}/resources" $RESOURCE_PATH 26 fi 27 28 if [ $LOGCAT ]; then 29 verbose "clearing the device logs..." 30 $ADB $DEVICE_SERIAL logcat -c; 31 fi 32 STATUS_FILENAME="/data/local/tmp/.skia_tmp_$(date +%s%N)" 33 CMD_FILENAME=".skia_cmd_tmp_$(date +%s%N)" 34 echo "LD_LIBRARY_PATH=/data/local/tmp:$LD_LIBRARY_PATH \ 35 /data/local/tmp/skia_launcher ${APP_ARGS[*]}; \ 36 echo \$? > ${STATUS_FILENAME}" > ${CMD_FILENAME} 37 chmod +x ${CMD_FILENAME} 38 verbose "======== To reproduce this run: ========" 39 verbose "android_run_skia ${APP_ARGS[*]}" 40 verbose "========================================" 41 verbose "pushing command file onto the device..." 42 $ADB ${DEVICE_SERIAL} push ${CMD_FILENAME} /data/local/tmp 43 rm ${CMD_FILENAME} 44 verbose "preparing to run ${APP_ARGS[0]} on the device..." 45 $ADB ${DEVICE_SERIAL} shell sh /data/local/tmp/${CMD_FILENAME} 46 47 if [ -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 53 fi 54 55 EXIT_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 59 if [[ ${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 65 fi 66 67 echo "EXIT_CODE is ${EXIT_CODE}" 68 if [ $'0\r' != "${EXIT_CODE}" ]; then 69 if [ $LOGCAT ]; then $ADB $DEVICE_SERIAL logcat -d; fi 70 exit 1 71 fi 72 exit 0 73