mirror of
https://github.com/servo/servo.git
synced 2025-07-28 09:40:33 +01:00
Auto merge of #24552 - paulrouget:clangformat, r=jdm
mach fmt calls clang-format Fix #24031 What would be the right way to also integrate this with tidy?
This commit is contained in:
commit
f626355b67
6 changed files with 72 additions and 29 deletions
|
@ -22,6 +22,7 @@ import six.moves.urllib as urllib
|
||||||
import base64
|
import base64
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from xml.etree.ElementTree import XML
|
||||||
from six import iteritems
|
from six import iteritems
|
||||||
|
|
||||||
from mach.registrar import Registrar
|
from mach.registrar import Registrar
|
||||||
|
@ -47,6 +48,8 @@ PROJECT_TOPLEVEL_PATH = os.path.abspath(os.path.join(SCRIPT_PATH, "..", ".."))
|
||||||
WEB_PLATFORM_TESTS_PATH = os.path.join("tests", "wpt", "web-platform-tests")
|
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/"]
|
||||||
|
|
||||||
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,
|
||||||
"stylo": False},
|
"stylo": False},
|
||||||
|
@ -323,7 +326,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")
|
||||||
def test_tidy(self, all_files, no_wpt, no_progress, self_test, stylo):
|
@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):
|
||||||
if self_test:
|
if self_test:
|
||||||
return test_tidy.do_tests()
|
return test_tidy.do_tests()
|
||||||
else:
|
else:
|
||||||
|
@ -334,9 +338,21 @@ class MachCommands(CommandBase):
|
||||||
tidy_failed = tidy.scan(not all_files, not no_progress, stylo=stylo)
|
tidy_failed = tidy.scan(not all_files, not no_progress, stylo=stylo)
|
||||||
self.install_rustfmt()
|
self.install_rustfmt()
|
||||||
rustfmt_failed = self.call_rustup_run(["cargo", "fmt", "--", "--check"])
|
rustfmt_failed = self.call_rustup_run(["cargo", "fmt", "--", "--check"])
|
||||||
if rustfmt_failed:
|
|
||||||
|
clangfmt_failed = False
|
||||||
|
if not no_cpp:
|
||||||
|
available, cmd, files = setup_clangfmt(all_files)
|
||||||
|
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
|
||||||
|
|
||||||
|
if rustfmt_failed or clangfmt_failed:
|
||||||
print("Run `./mach fmt` to fix the formatting")
|
print("Run `./mach fmt` to fix the formatting")
|
||||||
return tidy_failed or manifest_dirty or rustfmt_failed
|
|
||||||
|
return tidy_failed or manifest_dirty or rustfmt_failed or clangfmt_failed
|
||||||
|
|
||||||
@Command('test-webidl',
|
@Command('test-webidl',
|
||||||
description='Run the WebIDL parser tests',
|
description='Run the WebIDL parser tests',
|
||||||
|
@ -458,9 +474,16 @@ class MachCommands(CommandBase):
|
||||||
return run_update(self.context.topdir, **kwargs)
|
return run_update(self.context.topdir, **kwargs)
|
||||||
|
|
||||||
@Command('fmt',
|
@Command('fmt',
|
||||||
description='Format the Rust source files with rustfmt',
|
description='Format the Rust and CPP source files with rustfmt and clang-format',
|
||||||
category='testing')
|
category='testing')
|
||||||
def format_code(self, **kwargs):
|
@CommandArgument('--no-cpp', default=False, action="store_true", help="Skip CPP files")
|
||||||
|
def format_code(self, no_cpp):
|
||||||
|
|
||||||
|
if not no_cpp:
|
||||||
|
available, cmd, files = setup_clangfmt(True)
|
||||||
|
if available and len(files) > 0:
|
||||||
|
check_call([cmd, "-i"] + files)
|
||||||
|
|
||||||
self.install_rustfmt()
|
self.install_rustfmt()
|
||||||
return self.call_rustup_run(["cargo", "fmt"])
|
return self.call_rustup_run(["cargo", "fmt"])
|
||||||
|
|
||||||
|
@ -774,6 +797,25 @@ def create_parser_create():
|
||||||
return p
|
return p
|
||||||
|
|
||||||
|
|
||||||
|
def setup_clangfmt(all_files):
|
||||||
|
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']
|
||||||
|
if not all_files:
|
||||||
|
gitcmd.append('-m')
|
||||||
|
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>
|
||||||
|
|
|
@ -56,8 +56,8 @@ const char* get_clipboard_contents() {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height, float dpi,
|
Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height,
|
||||||
ServoDelegate &aDelegate)
|
float dpi, ServoDelegate &aDelegate)
|
||||||
: mWindowHeight(height), mWindowWidth(width), mDelegate(aDelegate) {
|
: mWindowHeight(height), mWindowWidth(width), mDelegate(aDelegate) {
|
||||||
|
|
||||||
capi::CInitOptions o;
|
capi::CInitOptions o;
|
||||||
|
@ -88,7 +88,8 @@ Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height, float dpi
|
||||||
|
|
||||||
// Example Call when *pfilters[] is used:
|
// Example Call when *pfilters[] is used:
|
||||||
// o.vslogger_mod_list = pfilters; // servo log modules
|
// o.vslogger_mod_list = pfilters; // servo log modules
|
||||||
// o.vslogger_mod_size = sizeof(pfilters) / sizeof(pfilters[0]) -1; // Important: Number of modules in pfilters
|
// o.vslogger_mod_size = sizeof(pfilters) / sizeof(pfilters[0]) -1; //
|
||||||
|
// Important: Number of modules in pfilters
|
||||||
o.vslogger_mod_list = NULL;
|
o.vslogger_mod_list = NULL;
|
||||||
o.vslogger_mod_size = 0;
|
o.vslogger_mod_size = 0;
|
||||||
|
|
||||||
|
|
|
@ -238,8 +238,8 @@ void ServoControl::Loop() {
|
||||||
if (mServo == nullptr) {
|
if (mServo == nullptr) {
|
||||||
log("Entering loop");
|
log("Entering loop");
|
||||||
ServoDelegate *sd = static_cast<ServoDelegate *>(this);
|
ServoDelegate *sd = static_cast<ServoDelegate *>(this);
|
||||||
mServo = std::make_unique<Servo>(mInitialURL, mArgs, panelWidth, panelHeight, mDPI,
|
mServo = std::make_unique<Servo>(mInitialURL, mArgs, panelWidth,
|
||||||
*sd);
|
panelHeight, mDPI, *sd);
|
||||||
} else {
|
} else {
|
||||||
// FIXME: this will fail since create_task didn't pick the thread
|
// FIXME: this will fail since create_task didn't pick the thread
|
||||||
// where Servo was running initially.
|
// where Servo was running initially.
|
||||||
|
|
|
@ -118,11 +118,11 @@ private:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void OnSurfaceTapped(IInspectable const &,
|
||||||
OnSurfaceTapped(IInspectable const &,
|
|
||||||
Windows::UI::Xaml::Input::TappedRoutedEventArgs const &);
|
Windows::UI::Xaml::Input::TappedRoutedEventArgs const &);
|
||||||
|
|
||||||
void OnSurfacePointerPressed(IInspectable const &,
|
void OnSurfacePointerPressed(
|
||||||
|
IInspectable const &,
|
||||||
Windows::UI::Xaml::Input::PointerRoutedEventArgs const &);
|
Windows::UI::Xaml::Input::PointerRoutedEventArgs const &);
|
||||||
|
|
||||||
void OnSurfacePointerCanceled(
|
void OnSurfacePointerCanceled(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue