trunk/bitbake/lib/bb/build.py:
[vuplus_bitbake] / lib / bb / build.py
index 5a72be7..cebf4c9 100644 (file)
@@ -25,18 +25,9 @@ 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, utils
+from bb import data, fetch, fatal, error, note, event, mkdirhier, utils
 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"""
@@ -76,13 +67,6 @@ class InvalidTask(TaskBase):
 
 # functions
 
-def init(data):
-    global _task_data, _task_graph, _task_stack
-    _task_data = data.init()
-    _task_graph = bb.digraph()
-    _task_stack = []
-
-
 def exec_func(func, d, dirs = None):
     """Execute an BB 'function'"""
 
@@ -130,7 +114,7 @@ def exec_func_python(func, d):
     g['bb'] = bb
     g['os'] = os
     g['d'] = d
-    exec comp in g
+    utils.better_exec(comp,g,tmp, bb.data.getVar('FILE',d,1))
     if os.path.exists(prevdir):
         os.chdir(prevdir)
 
@@ -162,7 +146,7 @@ def exec_func_shell(func, d):
 
     f = open(runfile, "w")
     f.write("#!/bin/sh -e\n")
-    if bb.debug_level > 0: f.write("set -x\n")
+    if bb.msg.debug_level > 0: f.write("set -x\n")
     data.emit_env(f, d)
 
     f.write("cd %s\n" % os.getcwd())
@@ -176,7 +160,7 @@ def exec_func_shell(func, d):
     # open logs
     si = file('/dev/null', 'r')
     try:
-        if bb.debug_level > 0:
+        if bb.msg.debug_level > 0:
             so = os.popen("tee \"%s\"" % logfile, "w")
         else:
             so = file(logfile, 'w')
@@ -203,7 +187,10 @@ def exec_func_shell(func, d):
     else:
         maybe_fakeroot = ''
     ret = os.system('%ssh -e %s' % (maybe_fakeroot, runfile))
-    os.chdir(prevdir)
+    try:
+        os.chdir(prevdir)
+    except:
+        pass
 
     # restore the backups
     os.dup2(osi[0], osi[1])
@@ -221,7 +208,7 @@ def exec_func_shell(func, d):
     os.close(ose[0])
 
     if ret==0:
-        if bb.debug_level > 0:
+        if bb.msg.debug_level > 0:
             os.remove(runfile)
 #            os.remove(logfile)
         return
@@ -278,7 +265,7 @@ def exec_task(task, d):
                 return 1
 
             try:
-                debug(1, "Executing task %s" % item)
+                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)
@@ -301,9 +288,49 @@ def exec_task(task, d):
     if not data.getVarFlag(task, 'nostamp', d):
         mkstamp(task, d)
 
+def stamp_is_current_cache(dataCache, file_name, task, checkdeps = 1):
+    """
+    Check status of a given task's stamp. 
+    Returns 0 if it is not current and needs updating.
+    Same as stamp_is_current but works against the dataCache instead of d
+    """
+    task_graph = dataCache.task_queues[file_name]
+
+    if not dataCache.stamp[file_name]:
+        return 0
+
+    stampfile = "%s.%s" % (dataCache.stamp[file_name], 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 'nostamp' in dataCache.task_deps[file_name] and task in dataCache.task_deps[file_name]['nostamp']:
+            return 1
+
+        if not stamp_is_current_cache(dataCache, file_name, task, 0):
+            return 0
+
+        depfile = "%s.%s" % (dataCache.stamp[file_name], task)
+        deptime = os.stat(depfile)[stat.ST_MTIME]
+        if deptime > tasktime:
+            return 0
+        return 1
+
+    return task_graph.walkdown(task, checkStamp)
 
 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."""
+    """
+    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()
@@ -349,9 +376,14 @@ def mkstamp(task, d):
     if not stamp:
         return
     stamp = "%s.%s" % (data.expand(stamp, d), task)
+    print "Updating %s" % stamp
     mkdirhier(os.path.dirname(stamp))
-    open(stamp, "w+")
-
+    # Remove the file and recreate to force timestamp
+    # change on broken NFS filesystems
+    if os.access(stamp, os.F_OK):
+        os.remove(stamp)
+    f = open(stamp, "w")
+    f.close()
 
 def add_task(task, deps, d):
     task_graph = data.getVar('_task_graph', d)
@@ -366,6 +398,21 @@ def add_task(task, deps, d):
     # 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 remove_task(task, kill, d):
     """Remove an BB 'task'.
@@ -391,6 +438,3 @@ def task_exists(task, d):
         task_graph = bb.digraph()
         data.setVar('_task_graph', task_graph, d)
     return task_graph.hasnode(task)
-
-def get_task_data():
-    return _task_data