Run test-tidy on Windows

This commit is contained in:
Paul Rouget 2019-11-08 09:42:12 +01:00
parent 5c92fd84ca
commit b71774d8fe
5 changed files with 67 additions and 50 deletions

View file

@ -17,7 +17,7 @@ AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true BinPackArguments: true
BinPackParameters: true BinPackParameters: true
BraceWrapping: BraceWrapping:
@ -39,6 +39,7 @@ BraceWrapping:
BreakBeforeBinaryOperators: None BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon BreakConstructorInitializers: BeforeColon
@ -79,6 +80,7 @@ MacroBlockBegin: ''
MacroBlockEnd: '' MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1 MaxEmptyLinesToKeep: 1
NamespaceIndentation: None NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2 ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true ObjCSpaceBeforeProtocolList: true
@ -87,20 +89,21 @@ PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300 PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120 PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000 PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000 PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60 PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right PointerAlignment: Right
RawStringFormats:
- Delimiter: pb
Language: TextProto
BasedOnStyle: google
ReflowComments: true ReflowComments: true
SortIncludes: false SortIncludes: false
SortUsingDeclarations: true SortUsingDeclarations: true
SpaceAfterCStyleCast: false SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1 SpacesBeforeTrailingComments: 1
SpacesInAngles: false SpacesInAngles: false
@ -109,6 +112,9 @@ SpacesInCStyleCastParentheses: false
SpacesInParentheses: false SpacesInParentheses: false
SpacesInSquareBrackets: false SpacesInSquareBrackets: false
Standard: Cpp11 Standard: Cpp11
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8 TabWidth: 8
UseTab: Never UseTab: Never
... ...

View file

@ -434,6 +434,7 @@ def windows_uwp_x64():
.with_script( .with_script(
"python mach build --dev --target=x86_64-uwp-windows-msvc", "python mach build --dev --target=x86_64-uwp-windows-msvc",
"python mach package --dev --target=x86_64-uwp-windows-msvc --uwp=x64", "python mach package --dev --target=x86_64-uwp-windows-msvc --uwp=x64",
"python mach test-tidy --force-cpp --no-wpt",
) )
.with_artifacts(appx_artifact(debug=True)) .with_artifacts(appx_artifact(debug=True))
.find_or_create("build.windows_uwp_x64_dev." + CONFIG.task_id()) .find_or_create("build.windows_uwp_x64_dev." + CONFIG.task_id())

View file

@ -28,7 +28,7 @@ class Lint(LintRunner):
yield f[len(working_dir):] yield f[len(working_dir):]
def run(self): def run(self):
if self.stylo: if self.stylo or self.no_wpt:
return return
wpt_working_dir = os.path.abspath(os.path.join(WPT_PATH, "web-platform-tests")) wpt_working_dir = os.path.abspath(os.path.join(WPT_PATH, "web-platform-tests"))

View file

@ -34,7 +34,7 @@ from mach.decorators import (
from servo.command_base import ( from servo.command_base import (
BuildNotFound, CommandBase, BuildNotFound, CommandBase,
call, check_call, set_osmesa_env, call, check_call, check_output, set_osmesa_env,
) )
from servo.util import host_triple 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") SERVO_TESTS_PATH = os.path.join("tests", "wpt", "mozilla", "tests")
CLANGFMT_CPP_DIRS = ["support/hololens/"] CLANGFMT_CPP_DIRS = ["support/hololens/"]
CLANGFMT_VERSION = "8"
TEST_SUITES = OrderedDict([ TEST_SUITES = OrderedDict([
("tidy", {"kwargs": {"all_files": False, "no_progress": False, "self_test": False, ("tidy", {"kwargs": {"all_files": False, "no_progress": False, "self_test": False,
@ -326,8 +327,8 @@ class MachCommands(CommandBase):
help="Run unit tests for tidy") help="Run unit tests for tidy")
@CommandArgument('--stylo', default=False, action="store_true", @CommandArgument('--stylo', default=False, action="store_true",
help="Only handle files in the stylo tree") help="Only handle files in the stylo tree")
@CommandArgument('--no-cpp', default=False, action="store_true", help="Skip CPP files") @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, no_cpp): def test_tidy(self, all_files, no_wpt, no_progress, self_test, stylo, force_cpp):
if self_test: if self_test:
return test_tidy.do_tests() return test_tidy.do_tests()
else: else:
@ -335,19 +336,22 @@ class MachCommands(CommandBase):
manifest_dirty = False manifest_dirty = False
else: else:
manifest_dirty = run_update(self.context.topdir, check_clean=True) 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() self.install_rustfmt()
rustfmt_failed = self.call_rustup_run(["cargo", "fmt", "--", "--check"]) rustfmt_failed = self.call_rustup_run(["cargo", "fmt", "--", "--check"])
env = self.build_env()
clangfmt_failed = False clangfmt_failed = False
if not no_cpp: available, cmd, files = setup_clangfmt(env)
available, cmd, files = setup_clangfmt() if available:
if available: for file in files:
for file in files: stdout = check_output([cmd, "-output-replacements-xml", file], env=env)
stdout = subprocess.check_output([cmd, "-output-replacements-xml", file]) if len(XML(stdout)) > 0:
if len(XML(stdout)) > 0: print("%s is not formatted correctly." % file)
print("%s is not formatted correctly." % file) clangfmt_failed = True
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: if rustfmt_failed or clangfmt_failed:
print("Run `./mach fmt` to fix the formatting") print("Run `./mach fmt` to fix the formatting")
@ -476,13 +480,12 @@ class MachCommands(CommandBase):
@Command('fmt', @Command('fmt',
description='Format the Rust and CPP source files with rustfmt and clang-format', description='Format the Rust and CPP source files with rustfmt and clang-format',
category='testing') category='testing')
@CommandArgument('--no-cpp', default=False, action="store_true", help="Skip CPP files") def format_code(self):
def format_code(self, no_cpp):
if not no_cpp: env = self.build_env()
available, cmd, files = setup_clangfmt() available, cmd, files = setup_clangfmt(env)
if available and len(files) > 0: if available and len(files) > 0:
check_call([cmd, "-i"] + files) check_call([cmd, "-i"] + files, env=env)
self.install_rustfmt() self.install_rustfmt()
return self.call_rustup_run(["cargo", "fmt"]) return self.call_rustup_run(["cargo", "fmt"])
@ -771,6 +774,23 @@ class MachCommands(CommandBase):
pass 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(): def create_parser_create():
import argparse import argparse
p = argparse.ArgumentParser() p = argparse.ArgumentParser()
@ -797,23 +817,6 @@ def create_parser_create():
return p 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 @CommandProvider
class WebPlatformTestsCreator(CommandBase): class WebPlatformTestsCreator(CommandBase):
template_prefix = """<!doctype html> template_prefix = """<!doctype html>

View file

@ -890,7 +890,7 @@ def check_spec(file_name, lines):
break break
def check_config_file(config_file, print_text=True): def check_config_file(config_file, print_text=True, no_wpt=False):
# Check if config file exists # Check if config file exists
if not os.path.exists(config_file): if not os.path.exists(config_file):
print("%s config file is required but was not found" % config_file) print("%s config file is required but was not found" % config_file)
@ -915,6 +915,11 @@ def check_config_file(config_file, print_text=True):
# Check for invalid listed ignored files # Check for invalid listed ignored files
invalid_files = [f for f in exclude.get("files", []) if not os.path.exists(f)] invalid_files = [f for f in exclude.get("files", []) if not os.path.exists(f)]
# Do not check for the existense of ignored files under tests/wpts if --no-wpt is used
if no_wpt:
wpt_dir = './tests/wpt/'
invalid_files = [f for f in invalid_files if not os.path.commonprefix([wpt_dir, f]) == wpt_dir]
current_table = "" current_table = ""
for idx, line in enumerate(lines): for idx, line in enumerate(lines):
# Ignore comment lines # Ignore comment lines
@ -1052,12 +1057,14 @@ def check_dep_license_errors(filenames, progress=True):
class LintRunner(object): class LintRunner(object):
def __init__(self, lint_path=None, only_changed_files=True, exclude_dirs=[], progress=True, stylo=False): def __init__(self, lint_path=None, only_changed_files=True,
exclude_dirs=[], progress=True, stylo=False, no_wpt=False):
self.only_changed_files = only_changed_files self.only_changed_files = only_changed_files
self.exclude_dirs = exclude_dirs self.exclude_dirs = exclude_dirs
self.progress = progress self.progress = progress
self.path = lint_path self.path = lint_path
self.stylo = stylo self.stylo = stylo
self.no_wpt = no_wpt
def check(self): def check(self):
if not os.path.exists(self.path): if not os.path.exists(self.path):
@ -1079,7 +1086,7 @@ class LintRunner(object):
return return
lint = module.Lint(self.path, self.only_changed_files, lint = module.Lint(self.path, self.only_changed_files,
self.exclude_dirs, self.progress, stylo=self.stylo) self.exclude_dirs, self.progress, stylo=self.stylo, no_wpt=self.no_wpt)
for error in lint.run(): for error in lint.run():
if type(error) is not tuple or (type(error) is tuple and len(error) != 3): if type(error) is not tuple or (type(error) is tuple and len(error) != 3):
yield (self.path, 1, "errors should be a tuple of (path, line, reason)") yield (self.path, 1, "errors should be a tuple of (path, line, reason)")
@ -1095,19 +1102,19 @@ class LintRunner(object):
yield (self.path, 0, "class 'Lint' should implement 'run' method") yield (self.path, 0, "class 'Lint' should implement 'run' method")
def run_lint_scripts(only_changed_files=False, progress=True, stylo=False): def run_lint_scripts(only_changed_files=False, progress=True, stylo=False, no_wpt=False):
runner = LintRunner(only_changed_files=only_changed_files, progress=progress, stylo=stylo) runner = LintRunner(only_changed_files=only_changed_files, progress=progress, stylo=stylo, no_wpt=no_wpt)
for path in config['lint-scripts']: for path in config['lint-scripts']:
runner.path = path runner.path = path
for error in runner.check(): for error in runner.check():
yield error yield error
def scan(only_changed_files=False, progress=True, stylo=False): def scan(only_changed_files=False, progress=True, stylo=False, no_wpt=False):
# check config file for errors # check config file for errors
config_errors = check_config_file(CONFIG_FILE_PATH) config_errors = check_config_file(CONFIG_FILE_PATH, no_wpt=no_wpt)
# check ini directories exist # check ini directories exist
if os.path.isfile(WPT_MANIFEST_PATH): if not no_wpt and os.path.isfile(WPT_MANIFEST_PATH):
manifest_errors = check_manifest_dirs(WPT_MANIFEST_PATH) manifest_errors = check_manifest_dirs(WPT_MANIFEST_PATH)
else: else:
manifest_errors = () manifest_errors = ()
@ -1122,7 +1129,7 @@ def scan(only_changed_files=False, progress=True, stylo=False):
# check dependecy licenses # check dependecy licenses
dep_license_errors = check_dep_license_errors(get_dep_toml_files(only_changed_files), progress) dep_license_errors = check_dep_license_errors(get_dep_toml_files(only_changed_files), progress)
# other lint checks # other lint checks
lint_errors = run_lint_scripts(only_changed_files, progress, stylo=stylo) lint_errors = run_lint_scripts(only_changed_files, progress, stylo=stylo, no_wpt=no_wpt)
# chain all the iterators # chain all the iterators
errors = itertools.chain(config_errors, manifest_errors, directory_errors, lint_errors, errors = itertools.chain(config_errors, manifest_errors, directory_errors, lint_errors,
file_errors, dep_license_errors) file_errors, dep_license_errors)