Bug 1398765 - Fix directory exclusion bug in py-compat linters, r=gps
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Mon, 11 Sep 2017 09:03:53 -0400
changeset 429927 237a3f842dc137837a91ce1234dd4697b00db307
parent 429926 8db97b50b5d387dd4961c30704b863a33deaa2bb
child 429928 776a65d43a5eaa098a1b7956ef6486d64729a0db
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs1398765
milestone57.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 1398765 - Fix directory exclusion bug in py-compat linters, r=gps The excluded directories aren't being properly handled in the py2/py3 compat linters. In order for FileFinder to apply the exclusions properly they need to either be relative to or contained by the base. This means that currently the following will work: ./mach lint -l py2 <topsrcdir> ./mach lint -l py2 testing/mochitest But this is broken: ./mach lint -l py2 testing This change fixes the compat linters so exclude paths will be made relative to the FileFinder base before passing them in. Any exclude not contained by the base is simply discarded as it won't be relevant to that FileFinder instance anyway. MozReview-Commit-ID: LJx97TvKlSa
tools/lint/python/compat.py
--- a/tools/lint/python/compat.py
+++ b/tools/lint/python/compat.py
@@ -4,16 +4,17 @@
 
 from __future__ import absolute_import, print_function
 
 import json
 import os
 import tempfile
 from distutils.spawn import find_executable
 
+import mozpack.path as mozpath
 from mozpack.files import FileFinder
 from mozprocess import ProcessHandlerMixin
 
 from mozlint import result
 
 here = os.path.abspath(os.path.dirname(__file__))
 
 results = []
@@ -40,25 +41,29 @@ def run_linter(python, paths, config, **
     binary = find_executable(python)
     if not binary:
         # TODO bootstrap python3 if not available
         print('error: {} not detected, aborting py-compat check'.format(python))
         if 'MOZ_AUTOMATION' in os.environ:
             return 1
         return []
 
+    root = lintargs['root']
     pattern = "**/*.py"
-    exclude = lintargs.get('exclude', [])
+    exclude = [mozpath.join(root, e) for e in lintargs.get('exclude', [])]
     files = []
     for path in paths:
+        path = mozpath.normsep(path)
         if os.path.isfile(path):
             files.append(path)
             continue
 
-        finder = FileFinder(path, ignore=exclude)
+        ignore = [e[len(path):].lstrip('/') for e in exclude
+                  if mozpath.commonprefix((path, e)) == path]
+        finder = FileFinder(path, ignore=ignore)
         files.extend([os.path.join(path, p) for p, f in finder.find(pattern)])
 
     with tempfile.NamedTemporaryFile(mode='w') as fh:
         fh.write('\n'.join(files))
         fh.flush()
 
         cmd = [binary, os.path.join(here, 'check_compat.py'), fh.name]