diff options
-rw-r--r-- | lib/bb/build.py | 65 | ||||
-rw-r--r-- | lib/bb/cooker.py | 8 | ||||
-rw-r--r-- | lib/bb/runqueue.py | 10 | ||||
-rw-r--r-- | lib/bb/shell.py | 6 |
4 files changed, 37 insertions, 52 deletions
diff --git a/lib/bb/build.py b/lib/bb/build.py index c04a31880..a9e3c06ff 100644 --- a/lib/bb/build.py +++ b/lib/bb/build.py @@ -41,19 +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) - """ - -class EventException(Exception): - """Exception which is associated with an Event.""" + def __init__(self, name, metadata, logfile = None): + self.name = name + self.metadata = metadata + self.logfile = logfile - def __init__(self, msg, event): - self.args = msg, event + 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""" @@ -80,13 +78,18 @@ 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 InvalidTask(TaskBase): - """Invalid Task""" +class InvalidTask(Exception): + def __init__(self, task, metadata): + self.task = task + self.metadata = metadata + + def __str__(self): + return "No such task '%s'" % self.task # functions @@ -218,12 +221,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): """Execute a shell BB 'function' Returns true if execution was successful. @@ -253,7 +255,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']: @@ -266,7 +268,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(task, d): @@ -278,7 +280,7 @@ def exec_task(task, d): # Check whther this is a valid task if not data.getVarFlag(task, 'task', d): - raise EventException("No such task", InvalidTask(task, d)) + raise InvalidTask(task, d) try: logger.debug(1, "Executing task %s", task) @@ -290,17 +292,10 @@ def exec_task(task, d): event.fire(TaskStarted(task, localdata), localdata) exec_func(task, localdata) event.fire(TaskSucceeded(task, localdata), localdata) - except FuncFailed as message: - # Try to extract the optional logfile - try: - (msg, logfile) = message - except: - logfile = None - msg = message - logger.info("Task failed: %s", message ) - failedevent = TaskFailed(msg, logfile, task, d) - event.fire(failedevent, d) - raise EventException("Function failed in task: %s" % message, failedevent) + except FuncFailed as exc: + logger.critical(str(exc)) + event.fire(TaskFailed(exc.name, exc.logfile, localdata), localdata) + raise # make stamp, or cause event and raise exception if not data.getVarFlag(task, 'nostamp', d) and not data.getVarFlag(task, 'selfstamp', d): diff --git a/lib/bb/cooker.py b/lib/bb/cooker.py index 722fa3101..0c4177b6c 100644 --- a/lib/bb/cooker.py +++ b/lib/bb/cooker.py @@ -679,9 +679,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) @@ -715,9 +713,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) diff --git a/lib/bb/runqueue.py b/lib/bb/runqueue.py index 004cdc1c0..8c99c33f3 100644 --- a/lib/bb/runqueue.py +++ b/lib/bb/runqueue.py @@ -1110,14 +1110,10 @@ class RunQueue: if not self.cooker.configuration.dry_run: bb.build.exec_task(taskname, the_data) - os._exit(0) - - except bb.build.EventException as e: - event = e.args[1] - logger.error("%s event exception, aborting" % bb.event.getName(event)) + except bb.build.FuncFailed as exc: os._exit(1) - except Exception: - logger.exception("Build of %s %s failed", fn, taskname) + except Exception as exc: + logger.critical(str(exc)) os._exit(1) os._exit(0) return pid, pipein, pipeout diff --git a/lib/bb/shell.py b/lib/bb/shell.py index f9ca9d5bd..c61e93a1c 100644 --- a/lib/bb/shell.py +++ b/lib/bb/shell.py @@ -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 |