build/pgo/profileserver.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/build/pgo/profileserver.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,80 @@
     1.4 +#!/usr/bin/python
     1.5 +#
     1.6 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.7 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.9 +
    1.10 +from mozprofile import FirefoxProfile, Profile, Preferences
    1.11 +from mozprofile.permissions import ServerLocations
    1.12 +from mozrunner import FirefoxRunner, CLI
    1.13 +from mozhttpd import MozHttpd
    1.14 +import json
    1.15 +import socket
    1.16 +import threading
    1.17 +import os
    1.18 +import sys
    1.19 +import shutil
    1.20 +import tempfile
    1.21 +from datetime import datetime
    1.22 +from mozbuild.base import MozbuildObject
    1.23 +from buildconfig import substs
    1.24 +
    1.25 +PORT = 8888
    1.26 +
    1.27 +if __name__ == '__main__':
    1.28 +  cli = CLI()
    1.29 +  debug_args, interactive = cli.debugger_arguments()
    1.30 +
    1.31 +  build = MozbuildObject.from_environment()
    1.32 +  httpd = MozHttpd(port=PORT,
    1.33 +                   docroot=os.path.join(build.topsrcdir, "build", "pgo"))
    1.34 +  httpd.start(block=False)
    1.35 +
    1.36 +  locations = ServerLocations()
    1.37 +  locations.add_host(host='127.0.0.1',
    1.38 +                     port=PORT,
    1.39 +                     options='primary,privileged')
    1.40 +
    1.41 +  #TODO: mozfile.TemporaryDirectory
    1.42 +  profilePath = tempfile.mkdtemp()
    1.43 +  try:
    1.44 +    #TODO: refactor this into mozprofile
    1.45 +    prefpath = os.path.join(build.topsrcdir, "testing", "profiles", "prefs_general.js")
    1.46 +    prefs = {}
    1.47 +    prefs.update(Preferences.read_prefs(prefpath))
    1.48 +    interpolation = { "server": "%s:%d" % httpd.httpd.server_address,
    1.49 +                      "OOP": "false"}
    1.50 +    prefs = json.loads(json.dumps(prefs) % interpolation)
    1.51 +    for pref in prefs:
    1.52 +      prefs[pref] = Preferences.cast(prefs[pref])
    1.53 +    profile = FirefoxProfile(profile=profilePath,
    1.54 +                             preferences=prefs,
    1.55 +                             addons=[os.path.join(build.distdir, 'xpi-stage', 'quitter')],
    1.56 +                             locations=locations)
    1.57 +
    1.58 +    env = os.environ.copy()
    1.59 +    env["MOZ_CRASHREPORTER_NO_REPORT"] = "1"
    1.60 +    env["XPCOM_DEBUG_BREAK"] = "warn"
    1.61 +
    1.62 +    # For VC12, make sure we can find the right bitness of pgort120.dll
    1.63 +    if "VS120COMNTOOLS" in env and not substs["HAVE_64BIT_OS"]:
    1.64 +      vc12dir = os.path.abspath(os.path.join(env["VS120COMNTOOLS"],
    1.65 +                                             "../../VC/bin"))
    1.66 +      if os.path.exists(vc12dir):
    1.67 +        env["PATH"] = vc12dir + ";" + env["PATH"]
    1.68 +
    1.69 +    jarlog = os.getenv("JARLOG_FILE")
    1.70 +    if jarlog:
    1.71 +      env["MOZ_JAR_LOG_FILE"] = os.path.abspath(jarlog)
    1.72 +      print "jarlog: %s" % env["MOZ_JAR_LOG_FILE"]
    1.73 +
    1.74 +    cmdargs = ["http://localhost:%d/index.html" % PORT]
    1.75 +    runner = FirefoxRunner(profile=profile,
    1.76 +                           binary=build.get_binary_path(where="staged-package"),
    1.77 +                           cmdargs=cmdargs,
    1.78 +                           env=env)
    1.79 +    runner.start(debug_args=debug_args, interactive=interactive)
    1.80 +    runner.wait()
    1.81 +    httpd.stop()
    1.82 +  finally:
    1.83 +    shutil.rmtree(profilePath)

mercurial