[CB-3627] start-emulator now properly starts, waits for and unlocks an emulator, consumed by run as well.

This commit is contained in:
Fil Maj 2013-06-14 17:22:57 -07:00
parent c0a39570c9
commit 0efd9fcac0
3 changed files with 78 additions and 75 deletions

View File

@ -16,7 +16,7 @@
# specific language governing permissions and limitations # specific language governing permissions and limitations
# under the License. # under the License.
devices=`adb devices | awk '/List of devices attached/ { while(getline > 0) { print $1;}}' | grep 'emulator'` devices=`adb devices | awk '/List of devices attached/ { while(getline > 0) { print $1;}}' | grep 'emulator' | grep -v 'offline'`
read -ra emulator_list <<< "$devices" read -ra emulator_list <<< "$devices"
if [[ ${#emulator_list[@]} > 0 ]] ; then if [[ ${#emulator_list[@]} > 0 ]] ; then
for i in ${emulator_list[@]} for i in ${emulator_list[@]}
@ -26,7 +26,7 @@ if [[ ${#emulator_list[@]} > 0 ]] ; then
done done
exit 0 exit 0
else else
echo "No started emulators found, you can start an emulator by using the command" echo "No started emulators found (it may still be booting up), you can start an emulator by using the command"
echo " 'cordova/lib/start-emulator'" echo " 'cordova/lib/start-emulator'"
exit 2 exit 2
fi fi

View File

@ -18,6 +18,50 @@
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROJECT_PATH=$( cd "$( dirname "$0" )/../.." && pwd ) PROJECT_PATH=$( cd "$( dirname "$0" )/../.." && pwd )
function dot {
sleep 1
echo -n "."
}
function wait_for_emulator {
local i="0"
echo -n "Waiting for emulator"
emulator_string=$($DIR/list-started-emulators)
while [ $? != 0 ]
do
dot
i=$[i+1]
emulator_string=$($DIR/list-started-emulators)
done
read -ra target <<< "$emulator_string"
echo ""
echo -n "Waiting for it to boot up (this can take a while)"
while [ $i -lt 300 ]
do
boot_anim=$(adb -s $target shell getprop init.svc.bootanim 2>&1)
if [[ "$boot_anim" =~ "stopped" ]] ; then
break
else
i=$[i+1]
dot
fi
done
# Device timeout: emulator has not started in time
if [ $i -eq 300 ]
then
echo ""
echo "Emulator timeout!"
exit 69
else
echo ""
echo "Connected!"
fi
# Unlock the device
adb -s $target shell input keyevent 82
exit 0
}
emulator_images=$("$DIR/list-emulator-images") emulator_images=$("$DIR/list-emulator-images")
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "No emulators found, if you would like to create an emulator follow the instructions" echo "No emulators found, if you would like to create an emulator follow the instructions"
@ -43,3 +87,5 @@ else
#xterm -e emulator -avd ${emulator_list[0]} & #xterm -e emulator -avd ${emulator_list[0]} &
emulator -avd ${emulator_list[0]} 1> /dev/null 2>&1 & emulator -avd ${emulator_list[0]} 1> /dev/null 2>&1 &
fi fi
wait_for_emulator

View File

@ -19,66 +19,40 @@
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROJECT_PATH=$( cd "$DIR/.." && pwd ) PROJECT_PATH=$( cd "$DIR/.." && pwd )
function wait_for_emulator { function run_on_device_or_emulator {
# TODO: this doesnt seem to work devices=`$DIR/lib/list-devices`
emulator_string=$("$DIR/lib/list-started-emulators") if [ $? = 0 ]; then
old_started=($emulator_string) $DIR/lib/install-device
local new_started
local new_emulator_name
local i="0"
echo -n "Waiting for emulator..."
while [ $i -lt 300 ]
do
emulator_string=$("$DIR/lib/list-started-emulators")
new_started=($emulator_string)
if [[ ${#new_started[@]} > ${#old_started[@]} && -z "$new_emulator_name" ]] ; then
# get the name of the started emulator
local count="0"
if [[ ${#old_started[@]} == 0 ]] ; then
new_emulator_name=${new_started[$count]}
else
for count in {0...${#old_started[@]}}
do
if [[ ! ${new_started[$count]} == ${old_started[$count]} ]] ; then
new_emulator_name=${new_started[$count]}
fi
done
if [[ -z "$new_emulator_name" ]] ; then
count=$[count+1]
new_emulator_name=${new_started[$count]}
fi
fi
elif [[ "$new_emulator_name" ]] ; then
boot_anim=`adb -s $new_emulator_name shell getprop init.svc.bootanim`
if [[ $boot_anim =~ "stopped" ]] ; then
break
else
sleep 1
i=$[i+1]
echo -n "."
fi
else
sleep 1
i=$[i+1]
echo -n "."
fi
done
# Device timeout: emulator has not started in time
if [ $i -eq 300 ]
then
echo "emulator timeout!"
exit 69
else else
echo "connected!" run_on_emulator
fi fi
} }
function run_on_emulator {
emulators=`$DIR/lib/list-started-emulators`
if [ $? = 0 ] ; then
$DIR/lib/install-emulator
else
images=`$DIR/lib/list-emulator-images`
if [ $? = 0 ] ; then
$DIR/lib/start-emulator
$DIR/lib/install-emulator
else
echo "No devices/emulators started nor images available to start. How are we supposed to do this, then?"
exit 2
fi
fi
}
if [[ "$#" -eq 2 ]] ; then if [[ "$#" -eq 2 ]] ; then
# TODO: the order of arguments here may be reversed from the assumption below
$DIR/build $2 $DIR/build $2
if [[ $1 == "--device" ]] ; then if [[ $1 == "--device" ]] ; then
$DIR/lib/install-device $DIR/lib/install-device
elif [[ $1 == "--emulator" ]] ; then elif [[ $1 == "--emulator" ]] ; then
$DIR/lib/install-emulator run_on_emulator
elif [[ $1 =~ "--target=" ]]; then elif [[ $1 =~ "--target=" ]]; then
$DIR/lib/install-device $1 $DIR/lib/install-device $1
else else
@ -87,12 +61,13 @@ if [[ "$#" -eq 2 ]] ; then
elif [[ "$#" -eq 1 ]] ; then elif [[ "$#" -eq 1 ]] ; then
if [[ $1 == "--debug" || $1 == "--release" || $1 == "--nobuild" ]] ; then if [[ $1 == "--debug" || $1 == "--release" || $1 == "--nobuild" ]] ; then
$DIR/build $1 $DIR/build $1
run_on_device_or_emulator
elif [[ $1 == "--device" ]] ; then elif [[ $1 == "--device" ]] ; then
$DIR/build $DIR/build
$DIR/lib/install-device $DIR/lib/install-device
elif [[ $1 == "--emulator" ]] ; then elif [[ $1 == "--emulator" ]] ; then
$DIR/build #$DIR/build
$DIR/lib/install-emulator run_on_emulator
elif [[ $1 =~ "--target=" ]]; then elif [[ $1 =~ "--target=" ]]; then
$DIR/build $DIR/build
$DIR/lib/install-device $1 $DIR/lib/install-device $1
@ -101,24 +76,6 @@ elif [[ "$#" -eq 1 ]] ; then
fi fi
else else
echo "Warning : [ --device | --emulate | --target=<targetID> ] not specified, using defaults." echo "Warning : [ --device | --emulate | --target=<targetID> ] not specified, using defaults."
#$DIR/build $DIR/build
devices=$("$DIR/lib/list-devices") run_on_device_or_emulator
if [ $? = 0 ]; then
$DIR/lib/install-device
else
emulators=$("$DIR/lib/list-started-emulators")
if [ $? = 0 ] ; then
$DIR/lib/install-emulator
else
images=$("$DIR/lib/list-emulator-images")
if [ $? = 0 ] ; then
$DIR/lib/start-emulator
wait_for_emulator
$DIR/lib/install-emulator
else
echo "No Android devices attached, nor emulator images available to start. How are we supposed to do this, then?"
exit 2
fi
fi
fi
fi fi