Bug 1394071 - Create a Finder for relevant moz.build files; r?mshal draft
authorGregory Szorc <gps@mozilla.com>
Fri, 25 Aug 2017 19:08:24 -0700
changeset 653548 d4f5805264f4fe97cffba60567e00b146cc94b20
parent 653538 31465a03c03d1eec31cd4dd5d6b803724dcb29cd
child 653549 afb2b187c73aa30d099ab181e73a401fbd919c13
push id76341
push usergszorc@mozilla.com
push dateSat, 26 Aug 2017 02:29:12 +0000
reviewersmshal
bugs1394071
milestone57.0a1
Bug 1394071 - Create a Finder for relevant moz.build files; r?mshal Not every moz.build file in the repo is a normal moz.build file. Some moz.build files are used for testing moz.build files. Others may exist in directories that should be ignored. all_mozbuild_path() already knew how to filter out moz.build files that should be ignored. Let's extract the Finder for doing this into an instance attribute so it can be used elsewhere. MozReview-Commit-ID: 9PaZQAbjIZO
python/mozbuild/mozbuild/frontend/reader.py
--- a/python/mozbuild/mozbuild/frontend/reader.py
+++ b/python/mozbuild/mozbuild/frontend/reader.py
@@ -847,16 +847,28 @@ class BuildReader(object):
     def __init__(self, config, finder=default_finder):
         self.config = config
 
         self._log = logging.getLogger(__name__)
         self._read_files = set()
         self._execution_stack = []
         self._finder = finder
 
+        # Finder patterns to ignore when searching for moz.build files.
+        ignores = {
+            # Ignore fake moz.build files used for testing moz.build.
+            'python/mozbuild/mozbuild/test',
+
+            # Ignore object directories.
+            'obj*',
+        }
+
+        self._relevant_mozbuild_finder = FileFinder(self.config.topsrcdir,
+                                                    ignore=ignores)
+
         max_workers = cpu_count()
         self._gyp_worker_pool = ProcessPoolExecutor(max_workers=max_workers)
         self._gyp_processors = []
         self._execution_time = 0.0
         self._file_count = 0
         self._gyp_execution_time = 0.0
         self._gyp_file_count = 0
 
@@ -899,30 +911,20 @@ class BuildReader(object):
         """Iterator over all available moz.build files.
 
         This method has little to do with the reader. It should arguably belong
         elsewhere.
         """
         # In the future, we may traverse moz.build files by looking
         # for DIRS references in the AST, even if a directory is added behind
         # a conditional. For now, just walk the filesystem.
-        ignore = {
-            # Ignore fake moz.build files used for testing moz.build.
-            'python/mozbuild/mozbuild/test',
-
-            # Ignore object directories.
-            'obj*',
-        }
-
-        finder = FileFinder(self.config.topsrcdir, ignore=ignore)
-
         # The root doesn't get picked up by FileFinder.
         yield 'moz.build'
 
-        for path, f in finder.find('**/moz.build'):
+        for path, f in self._relevant_mozbuild_finder.find('**/moz.build'):
             yield path
 
     def find_sphinx_variables(self):
         """This function finds all assignments of Sphinx documentation variables.
 
         This is a generator of tuples of (moz.build path, var, key, value). For
         variables that assign to keys in objects, key will be defined.