build/pgo/profileserver.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 #!/usr/bin/python
     2 #
     3 # This Source Code Form is subject to the terms of the Mozilla Public
     4 # License, v. 2.0. If a copy of the MPL was not distributed with this
     5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
     7 from mozprofile import FirefoxProfile, Profile, Preferences
     8 from mozprofile.permissions import ServerLocations
     9 from mozrunner import FirefoxRunner, CLI
    10 from mozhttpd import MozHttpd
    11 import json
    12 import socket
    13 import threading
    14 import os
    15 import sys
    16 import shutil
    17 import tempfile
    18 from datetime import datetime
    19 from mozbuild.base import MozbuildObject
    20 from buildconfig import substs
    22 PORT = 8888
    24 if __name__ == '__main__':
    25   cli = CLI()
    26   debug_args, interactive = cli.debugger_arguments()
    28   build = MozbuildObject.from_environment()
    29   httpd = MozHttpd(port=PORT,
    30                    docroot=os.path.join(build.topsrcdir, "build", "pgo"))
    31   httpd.start(block=False)
    33   locations = ServerLocations()
    34   locations.add_host(host='127.0.0.1',
    35                      port=PORT,
    36                      options='primary,privileged')
    38   #TODO: mozfile.TemporaryDirectory
    39   profilePath = tempfile.mkdtemp()
    40   try:
    41     #TODO: refactor this into mozprofile
    42     prefpath = os.path.join(build.topsrcdir, "testing", "profiles", "prefs_general.js")
    43     prefs = {}
    44     prefs.update(Preferences.read_prefs(prefpath))
    45     interpolation = { "server": "%s:%d" % httpd.httpd.server_address,
    46                       "OOP": "false"}
    47     prefs = json.loads(json.dumps(prefs) % interpolation)
    48     for pref in prefs:
    49       prefs[pref] = Preferences.cast(prefs[pref])
    50     profile = FirefoxProfile(profile=profilePath,
    51                              preferences=prefs,
    52                              addons=[os.path.join(build.distdir, 'xpi-stage', 'quitter')],
    53                              locations=locations)
    55     env = os.environ.copy()
    56     env["MOZ_CRASHREPORTER_NO_REPORT"] = "1"
    57     env["XPCOM_DEBUG_BREAK"] = "warn"
    59     # For VC12, make sure we can find the right bitness of pgort120.dll
    60     if "VS120COMNTOOLS" in env and not substs["HAVE_64BIT_OS"]:
    61       vc12dir = os.path.abspath(os.path.join(env["VS120COMNTOOLS"],
    62                                              "../../VC/bin"))
    63       if os.path.exists(vc12dir):
    64         env["PATH"] = vc12dir + ";" + env["PATH"]
    66     jarlog = os.getenv("JARLOG_FILE")
    67     if jarlog:
    68       env["MOZ_JAR_LOG_FILE"] = os.path.abspath(jarlog)
    69       print "jarlog: %s" % env["MOZ_JAR_LOG_FILE"]
    71     cmdargs = ["http://localhost:%d/index.html" % PORT]
    72     runner = FirefoxRunner(profile=profile,
    73                            binary=build.get_binary_path(where="staged-package"),
    74                            cmdargs=cmdargs,
    75                            env=env)
    76     runner.start(debug_args=debug_args, interactive=interactive)
    77     runner.wait()
    78     httpd.stop()
    79   finally:
    80     shutil.rmtree(profilePath)

mercurial