summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorChris Larson <chris_larson@mentor.com>2011-04-04 11:31:39 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2011-05-06 15:48:22 +0100
commit37cb4cc02b2e2b6c338c5943747e0a1ef15176b3 (patch)
tree454bba6a6c191c834ff26903137e4ba130873b18 /bitbake
parent8cf28d706b7e70f5835b1bd4da058ec64f520c6c (diff)
downloadpoky-37cb4cc02b2e2b6c338c5943747e0a1ef15176b3.tar.gz
event: improve output when eventhandler exec fails
- Name the event handler by its actual name, so the traceback shows it rather than 'tmpHandler'. - Rather than immediately aborting when encountering an event handler error, display an error message and try to continue. - Show a traceback for ordinary exceptions, skipping the first entry in the traceback, so it only shows the useful information. - Show an error, but no traceback, for SystemExit with a code other than 0. - For for SystemExit with a code of 0, simply continue silently. (Bitbake rev: faf682dfc23b7ef2ece04f7d50f9741224bb3bb0) Signed-off-by: Chris Larson <chris_larson@mentor.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/bb/event.py42
1 files changed, 31 insertions, 11 deletions
diff --git a/bitbake/lib/bb/event.py b/bitbake/lib/bb/event.py
index 9a07ed5c0a..ec6446d64c 100644
--- a/bitbake/lib/bb/event.py
+++ b/bitbake/lib/bb/event.py
@@ -37,6 +37,8 @@ import bb.utils
37worker_pid = 0 37worker_pid = 0
38worker_pipe = None 38worker_pipe = None
39 39
40logger = logging.getLogger('BitBake.Event')
41
40class Event(object): 42class Event(object):
41 """Base class for events""" 43 """Base class for events"""
42 44
@@ -58,18 +60,35 @@ _ui_handler_seq = 0
58bb.utils._context["NotHandled"] = NotHandled 60bb.utils._context["NotHandled"] = NotHandled
59bb.utils._context["Handled"] = Handled 61bb.utils._context["Handled"] = Handled
60 62
63def execute_handler(name, handler, event, d):
64 event.data = d
65 try:
66 ret = handler(event)
67 except Exception:
68 etype, value, tb = sys.exc_info()
69 logger.error("Execution of event handler '%s' failed" % name,
70 exc_info=(etype, value, tb.tb_next))
71 raise
72 except SystemExit as exc:
73 if exc.code != 0:
74 logger.error("Execution of event handler '%s' failed" % name)
75 raise
76 finally:
77 del event.data
78
79 if ret is not None:
80 warnings.warn("Using Handled/NotHandled in event handlers is deprecated",
81 DeprecationWarning, stacklevel = 2)
82
61def fire_class_handlers(event, d): 83def fire_class_handlers(event, d):
62 if isinstance(event, logging.LogRecord): 84 if isinstance(event, logging.LogRecord):
63 return 85 return
64 86
65 for handler in _handlers.itervalues(): 87 for name, handler in _handlers.iteritems():
66 event.data = d 88 try:
67 ret = handler(event) 89 execute_handler(name, handler, event, d)
68 if ret is not None: 90 except BaseException:
69 warnings.warn("Using Handled/NotHandled in event handlers is deprecated", 91 continue
70 DeprecationWarning, stacklevel = 2)
71
72 del event.data
73 92
74ui_queue = [] 93ui_queue = []
75@atexit.register 94@atexit.register
@@ -141,11 +160,12 @@ def register(name, handler):
141 if handler is not None: 160 if handler is not None:
142 # handle string containing python code 161 # handle string containing python code
143 if isinstance(handler, basestring): 162 if isinstance(handler, basestring):
144 tmp = "def tmpHandler(e):\n%s" % handler 163 tmp = "def %s(e):\n%s" % (name, handler)
145 comp = bb.utils.better_compile(tmp, "tmpHandler(e)", "bb.event._registerCode") 164 comp = bb.utils.better_compile(tmp, "%s(e)" % name,
165 "bb.event._registerCode")
146 env = {} 166 env = {}
147 bb.utils.simple_exec(comp, env) 167 bb.utils.simple_exec(comp, env)
148 func = bb.utils.better_eval("tmpHandler", env) 168 func = bb.utils.better_eval(name, env)
149 _handlers[name] = func 169 _handlers[name] = func
150 else: 170 else:
151 _handlers[name] = handler 171 _handlers[name] = handler