diff options
author | Steven Knight <knight@baldmt.com> | 2002-02-03 22:11:10 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2002-02-03 22:11:10 (GMT) |
commit | 5e8517111e036d0dfd191a8ad41e41bbf0950c2e (patch) | |
tree | 823a922d61b8ef25f70ca153b6cb30e1e4a6976b /src/engine | |
parent | e4055f33a18a5a462150a061b2b4009db0867c8c (diff) | |
download | SCons-5e8517111e036d0dfd191a8ad41e41bbf0950c2e.zip SCons-5e8517111e036d0dfd191a8ad41e41bbf0950c2e.tar.gz SCons-5e8517111e036d0dfd191a8ad41e41bbf0950c2e.tar.bz2 |
Support Scanner functions returning strings, not just Nodes.
Diffstat (limited to 'src/engine')
-rw-r--r-- | src/engine/SCons/Scanner/ScannerTests.py | 7 | ||||
-rw-r--r-- | src/engine/SCons/Scanner/__init__.py | 30 |
2 files changed, 25 insertions, 12 deletions
diff --git a/src/engine/SCons/Scanner/ScannerTests.py b/src/engine/SCons/Scanner/ScannerTests.py index 99cab94..76df18e 100644 --- a/src/engine/SCons/Scanner/ScannerTests.py +++ b/src/engine/SCons/Scanner/ScannerTests.py @@ -41,11 +41,14 @@ class ScannerTestBase: def test(self, scanner, env, filename, deps, *args): self.deps = deps - deps = scanner.scan(filename, env) + scanned = scanner.scan(filename, env) + scanned_strs = map(lambda x: str(x), scanned) self.failUnless(self.filename == filename, "the filename was passed incorrectly") self.failUnless(self.env == env, "the environment was passed incorrectly") - self.failUnless(self.deps == deps, "the dependencies were returned incorrectly") + self.failUnless(scanned_strs == deps, "the dependencies were returned incorrectly") + for d in scanned: + self.failUnless(type(d) != type(""), "got a string in the dependencies") if len(args) > 0: self.failUnless(self.arg == args[0], "the argument was passed incorrectly") diff --git a/src/engine/SCons/Scanner/__init__.py b/src/engine/SCons/Scanner/__init__.py index 25345a5..a00a75b 100644 --- a/src/engine/SCons/Scanner/__init__.py +++ b/src/engine/SCons/Scanner/__init__.py @@ -32,7 +32,8 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" __version__ = "__VERSION__" -from SCons.Util import scons_str2nodes +import SCons.Node.FS +import SCons.Util class _Null: @@ -48,7 +49,12 @@ class Base: straightforward, single-pass scanning of a single file. """ - def __init__(self, function, name = "NONE", argument=_null, skeys=[]): + def __init__(self, + function, + name = "NONE", + argument = _null, + skeys = [], + node_factory = SCons.Node.FS.default_fs.File): """ Construct a new scanner object given a scanner function. @@ -89,19 +95,26 @@ class Base: self.name = name self.argument = argument self.skeys = skeys + self.node_factory = node_factory def scan(self, node, env): """ This method scans a single object. 'node' is the node that will be passed to the scanner function, and 'env' is the environment that will be passed to the scanner function. A list of - direct dependency nodes for the specified filename will be returned. + direct dependency nodes for the specified node will be returned. """ if not self.argument is _null: - return self.function(node, env, self.argument) + list = self.function(node, env, self.argument) else: - return self.function(node, env) + list = self.function(node, env) + nodes = [] + for l in list: + if not isinstance(l, SCons.Node.FS.Entry): + l = self.node_factory(l) + nodes.append(l) + return nodes def instance(self, env): """ @@ -141,11 +154,8 @@ class Recursive(Base): deps = [] while nodes: n = nodes.pop(0) - if not self.argument is _null: - d = self.function(n, env, self.argument) - else: - d = self.function(n, env) - d = filter(lambda x, seen=seen: not seen.has_key(x), d) + d = filter(lambda x, seen=seen: not seen.has_key(x), + Base.scan(self, n, env)) if d: deps.extend(d) nodes.extend(d) |