Bug 1494069 - [lint] Explicitly list out objdirs rather than depend on 'obj*' in the global exclude, r=rwood

When using globs in exclude directorives, FileFinder will return every *file*
that gets matched. This is can be thousands of files in the case of an objdir.
While we now collapse these files down to highest possible directories, this
collapse operation can still take a noticeable amount of time (0.6s). This
simply scans topsrcdir for files that start with 'obj' to avoid the glob.

This also moves the '_activate_virtualenv' call to the top of the function
because in CI, this will cause an objdir to be created (to store the
virtualenv). If this happens *after* calculating the global excludes, we won't
catch it since it doesn't exist yet. This will result in the objdir's
virtualenv being linted and erroneous failures.

Depends on D7739

Differential Revision: https://phabricator.services.mozilla.com/D7740

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrew Halberstadt 2018-10-05 19:48:53 +00:00
parent 83df36524d
commit 1c02345779

View File

@ -18,8 +18,16 @@ from mach.decorators import (
Command,
)
try:
from os import scandir
except ImportError:
from scandir import scandir
here = os.path.abspath(os.path.dirname(__file__))
GLOBAL_EXCLUDES = [
'tools/lint/test/files',
]
def setup_argument_parser():
@ -27,6 +35,13 @@ def setup_argument_parser():
return cli.MozlintParser()
def get_global_excludes(topsrcdir):
excludes = GLOBAL_EXCLUDES[:]
excludes.extend([e.name for e in scandir(topsrcdir)
if e.name.startswith('obj') and e.is_dir()])
return excludes
@CommandProvider
class MachCommands(MachCommandBase):
@ -36,11 +51,12 @@ class MachCommands(MachCommandBase):
parser=setup_argument_parser)
def lint(self, *runargs, **lintargs):
"""Run linters."""
from mozlint import cli
lintargs.setdefault('root', self.topsrcdir)
lintargs['exclude'] = ['obj*', 'tools/lint/test/files']
cli.SEARCH_PATHS.append(here)
self._activate_virtualenv()
from mozlint import cli
lintargs.setdefault('root', self.topsrcdir)
lintargs['exclude'] = get_global_excludes(lintargs['root'])
cli.SEARCH_PATHS.append(here)
return cli.run(*runargs, **lintargs)
@Command('eslint', category='devenv',