diff options
author | Pyfisch <pyfisch@gmail.com> | 2018-10-15 12:14:28 +0200 |
---|---|---|
committer | Pyfisch <pyfisch@gmail.com> | 2018-11-06 22:28:29 +0100 |
commit | bf47f90da667e95eaffc8fee36ca8a88e72e276c (patch) | |
tree | 005a5010cdd46fac4b547c5307c54e7654a7b3d3 | |
parent | 6878dbbbeaa59b21a7b3608b6d6a911e88c1e443 (diff) | |
download | servo-bf47f90da667e95eaffc8fee36ca8a88e72e276c.tar.gz servo-bf47f90da667e95eaffc8fee36ca8a88e72e276c.zip |
Run rustfmt on test-tidy
Add ./mach fmt command.
Mach installs rustfmt if needed.
-rw-r--r-- | python/servo/devenv_commands.py | 13 | ||||
-rw-r--r-- | python/servo/testing_commands.py | 17 |
2 files changed, 16 insertions, 14 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..0e0c23baefc 100644 --- a/python/servo/testing_commands.py +++ b/python/servo/testing_commands.py @@ -304,6 +304,12 @@ class MachCommands(CommandBase): "tests/wpt/mozilla/.") return 0 + def install_rustfmt(self): + if self.call_rustup_run(["cargo", "fmt", "--version", "-q"], + stderr=open(os.devnull, "w")) != 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 +328,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 +451,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', |