Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce rustfmt on CI #22126

Merged
merged 6 commits into from Nov 7, 2018
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Run rustfmt on test-tidy

Add ./mach fmt command.
Mach installs rustfmt if needed.
  • Loading branch information
pyfisch committed Nov 6, 2018
commit bf47f90da667e95eaffc8fee36ca8a88e72e276c
@@ -233,19 +233,6 @@ def fetch(self):
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')
@@ -304,6 +304,12 @@ def test_content(self):
"tests/wpt/mozilla/.")
return 0

def install_rustfmt(self):
if self.call_rustup_run(["cargo", "fmt", "--version", "-q"],
stderr=open(os.devnull, "w")) != 0:

This comment has been minimized.

Copy link
@emilio

emilio Nov 6, 2018

Member

Doesn't this leak the file descriptor?

This comment has been minimized.

Copy link
@pyfisch

pyfisch Nov 6, 2018

Author Contributor

Good catch!

# 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 @@ def test_tidy(self, all_files, no_progress, self_test, stylo):
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 @@ def wptrunner(self, run_file, **kwargs):
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',
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.