def add_task(task, deps, d): task_graph = data.getVar('_task_graph', d) if not task_graph: task_graph = bb.digraph() data.setVarFlag(task, 'task', 1, d) task_graph.addnode(task, None) for dep in deps: if not task_graph.hasnode(dep): task_graph.addnode(dep, None) task_graph.addnode(task, dep) # don't assume holding a reference data.setVar('_task_graph', task_graph, d) task_deps = data.getVar('_task_deps', d) if not task_deps: task_deps = {} def getTask(name): deptask = data.getVarFlag(task, name, d) if deptask: if not name in task_deps: task_deps[name] = {} task_deps[name][task] = deptask getTask('deptask') getTask('rdeptask') getTask('recrdeptask') getTask('nostamp') data.setVar('_task_deps', task_deps, d)
def stamp_is_current(task, d, checkdeps = 1): """Check status of a given task's stamp. returns 0 if it is not current and needs updating.""" task_graph = data.getVar('_task_graph', d) if not task_graph: task_graph = bb.digraph() data.setVar('_task_graph', task_graph, d) stamp = data.getVar('STAMP', d) if not stamp: return 0 stampfile = "%s.%s" % (data.expand(stamp, d), task) if not os.access(stampfile, os.F_OK): return 0 if checkdeps == 0: return 1 import stat tasktime = os.stat(stampfile)[stat.ST_MTIME] _deps = [] def checkStamp(graph, task): # check for existance if data.getVarFlag(task, 'nostamp', d): return 1 if not stamp_is_current(task, d, 0): return 0 depfile = "%s.%s" % (data.expand(stamp, d), task) deptime = os.stat(depfile)[stat.ST_MTIME] if deptime > tasktime: return 0 return 1 return task_graph.walkdown(task, checkStamp)
def add_task(task, deps, d): task_graph = data.getVar('_task_graph', d) if not task_graph: task_graph = bb.digraph() data.setVar('_task_graph', task_graph, d) data.setVarFlag(task, 'task', 1, d) task_graph.addnode(task, None) for dep in deps: if not task_graph.hasnode(dep): task_graph.addnode(dep, None) task_graph.addnode(task, dep)
def extract_stamp_data(d, fn): """ Extracts stamp data from d which is either a data dictonary (fn unset) or a dataCache entry (fn set). """ if fn: return (d.task_queues[fn], d.stamp[fn], d.task_deps[fn]) task_graph = data.getVar('_task_graph', d) if not task_graph: task_graph = bb.digraph() data.setVar('_task_graph', task_graph, d) return (task_graph, data.getVar('STAMP', d, 1), None)
def exec_task(task, d): """Execute an BB 'task' The primary difference between executing a task versus executing a function is that a task exists in the task digraph, and therefore has dependencies amongst other tasks.""" # check if the task is in the graph.. task_graph = data.getVar('_task_graph', d) if not task_graph: task_graph = bb.digraph() data.setVar('_task_graph', task_graph, d) task_cache = data.getVar('_task_cache', d) if not task_cache: task_cache = [] data.setVar('_task_cache', task_cache, d) if not task_graph.hasnode(task): raise EventException("Missing node in task graph", InvalidTask(task, d)) # check whether this task needs executing.. if not data.getVarFlag(task, 'force', d): if stamp_is_current(task, d): return 1 # follow digraph path up, then execute our way back down def execute(graph, item): if data.getVarFlag(item, 'task', d): if item in task_cache: return 1 if task != item: # deeper than toplevel, exec w/ deps exec_task(item, d) return 1 try: bb.msg.debug(1, bb.msg.domain.Build, "Executing task %s" % item) old_overrides = data.getVar('OVERRIDES', d, 0) localdata = data.createCopy(d) data.setVar('OVERRIDES', 'task_%s:%s' % (item, old_overrides), localdata) data.update_data(localdata) event.fire(TaskStarted(item, localdata)) exec_func(item, localdata) event.fire(TaskSucceeded(item, localdata)) task_cache.append(item) data.setVar('_task_cache', task_cache, d) except FuncFailed, reason: note( "Task failed: %s" % reason ) failedevent = TaskFailed(item, d) event.fire(failedevent) raise EventException("Function failed in task: %s" % reason, failedevent)
def remove_task(task, kill, d): """Remove an BB 'task'. If kill is 1, also remove tasks that depend on this task.""" task_graph = data.getVar('_task_graph', d) if not task_graph: task_graph = bb.digraph() data.setVar('_task_graph', task_graph, d) if not task_graph.hasnode(task): return data.delVarFlag(task, 'task', d) ref = 1 if kill == 1: ref = 2 task_graph.delnode(task, ref)
def exec_task(task, d): """Execute an BB 'task' The primary difference between executing a task versus executing a function is that a task exists in the task digraph, and therefore has dependencies amongst other tasks.""" # check if the task is in the graph.. task_graph = data.getVar('_task_graph', d) if not task_graph: task_graph = bb.digraph() data.setVar('_task_graph', task_graph, d) task_cache = data.getVar('_task_cache', d) if not task_cache: task_cache = [] data.setVar('_task_cache', task_cache, d) if not task_graph.hasnode(task): raise EventException("", InvalidTask(task, d)) # check whether this task needs executing.. if not data.getVarFlag(task, 'force', d): if stamp_is_current(task, d): return 1 # follow digraph path up, then execute our way back down def execute(graph, item): if data.getVarFlag(item, 'task', d): if item in task_cache: return 1 if task != item: # deeper than toplevel, exec w/ deps exec_task(item, d) return 1 try: debug(1, "Executing task %s" % item) event.fire(TaskStarted(item, d)) exec_func(item, d) event.fire(TaskSucceeded(item, d)) task_cache.append(item) except FuncFailed, reason: note( "Task failed: %s" % reason ) failedevent = TaskFailed(item, d) event.fire(failedevent) raise EventException(None, failedevent)
def add_tasks(tasklist, d): task_graph = data.getVar('_task_graph', d) task_deps = data.getVar('_task_deps', d) if not task_graph: task_graph = bb.digraph() if not task_deps: task_deps = {} for task in tasklist: deps = tasklist[task] task = data.expand(task, d) data.setVarFlag(task, 'task', 1, d) task_graph.addnode(task, None) for dep in deps: dep = data.expand(dep, d) if not task_graph.hasnode(dep): task_graph.addnode(dep, None) task_graph.addnode(task, dep) flags = data.getVarFlags(task, d) def getTask(name): if name in flags: deptask = data.expand(flags[name], d) if not name in task_deps: task_deps[name] = {} task_deps[name][task] = deptask getTask('depends') getTask('deptask') getTask('rdeptask') getTask('recrdeptask') getTask('nostamp') # don't assume holding a reference data.setVar('_task_graph', task_graph, d) data.setVar('_task_deps', task_deps, d)
def init(data): global _task_data, _task_graph, _task_stack _task_data = data.init() _task_graph = bb.digraph() _task_stack = []
def task_exists(task, d): task_graph = data.getVar('_task_graph', d) if not task_graph: task_graph = bb.digraph() data.setVar('_task_graph', task_graph, d) return task_graph.hasnode(task)
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Based on functions from the base bb module, Copyright 2003 Holger Schurig """ from bb import debug, data, fetch, fatal, error, note, event, mkdirhier import bb, os # data holds flags and function name for a given task _task_data = data.init() # graph represents task interdependencies _task_graph = bb.digraph() # stack represents execution order, excepting dependencies _task_stack = [] # events class FuncFailed(Exception): """Executed function failed""" class EventException(Exception): """Exception which is associated with an Event.""" def __init__(self, msg, event): self.event = event def getEvent(self):