From: stevenknight Date: Wed, 23 Jan 2002 16:47:35 +0000 (+0000) Subject: Make the C Scanner always return the dependencies sorted, so order differences don... X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4f83834037fa69b5241fc3063fab53fe6e99155a;p=scons.git Make the C Scanner always return the dependencies sorted, so order differences don't cause unnecessary rebuilds. git-svn-id: http://scons.tigris.org/svn/scons/trunk@215 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 3e19a1ec..462e06ab 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -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. diff --git a/src/engine/SCons/Scanner/C.py b/src/engine/SCons/Scanner/C.py index 2c512234..58d065b0 100644 --- a/src/engine/SCons/Scanner/C.py +++ b/src/engine/SCons/Scanner/C.py @@ -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) diff --git a/src/engine/SCons/Scanner/CTests.py b/src/engine/SCons/Scanner/CTests.py index d8386430..e9c2d659 100644 --- a/src/engine/SCons/Scanner/CTests.py +++ b/src/engine/SCons/Scanner/CTests.py @@ -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))