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
--- 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