diff options
Diffstat (limited to 'python/servo')
-rw-r--r-- | python/servo/build_commands.py | 3 | ||||
-rw-r--r-- | python/servo/package_commands.py | 59 | ||||
-rw-r--r-- | python/servo/testing_commands.py | 97 |
3 files changed, 125 insertions, 34 deletions
diff --git a/python/servo/build_commands.py b/python/servo/build_commands.py index f344b050f4e..df727e2776f 100644 --- a/python/servo/build_commands.py +++ b/python/servo/build_commands.py @@ -236,6 +236,9 @@ class MachCommands(CommandBase): cargo_binary = "cargo" + BIN_SUFFIX + if sys.platform == "win32" or sys.platform == "msys": + env["RUSTFLAGS"] = "-C link-args=-Wl,--subsystem,windows" + status = call( [cargo_binary, "build"] + opts, env=env, cwd=self.servo_crate(), verbose=verbose) diff --git a/python/servo/package_commands.py b/python/servo/package_commands.py index d3d7877c674..1bd91e6eae1 100644 --- a/python/servo/package_commands.py +++ b/python/servo/package_commands.py @@ -9,8 +9,11 @@ from __future__ import print_function, unicode_literals -import os +import sys import os.path as path +sys.path.append(path.join(path.dirname(sys.argv[0]), "components", "style", "properties", "Mako-0.9.1.zip")) + +import os import shutil import subprocess import tarfile @@ -24,7 +27,9 @@ from mach.decorators import ( Command, ) -from servo.command_base import CommandBase, cd, BuildNotFound, is_macosx +from mako.template import Template + +from servo.command_base import CommandBase, cd, BuildNotFound, is_macosx, is_windows from servo.post_build_commands import find_dep_path_newest @@ -42,6 +47,11 @@ def otool(s): yield l.split(' ', 1)[0][1:] +def listfiles(directory): + return [f for f in os.listdir(directory) + if path.isfile(path.join(directory, f))] + + def install_name_tool(old, new, binary): try: subprocess.check_call(['install_name_tool', '-change', old, '@executable_path/' + new, binary]) @@ -76,7 +86,7 @@ class PackageCommands(CommandBase): env["ANT_FLAVOR"] = "release" dev_flag = "" - target_dir = os.path.dirname(binary_path) + target_dir = path.dirname(binary_path) output_apk = "{}.apk".format(binary_path) try: with cd(path.join("support", "android", "build-apk")): @@ -91,7 +101,7 @@ class PackageCommands(CommandBase): dir_to_app = dir_to_dmg + '/Servo.app' dir_to_resources = dir_to_app + '/Contents/Resources/' dir_to_root = '/'.join(binary_path.split('/')[:-3]) - if os.path.exists(dir_to_dmg): + if path.exists(dir_to_dmg): print("Cleaning up from previous packaging") delete(dir_to_dmg) browserhtml_path = find_dep_path_newest('browserhtml', binary_path) @@ -123,7 +133,7 @@ class PackageCommands(CommandBase): continue need_relinked = set(otool(f)) new_path = dir_to_app + '/Contents/MacOS/' + f.split('/')[-1] - if not os.path.exists(new_path): + if not path.exists(new_path): shutil.copyfile(f, new_path) for dylib in need_relinked: if '/System/Library' in dylib or '/usr/lib' in dylib or 'servo' in dylib: @@ -153,6 +163,45 @@ class PackageCommands(CommandBase): print("Cleaning up") delete(dir_to_dmg) print("Packaged Servo into " + dmg_path) + elif is_windows(): + dir_to_package = path.dirname(binary_path) + dir_to_root = self.get_top_dir() + dir_to_msi = path.join(dir_to_package, 'msi') + if path.exists(dir_to_msi): + print("Cleaning up from previous packaging") + delete(dir_to_msi) + os.makedirs(dir_to_msi) + top_path = dir_to_root + browserhtml_path = find_dep_path_newest('browserhtml', binary_path) + if browserhtml_path is None: + print("Could not find browserhtml package; perhaps you haven't built Servo.") + return 1 + browserhtml_path = path.join(browserhtml_path, "out") + # generate Servo.wxs + template_path = path.join(dir_to_root, "support", "windows", "Servo.wxs.mako") + template = Template(open(template_path).read()) + wxs_path = path.join(dir_to_msi, "Servo.wxs") + open(wxs_path, "w").write(template.render( + exe_path=dir_to_package, + top_path=top_path, + browserhtml_path=browserhtml_path)) + # run candle and light + print("Creating MSI") + try: + with cd(dir_to_msi): + subprocess.check_call(['candle', wxs_path]) + except subprocess.CalledProcessError as e: + print("WiX candle exited with return value %d" % e.returncode) + return e.returncode + try: + wxsobj_path = "{}.wixobj".format(path.splitext(wxs_path)[0]) + with cd(dir_to_msi): + subprocess.check_call(['light', wxsobj_path]) + except subprocess.CalledProcessError as e: + print("WiX light exited with return value %d" % e.returncode) + return e.returncode + msi_path = path.join(dir_to_msi, "Servo.msi") + print("Packaged Servo into {}".format(msi_path)) else: dir_to_package = '/'.join(binary_path.split('/')[:-1]) dir_to_root = '/'.join(binary_path.split('/')[:-3]) diff --git a/python/servo/testing_commands.py b/python/servo/testing_commands.py index fb0d0d20415..b4c045d4a70 100644 --- a/python/servo/testing_commands.py +++ b/python/servo/testing_commands.py @@ -14,6 +14,7 @@ import re import sys import os import os.path as path +import copy from collections import OrderedDict from time import time @@ -35,6 +36,26 @@ PROJECT_TOPLEVEL_PATH = os.path.abspath(os.path.join(SCRIPT_PATH, "..", "..")) WEB_PLATFORM_TESTS_PATH = os.path.join("tests", "wpt", "web-platform-tests") SERVO_TESTS_PATH = os.path.join("tests", "wpt", "mozilla", "tests") +TEST_SUITES = OrderedDict([ + ("tidy", {"kwargs": {"all_files": False, "no_progress": False, "self_test": False}, + "include_arg": "include"}), + ("wpt", {"kwargs": {"release": False}, + "paths": [path.abspath(WEB_PLATFORM_TESTS_PATH), + path.abspath(SERVO_TESTS_PATH)], + "include_arg": "include"}), + ("css", {"kwargs": {"release": False}, + "paths": [path.abspath(path.join("tests", "wpt", "css-tests"))], + "include_arg": "include"}), + ("unit", {"kwargs": {}, + "paths": [path.abspath(path.join("tests", "unit"))], + "include_arg": "test_name"}), + ("compiletest", {"kwargs": {"release": False}, + "paths": [path.abspath(path.join("tests", "compiletest"))], + "include_arg": "test_name"}) +]) + +TEST_SUITES_BY_PREFIX = {path: k for k, v in TEST_SUITES.iteritems() if "paths" in v for path in v["paths"]} + def create_parser_wpt(): parser = wptcommandline.create_parser() @@ -79,25 +100,12 @@ class MachCommands(CommandBase): help="Run all test suites") def test(self, params, render_mode=DEFAULT_RENDER_MODE, release=False, tidy_all=False, no_progress=False, self_test=False, all_suites=False): - suites = OrderedDict([ - ("tidy", {"kwargs": {"all_files": tidy_all, "no_progress": no_progress, "self_test": self_test}, - "include_arg": "include"}), - ("wpt", {"kwargs": {"release": release}, - "paths": [path.abspath(path.join("tests", "wpt", "web-platform-tests")), - path.abspath(path.join("tests", "wpt", "mozilla"))], - "include_arg": "include"}), - ("css", {"kwargs": {"release": release}, - "paths": [path.abspath(path.join("tests", "wpt", "css-tests"))], - "include_arg": "include"}), - ("unit", {"kwargs": {}, - "paths": [path.abspath(path.join("tests", "unit"))], - "include_arg": "test_name"}), - ("compiletest", {"kwargs": {"release": release}, - "paths": [path.abspath(path.join("tests", "compiletest"))], - "include_arg": "test_name"}) - ]) - - suites_by_prefix = {path: k for k, v in suites.iteritems() if "paths" in v for path in v["paths"]} + suites = copy.deepcopy(TEST_SUITES) + suites["tidy"]["kwargs"] = {"all_files": tidy_all, "no_progress": no_progress, "self_test": self_test} + suites["wpt"]["kwargs"] = {"release": release} + suites["css"]["kwargs"] = {"release": release} + suites["unit"]["kwargs"] = {} + suites["compiletest"]["kwargs"] = {"release": release} selected_suites = OrderedDict() @@ -115,16 +123,14 @@ class MachCommands(CommandBase): if arg in suites and arg not in selected_suites: selected_suites[arg] = [] found = True - - elif os.path.exists(path.abspath(arg)): - abs_path = path.abspath(arg) - for prefix, suite in suites_by_prefix.iteritems(): - if abs_path.startswith(prefix): - if suite not in selected_suites: - selected_suites[suite] = [] - selected_suites[suite].append(arg) - found = True - break + else: + suite = self.suite_for_path(arg) + if suite is not None: + if suite not in selected_suites: + selected_suites[suite] = [] + selected_suites[suite].append(arg) + found = True + break if not found: print("%s is not a valid test path or suite name" % arg) @@ -143,6 +149,15 @@ class MachCommands(CommandBase): print("Tests completed in %0.2fs" % elapsed) + # Helper to determine which test suite owns the path + def suite_for_path(self, path_arg): + if os.path.exists(path.abspath(path_arg)): + abs_path = path.abspath(path_arg) + for prefix, suite in TEST_SUITES_BY_PREFIX.iteritems(): + if abs_path.startswith(prefix): + return suite + return None + @Command('test-unit', description='Run unit tests', category='testing') @@ -322,11 +337,32 @@ class MachCommands(CommandBase): parser=create_parser_wpt) def test_wpt(self, **kwargs): self.ensure_bootstrapped() + return self.run_test_list_or_dispatch(kwargs["test_list"], "wpt", self._test_wpt, **kwargs) + + def _test_wpt(self, **kwargs): hosts_file_path = path.join(self.context.topdir, 'tests', 'wpt', 'hosts') os.environ["hosts_file_path"] = hosts_file_path run_file = path.abspath(path.join(self.context.topdir, "tests", "wpt", "run_wpt.py")) return self.wptrunner(run_file, **kwargs) + # Helper to ensure all specified paths are handled, otherwise dispatch to appropriate test suite. + def run_test_list_or_dispatch(self, requested_paths, correct_suite, correct_function, **kwargs): + if not requested_paths: + return correct_function(**kwargs) + else: + # Paths specified on command line. Ensure they can be handled, re-dispatch otherwise. + all_handled = True + for test_path in requested_paths: + suite = self.suite_for_path(test_path) + if suite is not None and correct_suite != suite: + all_handled = False + print("Warning: %s is not a %s test. Delegating to test-%s." % (test_path, correct_suite, suite)) + if all_handled: + return correct_function(**kwargs) + else: + # Dispatch each test to the correct suite via test() + Registrar.dispatch("test", context=self.context, params=requested_paths) + # Helper for test_css and test_wpt: def wptrunner(self, run_file, **kwargs): os.environ["RUST_BACKTRACE"] = "1" @@ -413,6 +449,9 @@ class MachCommands(CommandBase): parser=create_parser_wpt) def test_css(self, **kwargs): self.ensure_bootstrapped() + return self.run_test_list_or_dispatch(kwargs["test_list"], "css", self._test_css, **kwargs) + + def _test_css(self, **kwargs): run_file = path.abspath(path.join("tests", "wpt", "run_css.py")) return self.wptrunner(run_file, **kwargs) |