diff options
Diffstat (limited to 'python')
-rw-r--r-- | python/servo/devenv_commands.py | 13 | ||||
-rw-r--r-- | python/servo/testing_commands.py | 18 | ||||
-rw-r--r-- | python/tidy/servo_tidy/tidy.py | 32 | ||||
-rw-r--r-- | python/tidy/servo_tidy_tests/test_tidy.py | 6 |
4 files changed, 17 insertions, 52 deletions
diff --git a/python/servo/devenv_commands.py b/python/servo/devenv_commands.py index 71181220b76..46862754bd1 100644 --- a/python/servo/devenv_commands.py +++ b/python/servo/devenv_commands.py @@ -233,19 +233,6 @@ class MachCommands(CommandBase): with cd(self.context.topdir): return self.call_rustup_run(["cargo", "fetch"], env=self.build_env()) - @Command('rustfmt', - description='Format the Rust code using Cargo fmt', - category='devenv') - @CommandArgument( - '--directory', '-d', default=None, - help='Command-line argument to specify the directory for formatting') - def rustfmt(self, directory=""): - if directory == "": - directory = self.context.topdir - - with cd(self.context.topdir): - return self.call_rustup_run(["cargo", "fmt", "--", directory], env=self.build_env()) - @Command('ndk-stack', description='Invoke the ndk-stack tool with the expected symbol paths', category='devenv') diff --git a/python/servo/testing_commands.py b/python/servo/testing_commands.py index 506d20874a4..771d1746351 100644 --- a/python/servo/testing_commands.py +++ b/python/servo/testing_commands.py @@ -304,6 +304,13 @@ class MachCommands(CommandBase): "tests/wpt/mozilla/.") return 0 + def install_rustfmt(self): + with open(os.devnull, "w") as devnull: + if self.call_rustup_run(["cargo", "fmt", "--version", "-q"], + stderr=devnull) != 0: + # Rustfmt is not installed. Install: + self.call_rustup_run(["rustup", "component", "add", "rustfmt-preview"]) + @Command('test-tidy', description='Run the source code tidiness check', category='testing') @@ -322,7 +329,9 @@ class MachCommands(CommandBase): else: manifest_dirty = run_update(self.context.topdir, check_clean=True) tidy_failed = tidy.scan(not all_files, not no_progress, stylo=stylo) - return tidy_failed or manifest_dirty + self.install_rustfmt() + rustfmt_failed = self.call_rustup_run(["cargo", "fmt", "--", "--check"]) + return tidy_failed or manifest_dirty or rustfmt_failed @Command('test-webidl', description='Run the WebIDL parser tests', @@ -443,6 +452,13 @@ class MachCommands(CommandBase): def update_manifest(self, **kwargs): return run_update(self.context.topdir, **kwargs) + @Command('fmt', + description='Format the Rust source files with rustfmt', + category='testing') + def format_code(self, **kwargs): + self.install_rustfmt() + return self.call_rustup_run(["cargo", "fmt"]) + @Command('update-wpt', description='Update the web platform tests', category='testing', diff --git a/python/tidy/servo_tidy/tidy.py b/python/tidy/servo_tidy/tidy.py index 9059c1f9843..f8def74e57c 100644 --- a/python/tidy/servo_tidy/tidy.py +++ b/python/tidy/servo_tidy/tidy.py @@ -509,10 +509,8 @@ def check_rust(file_name, lines): is_lib_rs_file = file_name.endswith("lib.rs") - prev_use = None prev_open_brace = False multi_line_string = False - current_indent = 0 prev_crate = {} prev_mod = {} prev_feature_name = "" @@ -716,36 +714,6 @@ def check_rust(file_name, lines): # not a feature attribute line, so empty previous name prev_feature_name = "" - # imports must be in the same line, alphabetically sorted, and merged - # into a single import block - if line.startswith("use "): - import_block = True - if not line.endswith(";") and '{' in line: - yield (idx + 1, "use statement spans multiple lines") - if '{ ' in line: - yield (idx + 1, "extra space after {") - if ' }' in line: - yield (idx + 1, "extra space before }") - # strip "use" from the begin and ";" from the end - current_use = line[4:-1] - if prev_use: - current_use_cut = current_use.replace("{self,", ".").replace("{", ".") - prev_use_cut = prev_use.replace("{self,", ".").replace("{", ".") - if indent == current_indent and current_use_cut < prev_use_cut and check_alphabetical_order: - yield(idx + 1, decl_message.format("use statement") - + decl_expected.format(prev_use) - + decl_found.format(current_use)) - prev_use = current_use - current_indent = indent - - if whitespace or not import_block: - current_indent = 0 - - # do not allow blank lines in an import block - if import_block and whitespace and line.startswith("use "): - whitespace = False - yield(idx, "encountered whitespace following a use statement") - # modules must be in the same line and alphabetically sorted if line.startswith("mod ") or line.startswith("pub mod "): # strip /(pub )?mod/ from the left and ";" from the right diff --git a/python/tidy/servo_tidy_tests/test_tidy.py b/python/tidy/servo_tidy_tests/test_tidy.py index dbc3f9d4f8b..c1dec57ab89 100644 --- a/python/tidy/servo_tidy_tests/test_tidy.py +++ b/python/tidy/servo_tidy_tests/test_tidy.py @@ -105,14 +105,8 @@ class CheckTidiness(unittest.TestCase): def test_rust(self): errors = tidy.collect_errors_for_files(iterFile('rust_tidy.rs'), [], [tidy.check_rust], print_text=False) self.assertEqual('extra space after use', errors.next()[2]) - self.assertEqual('extra space after {', errors.next()[2]) - self.assertEqual('extra space before }', errors.next()[2]) - self.assertEqual('use statement spans multiple lines', errors.next()[2]) self.assertEqual('missing space before }', errors.next()[2]) - self.assertTrue('use statement is not in alphabetical order' in errors.next()[2]) self.assertEqual('use statement contains braces for single import', errors.next()[2]) - self.assertTrue('use statement is not in alphabetical order' in errors.next()[2]) - self.assertEqual('encountered whitespace following a use statement', errors.next()[2]) self.assertTrue('mod declaration is not in alphabetical order' in errors.next()[2]) self.assertEqual('mod declaration spans multiple lines', errors.next()[2]) self.assertTrue('extern crate declaration is not in alphabetical order' in errors.next()[2]) |