From c596c9f887f6f2fc50b1f586d2c36417c5793ef9 Mon Sep 17 00:00:00 2001 From: Bogdan Marinescu Date: Fri, 31 May 2013 14:19:14 +0000 Subject: [PATCH] bitbake: bitbake: Add event mask flag support Add a flag to event handlers which lists the events a given handler wishes to process. By default event handlers recieve all events but this means we can stop running code in many cases if we know it doesn't want the event. This is part of the fix for YOCTO #3812, but implements filtering only for class event handlers; the other part (events filter for UIs) will be the subject of a different patch. (Bitbake rev: 074003a4e7530a72863b9c685fc5c31b0f08c039) Signed-off-by: Bogdan Marinescu Signed-off-by: Richard Purdie --- bitbake/lib/bb/cookerdata.py | 2 +- bitbake/lib/bb/event.py | 23 ++++++++++++++++++----- bitbake/lib/bb/parse/ast.py | 3 +-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/bitbake/lib/bb/cookerdata.py b/bitbake/lib/bb/cookerdata.py index 1bed455..4ddc2a5 100644 --- a/bitbake/lib/bb/cookerdata.py +++ b/bitbake/lib/bb/cookerdata.py @@ -269,7 +269,7 @@ class CookerDataBuilder(object): # Nomally we only register event handlers at the end of parsing .bb files # We register any handlers we've found so far here... for var in data.getVar('__BBHANDLERS') or []: - bb.event.register(var, data.getVar(var)) + bb.event.register(var, data.getVar(var), (data.getVarFlag(var, "eventmask", True) or "").split()) if data.getVar("BB_WORKERCONTEXT", False) is None: bb.fetch.fetcher_init(data) diff --git a/bitbake/lib/bb/event.py b/bitbake/lib/bb/event.py index d73067f..9c134ee 100644 --- a/bitbake/lib/bb/event.py +++ b/bitbake/lib/bb/event.py @@ -64,6 +64,8 @@ def clean_class_handlers(): _handlers = clean_class_handlers() _ui_handlers = {} _ui_handler_seq = 0 +_event_handler_map = {} +_catchall_handlers = {} def execute_handler(name, handler, event, d): event.data = d @@ -87,11 +89,14 @@ def fire_class_handlers(event, d): if isinstance(event, logging.LogRecord): return + eid = str(event.__class__)[8:-2] + evt_hmap = _event_handler_map.get(eid, {}) for name, handler in _handlers.iteritems(): - try: - execute_handler(name, handler, event, d) - except Exception: - continue + if name in _catchall_handlers or name in evt_hmap: + try: + execute_handler(name, handler, event, d) + except Exception: + continue ui_queue = [] @atexit.register @@ -160,7 +165,7 @@ def fire_from_worker(event, d): fire_ui_handlers(event, d) noop = lambda _: None -def register(name, handler): +def register(name, handler, mask=[]): """Register an Event handler""" # already registered @@ -185,6 +190,14 @@ def register(name, handler): else: _handlers[name] = handler + if not mask: + _catchall_handlers[name] = True + else: + for m in mask: + if _event_handler_map.get(m, None) is None: + _event_handler_map[m] = {} + _event_handler_map[m][name] = True + return Registered def remove(name, handler): diff --git a/bitbake/lib/bb/parse/ast.py b/bitbake/lib/bb/parse/ast.py index 713bef1..6e7fd84 100644 --- a/bitbake/lib/bb/parse/ast.py +++ b/bitbake/lib/bb/parse/ast.py @@ -320,8 +320,7 @@ def finalize(fn, d, variant = None): all_handlers = {} for var in d.getVar('__BBHANDLERS') or []: # try to add the handler - handler = d.getVar(var) - bb.event.register(var, handler) + bb.event.register(var, d.getVar(var), (d.getVarFlag(var, "eventmask", True) or "").split()) bb.event.fire(bb.event.RecipePreFinalise(fn), d) -- 2.7.4