build: refactor the object reduction code
authorAndrew Tridgell <tridge@samba.org>
Wed, 31 Mar 2010 09:13:55 +0000 (20:13 +1100)
committerAndrew Tridgell <tridge@samba.org>
Tue, 6 Apr 2010 10:27:21 +0000 (20:27 +1000)
split it out into a separate function, and use the final_* attributes
instead of the direct_* and indirect_* attributes

buildtools/wafsamba/samba_deps.py

index 674dc0725451aa0e796a255b8bf29908a90b3b1f..31062e71a87a761027b591b18e1c5533d355764c 100644 (file)
@@ -440,18 +440,16 @@ def extended_objects(bld, t, chain):
     if ret is not None: return ret
 
     ret = set()
-    ret = ret.union(t.direct_objects)
-    ret = ret.union(t.indirect_objects)
+    ret = ret.union(t.final_objects)
 
-    for lib in t.direct_libs:
+    for lib in t.final_libs:
         if lib in chain:
             continue
         t2 = bld.name_to_obj(lib, bld.env)
         chain.add(lib)
         r2 = extended_objects(bld, t2, chain)
         chain.remove(lib)
-        ret = ret.union(t2.direct_objects)
-        ret = ret.union(t2.indirect_objects)
+        ret = ret.union(t2.final_objects)
         ret = ret.union(r2)
 
     t.extended_objects = ret
@@ -576,34 +574,13 @@ def break_dependency_loops(bld, tgt_list):
                     objs = objs.union(diff)
             setattr(t, 'includes_objects', objs)
 
-def calculate_final_deps(bld, tgt_list, loops):
-    '''calculate the final library and object dependencies'''
-    for t in tgt_list:
-        # start with the maximum possible list
-        t.final_libs    = t.direct_libs.union(indirect_libs(bld, t, set(), loops))
-        t.final_objects = t.direct_objects.union(indirect_objects(bld, t, set(), loops))
 
-    for t in tgt_list:
-        # don't depend on ourselves
-        if t.sname in t.final_libs:
-            t.final_libs.remove(t.sname)
-        if t.sname in t.final_objects:
-            t.final_objects.remove(t.sname)
+def reduce_objects(bld, tgt_list):
+    '''reduce objects by looking for indirect object dependencies'''
+    rely_on = {}
 
-    # find any library loops
     for t in tgt_list:
-        if t.samba_type in ['LIBRARY', 'PYTHON']:
-            for l in t.final_libs.copy():
-                t2 = bld.name_to_obj(l, bld.env)
-                if t.sname in t2.final_libs:
-                    # we could break this in either direction. If one of the libraries
-                    # has a version number, and will this be distributed publicly, then
-                    # we should make it the lower level library in the DAG
-                    debug('deps: removing library loop %s from %s', t.sname, t2.sname)
-                    dependency_loop(loops, t, t2.sname)
-                    t2.final_libs.remove(t.sname)
-
-    rely_on = {}
+        t.extended_objects = None
 
     for type in ['BINARY', 'PYTHON', 'LIBRARY']:
         for t in tgt_list:
@@ -629,6 +606,35 @@ def calculate_final_deps(bld, tgt_list, loops):
         t = bld.name_to_obj(r, bld.env)
         t.final_objects = t.final_objects.union(rely_on[r])
 
+
+def calculate_final_deps(bld, tgt_list, loops):
+    '''calculate the final library and object dependencies'''
+    for t in tgt_list:
+        # start with the maximum possible list
+        t.final_libs    = t.direct_libs.union(indirect_libs(bld, t, set(), loops))
+        t.final_objects = t.direct_objects.union(indirect_objects(bld, t, set(), loops))
+
+    for t in tgt_list:
+        # don't depend on ourselves
+        if t.sname in t.final_libs:
+            t.final_libs.remove(t.sname)
+        if t.sname in t.final_objects:
+            t.final_objects.remove(t.sname)
+
+    # find any library loops
+    for t in tgt_list:
+        if t.samba_type in ['LIBRARY', 'PYTHON']:
+            for l in t.final_libs.copy():
+                t2 = bld.name_to_obj(l, bld.env)
+                if t.sname in t2.final_libs:
+                    # we could break this in either direction. If one of the libraries
+                    # has a version number, and will this be distributed publicly, then
+                    # we should make it the lower level library in the DAG
+                    debug('deps: removing library loop %s from %s', t.sname, t2.sname)
+                    dependency_loop(loops, t, t2.sname)
+                    t2.final_libs.remove(t.sname)
+
+
     for loop in loops:
         debug('deps: Found dependency loops for target %s : %s', loop, loops[loop])
 
@@ -647,6 +653,9 @@ def calculate_final_deps(bld, tgt_list, loops):
                         debug('deps: Expanded target %s by loop %s libraries %s', t.sname, loop, diff)
                         t.final_libs = t.final_libs.union(diff)
 
+    # remove objects that are also available in linked libs
+    reduce_objects(bld, tgt_list)
+
     # add in any syslib dependencies
     for t in tgt_list:
         if not t.samba_type in ['BINARY','PYTHON','LIBRARY']: