Bug 1353656 - Use SubProcess.jsm from WebIDE instead of SDK equivalent. r=jryans draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Mon, 24 Jul 2017 19:23:09 +0200
changeset 616171 a1d20d14a167201d79fda735bdf9a094bbd214f1
parent 615779 e8400551c2e39f24c75a009ebed496c7acd7bf47
child 616172 977091e8a575f79f25855f3f91fb4ec7383bb7a0
push id70619
push userbmo:poirot.alex@gmail.com
push dateWed, 26 Jul 2017 20:27:55 +0000
reviewersjryans
bugs1353656
milestone56.0a1
Bug 1353656 - Use SubProcess.jsm from WebIDE instead of SDK equivalent. r=jryans MozReview-Commit-ID: Lu0Ptuhopxh
devtools/client/webide/modules/simulator-process.js
--- a/devtools/client/webide/modules/simulator-process.js
+++ b/devtools/client/webide/modules/simulator-process.js
@@ -5,19 +5,20 @@
 
 "use strict";
 
 const { Cc, Ci, Cu } = require("chrome");
 
 const Environment = Cc["@mozilla.org/process/environment;1"]
                       .getService(Ci.nsIEnvironment);
 const EventEmitter = require("devtools/shared/event-emitter");
-const Subprocess = require("sdk/system/child_process/subprocess");
 const Services = require("Services");
 
+const {Subprocess} = Cu.import("resource://gre/modules/Subprocess.jsm", {});
+
 loader.lazyGetter(this, "OS", () => {
   switch (Services.appinfo.OS) {
     case "Darwin":
       return "mac64";
     case "Linux":
       if (Services.appinfo.XPCOMABI.indexOf("x86_64") === 0) {
         return "linux64";
       } else {
@@ -80,29 +81,40 @@ SimulatorProcess.prototype = {
       ["DISPLAY", "XAUTHORITY"]
         .filter(key => Environment.exists(key))
         .forEach(key => {
           environment.push(key + "=" + Environment.get(key));
         });
     }
 
     // Spawn a B2G instance.
-    this.process = Subprocess.call({
-      command: b2g,
+    Subprocess.call({
+      command: b2g.path,
       arguments: this.args,
+      environmentAppend: true,
       environment: environment,
-      stdout: data => this.emit("stdout", data),
-      stderr: data => this.emit("stderr", data),
+      stderr: "pipe",
+    }).then(process => {
+      this.process = process;
+      let dumpPipe = async (pipe, type) => {
+        let data = await pipe.readString();
+        while (data) {
+          this.emit(type, data);
+          data = await pipe.readString();
+        }
+      };
+      dumpPipe(process.stdout, "stdout");
+      dumpPipe(process.stderr, "stderr");
+
       // On B2G instance exit, reset tracked process, remote debugger port and
       // shuttingDown flag, then finally emit an exit event.
-      done: result => {
-        console.log("B2G terminated with " + result.exitCode);
+      process.wait().then(result => {
         this.process = null;
         this.emit("exit", result.exitCode);
-      }
+      });
     });
   },
 
   // Request a B2G instance kill.
   kill() {
     return new Promise(resolve => {
       if (this.process) {
         this.once("exit", (e, exitCode) => {