michael@0: #!/usr/bin/python michael@0: # michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: from mozprofile import FirefoxProfile, Profile, Preferences michael@0: from mozprofile.permissions import ServerLocations michael@0: from mozrunner import FirefoxRunner, CLI michael@0: from mozhttpd import MozHttpd michael@0: import json michael@0: import socket michael@0: import threading michael@0: import os michael@0: import sys michael@0: import shutil michael@0: import tempfile michael@0: from datetime import datetime michael@0: from mozbuild.base import MozbuildObject michael@0: from buildconfig import substs michael@0: michael@0: PORT = 8888 michael@0: michael@0: if __name__ == '__main__': michael@0: cli = CLI() michael@0: debug_args, interactive = cli.debugger_arguments() michael@0: michael@0: build = MozbuildObject.from_environment() michael@0: httpd = MozHttpd(port=PORT, michael@0: docroot=os.path.join(build.topsrcdir, "build", "pgo")) michael@0: httpd.start(block=False) michael@0: michael@0: locations = ServerLocations() michael@0: locations.add_host(host='127.0.0.1', michael@0: port=PORT, michael@0: options='primary,privileged') michael@0: michael@0: #TODO: mozfile.TemporaryDirectory michael@0: profilePath = tempfile.mkdtemp() michael@0: try: michael@0: #TODO: refactor this into mozprofile michael@0: prefpath = os.path.join(build.topsrcdir, "testing", "profiles", "prefs_general.js") michael@0: prefs = {} michael@0: prefs.update(Preferences.read_prefs(prefpath)) michael@0: interpolation = { "server": "%s:%d" % httpd.httpd.server_address, michael@0: "OOP": "false"} michael@0: prefs = json.loads(json.dumps(prefs) % interpolation) michael@0: for pref in prefs: michael@0: prefs[pref] = Preferences.cast(prefs[pref]) michael@0: profile = FirefoxProfile(profile=profilePath, michael@0: preferences=prefs, michael@0: addons=[os.path.join(build.distdir, 'xpi-stage', 'quitter')], michael@0: locations=locations) michael@0: michael@0: env = os.environ.copy() michael@0: env["MOZ_CRASHREPORTER_NO_REPORT"] = "1" michael@0: env["XPCOM_DEBUG_BREAK"] = "warn" michael@0: michael@0: # For VC12, make sure we can find the right bitness of pgort120.dll michael@0: if "VS120COMNTOOLS" in env and not substs["HAVE_64BIT_OS"]: michael@0: vc12dir = os.path.abspath(os.path.join(env["VS120COMNTOOLS"], michael@0: "../../VC/bin")) michael@0: if os.path.exists(vc12dir): michael@0: env["PATH"] = vc12dir + ";" + env["PATH"] michael@0: michael@0: jarlog = os.getenv("JARLOG_FILE") michael@0: if jarlog: michael@0: env["MOZ_JAR_LOG_FILE"] = os.path.abspath(jarlog) michael@0: print "jarlog: %s" % env["MOZ_JAR_LOG_FILE"] michael@0: michael@0: cmdargs = ["http://localhost:%d/index.html" % PORT] michael@0: runner = FirefoxRunner(profile=profile, michael@0: binary=build.get_binary_path(where="staged-package"), michael@0: cmdargs=cmdargs, michael@0: env=env) michael@0: runner.start(debug_args=debug_args, interactive=interactive) michael@0: runner.wait() michael@0: httpd.stop() michael@0: finally: michael@0: shutil.rmtree(profilePath)