diff options
author | Paul Rouget <me@paulrouget.com> | 2019-11-08 09:42:12 +0100 |
---|---|---|
committer | Paul Rouget <me@paulrouget.com> | 2019-11-21 09:56:39 +0100 |
commit | b71774d8fe029a11ba95d13ea25692ecfe74dec6 (patch) | |
tree | 5d6376f1c077421780833422e3de18404d6f65f8 /python/servo/testing_commands.py | |
parent | 5c92fd84cab4d4e214a8e16042812a38480817ba (diff) | |
download | servo-b71774d8fe029a11ba95d13ea25692ecfe74dec6.tar.gz servo-b71774d8fe029a11ba95d13ea25692ecfe74dec6.zip |
Run test-tidy on Windows
Diffstat (limited to 'python/servo/testing_commands.py')
-rw-r--r-- | python/servo/testing_commands.py | 73 |
1 files changed, 38 insertions, 35 deletions
diff --git a/python/servo/testing_commands.py b/python/servo/testing_commands.py index 1aa2b0961e5..f094ad9bb1b 100644 --- a/python/servo/testing_commands.py +++ b/python/servo/testing_commands.py @@ -34,7 +34,7 @@ from mach.decorators import ( from servo.command_base import ( BuildNotFound, CommandBase, - call, check_call, set_osmesa_env, + call, check_call, check_output, set_osmesa_env, ) from servo.util import host_triple @@ -49,6 +49,7 @@ WEB_PLATFORM_TESTS_PATH = os.path.join("tests", "wpt", "web-platform-tests") SERVO_TESTS_PATH = os.path.join("tests", "wpt", "mozilla", "tests") CLANGFMT_CPP_DIRS = ["support/hololens/"] +CLANGFMT_VERSION = "8" TEST_SUITES = OrderedDict([ ("tidy", {"kwargs": {"all_files": False, "no_progress": False, "self_test": False, @@ -326,8 +327,8 @@ class MachCommands(CommandBase): help="Run unit tests for tidy") @CommandArgument('--stylo', default=False, action="store_true", help="Only handle files in the stylo tree") - @CommandArgument('--no-cpp', default=False, action="store_true", help="Skip CPP files") - def test_tidy(self, all_files, no_wpt, no_progress, self_test, stylo, no_cpp): + @CommandArgument('--force-cpp', default=False, action="store_true", help="Force CPP check") + def test_tidy(self, all_files, no_wpt, no_progress, self_test, stylo, force_cpp): if self_test: return test_tidy.do_tests() else: @@ -335,19 +336,22 @@ class MachCommands(CommandBase): manifest_dirty = False else: manifest_dirty = run_update(self.context.topdir, check_clean=True) - tidy_failed = tidy.scan(not all_files, not no_progress, stylo=stylo) + tidy_failed = tidy.scan(not all_files, not no_progress, stylo=stylo, no_wpt=no_wpt) self.install_rustfmt() rustfmt_failed = self.call_rustup_run(["cargo", "fmt", "--", "--check"]) + env = self.build_env() clangfmt_failed = False - if not no_cpp: - available, cmd, files = setup_clangfmt() - if available: - for file in files: - stdout = subprocess.check_output([cmd, "-output-replacements-xml", file]) - if len(XML(stdout)) > 0: - print("%s is not formatted correctly." % file) - clangfmt_failed = True + available, cmd, files = setup_clangfmt(env) + if available: + for file in files: + stdout = check_output([cmd, "-output-replacements-xml", file], env=env) + if len(XML(stdout)) > 0: + print("%s is not formatted correctly." % file) + clangfmt_failed = True + elif force_cpp: + print("Error: can't find suitable clang-format version. Required with --force-cpp.") + return True if rustfmt_failed or clangfmt_failed: print("Run `./mach fmt` to fix the formatting") @@ -476,13 +480,12 @@ class MachCommands(CommandBase): @Command('fmt', description='Format the Rust and CPP source files with rustfmt and clang-format', category='testing') - @CommandArgument('--no-cpp', default=False, action="store_true", help="Skip CPP files") - def format_code(self, no_cpp): + def format_code(self): - if not no_cpp: - available, cmd, files = setup_clangfmt() - if available and len(files) > 0: - check_call([cmd, "-i"] + files) + env = self.build_env() + available, cmd, files = setup_clangfmt(env) + if available and len(files) > 0: + check_call([cmd, "-i"] + files, env=env) self.install_rustfmt() return self.call_rustup_run(["cargo", "fmt"]) @@ -771,6 +774,23 @@ class MachCommands(CommandBase): pass +def setup_clangfmt(env): + cmd = "clang-format.exe" if sys.platform == "win32" else "clang-format" + try: + version = check_output([cmd, "--version"], env=env).rstrip() + print(version) + if not version.startswith("clang-format version {}.".format(CLANGFMT_VERSION)): + print("clang-format: wrong version (v{} required). Skipping CPP formatting.".format(CLANGFMT_VERSION)) + return False, None, None + except OSError: + print("clang-format not installed. Skipping CPP formatting.") + return False, None, None + gitcmd = ['git', 'ls-files'] + gitfiles = check_output(gitcmd + CLANGFMT_CPP_DIRS).splitlines() + filtered = [line for line in gitfiles if line.endswith(".h") or line.endswith(".cpp")] + return True, cmd, filtered + + def create_parser_create(): import argparse p = argparse.ArgumentParser() @@ -797,23 +817,6 @@ def create_parser_create(): return p -def setup_clangfmt(): - cmd = "clang-format.exe" if sys.platform == "win32" else "clang-format" - try: - version = subprocess.check_output([cmd, "--version"]).rstrip() - print(version) - if not version.startswith("clang-format version 6."): - print("clang-format: wrong version (v6 required). Skipping CPP formatting.") - return False, None, None - except OSError: - print("clang-format not installed. Skipping CPP formatting.") - return False, None, None - gitcmd = ['git', 'ls-files'] - gitfiles = subprocess.check_output(gitcmd + CLANGFMT_CPP_DIRS).splitlines() - filtered = [line for line in gitfiles if line.endswith(".h") or line.endswith(".cpp")] - return True, cmd, filtered - - @CommandProvider class WebPlatformTestsCreator(CommandBase): template_prefix = """<!doctype html> |