[CB-4495] Modify start-emulator script to exit immediately on a fatal emulator error. (cherry picked from commit 121b74fa0c8b5c2aea25173d128b5745c3b85390)
Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/bb7bc33a Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/bb7bc33a Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/bb7bc33a Branch: refs/heads/2.9.x Commit: bb7bc33a8ab2a12bcd5540b4b6420b47a9ee76c9 Parents: 64c617d Author: Tomaz Muraus <[email protected]> Authored: Sat Aug 3 02:52:48 2013 +0200 Committer: Andrew Grieve <[email protected]> Committed: Tue Oct 22 15:15:58 2013 -0400 ---------------------------------------------------------------------- bin/templates/cordova/lib/start-emulator | 30 ++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-android/blob/bb7bc33a/bin/templates/cordova/lib/start-emulator ---------------------------------------------------------------------- diff --git a/bin/templates/cordova/lib/start-emulator b/bin/templates/cordova/lib/start-emulator index 10e73ce..c7ce01a 100755 --- a/bin/templates/cordova/lib/start-emulator +++ b/bin/templates/cordova/lib/start-emulator @@ -24,7 +24,24 @@ function dot { echo -n "." } -function wait_for_emulator { +function wait_for_emulator() { + local emulator_log_path="$1" + local error_string + local status + + # Try to detect fatal errors early + sleep 1.5 + error_string=$(grep -F "ERROR: " ${emulator_log_path}) + status=$? + + if [ $status -eq 0 ]; then + echo "Emulator failed to start, fatal error detected" + echo "Error: ${error_string}" + echo "Full log available at: ${emulator_log_path}" + echo "Exiting..." + exit 1 + fi + local i="0" echo -n "Waiting for emulator" emulator_string=$($DIR/list-started-emulators) @@ -70,22 +87,25 @@ if [ $? != 0 ]; then exit 2 fi +# start first emulator +log_path=$(mktemp -t android_emulator) + # if target emulator is provided if [[ "$#" -eq 1 ]] ; then # check that it exists if [[ $emulator_images =~ $1 ]] ; then #xterm -e emulator -avd $1 & - emulator -avd $1 1> /dev/null 2>&1 & + emulator -avd $1 1> "${log_path}" 2>&1 & else echo "Could not find the provided emulator '$1', make sure the emulator exists" echo " by checking 'cordova/lib/list-emulator-images'" exit 2 fi else - # start first emulator read -ra emulator_list <<< "$emulator_images" #xterm -e emulator -avd ${emulator_list[0]} & - emulator -avd ${emulator_list[0]} 1> /dev/null 2>&1 & + emulator -avd ${emulator_list[0]} 1> "${log_path}" 2>&1 & fi -wait_for_emulator +echo "Saving emulator log to: ${log_path}" +wait_for_emulator "$log_path"
