2013-08-06 20:32:29 +00:00
|
|
|
#!/bin/bash
|
2015-04-01 19:15:39 +00:00
|
|
|
###############################################################################
|
|
|
|
# Copyright 2015 Google Inc.
|
|
|
|
#
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
###############################################################################
|
2013-08-06 20:32:29 +00:00
|
|
|
#
|
|
|
|
# android_setup.sh: Sets environment variables used by other Android scripts.
|
|
|
|
|
2014-04-04 16:26:42 +00:00
|
|
|
# Fail-fast if anything in the script fails.
|
|
|
|
set -e
|
|
|
|
|
2016-12-01 19:37:41 +00:00
|
|
|
IS_DEBUG="false"
|
2014-04-04 16:26:42 +00:00
|
|
|
|
2013-08-06 20:32:29 +00:00
|
|
|
while (( "$#" )); do
|
2017-01-04 19:02:52 +00:00
|
|
|
if [[ "$1" == "-C" ]]; then
|
|
|
|
SKIA_OUT=$2
|
2013-08-06 20:32:29 +00:00
|
|
|
shift
|
2014-06-30 05:38:54 +00:00
|
|
|
elif [[ "$1" == "-i" || "$1" == "--resourcePath" ]]; then
|
|
|
|
RESOURCE_PATH=$2
|
|
|
|
APP_ARGS=("${APP_ARGS[@]}" "${1}" "${2}")
|
|
|
|
shift
|
2014-04-04 16:26:42 +00:00
|
|
|
elif [[ "$1" == "-s" ]]; then
|
2013-08-12 12:30:04 +00:00
|
|
|
DEVICE_SERIAL="-s $2"
|
|
|
|
shift
|
2015-01-22 18:43:34 +00:00
|
|
|
elif [[ "$1" == "--logcat" ]]; then
|
|
|
|
LOGCAT=1
|
2015-05-14 13:37:23 +00:00
|
|
|
elif [[ "$1" == "--verbose" ]]; then
|
2015-06-10 19:37:56 +00:00
|
|
|
VERBOSE="true"
|
2013-08-06 20:32:29 +00:00
|
|
|
else
|
2013-08-12 12:30:04 +00:00
|
|
|
APP_ARGS=("${APP_ARGS[@]}" "${1}")
|
2013-08-06 20:32:29 +00:00
|
|
|
fi
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2013-09-30 20:42:10 +00:00
|
|
|
function verbose {
|
2014-04-04 16:26:42 +00:00
|
|
|
if [[ -n $VERBOSE ]]; then
|
|
|
|
echo $@
|
|
|
|
fi
|
2013-09-30 20:42:10 +00:00
|
|
|
}
|
|
|
|
|
2013-04-29 12:09:31 +00:00
|
|
|
function exportVar {
|
|
|
|
NAME=$1
|
|
|
|
VALUE=$2
|
2013-09-30 20:42:10 +00:00
|
|
|
verbose export $NAME=\"$VALUE\"
|
2013-04-29 12:09:31 +00:00
|
|
|
export $NAME="$VALUE"
|
|
|
|
}
|
|
|
|
|
2014-04-04 16:26:42 +00:00
|
|
|
function absPath {
|
|
|
|
(cd $1; pwd)
|
|
|
|
}
|
|
|
|
|
2016-12-01 19:37:41 +00:00
|
|
|
UTIL_DIR=$(absPath "$(dirname "$BASH_SOURCE[0]}")")
|
2013-04-29 12:09:31 +00:00
|
|
|
|
|
|
|
if [ -z "$ANDROID_SDK_ROOT" ]; then
|
2014-04-04 16:26:42 +00:00
|
|
|
if ANDROID_SDK_ROOT="$(dirname $(which android))/.."; then
|
|
|
|
exportVar ANDROID_SDK_ROOT $ANDROID_SDK_ROOT
|
|
|
|
else
|
|
|
|
echo "No ANDROID_SDK_ROOT set and can't auto detect it from location of android binary."
|
|
|
|
exit 1
|
2013-04-29 12:09:31 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2016-12-01 19:37:41 +00:00
|
|
|
if [ -z "$ANDROID_NDK_ROOT" ]; then
|
|
|
|
if [ -d "${ANDROID_SDK_ROOT}/ndk-bundle" ]; then
|
|
|
|
exportVar ANDROID_NDK_ROOT ${ANDROID_SDK_ROOT}/ndk-bundle
|
|
|
|
else
|
|
|
|
echo "No ANDROID_NDK_ROOT set and can't auto detect it from location of SDK."
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-04-29 15:09:43 +00:00
|
|
|
fi
|
|
|
|
|
2013-06-27 13:43:04 +00:00
|
|
|
# adb_pull_if_needed(android_src, host_dst)
|
|
|
|
adb_pull_if_needed() {
|
2013-04-29 12:09:31 +00:00
|
|
|
|
2013-06-27 13:43:04 +00:00
|
|
|
# get adb location
|
|
|
|
source $SCRIPT_DIR/utils/setup_adb.sh
|
|
|
|
|
|
|
|
# read input params
|
|
|
|
ANDROID_SRC="$1"
|
|
|
|
HOST_DST="$2"
|
2013-04-29 12:09:31 +00:00
|
|
|
|
2013-07-11 13:57:29 +00:00
|
|
|
if [ -f $HOST_DST ];
|
2013-06-27 13:43:04 +00:00
|
|
|
then
|
2015-05-11 12:54:19 +00:00
|
|
|
#get the MD5 for dst and src depending on OS and/or OS revision
|
|
|
|
ANDROID_MD5_SUPPORT=`$ADB $DEVICE_SERIAL shell ls -ld /system/bin/md5`
|
|
|
|
if [ "${ANDROID_MD5_SUPPORT:0:15}" != "/system/bin/md5" ]; then
|
|
|
|
ANDROID_MD5=`$ADB $DEVICE_SERIAL shell md5 $ANDROID_DST`
|
|
|
|
else
|
|
|
|
ANDROID_MD5=`$ADB $DEVICE_SERIAL shell md5sum $ANDROID_DST`
|
|
|
|
fi
|
2013-09-11 16:56:20 +00:00
|
|
|
if [ $(uname) == "Darwin" ]; then
|
|
|
|
HOST_MD5=`md5 -q $HOST_DST`
|
|
|
|
else
|
|
|
|
HOST_MD5=`md5sum $HOST_DST`
|
|
|
|
fi
|
2013-06-27 13:43:04 +00:00
|
|
|
|
2014-04-04 16:26:42 +00:00
|
|
|
if [ "${ANDROID_MD5:0:32}" != "${HOST_MD5:0:32}" ]; then
|
|
|
|
echo -n "$HOST_DST "
|
2013-08-12 12:30:04 +00:00
|
|
|
$ADB $DEVICE_SERIAL pull $ANDROID_SRC $HOST_DST
|
2013-06-27 13:43:04 +00:00
|
|
|
fi
|
|
|
|
else
|
2014-04-04 16:26:42 +00:00
|
|
|
echo -n "$HOST_DST "
|
2013-08-12 12:30:04 +00:00
|
|
|
$ADB $DEVICE_SERIAL pull $ANDROID_SRC $HOST_DST
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# adb_push_if_needed(host_src, android_dst)
|
|
|
|
adb_push_if_needed() {
|
|
|
|
|
|
|
|
# get adb location
|
|
|
|
source $SCRIPT_DIR/utils/setup_adb.sh
|
|
|
|
|
|
|
|
# read input params
|
2014-06-30 05:38:54 +00:00
|
|
|
local HOST_SRC="$1"
|
|
|
|
local ANDROID_DST="$2"
|
2013-08-12 12:30:04 +00:00
|
|
|
|
2016-03-17 17:45:47 +00:00
|
|
|
# disable crashing on failed commands since newer (N+) versions of Android
|
|
|
|
# return an error when attempting to run ls on a directory or file that does
|
|
|
|
# not exist.
|
|
|
|
set +e
|
|
|
|
|
2013-08-12 12:30:04 +00:00
|
|
|
ANDROID_LS=`$ADB $DEVICE_SERIAL shell ls -ld $ANDROID_DST`
|
2014-06-30 05:38:54 +00:00
|
|
|
HOST_LS=`ls -ld $HOST_SRC`
|
|
|
|
if [ "${ANDROID_LS:0:1}" == "d" -a "${HOST_LS:0:1}" == "-" ];
|
2013-08-12 12:30:04 +00:00
|
|
|
then
|
|
|
|
ANDROID_DST="${ANDROID_DST}/$(basename ${HOST_SRC})"
|
|
|
|
fi
|
|
|
|
|
2016-03-17 17:45:47 +00:00
|
|
|
ANDROID_LS=`$ADB $DEVICE_SERIAL shell ls -ld $ANDROID_DST 2> /dev/null`
|
2014-04-04 16:26:42 +00:00
|
|
|
if [ "${ANDROID_LS:0:1}" == "-" ]; then
|
2015-05-11 12:54:19 +00:00
|
|
|
#get the MD5 for dst and src depending on OS and/or OS revision
|
2016-03-17 17:45:47 +00:00
|
|
|
ANDROID_MD5_SUPPORT=`$ADB $DEVICE_SERIAL shell ls -ld /system/bin/md5 2> /dev/null`
|
|
|
|
if [ "${ANDROID_MD5_SUPPORT:0:1}" == "-" ]; then
|
2015-05-11 12:54:19 +00:00
|
|
|
ANDROID_MD5=`$ADB $DEVICE_SERIAL shell md5 $ANDROID_DST`
|
|
|
|
else
|
|
|
|
ANDROID_MD5=`$ADB $DEVICE_SERIAL shell md5sum $ANDROID_DST`
|
|
|
|
fi
|
|
|
|
|
2013-09-11 16:56:20 +00:00
|
|
|
if [ $(uname) == "Darwin" ]; then
|
|
|
|
HOST_MD5=`md5 -q $HOST_SRC`
|
|
|
|
else
|
|
|
|
HOST_MD5=`md5sum $HOST_SRC`
|
|
|
|
fi
|
2013-08-12 12:30:04 +00:00
|
|
|
|
2014-04-04 16:26:42 +00:00
|
|
|
if [ "${ANDROID_MD5:0:32}" != "${HOST_MD5:0:32}" ]; then
|
|
|
|
echo -n "$ANDROID_DST "
|
2013-08-12 12:30:04 +00:00
|
|
|
$ADB $DEVICE_SERIAL push $HOST_SRC $ANDROID_DST
|
|
|
|
fi
|
2014-06-30 05:38:54 +00:00
|
|
|
elif [ "${ANDROID_LS:0:1}" == "d" ]; then
|
|
|
|
for FILE_ITEM in `ls $HOST_SRC`; do
|
|
|
|
adb_push_if_needed "${HOST_SRC}/${FILE_ITEM}" "${ANDROID_DST}/${FILE_ITEM}"
|
|
|
|
done
|
2013-08-12 12:30:04 +00:00
|
|
|
else
|
2014-06-30 05:38:54 +00:00
|
|
|
HOST_LS=`ls -ld $HOST_SRC`
|
|
|
|
if [ "${HOST_LS:0:1}" == "d" ]; then
|
|
|
|
$ADB $DEVICE_SERIAL shell mkdir -p $ANDROID_DST
|
|
|
|
adb_push_if_needed $HOST_SRC $ANDROID_DST
|
|
|
|
else
|
|
|
|
echo -n "$ANDROID_DST "
|
|
|
|
$ADB $DEVICE_SERIAL shell mkdir -p "$(dirname "$ANDROID_DST")"
|
|
|
|
$ADB $DEVICE_SERIAL push $HOST_SRC $ANDROID_DST
|
|
|
|
fi
|
2013-06-27 13:43:04 +00:00
|
|
|
fi
|
2016-03-17 17:45:47 +00:00
|
|
|
|
|
|
|
# turn error checking back on
|
|
|
|
set -e
|
2013-06-27 13:43:04 +00:00
|
|
|
}
|