diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2019-11-04 04:48:20 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-04 04:48:20 -0500 |
commit | f626355b67fc007d5961c446d5a4ddbcc3785698 (patch) | |
tree | 0ed88da63b5fd96bf71a434ab12c655b9b2e5835 | |
parent | 84f13342f66c6b5ea8f2c33dad17de48fc4f8b18 (diff) | |
parent | 36c16692152b6bc66122c26fcd90e82469020a21 (diff) | |
download | servo-f626355b67fc007d5961c446d5a4ddbcc3785698.tar.gz servo-f626355b67fc007d5961c446d5a4ddbcc3785698.zip |
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?
-rw-r--r-- | .clang-format (renamed from support/hololens/.clang-format) | 0 | ||||
-rw-r--r-- | python/servo/testing_commands.py | 52 | ||||
-rw-r--r-- | support/hololens/ServoApp/BrowserPage.cpp | 2 | ||||
-rw-r--r-- | support/hololens/ServoApp/ServoControl/Servo.cpp | 33 | ||||
-rw-r--r-- | support/hololens/ServoApp/ServoControl/ServoControl.cpp | 4 | ||||
-rw-r--r-- | support/hololens/ServoApp/ServoControl/ServoControl.h | 10 |
6 files changed, 72 insertions, 29 deletions
diff --git a/support/hololens/.clang-format b/.clang-format index a84532a0cf3..a84532a0cf3 100644 --- a/support/hololens/.clang-format +++ b/.clang-format diff --git a/python/servo/testing_commands.py b/python/servo/testing_commands.py index c5a6e4cc620..53e7c3c901f 100644 --- a/python/servo/testing_commands.py +++ b/python/servo/testing_commands.py @@ -22,6 +22,7 @@ import six.moves.urllib as urllib import base64 import shutil import subprocess +from xml.etree.ElementTree import XML from six import iteritems 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") SERVO_TESTS_PATH = os.path.join("tests", "wpt", "mozilla", "tests") +CLANGFMT_CPP_DIRS = ["support/hololens/"] + TEST_SUITES = OrderedDict([ ("tidy", {"kwargs": {"all_files": False, "no_progress": False, "self_test": False, "stylo": False}, @@ -323,7 +326,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") - 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: return test_tidy.do_tests() else: @@ -334,9 +338,21 @@ class MachCommands(CommandBase): tidy_failed = tidy.scan(not all_files, not no_progress, stylo=stylo) self.install_rustfmt() 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") - return tidy_failed or manifest_dirty or rustfmt_failed + + return tidy_failed or manifest_dirty or rustfmt_failed or clangfmt_failed @Command('test-webidl', description='Run the WebIDL parser tests', @@ -458,9 +474,16 @@ class MachCommands(CommandBase): return run_update(self.context.topdir, **kwargs) @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') - 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() return self.call_rustup_run(["cargo", "fmt"]) @@ -774,6 +797,25 @@ def create_parser_create(): 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 class WebPlatformTestsCreator(CommandBase): template_prefix = """<!doctype html> diff --git a/support/hololens/ServoApp/BrowserPage.cpp b/support/hololens/ServoApp/BrowserPage.cpp index 61341dfcc29..a9de7e2942d 100644 --- a/support/hololens/ServoApp/BrowserPage.cpp +++ b/support/hololens/ServoApp/BrowserPage.cpp @@ -69,7 +69,7 @@ void BrowserPage::SetTransientMode(bool transient) { navigationBar().Visibility(transient ? Visibility::Collapsed : Visibility::Visible); transientLoadingIndicator().Visibility(transient ? Visibility::Visible - : Visibility::Collapsed); + : Visibility::Collapsed); } void BrowserPage::SetArgs(hstring args) { servoControl().SetArgs(args); } diff --git a/support/hololens/ServoApp/ServoControl/Servo.cpp b/support/hololens/ServoApp/ServoControl/Servo.cpp index 17aeb0d64e6..8c66e8cdeb3 100644 --- a/support/hololens/ServoApp/ServoControl/Servo.cpp +++ b/support/hololens/ServoApp/ServoControl/Servo.cpp @@ -47,17 +47,17 @@ void on_ime_state_changed(bool aShow) { sServo->Delegate().OnServoIMEStateChanged(aShow); } -void set_clipboard_contents(const char* content) { +void set_clipboard_contents(const char *content) { // FIXME } -const char* get_clipboard_contents() { +const char *get_clipboard_contents() { // FIXME return nullptr; } -Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height, float dpi, - ServoDelegate &aDelegate) +Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height, + float dpi, ServoDelegate &aDelegate) : mWindowHeight(height), mWindowWidth(width), mDelegate(aDelegate) { capi::CInitOptions o; @@ -73,22 +73,23 @@ Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height, float dpi // 7 filter modules. /* Sample list of servo modules to filter. static char *pfilters[] = { - "servo", - "simpleservo", - "simpleservo::jniapi", - "simpleservo::gl_glue::egl", - // Show JS errors by default. - "script::dom::bindings::error", - // Show GL errors by default. - "canvas::webgl_thread", - "compositing::compositor", - "constellation::constellation", + "servo", + "simpleservo", + "simpleservo::jniapi", + "simpleservo::gl_glue::egl", + // Show JS errors by default. + "script::dom::bindings::error", + // Show GL errors by default. + "canvas::webgl_thread", + "compositing::compositor", + "constellation::constellation", }; */ // Example Call when *pfilters[] is used: // 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_size = 0; @@ -135,7 +136,7 @@ std::unique_ptr<char *> hstring2char(hstring hstr) { char *str = new char[size]; size_t converted = 0; wcstombs_s(&converted, str, size, wc, hstr.size()); - return std::make_unique<char*>(str); + return std::make_unique<char *>(str); } } // namespace winrt::servo diff --git a/support/hololens/ServoApp/ServoControl/ServoControl.cpp b/support/hololens/ServoApp/ServoControl/ServoControl.cpp index 47e6ab7b5c0..9e7323ae8f2 100644 --- a/support/hololens/ServoApp/ServoControl/ServoControl.cpp +++ b/support/hololens/ServoApp/ServoControl/ServoControl.cpp @@ -238,8 +238,8 @@ void ServoControl::Loop() { if (mServo == nullptr) { log("Entering loop"); ServoDelegate *sd = static_cast<ServoDelegate *>(this); - mServo = std::make_unique<Servo>(mInitialURL, mArgs, panelWidth, panelHeight, mDPI, - *sd); + mServo = std::make_unique<Servo>(mInitialURL, mArgs, panelWidth, + panelHeight, mDPI, *sd); } else { // FIXME: this will fail since create_task didn't pick the thread // where Servo was running initially. diff --git a/support/hololens/ServoApp/ServoControl/ServoControl.h b/support/hololens/ServoApp/ServoControl/ServoControl.h index 816e68d095c..77645f6ffaf 100644 --- a/support/hololens/ServoApp/ServoControl/ServoControl.h +++ b/support/hololens/ServoApp/ServoControl/ServoControl.h @@ -118,12 +118,12 @@ private: } } - void - OnSurfaceTapped(IInspectable const &, - Windows::UI::Xaml::Input::TappedRoutedEventArgs const &); + void OnSurfaceTapped(IInspectable const &, + Windows::UI::Xaml::Input::TappedRoutedEventArgs const &); - void OnSurfacePointerPressed(IInspectable const &, - Windows::UI::Xaml::Input::PointerRoutedEventArgs const &); + void OnSurfacePointerPressed( + IInspectable const &, + Windows::UI::Xaml::Input::PointerRoutedEventArgs const &); void OnSurfacePointerCanceled( IInspectable const &, |