mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-07 18:04:46 +00:00
Bug 1132452 - Remove useless JS files from FxOS simulator addon. r=jryans
This commit is contained in:
parent
6e07fc601b
commit
f585881d65
@ -10,7 +10,6 @@
|
||||
# - retrieve usefull app version metadata from the build system
|
||||
# - finally, use addon sdk's cfx tool to build the addon xpi
|
||||
# that ships:
|
||||
# * a small firefox addon registering to the app manager
|
||||
# * b2g desktop runtime
|
||||
# * gaia profile
|
||||
|
||||
@ -126,19 +125,10 @@ def main(platform):
|
||||
app_buildid,
|
||||
update_url)
|
||||
|
||||
options_file = os.path.join(build.topobjdir, "b2g", "simulator", "options.xul")
|
||||
preprocess_file(os.path.join(srcdir, "options.xul.in"),
|
||||
options_file,
|
||||
version,
|
||||
app_buildid,
|
||||
update_url)
|
||||
|
||||
with JarWriter(xpi_path, optimize=False) as zip:
|
||||
# Ship addon files into the .xpi
|
||||
add_dir_to_zip(zip, os.path.join(srcdir, "lib"), "lib")
|
||||
add_file_to_zip(zip, manifest, "install.rdf")
|
||||
add_file_to_zip(zip, os.path.join(srcdir, "bootstrap.js"), "bootstrap.js")
|
||||
add_file_to_zip(zip, options_file, "options.xul")
|
||||
add_file_to_zip(zip, os.path.join(srcdir, "icon.png"), "icon.png")
|
||||
add_file_to_zip(zip, os.path.join(srcdir, "icon64.png"), "icon64.png")
|
||||
|
||||
|
@ -1,92 +0,0 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
const { Cc, Ci, Cu } = require("chrome");
|
||||
|
||||
const { AddonManager } = Cu.import("resource://gre/modules/AddonManager.jsm", {});
|
||||
const { Promise: promise } = Cu.import("resource://gre/modules/Promise.jsm", {});
|
||||
const { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
|
||||
const { Simulator } = Cu.import("resource://gre/modules/devtools/shared/apps/Simulator.jsm");
|
||||
const { SimulatorProcess } = require("./simulator-process");
|
||||
const Runtime = require("sdk/system/runtime");
|
||||
const URL = require("sdk/url");
|
||||
|
||||
const ROOT_URI = require("addon").uri;
|
||||
const PROFILE_URL = ROOT_URI + "profile/";
|
||||
const BIN_URL = ROOT_URI + "b2g/";
|
||||
|
||||
var process;
|
||||
|
||||
function launch(options) {
|
||||
// Close already opened simulation.
|
||||
if (process) {
|
||||
return close().then(launch.bind(null, options));
|
||||
}
|
||||
|
||||
// Compute B2G runtime path.
|
||||
let path;
|
||||
try {
|
||||
let pref = "extensions." + require("addon").id + ".customRuntime";
|
||||
path = Services.prefs.getComplexValue(pref, Ci.nsIFile);
|
||||
} catch(e) {}
|
||||
|
||||
if (!path) {
|
||||
let executables = {
|
||||
WINNT: "b2g-bin.exe",
|
||||
Darwin: "B2G.app/Contents/MacOS/b2g-bin",
|
||||
Linux: "b2g-bin",
|
||||
};
|
||||
path = URL.toFilename(BIN_URL);
|
||||
path += Runtime.OS == "WINNT" ? "\\" : "/";
|
||||
path += executables[Runtime.OS];
|
||||
}
|
||||
options.runtimePath = path;
|
||||
console.log("simulator path:", options.runtimePath);
|
||||
|
||||
// Compute Gaia profile path.
|
||||
if (!options.profilePath) {
|
||||
let gaiaProfile;
|
||||
try {
|
||||
let pref = "extensions." + require("addon").id + ".gaiaProfile";
|
||||
gaiaProfile = Services.prefs.getComplexValue(pref, Ci.nsIFile).path;
|
||||
} catch(e) {}
|
||||
|
||||
options.profilePath = gaiaProfile || URL.toFilename(PROFILE_URL);
|
||||
}
|
||||
|
||||
process = new SimulatorProcess(options);
|
||||
process.run();
|
||||
|
||||
return promise.resolve();
|
||||
}
|
||||
|
||||
function close() {
|
||||
if (!process) {
|
||||
return promise.resolve();
|
||||
}
|
||||
let p = process;
|
||||
process = null;
|
||||
return p.kill();
|
||||
}
|
||||
|
||||
var name;
|
||||
|
||||
AddonManager.getAddonByID(require("addon").id, function (addon) {
|
||||
name = addon.name.replace(" Simulator", "");
|
||||
|
||||
Simulator.register(name, {
|
||||
// We keep the deprecated `appinfo` object so that recent simulator addons
|
||||
// remain forward-compatible with older Firefox.
|
||||
appinfo: { label: name },
|
||||
launch: launch,
|
||||
close: close
|
||||
});
|
||||
});
|
||||
|
||||
exports.shutdown = function () {
|
||||
Simulator.unregister(name);
|
||||
close();
|
||||
}
|
||||
|
@ -1,165 +0,0 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const { Cc, Ci, Cu, ChromeWorker } = require("chrome");
|
||||
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const Environment = require("sdk/system/environment").env;
|
||||
const Runtime = require("sdk/system/runtime");
|
||||
const Subprocess = require("sdk/system/child_process/subprocess");
|
||||
const { Promise: promise } = Cu.import("resource://gre/modules/Promise.jsm", {});
|
||||
const { EventEmitter } = Cu.import("resource://gre/modules/devtools/shared/event-emitter.js", {});
|
||||
|
||||
|
||||
// Log subprocess error and debug messages to the console. This logs messages
|
||||
// for all consumers of the API. We trim the messages because they sometimes
|
||||
// have trailing newlines. And note that registerLogHandler actually registers
|
||||
// an error handler, despite its name.
|
||||
Subprocess.registerLogHandler(
|
||||
s => console.error("subprocess: " + s.trim())
|
||||
);
|
||||
Subprocess.registerDebugHandler(
|
||||
s => console.debug("subprocess: " + s.trim())
|
||||
);
|
||||
|
||||
function SimulatorProcess(options) {
|
||||
this.options = options;
|
||||
|
||||
EventEmitter.decorate(this);
|
||||
this.on("stdout", (e, data) => { console.log(data.trim()) });
|
||||
this.on("stderr", (e, data) => { console.error(data.trim()) });
|
||||
}
|
||||
|
||||
SimulatorProcess.prototype = {
|
||||
|
||||
// check if b2g is running
|
||||
get isRunning() {
|
||||
return !!this.process;
|
||||
},
|
||||
|
||||
/**
|
||||
* Start the process and connect the debugger client.
|
||||
*/
|
||||
run: function() {
|
||||
// kill before start if already running
|
||||
if (this.process != null) {
|
||||
this.process
|
||||
.kill()
|
||||
.then(this.run.bind(this));
|
||||
return;
|
||||
}
|
||||
|
||||
// resolve b2g binaries path (raise exception if not found)
|
||||
let b2gExecutable = this.b2gExecutable;
|
||||
|
||||
this.once("stdout", function () {
|
||||
if (Runtime.OS == "Darwin") {
|
||||
console.debug("WORKAROUND run osascript to show b2g-desktop window"+
|
||||
" on Runtime.OS=='Darwin'");
|
||||
// Escape double quotes and escape characters for use in AppleScript.
|
||||
let path = b2gExecutable.path
|
||||
.replace(/\\/g, "\\\\").replace(/\"/g, '\\"');
|
||||
|
||||
Subprocess.call({
|
||||
command: "/usr/bin/osascript",
|
||||
arguments: ["-e", 'tell application "' + path + '" to activate'],
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
let environment;
|
||||
if (Runtime.OS == "Linux") {
|
||||
environment = ["TMPDIR=" + Services.dirsvc.get("TmpD", Ci.nsIFile).path];
|
||||
if ("DISPLAY" in Environment) {
|
||||
environment.push("DISPLAY=" + Environment.DISPLAY);
|
||||
}
|
||||
}
|
||||
|
||||
// spawn a b2g instance
|
||||
this.process = Subprocess.call({
|
||||
command: b2gExecutable,
|
||||
arguments: this.b2gArguments,
|
||||
environment: environment,
|
||||
|
||||
// emit stdout event
|
||||
stdout: data => {
|
||||
this.emit("stdout", data);
|
||||
},
|
||||
|
||||
// emit stderr event
|
||||
stderr: data => {
|
||||
this.emit("stderr", data);
|
||||
},
|
||||
|
||||
// on b2g instance exit, reset tracked process, remote debugger port and
|
||||
// shuttingDown flag, then finally emit an exit event
|
||||
done: (function(result) {
|
||||
console.log("B2G terminated with " + result.exitCode);
|
||||
this.process = null;
|
||||
this.emit("exit", result.exitCode);
|
||||
}).bind(this)
|
||||
});
|
||||
},
|
||||
|
||||
// request a b2g instance kill
|
||||
kill: function() {
|
||||
let deferred = promise.defer();
|
||||
if (this.process) {
|
||||
this.once("exit", (e, exitCode) => {
|
||||
this.shuttingDown = false;
|
||||
deferred.resolve(exitCode);
|
||||
});
|
||||
if (!this.shuttingDown) {
|
||||
this.shuttingDown = true;
|
||||
this.emit("kill", null);
|
||||
this.process.kill();
|
||||
}
|
||||
return deferred.promise;
|
||||
} else {
|
||||
return promise.resolve(undefined);
|
||||
}
|
||||
},
|
||||
|
||||
// compute current b2g file handle
|
||||
get b2gExecutable() {
|
||||
if (this._executable) {
|
||||
return this._executable;
|
||||
}
|
||||
|
||||
let executable = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
|
||||
executable.initWithPath(this.options.runtimePath);
|
||||
|
||||
if (!executable.exists()) {
|
||||
// B2G binaries not found
|
||||
throw Error("b2g-desktop Executable not found.");
|
||||
}
|
||||
|
||||
this._executable = executable;
|
||||
|
||||
return executable;
|
||||
},
|
||||
|
||||
// compute b2g CLI arguments
|
||||
get b2gArguments() {
|
||||
let args = [];
|
||||
|
||||
let profile = this.options.profilePath;
|
||||
args.push("-profile", profile);
|
||||
console.log("profile", profile);
|
||||
|
||||
// NOTE: push dbgport option on the b2g-desktop commandline
|
||||
args.push("-start-debugger-server", "" + this.options.port);
|
||||
|
||||
// Ignore eventual zombie instances of b2g that are left over
|
||||
args.push("-no-remote");
|
||||
|
||||
return args;
|
||||
},
|
||||
};
|
||||
|
||||
exports.SimulatorProcess = SimulatorProcess;
|
@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" ?>
|
||||
<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
<setting pref="extensions.@ADDON_ID@.gaiaProfile" type="directory" title="Select a custom Gaia profile directory"/>
|
||||
<setting pref="extensions.@ADDON_ID@.customRuntime" type="file" title="Select a custom runtime executable"/>
|
||||
</vbox>
|
Loading…
Reference in New Issue
Block a user