summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2011-02-24 21:53:59 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2011-02-24 21:57:01 +0000
commit44dcec236f3b15c68c87e3fa3bfa2d265a910917 (patch)
treea3062389ee970394a41f5fe089b0ac1ae6cbd9ad /lib
parent1265ce98d7a2ab024e639647ac6300c3cf808730 (diff)
downloadbitbake-44dcec236f3b15c68c87e3fa3bfa2d265a910917.tar.gz
build.py: Improve exec_task standalone usage
This commit consolidates all the task execution code and exception handling into one place, the exec_task funciton where it should be. This function now returns an exit code value and handles all exceptions. This ensures the task success/failure/invalid events are always sent. TaskInvalid also becomes an event rather than being an exception. Based upon changes in Poky. Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/bb/build.py34
-rw-r--r--lib/bb/runqueue.py9
2 files changed, 31 insertions, 12 deletions
diff --git a/lib/bb/build.py b/lib/bb/build.py
index 6da5bafd0..50058faee 100644
--- a/lib/bb/build.py
+++ b/lib/bb/build.py
@@ -94,13 +94,11 @@ class TaskFailed(TaskBase):
self.logfile = logfile
super(TaskFailed, self).__init__(task, metadata)
-class InvalidTask(Exception):
- def __init__(self, task, metadata):
- self.task = task
- self.metadata = metadata
+class TaskInvalid(TaskBase):
- def __str__(self):
- return "No such task '%s'" % self.task
+ def __init__(self, task, metadata):
+ super(TaskInvalid, self).__init__(task, metadata)
+ self._message = "No such task '%s'" % task
class LogTee(object):
@@ -249,14 +247,16 @@ def _task_data(fn, task, d):
data.expandKeys(localdata)
return localdata
-def exec_task(fn, task, d):
+def _exec_task(fn, task, d):
"""Execute a BB 'task'
Execution of a task involves a bit more setup than executing a function,
running it with its own local metadata, and with some useful variables set.
"""
if not data.getVarFlag(task, 'task', d):
- raise InvalidTask(task, d)
+ event.fire(TaskInvalid(task, d), d)
+ logger.error("No such task: %s" % task)
+ return 1
logger.debug(1, "Executing task %s", task)
@@ -288,8 +288,9 @@ def exec_task(fn, task, d):
for func in (postfuncs or '').split():
exec_func(func, localdata, logfile=logfile)
except FuncFailed as exc:
- event.fire(TaskFailed(exc.name, exc.logfile, localdata), localdata)
- raise
+ logger.error(str(exc))
+ event.fire(TaskFailed(task, logfn, localdata), localdata)
+ return 1
finally:
logfile.close()
if os.path.exists(logfn) and os.path.getsize(logfn) == 0:
@@ -301,6 +302,19 @@ def exec_task(fn, task, d):
if not localdata.getVarFlag(task, 'nostamp') and not localdata.getVarFlag(task, 'selfstamp'):
make_stamp(task, localdata)
+ return 0
+
+def exec_task(fn, task, d):
+ try:
+ return _exec_task(fn, task, d)
+ except Exception:
+ from traceback import format_exc
+ logger.error("Build of %s failed" % (task))
+ logger.error(format_exc())
+ failedevent = TaskFailed(task, None, d)
+ event.fire(failedevent, d)
+ return 1
+
def stamp_internal(taskname, d, file_name):
"""
Internal stamp helper function
diff --git a/lib/bb/runqueue.py b/lib/bb/runqueue.py
index 9f397f6f3..bdc781d9c 100644
--- a/lib/bb/runqueue.py
+++ b/lib/bb/runqueue.py
@@ -1085,16 +1085,21 @@ class RunQueueExecute:
bb.data.setVar("__RUNQUEUE_DO_NOT_USE_EXTERNALLY", self, self.cooker.configuration.data)
bb.data.setVar("__RUNQUEUE_DO_NOT_USE_EXTERNALLY2", fn, self.cooker.configuration.data)
bb.parse.siggen.set_taskdata(self.rqdata.hashes, self.rqdata.hash_deps)
+ ret = 0
try:
the_data = bb.cache.Cache.loadDataFull(fn, self.cooker.get_file_appends(fn), self.cooker.configuration.data)
the_data.setVar('BB_TASKHASH', self.rqdata.runq_hash[task])
os.environ.update(bb.data.exported_vars(the_data))
- bb.build.exec_task(fn, taskname, the_data)
except Exception as exc:
if not quieterrors:
logger.critical(str(exc))
os._exit(1)
- os._exit(0)
+ try:
+ ret = bb.build.exec_task(fn, taskname, the_data)
+ os._exit(ret)
+ except:
+ os._exit(1)
+
return pid, pipein, pipeout
class RunQueueExecuteDummy(RunQueueExecute):