You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/08/15 17:49:44 UTC

[2/2] android commit: [CB-4495] Modify start-emulator script to exit immediately on a fatal emulator error.

[CB-4495] Modify start-emulator script to exit immediately on a fatal emulator error.


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/121b74fa
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/121b74fa
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/121b74fa

Branch: refs/heads/master
Commit: 121b74fa0c8b5c2aea25173d128b5745c3b85390
Parents: 5451320
Author: Tomaz Muraus <to...@tomaz.me>
Authored: Sat Aug 3 02:52:48 2013 +0200
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Thu Aug 15 11:46:50 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/121b74fa/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"