Simplify build exception handling
- Drop EventException - Use FuncFailed as the primary function failure exception, using TaskFailed for the event (leaving it up to the process running exec_{func,task} to display the more detailed information available in the exception). - Switch InvalidTask to an exception rather than an event, as that's a critical issue. - Reduce the number of messages shown to the user when a task fails -- they don't need to be told it fails 12 times. Work remains in this area though. (Bitbake rev: 06b742aae2b8013cbb269cc30554cff89e3a5667) Signed-off-by: Chris Larson <chris_larson@mentor.com> Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
This commit is contained in:
parent
1e7204a7b5
commit
9897d56861
|
@ -41,13 +41,17 @@ logger = logging.getLogger("BitBake.Build")
|
|||
__builtins__['bb'] = bb
|
||||
__builtins__['os'] = os
|
||||
|
||||
# events
|
||||
class FuncFailed(Exception):
|
||||
"""
|
||||
Executed function failed
|
||||
First parameter a message
|
||||
Second paramter is a logfile (optional)
|
||||
"""
|
||||
def __init__(self, name, metadata, logfile = None):
|
||||
self.name = name
|
||||
self.metadata = metadata
|
||||
self.logfile = logfile
|
||||
|
||||
def __str__(self):
|
||||
msg = "Function '%s' failed" % self.name
|
||||
if self.logfile:
|
||||
msg += " (see %s for further information)" % self.logfile
|
||||
return msg
|
||||
|
||||
class TaskBase(event.Event):
|
||||
"""Base class for task events"""
|
||||
|
@ -74,13 +78,16 @@ class TaskSucceeded(TaskBase):
|
|||
|
||||
class TaskFailed(TaskBase):
|
||||
"""Task execution failed"""
|
||||
def __init__(self, msg, logfile, t, d ):
|
||||
|
||||
def __init__(self, task, logfile, metadata):
|
||||
self.logfile = logfile
|
||||
self.msg = msg
|
||||
TaskBase.__init__(self, t, d)
|
||||
super(TaskFailed, self).__init__(task, metadata)
|
||||
|
||||
class TaskInvalid(TaskBase):
|
||||
"""Invalid Task"""
|
||||
|
||||
def __init__(self, task, metadata):
|
||||
super(TaskInvalid, self).__init__(task, metadata)
|
||||
self._message = "No such task '%s'" % task
|
||||
|
||||
# functions
|
||||
|
||||
|
@ -171,12 +178,11 @@ def exec_func_python(func, d, runfile, logfile):
|
|||
comp = utils.better_compile(tmp, func, bbfile)
|
||||
try:
|
||||
utils.better_exec(comp, {"d": d}, tmp, bbfile)
|
||||
except:
|
||||
(t, value, tb) = sys.exc_info()
|
||||
|
||||
if t in [bb.parse.SkipPackage, bb.build.FuncFailed]:
|
||||
except Exception as exc:
|
||||
if isinstance(exc, (bb.parse.SkipPackage, bb.build.FuncFailed)):
|
||||
raise
|
||||
raise FuncFailed("Function %s failed" % func, logfile)
|
||||
|
||||
raise FuncFailed(func, d, logfile)
|
||||
|
||||
|
||||
def exec_func_shell(func, d, runfile, logfile, flags):
|
||||
|
@ -207,7 +213,7 @@ def exec_func_shell(func, d, runfile, logfile, flags):
|
|||
f.close()
|
||||
os.chmod(runfile, 0775)
|
||||
if not func:
|
||||
raise FuncFailed("Function not specified for exec_func_shell")
|
||||
raise TypeError("Function argument must be a string")
|
||||
|
||||
# execute function
|
||||
if flags['fakeroot'] and not flags['task']:
|
||||
|
@ -219,7 +225,7 @@ def exec_func_shell(func, d, runfile, logfile, flags):
|
|||
if ret == 0:
|
||||
return
|
||||
|
||||
raise FuncFailed("function %s failed" % func, logfile)
|
||||
raise FuncFailed(func, d, logfile)
|
||||
|
||||
|
||||
def exec_task(fn, task, d):
|
||||
|
@ -310,16 +316,10 @@ def exec_task(fn, task, d):
|
|||
if not data.getVarFlag(task, 'nostamp', d) and not data.getVarFlag(task, 'selfstamp', d):
|
||||
make_stamp(task, d)
|
||||
|
||||
except FuncFailed as message:
|
||||
# Try to extract the optional logfile
|
||||
try:
|
||||
(msg, logfile) = message
|
||||
except:
|
||||
logfile = None
|
||||
msg = message
|
||||
except FuncFailed as exc:
|
||||
if not quieterr:
|
||||
logger.error("Task failed: %s" % message )
|
||||
failedevent = TaskFailed(msg, logfile, task, d)
|
||||
logger.error(str(exc))
|
||||
failedevent = TaskFailed(exc.name, exc.logfile, task, d)
|
||||
event.fire(failedevent, d)
|
||||
return 1
|
||||
|
||||
|
|
|
@ -690,9 +690,7 @@ class BBCooker:
|
|||
try:
|
||||
retval = rq.execute_runqueue()
|
||||
except runqueue.TaskFailure as exc:
|
||||
for fnid in exc.args:
|
||||
buildlog.error("'%s' failed" % taskdata.fn_index[fnid])
|
||||
failures = failures + 1
|
||||
failures += len(exc.args)
|
||||
retval = False
|
||||
if not retval:
|
||||
bb.event.fire(bb.event.BuildCompleted(buildname, item, failures), self.configuration.event_data)
|
||||
|
@ -727,9 +725,7 @@ class BBCooker:
|
|||
try:
|
||||
retval = rq.execute_runqueue()
|
||||
except runqueue.TaskFailure as exc:
|
||||
for fnid in exc.args:
|
||||
buildlog.error("'%s' failed" % taskdata.fn_index[fnid])
|
||||
failures = failures + 1
|
||||
failures += len(exc.args)
|
||||
retval = False
|
||||
if not retval:
|
||||
bb.event.fire(bb.event.BuildCompleted(buildname, targets, failures), self.configuration.event_data)
|
||||
|
|
|
@ -180,11 +180,9 @@ class BitBakeShellCommands:
|
|||
last_exception = Providers.NoProvider
|
||||
|
||||
except runqueue.TaskFailure as fnids:
|
||||
for fnid in fnids:
|
||||
print("ERROR: '%s' failed" % td.fn_index[fnid])
|
||||
last_exception = runqueue.TaskFailure
|
||||
|
||||
except build.EventException as e:
|
||||
except build.FuncFailed as e:
|
||||
print("ERROR: Couldn't build '%s'" % names)
|
||||
last_exception = e
|
||||
|
||||
|
@ -247,7 +245,7 @@ class BitBakeShellCommands:
|
|||
cooker.buildFile(bf, cmd)
|
||||
except parse.ParseError:
|
||||
print("ERROR: Unable to open or parse '%s'" % bf)
|
||||
except build.EventException as e:
|
||||
except build.FuncFailed as e:
|
||||
print("ERROR: Couldn't build '%s'" % name)
|
||||
last_exception = e
|
||||
|
||||
|
|
Loading…
Reference in New Issue