From 37eedc4bbe20d935337e4f2b31bb9857fbe86fa2 Mon Sep 17 00:00:00 2001 From: Justin SB Date: Fri, 3 Oct 2014 12:32:06 -0700 Subject: [PATCH] spawn, don't own, android tool for configure-android Probably should actually depend on which command we run --- tools/commands-cordova.js | 33 +++++++++++++++++++++++++++------ tools/processes.js | 11 +++++++++-- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/tools/commands-cordova.js b/tools/commands-cordova.js index 6333068872..e4d5a14d2b 100644 --- a/tools/commands-cordova.js +++ b/tools/commands-cordova.js @@ -1632,8 +1632,11 @@ _.extend(Android.prototype, { var androidToolPath = path.join(androidBundlePath, 'android-sdk', 'tools', 'android'); options = options || {}; - options.env = _.extend({}, process.env, { 'ANDROID_SDK_HOME': androidBundlePath }); + options.env = _.extend({}, process.env, options.env || {}, { 'ANDROID_SDK_HOME': androidBundlePath }); var cmd = new processes.RunCommand(androidToolPath, args, options); + if (options.detached) { + return cmd.start(); + } var execution = cmd.run(); if (execution.exitCode !== 0) { Console.warn("Unexpected exit code from android process: " + execution.exitCode); @@ -1663,6 +1666,11 @@ _.extend(Android.prototype, { return _.contains(self.listAvds(), avd); }, + getAvdName: function () { + var self = this; + return "meteor"; + }, + hasTarget: function (findApi, findArch) { var self = this; @@ -1696,6 +1704,15 @@ _.extend(Android.prototype, { startEmulator: function (avd, options) { var self = this; + if (!avd) { + avd = self.getAvdName(); + } + + if (!self.hasAvd(avd)) { + Console.error("'" + avd + "' android virtual device (AVD) does not exist"); + throw new Error("AVD not found: " + avd); + } + var androidBundlePath = self.getAndroidBundlePath(); // XXX: Use emulator64-x86? What difference does it make? @@ -1887,7 +1904,7 @@ _.extend(Android.prototype, { okay = fix; } - var avdName = 'meteor'; + var avdName = self.getAvdName(); if (self.hasAvd(avdName)) { log && Console.info(Console.success("'" + avdName + "' android virtual device (AVD) found")); } else { @@ -2027,13 +2044,17 @@ main.registerCommand({ maxArgs: Infinity }, function (options) { cordova.setVerboseness(options.verbose); + Console.setVerbose(options.verbose); requirePlatformReady('android'); - var androidArgs = options.args || []; + var runOptions = {}; + runOptions.detached = true; + runOptions.pipeOutput = true; + + var args = options.args || []; try { - var execOptions = { pipeOutput: true, verbose: options.verbose }; - execFileSyncOrThrow(localAndroid, androidArgs, execOptions); + Android.runAndroidTool(args, runOptions); } catch (err) { // this tool can crash for whatever reason, ignore its failures } @@ -2052,7 +2073,7 @@ main.registerCommand({ requirePlatformReady('android'); var args = options.args; - var avd = 'meteor'; + var avd = Android.getAvdName(); if (args.length) { avd = args[0]; } diff --git a/tools/processes.js b/tools/processes.js index 24e1862847..8525e5529f 100644 --- a/tools/processes.js +++ b/tools/processes.js @@ -34,9 +34,10 @@ _.extend(RunCommand.prototype, { throw new Error("Process already started"); } Console.debug("Running command", self.command, self.args.join(' ')); + self.process = child_process.spawn( self.command, - self.args, - self.options); + self.args, + self.options); self.process.on('close', function (exitCode) { self.exitCode = exitCode; @@ -54,10 +55,16 @@ _.extend(RunCommand.prototype, { self.process.stdout.on('data', function (data) { self.stdout = self.stdout + data; + if (self.options.pipeOutput) { + Console.stdout.write(data); + } }); self.process.stderr.on('data', function (data) { self.stderr = self.stderr + data; + if (self.options.pipeOutput) { + Console.stderr.write(data); + } }); self.stdin = self.process.stdin;