Make the C Scanner always return the dependencies sorted, so order differences don...
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Wed, 23 Jan 2002 16:47:35 +0000 (16:47 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Wed, 23 Jan 2002 16:47:35 +0000 (16:47 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@215 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/CHANGES.txt
src/engine/SCons/Scanner/C.py
src/engine/SCons/Scanner/CTests.py

index 3e19a1ec00975fd32f9c69c3442360437fa15e46..462e06ab8079ee2f0b80fe1170b85217d03fa9cc 100644 (file)
@@ -35,6 +35,9 @@ RELEASE 0.04 -
 
   - Add examples using Library, LIBS, and LIBPATH.
 
+  - The C Scanner now always returns a sorted list of dependencies
+    so order changes don't cause unnecessary rebuilds.
+
   From Steve Leblanc:
 
   - Add var=value command-line arguments.
index 2c5122342d47e0963cb1558463f6d74e5c8a47c9..58d065b0d798d39897173b93cd11e4677866d7c8 100644 (file)
@@ -118,5 +118,18 @@ def scan(node, env, args = [SCons.Node.FS.default_fs, ()]):
             if not node is None:
                 nodes.append(node)
 
-    return nodes
+    # Schwartzian transform from the Python FAQ Wizard
+    def st(List, Metric):
+        def pairing(element, M = Metric):
+            return (M(element), element)
+        def stripit(pair):
+            return pair[1]
+        paired = map(pairing, List)
+        paired.sort()
+        return map(stripit, paired)
+
+    def normalize(node):
+        return os.path.normpath(str(node))
+
+    return st(nodes, normalize)
 
index d8386430fb762e55c6cc573e6d5f6b4a642dbba2..e9c2d659c84bdc4909be60fab9bc406a11865517 100644 (file)
@@ -134,8 +134,6 @@ class DummyEnvironment:
 def deps_match(self, deps, headers):
     scanned = map(os.path.normpath, map(str, deps))
     expect = map(os.path.normpath, headers)
-    scanned.sort()
-    expect.sort()
     self.failUnless(scanned == expect, "expect %s != scanned %s" % (expect, scanned))
 
 def make_node(filename, fs=SCons.Node.FS.default_fs):
@@ -156,7 +154,7 @@ class CScannerTestCase2(unittest.TestCase):
         env = DummyEnvironment([test.workpath("d1")])
         s = SCons.Scanner.C.CScan()
         deps = s.instance(env).scan(make_node('f1.cpp'), env)
-        headers = ['f1.h', 'd1/f2.h']
+        headers = ['d1/f2.h', 'f1.h']
         deps_match(self, deps, map(test.workpath, headers))
 
 class CScannerTestCase3(unittest.TestCase):
@@ -164,7 +162,7 @@ class CScannerTestCase3(unittest.TestCase):
         env = DummyEnvironment([test.workpath("d1")])
         s = SCons.Scanner.C.CScan()
         deps = s.instance(env).scan(make_node('f2.cpp'), env)
-        headers = ['f1.h', 'd1/f1.h', 'd1/d2/f1.h']
+        headers = ['d1/d2/f1.h', 'd1/f1.h', 'f1.h']
         deps_match(self, deps, map(test.workpath, headers))
 
 class CScannerTestCase4(unittest.TestCase):
@@ -172,7 +170,7 @@ class CScannerTestCase4(unittest.TestCase):
         env = DummyEnvironment([test.workpath("d1"), test.workpath("d1/d2")])
         s = SCons.Scanner.C.CScan()
         deps = s.instance(env).scan(make_node('f2.cpp'), env)
-        headers =  ['f1.h', 'd1/f1.h', 'd1/d2/f1.h', 'd1/d2/f4.h']
+        headers =  ['d1/d2/f1.h', 'd1/d2/f4.h', 'd1/f1.h', 'f1.h']
         deps_match(self, deps, map(test.workpath, headers))
         
 class CScannerTestCase5(unittest.TestCase):
@@ -185,8 +183,8 @@ class CScannerTestCase5(unittest.TestCase):
         # scanned, essential for cooperation with BuildDir functionality.
         assert SCons.Node.FS.default_fs.File(test.workpath('f3.cpp')).created
         
-        headers =  ['f1.h', 'f2.h', 'f3.h', 'fi.h', 'fj.h',
-                    'd1/f1.h', 'd1/f2.h', 'd1/f3.h']
+        headers =  ['d1/f1.h', 'd1/f2.h', 'd1/f3.h',
+                    'f1.h', 'f2.h', 'f3.h', 'fi.h', 'fj.h']
         deps_match(self, deps, map(test.workpath, headers))
 
 class CScannerTestCase6(unittest.TestCase):
@@ -202,8 +200,8 @@ class CScannerTestCase6(unittest.TestCase):
         assert s1 is s3
         deps1 = s1.scan(make_node('f1.cpp'), None)
         deps2 = s2.scan(make_node('f1.cpp'), None)
-        headers1 =  ['f1.h', 'd1/f2.h']
-        headers2 =  ['f1.h', 'd1/d2/f2.h']
+        headers1 =  ['d1/f2.h', 'f1.h']
+        headers2 =  ['d1/d2/f2.h', 'f1.h']
         deps_match(self, deps1, map(test.workpath, headers1))
         deps_match(self, deps2, map(test.workpath, headers2))