]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
build.py: Improve exec_task standalone usage
authorRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 24 Feb 2011 21:53:59 +0000 (21:53 +0000)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 24 Feb 2011 21:57:01 +0000 (21:57 +0000)
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>
lib/bb/build.py
lib/bb/runqueue.py

index 6da5bafd04f9c4f0c1a92d4ea6f351b16a37adf9..50058faeea5eeae1ae57d89ffdfde78d27598f98 100644 (file)
@@ -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
index 9f397f6f3a32d2c0264ef961be8a3faa72a1e79d..bdc781d9c65fa4cbff4b78f5b543953140a36aa7 100644 (file)
@@ -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):