Skip to content
Permalink
Browse files

Run test-tidy on Windows

  • Loading branch information
paulrouget committed Nov 8, 2019
1 parent 5c92fd8 commit b71774d8fe029a11ba95d13ea25692ecfe74dec6
@@ -17,7 +17,7 @@ AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
@@ -39,6 +39,7 @@ BraceWrapping:
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
@@ -79,6 +80,7 @@ MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
@@ -87,20 +89,21 @@ PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
RawStringFormats:
- Delimiter: pb
Language: TextProto
BasedOnStyle: google
ReflowComments: true
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
@@ -109,6 +112,9 @@ SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseTab: Never
...
@@ -434,6 +434,7 @@ def windows_uwp_x64():
.with_script(
"python mach build --dev --target=x86_64-uwp-windows-msvc",
"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))
.find_or_create("build.windows_uwp_x64_dev." + CONFIG.task_id())
@@ -28,7 +28,7 @@ def _get_wpt_files(self, suite):
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 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 @@
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,28 +327,31 @@ def install_rustfmt(self):
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:
if no_wpt:
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 @@ def update_manifest(self, **kwargs):
@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 @@ def set_software_rendering_env(self, use_release):
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>
@@ -890,7 +890,7 @@ def check_spec(file_name, lines):
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
if not os.path.exists(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
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 = ""
for idx, line in enumerate(lines):
# Ignore comment lines
@@ -1052,12 +1057,14 @@ def check_dep_license_errors(filenames, progress=True):


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.exclude_dirs = exclude_dirs
self.progress = progress
self.path = lint_path
self.stylo = stylo
self.no_wpt = no_wpt

def check(self):
if not os.path.exists(self.path):
@@ -1079,7 +1086,7 @@ def check(self):
return

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():
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)")
@@ -1095,19 +1102,19 @@ def run(self):
yield (self.path, 0, "class 'Lint' should implement 'run' method")


def run_lint_scripts(only_changed_files=False, progress=True, stylo=False):
runner = LintRunner(only_changed_files=only_changed_files, progress=progress, stylo=stylo)
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, no_wpt=no_wpt)
for path in config['lint-scripts']:
runner.path = path
for error in runner.check():
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
config_errors = check_config_file(CONFIG_FILE_PATH)
config_errors = check_config_file(CONFIG_FILE_PATH, no_wpt=no_wpt)
# 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)
else:
manifest_errors = ()
@@ -1122,7 +1129,7 @@ def scan(only_changed_files=False, progress=True, stylo=False):
# check dependecy licenses
dep_license_errors = check_dep_license_errors(get_dep_toml_files(only_changed_files), progress)
# 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
errors = itertools.chain(config_errors, manifest_errors, directory_errors, lint_errors,
file_errors, dep_license_errors)

0 comments on commit b71774d

Please sign in to comment.
You can’t perform that action at this time.