bitbake: event: Inject 'd' into event handlers

To quote Chris Larson:

"""
e.data.getVar() gets a bit old in a large event handler, and it means a
simple handler has to be modified if switching between an event handler
(e.g. RecipeParsed) and anonymous python. I think it would make sense
to restore the 'd' convention here to align with python elsewhere.
It'd just be a convenience, d==e.data, to avoid the common pattern of
setting it at the top of the event handler.
"""

I couldn't find a way to inject 'd' via locals/globals due to the use
of a function parameter so this left __builtins__ as the only way
I could find to make this work.

[YOCTO #7668]

(Bitbake rev: 44ac81e5281fb62ad00e2f79a9d754118ea62526)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Richard Purdie 2015-06-19 09:27:14 +01:00
parent 69b6919341
commit df123ddab4
1 changed files with 2 additions and 0 deletions

View File

@ -72,6 +72,7 @@ _eventfilter = None
def execute_handler(name, handler, event, d):
event.data = d
__builtins__['d'] = d
try:
ret = handler(event)
except (bb.parse.SkipRecipe, bb.BBHandledException):
@ -87,6 +88,7 @@ def execute_handler(name, handler, event, d):
raise
finally:
del event.data
del __builtins__['d']
def fire_class_handlers(event, d):
if isinstance(event, logging.LogRecord):