Bug 1645869 - mozlint/rustfmt: make the check relevant r=undef1nd
authorSylvestre Ledru <sledru@mozilla.com>
Wed, 17 Jun 2020 07:16:09 +0000
changeset 536002 1e3e996bb9a125cd6b152dc17c03ead45f0d3859
parent 536001 00b1e2a78573e809ef86a70d72b9cb7253f0caea
child 536003 c216429dfc9d7e468b7b9670a3b9c48322a82188
push id37515
push usernerli@mozilla.com
push dateWed, 17 Jun 2020 14:49:45 +0000
treeherdermozilla-central@1e3e996bb9a1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersundef1nd
bugs1645869
milestone79.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1645869 - mozlint/rustfmt: make the check relevant r=undef1nd The version check is done above. So, it will fail there. Move the binary check earlier to have a better error message + simplify the code Differential Revision: https://phabricator.services.mozilla.com/D79725
tools/lint/rust/__init__.py
--- a/tools/lint/rust/__init__.py
+++ b/tools/lint/rust/__init__.py
@@ -120,49 +120,49 @@ def get_rustfmt_version(binary):
             [binary, "--version"],
             stderr=subprocess.STDOUT,
             universal_newlines=True,
         )
     except subprocess.CalledProcessError as e:
         output = e.output
 
     version = re.findall(r'\d.\d+.\d+', output)[0]
-    version = StrictVersion(version)
-    return version
+    return StrictVersion(version)
 
 
 def lint(paths, config, fix=None, **lintargs):
     log = lintargs['log']
     paths = list(expand_exclusions(paths, config, lintargs['root']))
 
     # An empty path array can occur when the user passes in `-n`. If we don't
     # return early in this case, rustfmt will attempt to read stdin and hang.
     if not paths:
         return []
 
     binary = get_rustfmt_binary()
+
+    if not binary:
+        print(RUSTFMT_NOT_FOUND)
+        if "MOZ_AUTOMATION" in os.environ:
+            return 1
+        return []
+
     min_version_str = config.get('min_rustfmt_version')
     min_version = StrictVersion(min_version_str)
     actual_version = get_rustfmt_version(binary)
     log.debug(
         "Found version: {}. Minimal expected version: {}".format(
             actual_version, min_version
         )
     )
 
     if actual_version < min_version:
         print(RUSTFMT_WRONG_VERSION.format(version=min_version_str))
         return 1
 
-    if not binary:
-        print(RUSTFMT_NOT_FOUND)
-        if "MOZ_AUTOMATION" in os.environ:
-            return 1
-        return []
-
     cmd_args = [binary]
     if not fix:
         cmd_args.append("--check")
     base_command = cmd_args + paths
     log.debug("Command: {}".format(' '.join(cmd_args)))
     output = run_process(config, base_command)
 
     if fix: