mirror of
https://github.com/servo/servo.git
synced 2025-07-03 13:33:39 +01:00
Run test-tidy on Windows
This commit is contained in:
parent
5c92fd84ca
commit
b71774d8fe
5 changed files with 67 additions and 50 deletions
|
@ -28,7 +28,7 @@ class Lint(LintRunner):
|
|||
yield f[len(working_dir):]
|
||||
|
||||
def run(self):
|
||||
if self.stylo:
|
||||
if self.stylo or self.no_wpt:
|
||||
return
|
||||
|
||||
wpt_working_dir = os.path.abspath(os.path.join(WPT_PATH, "web-platform-tests"))
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue