Bug 1320194 - Add ability to specify custom emitter function in TreeMetadataEmitter draft
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Fri, 27 Jan 2017 11:54:09 -0500
changeset 482038 0edf877a6166e85b16216b65bba32dddda087d97
parent 482037 ecd9bfd17fff0531e391156df903ac6ce7aa9fdd
child 482039 25a2d85e93d36684df183ebf79b58ebc65ac2dd9
push id44987
push userahalberstadt@mozilla.com
push dateFri, 10 Feb 2017 21:37:10 +0000
bugs1320194
milestone54.0a1
Bug 1320194 - Add ability to specify custom emitter function in TreeMetadataEmitter Currently, the only way to emit objects after reading moz.build, is to emit everything. Though, sometimes it may be desirable to only emit certain types of objects. This adds a new argument that allows consumers to specify a custom emitter function. This gives them the flexibility to do whatever they want. This will be used when resolving tests, so only TestManifest objects are emitted. MozReview-Commit-ID: DPGgNmn2JvE
python/mozbuild/mozbuild/frontend/emitter.py
--- a/python/mozbuild/mozbuild/frontend/emitter.py
+++ b/python/mozbuild/mozbuild/frontend/emitter.py
@@ -149,23 +149,24 @@ class TreeMetadataEmitter(LoggingMixin):
 
     def summary(self):
         return ExecutionSummary(
             'Processed into {object_count:d} build config descriptors in '
             '{execution_time:.2f}s',
             execution_time=self._emitter_time,
             object_count=self._object_count)
 
-    def emit(self, output):
+    def emit(self, output, emitfn=None):
         """Convert the BuildReader output into data structures.
 
         The return value from BuildReader.read_topsrcdir() (a generator) is
         typically fed into this function.
         """
         contexts = {}
+        emitfn = emitfn or self.emit_from_context
 
         def emit_objs(objs):
             for o in objs:
                 self._object_count += 1
                 yield o
 
         for out in output:
             # Nothing in sub-contexts is currently of interest to us. Filter
@@ -174,17 +175,17 @@ class TreeMetadataEmitter(LoggingMixin):
                 continue
 
             if isinstance(out, Context):
                 # Keep all contexts around, we will need them later.
                 contexts[out.objdir] = out
 
                 start = time.time()
                 # We need to expand the generator for the timings to work.
-                objs = list(self.emit_from_context(out))
+                objs = list(emitfn(out))
                 self._emitter_time += time.time() - start
 
                 for o in emit_objs(objs): yield o
 
             else:
                 raise Exception('Unhandled output type: %s' % type(out))
 
         # Don't emit Linkable objects when COMPILE_ENVIRONMENT is not set