Repository: cordova-medic
Updated Branches:
  refs/heads/master 50770495d -> 50d20dca3


CB-10474: Fix medic-log behavior for cordova-ios. Adding --app flag to 
medic-log for iOS. This closes #73.


Project: http://git-wip-us.apache.org/repos/asf/cordova-medic/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-medic/commit/50d20dca
Tree: http://git-wip-us.apache.org/repos/asf/cordova-medic/tree/50d20dca
Diff: http://git-wip-us.apache.org/repos/asf/cordova-medic/diff/50d20dca

Branch: refs/heads/master
Commit: 50d20dca3173fd658c09b104c086b81c4ef64163
Parents: 5077049
Author: Richard Knoll <[email protected]>
Authored: Thu Jan 28 17:18:22 2016 -0800
Committer: Dmitry Blotsky <[email protected]>
Committed: Wed Feb 3 19:39:23 2016 -0800

----------------------------------------------------------------------
 buildbot-conf/cordova.conf |  1 +
 medic/medic-log.js         | 82 +++++++++++++++++++++++++++++++++++++----
 2 files changed, 75 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/50d20dca/buildbot-conf/cordova.conf
----------------------------------------------------------------------
diff --git a/buildbot-conf/cordova.conf b/buildbot-conf/cordova.conf
index 569ac3d..b8b3962 100644
--- a/buildbot-conf/cordova.conf
+++ b/buildbot-conf/cordova.conf
@@ -368,6 +368,7 @@ def cordova_steps_run_tests(platform, extra_args=list()):
                 'cordova-medic/medic/medic.js',
                 'log',
                 '--platform', platform,
+                '--app',     TEST_APP_NAME,
                 '--timeout', TEST_RUN_TIMEOUT
             ],
             description    = 'gathering logs',

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/50d20dca/medic/medic-log.js
----------------------------------------------------------------------
diff --git a/medic/medic-log.js b/medic/medic-log.js
index be63209..8432697 100644
--- a/medic/medic-log.js
+++ b/medic/medic-log.js
@@ -33,6 +33,7 @@ var util = require("../lib/util");
 // constants
 var DEVICE_ROW_PATTERN = /(emulator|device|host)/m;
 var HEADING_LINE_PATTERN = /List of devices/m;
+var DEFAULT_APP_PATH = "mobilespec";
 
 // helpers
 function logAndroid() {
@@ -69,18 +70,72 @@ function logBlackberry() {
     return;
 }
 
-function logIOS() {
-    var logScriptpath = path.join("mobilespec", "platforms", "ios", "cordova", 
"console.log");
-    var command = "cat " + logScriptpath;
+function logIOS(appPath) {
+    // We need to print out the system log for the simulator app. In order to 
figure
+    // out the path to that file, we need to find the ID of the simulator 
running
+    // mobilespec
+
+    // First, figure out the simulator that ran mobilespec. "cordova run"" 
just chooses
+    // the last simulator in this list that starts with the word "iPhone"
+    shelljs.pushd(appPath);
+
+    var findSimCommand = getLocalCLI() + " run --list --emulator | grep 
^iPhone | tail -n1";
 
     util.medicLog("running:");
-    util.medicLog("    " + command);
+    util.medicLog("    " + findSimCommand);
 
-    shelljs.exec(command, function (code, output) {
-        if (code > 0) {
-            util.fatal("Failed to run log command.");
+    var findSimResult = shelljs.exec(findSimCommand);
+
+    if (findSimResult.code > 0) {
+        util.fatal("Failed to find simulator we deployed to");
+        return;
+    }
+
+    var split = findSimResult.output.split(", ");
+
+    // Format of the output is "iPhone-6s-Plus, 9.1"
+    // Extract the device name and the version number
+    var device = split[0].replace(/-/g, " ").trim();
+    var version = split[1].trim();
+
+    // Next, figure out the ID of the simulator we found
+    var instrCommand = "instruments -s devices | grep ^iPhone";
+    util.medicLog("running:");
+    util.medicLog("    " + instrCommand);
+
+    var instrResult = shelljs.exec(instrCommand);
+
+    if (instrResult.code > 0) {
+        util.fatal("Failed to get the list of simulators");
+        return;
+    }
+
+    // This matches <device> (<version>) [<simulator-id>]
+    var simIdRegex = /^([a-zA-Z\d ]+) \(([\d.]+)\) \[([a-zA-Z\d\-]*)\]$/;
+
+    var simId = null;
+    var lines = instrResult.output.split(/\n/);
+    lines.forEach(function(line) {
+        var simIdMatch = simIdRegex.exec(line);
+        if (simIdMatch && simIdMatch.length === 4 && simIdMatch[1] === device 
&& simIdMatch[2] === version) {
+            simId = encodeURIComponent(simIdMatch[3]);
         }
     });
+
+    if (simId) {
+        // Now we can print out the log file
+        var logPath = path.join("~", "Library", "Logs", "CoreSimulator", 
simId, "system.log");
+        var logCommand = "cat " + logPath;
+
+        util.medicLog("Attempting to print the iOS simulator system log");
+
+        var logResult = shelljs.exec(logCommand);
+        if (logResult.code > 0) {
+            util.fatal("Failed to cat the simulator log");
+        }
+    } else {
+        util.fatal("Failed to find ID of mobilespec simulator");
+    }
 }
 
 function logWindows(timeout) {
@@ -102,6 +157,14 @@ function logWP8() {
     return;
 }
 
+function getLocalCLI() {
+    if (util.isWindows()) {
+        return "cordova.bat";
+    } else {
+        return "./cordova";
+    }
+}
+
 // main
 function main() {
 
@@ -113,12 +176,15 @@ function main() {
     var argv = optimist
         .usage("Usage: $0 [options]")
         .demand("platform")
+        .default("app", DEFAULT_APP_PATH)
         .describe("platform", "Gather logs for this platform.")
+        .describe("app", "iOS only, path to a Cordova Application.")
         .describe("timeout", "Windows only, gather logs for last n seconds.")
         .argv;
 
     var platform = argv.platform;
     var timeout = argv.timeout;
+    var appPath = argv.app ? argv.app : DEFAULT_APP_PATH;
 
     switch (platform) {
         case util.ANDROID:
@@ -128,7 +194,7 @@ function main() {
             logBlackberry();
             break;
         case util.IOS:
-            logIOS();
+            logIOS(appPath);
             break;
         case util.WINDOWS:
             logWindows(timeout);


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to