Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | #!/usr/bin/python |
michael@0 | 2 | |
michael@0 | 3 | # This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 5 | # You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 6 | |
michael@0 | 7 | from argparse import ArgumentParser |
michael@0 | 8 | from shutil import rmtree |
michael@0 | 9 | from subprocess import Popen |
michael@0 | 10 | from sys import argv |
michael@0 | 11 | from sys import exit |
michael@0 | 12 | from tempfile import mkdtemp |
michael@0 | 13 | |
michael@0 | 14 | DEFAULT_PORT = 8080 |
michael@0 | 15 | DEFAULT_HOSTNAME = 'localhost' |
michael@0 | 16 | |
michael@0 | 17 | def run_server(srcdir, objdir, js_file, hostname=DEFAULT_HOSTNAME, |
michael@0 | 18 | port=DEFAULT_PORT): |
michael@0 | 19 | |
michael@0 | 20 | dist_dir = '%s/dist' % objdir |
michael@0 | 21 | head_dir = '%s/services/common/tests/unit' % srcdir |
michael@0 | 22 | |
michael@0 | 23 | head_paths = [ |
michael@0 | 24 | 'head_global.js', |
michael@0 | 25 | 'head_helpers.js', |
michael@0 | 26 | 'head_http.js', |
michael@0 | 27 | ] |
michael@0 | 28 | |
michael@0 | 29 | head_paths = ['"%s/%s"' % (head_dir, path) for path in head_paths] |
michael@0 | 30 | |
michael@0 | 31 | args = [ |
michael@0 | 32 | '%s/bin/xpcshell' % dist_dir, |
michael@0 | 33 | '-g', '%s/bin' % dist_dir, |
michael@0 | 34 | '-a', '%s/bin' % dist_dir, |
michael@0 | 35 | '-r', '%s/bin/components/httpd.manifest' % dist_dir, |
michael@0 | 36 | '-m', |
michael@0 | 37 | '-n', |
michael@0 | 38 | '-s', |
michael@0 | 39 | '-f', '%s/testing/xpcshell/head.js' % srcdir, |
michael@0 | 40 | '-e', 'const _SERVER_ADDR = "%s";' % hostname, |
michael@0 | 41 | '-e', 'const _TESTING_MODULES_DIR = "%s/_tests/modules";' % objdir, |
michael@0 | 42 | '-e', 'const SERVER_PORT = "%s";' % port, |
michael@0 | 43 | '-e', 'const INCLUDE_FILES = [%s];' % ', '.join(head_paths), |
michael@0 | 44 | '-e', '_register_protocol_handlers();', |
michael@0 | 45 | '-e', 'for each (let name in INCLUDE_FILES) load(name);', |
michael@0 | 46 | '-e', '_fakeIdleService.activate();', |
michael@0 | 47 | '-f', '%s/services/common/tests/%s' % (srcdir, js_file) |
michael@0 | 48 | ] |
michael@0 | 49 | |
michael@0 | 50 | profile_dir = mkdtemp() |
michael@0 | 51 | print 'Created profile directory: %s' % profile_dir |
michael@0 | 52 | |
michael@0 | 53 | try: |
michael@0 | 54 | env = {'XPCSHELL_TEST_PROFILE_DIR': profile_dir} |
michael@0 | 55 | proc = Popen(args, env=env) |
michael@0 | 56 | |
michael@0 | 57 | return proc.wait() |
michael@0 | 58 | |
michael@0 | 59 | finally: |
michael@0 | 60 | print 'Removing profile directory %s' % profile_dir |
michael@0 | 61 | rmtree(profile_dir) |
michael@0 | 62 | |
michael@0 | 63 | if __name__ == '__main__': |
michael@0 | 64 | parser = ArgumentParser(description="Run a standalone JS server.") |
michael@0 | 65 | parser.add_argument('srcdir', |
michael@0 | 66 | help="Root directory of Firefox source code.") |
michael@0 | 67 | parser.add_argument('objdir', |
michael@0 | 68 | help="Root directory object directory created during build.") |
michael@0 | 69 | parser.add_argument('js_file', |
michael@0 | 70 | help="JS file (in this directory) to execute.") |
michael@0 | 71 | parser.add_argument('--port', default=DEFAULT_PORT, type=int, |
michael@0 | 72 | help="Port to run server on.") |
michael@0 | 73 | parser.add_argument('--address', default=DEFAULT_HOSTNAME, |
michael@0 | 74 | help="Hostname to bind server to.") |
michael@0 | 75 | |
michael@0 | 76 | args = parser.parse_args() |
michael@0 | 77 | |
michael@0 | 78 | exit(run_server(args.srcdir, args.objdir, args.js_file, args.address, |
michael@0 | 79 | args.port)) |