Further reduce the no-op build times (by 35% compared the original) master-torture
authorThomas Nagy <tnagy2pow10@gmail.com>
Fri, 3 Oct 2014 19:01:57 +0000 (21:01 +0200)
committerMichael Adam <obnox@samba.org>
Mon, 6 Oct 2014 14:25:11 +0000 (16:25 +0200)
buildtools/wafsamba/samba_optimisation.py

index 1333f8b740791f83b7c75a8e644870b0b3021337..18a84e96b5c527ce4a998b798aed57f6e13028c8 100644 (file)
@@ -20,23 +20,10 @@ def apply_incpaths(self):
     except AttributeError:
         kak = self.bld.kak = {}
 
-    # TODO move the uselib processing out of here
-    for lib in self.to_list(self.uselib):
-        for path in self.env['CPPPATH_' + lib]:
-            if not path in lst:
-                lst.append(path)
-    if preproc.go_absolute:
-        for path in preproc.standard_includes:
-            if not path in lst:
-                lst.append(path)
-
-    for path in self.to_list(self.includes):
-        if not path in lst:
-            if preproc.go_absolute or path[0] != '/':  # os.path.isabs(path):
-                lst.append(path)
-            else:
-                self.env.prepend_value('CPPPATH', path)
+    # assume that there are no relative paths given in CPPPATH+uselib
+    lst.extend(self.to_list(self.includes))
 
+    nodes = []
     for path in lst:
         node = None
         if path[0] == '/': # os.path.isabs(path):
@@ -56,14 +43,14 @@ def apply_incpaths(self):
                 kak[(self.path.id, path)] = node = self.path.find_dir(path)
 
         if node:
-            self.env.append_value('INC_PATHS', node)
+             nodes.append(node)
+    self.env.append_value('INC_PATHS', nodes)
 
 @feature('cc')
 @after('apply_incpaths')
 def apply_obj_vars_cc(self):
     """after apply_incpaths for INC_PATHS"""
     env = self.env
-    app = env.append_unique
     cpppath_st = env['CPPPATH_ST']
 
     lss = env['_CCINCFLAGS']
@@ -85,9 +72,10 @@ def apply_obj_vars_cc(self):
             lss.extend(cac[i.id])
 
     env['_CCINCFLAGS'] = lss
+
     # set the library include paths
-    for i in env['CPPPATH']:
-        app('_CCINCFLAGS', cpppath_st % i)
+    buf = [cpppath_st % i for i in env['CPPPATH']]
+    env.append_unique('_CCINCFLAGS', buf)
 
 import Node, Environment
 
@@ -250,6 +238,11 @@ def apply_lib_vars(self):
     self.uselib = self.to_list(self.uselib)
     names = self.to_list(self.uselib_local)
 
+    try:
+        self.link_task.dep_nodes = dep_nodes = getattr(self.link_task, 'dep_nodes', [])
+    except AttributeError:
+        pass
+
     seen = set([])
     tmp = Utils.deque(names) # consume a copy of the list of names
     while tmp:
@@ -268,31 +261,29 @@ def apply_lib_vars(self):
         tmp.extend(y.shared_ancestors())
 
         # link task and flags
-        if getattr(y, 'link_task', None):
+
+        try:
+            ylink = y.link_task
+        except AttributeError:
+            pass
+        else:
 
             link_name = y.target[y.target.rfind('/') + 1:]
             if 'cstaticlib' in y.features:
                 app('STATICLIB', link_name)
-            elif 'cshlib' in y.features or 'cprogram' in y.features:
-                # WARNING some linkers can link against programs
+            else:
                 app('LIB', link_name)
 
             # the order
-            self.link_task.set_run_after(y.link_task)
+            self.link_task.set_run_after(ylink)
 
-            # for the recompilation
-            dep_nodes = getattr(self.link_task, 'dep_nodes', [])
-            self.link_task.dep_nodes = dep_nodes + y.link_task.outputs
+            dep_nodes.extend(ylink.outputs)
 
-            # OPTIMIZATION 3: reduce the amount of function calls
             # add the link path too
-            par = y.link_task.outputs[0].parent
-            if id(par) not in seen_libpaths:
-                seen_libpaths.add(id(par))
-                tmp_path = par.bldpath(self.env)
-                if not tmp_path in env['LIBPATH']:
-                    env.prepend_value('LIBPATH', tmp_path)
-
+            par = ylink.outputs[0].parent
+            tmp_path = par.bldpath(self.env)
+            if tmp_path not in env['LIBPATH']:
+                env.prepend_value('LIBPATH', tmp_path)
 
         # add ancestors uselib too - but only propagate those that have no staticlib
         for v in self.to_list(y.uselib):
@@ -303,8 +294,36 @@ def apply_lib_vars(self):
                         self.uselib.insert(0, v)
 
     # 2. the case of the libs defined outside
+    pf = self.p_flag_vars
     for x in self.uselib:
-        for v in self.p_flag_vars:
+        for v in pf:
             val = self.env[v + '_' + x]
             if val:
                 self.env.append_value(v, val)
+
+
+def bldpath(self, env=None):
+
+    try:
+        cache = self.__class__.bld.cache_node_bldpath
+    except AttributeError:
+        cache = self.__class__.bld.cache_node_bldpath = {}
+    else:
+        try:
+            return cache[self.id]
+        except KeyError:
+            pass
+
+    if self.id & 3 == Node.FILE:
+        ret = self.relpath_gen(self.__class__.bld.bldnode)
+    else:
+        p = self.path_to_parent(self.__class__.bld.srcnode)
+        if p is not '':
+            ret = env.variant() + '/' + p
+        else:
+            ret = env.variant()
+
+    cache[self.id] = ret
+    return ret
+
+Node.Node.bldpath = bldpath