Bug 1203266 - Remove uses of the emitter in files_info now that they're no longer needed. r=gps draft
authorChris Manchester <cmanchester@mozilla.com>
Wed, 02 Mar 2016 17:26:10 -0800
changeset 336365 a8245711aba2c1be403cfdc435d792015f2d3e06
parent 336363 abf4910b43b9935169bfedd88e98362f60d9dbf8
child 515371 71febddac6c3707d709d58968bce613452e99f65
push id12039
push usercmanchester@mozilla.com
push dateThu, 03 Mar 2016 01:32:39 +0000
reviewersgps
bugs1203266
milestone47.0a1
Bug 1203266 - Remove uses of the emitter in files_info now that they're no longer needed. r=gps MozReview-Commit-ID: 3S8M1K8CIvy
python/mozbuild/mozbuild/frontend/reader.py
python/mozbuild/mozbuild/test/frontend/data/files-test-metadata/default/moz.build
python/mozbuild/mozbuild/test/frontend/test_reader.py
--- a/python/mozbuild/mozbuild/frontend/reader.py
+++ b/python/mozbuild/mozbuild/frontend/reader.py
@@ -1346,17 +1346,16 @@ class BuildReader(object):
         3. Iterate over Files sub-contexts.
         4. If the file pattern matches the file we're seeking info on,
            apply attribute updates.
         5. Return the most recent value of attributes.
         """
         paths, _ = self.read_relevant_mozbuilds(paths)
 
         r = {}
-        test_ctx_reader = TestContextReader(self.config)
 
         for path, ctxs in paths.items():
             flags = Files(Context())
 
             for ctx in ctxs:
                 if not isinstance(ctx, Files):
                     continue
 
@@ -1366,66 +1365,44 @@ class BuildReader(object):
                 # Only do wildcard matching if the '*' character is present.
                 # Otherwise, mozpath.match will match directories, which we've
                 # arbitrarily chosen to not allow.
                 if pattern == relpath or \
                         ('*' in pattern and mozpath.match(relpath, pattern)):
                     flags += ctx
 
             if not any([flags.test_tags, flags.test_files, flags.test_flavors]):
-                flags += test_ctx_reader.test_defaults_for_path(path, ctxs)
+                flags += self.test_defaults_for_path(ctxs)
 
             r[path] = flags
 
         return r
 
-
-class TestContextReader(object):
-    """Helper to extract test patterns defaults from moz.build files.
-
-    Given paths of interest and relevant contexts, populates a Files
-    object with patterns matching all tests mentioned in the given
-    contexts.
-    """
-    def __init__(self, config):
-        self.config = config
-
+    def test_defaults_for_path(self, ctxs):
         # This names the context keys that will end up emitting a test
         # manifest.
-        self._test_manifest_contexts = set(
+        test_manifest_contexts = set(
             ['%s_MANIFESTS' % key for key in TEST_MANIFESTS] +
             ['%s_MANIFESTS' % flavor.upper() for flavor in REFTEST_FLAVORS] +
-            ['%s_MANIFESTS' % flavor.upper().replace('-', '_') for flavor in WEB_PATFORM_TESTS_FLAVORS] +
-            # The emitter requires JAR_MANIFESTS in contexts if they exist on
-            # disk, so include them here.
-            ['JAR_MANIFESTS']
+            ['%s_MANIFESTS' % flavor.upper().replace('-', '_') for flavor in WEB_PATFORM_TESTS_FLAVORS]
         )
 
-
-    def test_defaults_for_path(self, path, ctxs):
-        # Using the emitter here creates a circular import (and crosses some
-        # abstraction boundaries), but it's a convenient way to get the build
-        # system's view of tests.
-        # Bug 1203266 tracks features that would allow improving this situation
-        # and removing this abuse of the TreeMetadataEmitter
-        from .emitter import TreeMetadataEmitter, TestManifest
-        emitter = TreeMetadataEmitter(self.config)
-
         result_context = Files(Context())
-
         for ctx in ctxs:
-            test_context = Context(VARIABLES, self.config)
-            test_context.main_path = ctx.main_path
-
-            # Clone just the keys that will result in test manifests.
-            manifest_keys = [key for key in ctx if key in self._test_manifest_contexts]
-            for key in manifest_keys:
-                test_context[key] = ctx[key]
-            for obj in emitter.emit_from_context(test_context):
-                if isinstance(obj, TestManifest):
-                    for t in obj.tests:
-                        if 'relpath' not in t:
-                            # wpt manifests do not generate relpaths (bug 1207678).
-                            t['relpath'] = mozpath.relpath(t['path'],
-                                                           self.config.topsrcdir)
-                        # Pull in the entire directory of tests.
-                        result_context.test_files.add(mozpath.dirname(t['relpath']) + '/**')
+            for key in ctx:
+                if key not in test_manifest_contexts:
+                    continue
+                for paths, obj in ctx[key]:
+                    if isinstance(paths, tuple):
+                        path, tests_root = paths
+                        tests_root = mozpath.join(ctx.relsrcdir, tests_root)
+                        for t in (mozpath.join(tests_root, path) for path, _ in obj):
+                            result_context.test_files.add(mozpath.dirname(t) + '/**')
+                    else:
+                        for t in obj.tests:
+                            if isinstance(t, tuple):
+                                path, _ = t
+                                relpath = mozpath.relpath(path,
+                                                          self.config.topsrcdir)
+                            else:
+                                relpath = t['relpath']
+                            result_context.test_files.add(mozpath.dirname(relpath) + '/**')
         return result_context
--- a/python/mozbuild/mozbuild/test/frontend/data/files-test-metadata/default/moz.build
+++ b/python/mozbuild/mozbuild/test/frontend/data/files-test-metadata/default/moz.build
@@ -1,5 +1,6 @@
 XPCSHELL_TESTS_MANIFESTS += ['tests/xpcshell/xpcshell.ini']
+REFTEST_MANIFESTS += ['tests/reftests/reftest.list']
 
 EXTRA_JS_MODULES += [
     'module.js',
 ]
\ No newline at end of file
--- a/python/mozbuild/mozbuild/test/frontend/test_reader.py
+++ b/python/mozbuild/mozbuild/test/frontend/test_reader.py
@@ -429,17 +429,18 @@ class TestBuildReader(unittest.TestCase)
 
     def test_file_test_deps_default(self):
         reader = self.reader('files-test-metadata')
         v = reader.files_info([
             'default/module.js',
         ])
 
         expected = {
-            'default/module.js': set(['default/tests/xpcshell/**']),
+            'default/module.js': set(['default/tests/xpcshell/**',
+                                      'default/tests/reftests/**']),
         }
 
         for path, pattern_set in expected.items():
             self.assertEqual(v[path].test_files,
                              expected[path])
 
     def test_file_test_deps_tags(self):
         reader = self.reader('files-test-metadata')