diff options
author | Steven Knight <knight@baldmt.com> | 2001-11-22 14:10:14 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2001-11-22 14:10:14 (GMT) |
commit | 139a0052dc0bff059dc9b8cf1739396304e7c129 (patch) | |
tree | ab6d8e92abb65f4f8a15bdd926bcbeedd038d04d /src/engine/SCons | |
parent | 872263c70af22c6dd1a1f4f0eb1445a2310a205b (diff) | |
download | SCons-139a0052dc0bff059dc9b8cf1739396304e7c129.zip SCons-139a0052dc0bff059dc9b8cf1739396304e7c129.tar.gz SCons-139a0052dc0bff059dc9b8cf1739396304e7c129.tar.bz2 |
Complete CPPPATH work.
Diffstat (limited to 'src/engine/SCons')
-rw-r--r-- | src/engine/SCons/Scanner/C.py | 5 | ||||
-rw-r--r-- | src/engine/SCons/Scanner/CTests.py | 21 | ||||
-rw-r--r-- | src/engine/SCons/Scanner/Prog.py | 2 | ||||
-rw-r--r-- | src/engine/SCons/Scanner/ScannerTests.py | 8 | ||||
-rw-r--r-- | src/engine/SCons/Scanner/__init__.py | 43 |
5 files changed, 64 insertions, 15 deletions
diff --git a/src/engine/SCons/Scanner/C.py b/src/engine/SCons/Scanner/C.py index e2842e1..90cb141 100644 --- a/src/engine/SCons/Scanner/C.py +++ b/src/engine/SCons/Scanner/C.py @@ -40,8 +40,9 @@ quote_re = re.compile('^[ \t]*#[ \t]*include[ \t]+"([\\w./\\\\]+)"', re.M) def CScan(): "Return a Scanner instance for scanning C/C++ source files" - s = SCons.Scanner.Scanner(scan, SCons.Node.FS.default_fs.File, - [".c", ".C", ".cxx", ".cpp", ".c++"]) + s = SCons.Scanner.Recursive(scan, SCons.Node.FS.default_fs.File, + [".c", ".C", ".cxx", ".cpp", ".c++", + ".h", ".H", ".hxx", ".hpp"]) s.name = "CScan" return s diff --git a/src/engine/SCons/Scanner/CTests.py b/src/engine/SCons/Scanner/CTests.py index e6bd29e..02a423b 100644 --- a/src/engine/SCons/Scanner/CTests.py +++ b/src/engine/SCons/Scanner/CTests.py @@ -79,13 +79,22 @@ int main() test.subdir('d1', ['d1', 'd2']) -headers = ['f1.h','f2.h', 'f3.h', 'never.h', - 'd1/f1.h', 'd1/f2.h', 'd1/f3.h', - 'd1/d2/f1.h', 'd1/d2/f2.h', 'd1/d2/f3.h', 'd1/d2/f4.h'] +headers = ['f1.h','f2.h', 'f3.h', 'fi.h', 'fj.h', 'never.h', + 'd1/f1.h', 'd1/f2.h', 'd1/f3.h', 'd1/fi.h', 'd1/fj.h', + 'd1/d2/f1.h', 'd1/d2/f2.h', 'd1/d2/f3.h', + 'd1/d2/f4.h', 'd1/d2/fi.h', 'd1/d2/fj.h'] for h in headers: test.write(h, " ") +test.write('f2.h',""" +#include "fi.h" +""") + +test.write('f3.h',""" +#include <fj.h> +""") + # define some helpers: class DummyEnvironment: @@ -115,7 +124,8 @@ class CScannerTestCase1(unittest.TestCase): env = DummyEnvironment([]) s = SCons.Scanner.C.CScan() deps = s.scan(test.workpath('f1.cpp'), env) - self.failUnless(deps_match(deps, ['f1.h', 'f2.h']), map(str, deps)) + headers = ['f1.h', 'f2.h', 'fi.h'] + self.failUnless(deps_match(deps, headers), map(str, deps)) class CScannerTestCase2(unittest.TestCase): def runTest(self): @@ -146,7 +156,8 @@ class CScannerTestCase5(unittest.TestCase): env = DummyEnvironment([]) s = SCons.Scanner.C.CScan() deps = s.scan(test.workpath('f3.cpp'), env) - headers = ['f1.h', 'f2.h', 'f3.h', 'd1/f1.h', 'd1/f2.h', 'd1/f3.h'] + headers = ['f1.h', 'f2.h', 'f3.h', 'fi.h', 'fj.h', + 'd1/f1.h', 'd1/f2.h', 'd1/f3.h'] self.failUnless(deps_match(deps, headers), map(str, deps)) def suite(): diff --git a/src/engine/SCons/Scanner/Prog.py b/src/engine/SCons/Scanner/Prog.py index f9d352c..62dee97 100644 --- a/src/engine/SCons/Scanner/Prog.py +++ b/src/engine/SCons/Scanner/Prog.py @@ -30,7 +30,7 @@ import SCons.Util def ProgScan(): """Return a Scanner instance for scanning executable files for static-lib dependencies""" - s = SCons.Scanner.Scanner(scan, SCons.Node.FS.default_fs.File) + s = SCons.Scanner.Base(scan, SCons.Node.FS.default_fs.File) s.name = "ProgScan" return s diff --git a/src/engine/SCons/Scanner/ScannerTests.py b/src/engine/SCons/Scanner/ScannerTests.py index 757f239..5d434a6 100644 --- a/src/engine/SCons/Scanner/ScannerTests.py +++ b/src/engine/SCons/Scanner/ScannerTests.py @@ -59,7 +59,7 @@ class DummyEnvironment: class ScannerPositionalTestCase(ScannerTestBase, unittest.TestCase): "Test the Scanner class using the position argument" def runTest(self): - s = SCons.Scanner.Scanner(self.func) + s = SCons.Scanner.Base(self.func) env = DummyEnvironment() env.VARIABLE = "var1" self.test(s, env, 'f1.cpp', ['f1.h', 'f1.hpp']) @@ -67,7 +67,7 @@ class ScannerPositionalTestCase(ScannerTestBase, unittest.TestCase): class ScannerKeywordTestCase(ScannerTestBase, unittest.TestCase): "Test the Scanner class using the keyword argument" def runTest(self): - s = SCons.Scanner.Scanner(function = self.func) + s = SCons.Scanner.Base(function = self.func) env = DummyEnvironment() env.VARIABLE = "var2" self.test(s, env, 'f2.cpp', ['f2.h', 'f2.hpp']) @@ -76,7 +76,7 @@ class ScannerPositionalArgumentTestCase(ScannerTestBase, unittest.TestCase): "Test the Scanner class using the position argument and optional argument" def runTest(self): arg = "this is the argument" - s = SCons.Scanner.Scanner(self.func, arg) + s = SCons.Scanner.Base(self.func, arg) env = DummyEnvironment() env.VARIABLE = "var3" self.test(s, env, 'f3.cpp', ['f3.h', 'f3.hpp'], arg) @@ -85,7 +85,7 @@ class ScannerKeywordArgumentTestCase(ScannerTestBase, unittest.TestCase): "Test the Scanner class using the keyword argument and optional argument" def runTest(self): arg = "this is another argument" - s = SCons.Scanner.Scanner(function = self.func, argument = arg) + s = SCons.Scanner.Base(function = self.func, argument = arg) env = DummyEnvironment() env.VARIABLE = "var4" self.test(s, env, 'f4.cpp', ['f4.h', 'f4.hpp'], arg) diff --git a/src/engine/SCons/Scanner/__init__.py b/src/engine/SCons/Scanner/__init__.py index 28fab7a..3c53396 100644 --- a/src/engine/SCons/Scanner/__init__.py +++ b/src/engine/SCons/Scanner/__init__.py @@ -42,7 +42,11 @@ class _Null: # used as an actual argument value. _null = _Null -class Scanner: +class Base: + """ + The base class for dependency scanners. This implements + straightforward, single-pass scanning of a single file. + """ def __init__(self, function, argument=_null, skeys=[]): """ @@ -86,10 +90,10 @@ class Scanner: def scan(self, filename, env): """ - This method does the actually scanning. 'filename' is the filename + This method scans a single object. 'filename' is the filename that will be passed to the scanner function, and 'env' is the environment that will be passed to the scanner function. A list of - dependencies will be returned (i.e. a list of 'Node's). + direct dependency nodes for the specified filename will be returned. """ if not self.argument is _null: @@ -108,3 +112,36 @@ class Scanner: if len(slist) == 1: slist = slist[0] return slist + +class Recursive(Base): + """ + The class for recursive dependency scanning. This will + re-scan any new files returned by each call to the + underlying scanning function, and return the aggregate + list of all dependencies. + """ + + def scan(self, filename, env): + """ + This method does the actual scanning. 'filename' is the filename + that will be passed to the scanner function, and 'env' is the + environment that will be passed to the scanner function. An + aggregate list of dependency nodes for the specified filename + and any of its scanned dependencies will be returned. + """ + + files = [filename] + seen = [filename] + deps = [] + while files: + f = files.pop(0) + if not self.argument is _null: + d = self.function(f, env, self.argument) + else: + d = self.function(f, env) + d = filter(lambda x, seen=seen: str(x) not in seen, d) + deps.extend(d) + s = map(str, d) + seen.extend(s) + files.extend(s) + return deps |