diff options
author | Steven Knight <knight@baldmt.com> | 2005-02-14 03:22:34 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2005-02-14 03:22:34 (GMT) |
commit | 08d7c4cd103fb39b6010b980209a777ceea1ead2 (patch) | |
tree | 1fea16d051dcdb1147ced94deefb11fd31b151c5 /src/engine/SCons/Scanner | |
parent | 35451af4f3052befef3b41b3a971b3a8025b0577 (diff) | |
download | SCons-08d7c4cd103fb39b6010b980209a777ceea1ead2.zip SCons-08d7c4cd103fb39b6010b980209a777ceea1ead2.tar.gz SCons-08d7c4cd103fb39b6010b980209a777ceea1ead2.tar.bz2 |
Don't read up entire directories to decide if an Alias is up-to-date.
Diffstat (limited to 'src/engine/SCons/Scanner')
-rw-r--r-- | src/engine/SCons/Scanner/Dir.py | 62 | ||||
-rw-r--r-- | src/engine/SCons/Scanner/DirTests.py | 80 | ||||
-rw-r--r-- | src/engine/SCons/Scanner/ScannerTests.py | 26 | ||||
-rw-r--r-- | src/engine/SCons/Scanner/__init__.py | 23 |
4 files changed, 182 insertions, 9 deletions
diff --git a/src/engine/SCons/Scanner/Dir.py b/src/engine/SCons/Scanner/Dir.py new file mode 100644 index 0000000..6161059 --- /dev/null +++ b/src/engine/SCons/Scanner/Dir.py @@ -0,0 +1,62 @@ +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import string + +import SCons.Node.FS +import SCons.Scanner + +def DirScanner(fs = SCons.Node.FS.default_fs, **kw): + """Return a prototype Scanner instance for scanning + directories for on-disk files""" + def only_dirs(nodes, fs=fs): + return filter(lambda n: isinstance(n.disambiguate(), SCons.Node.FS.Dir), nodes) + kw['node_factory'] = fs.Entry + kw['recursive'] = only_dirs + ds = apply(SCons.Scanner.Base, [scan, "DirScanner"], kw) + return ds + +skip_entry = { + '.' : 1, + '..' : 1, + '.sconsign' : 1, + '.sconsign.dblite' : 1, +} + +def scan(node, env, path=()): + """ + This scanner scans program files for static-library + dependencies. It will search the LIBPATH environment variable + for libraries specified in the LIBS variable, returning any + files it finds as dependencies. + """ + try: + flist = node.fs.listdir(node.abspath) + except OSError: + return [] + dont_scan = lambda k: not skip_entry.has_key(k) + flist = filter(dont_scan, flist) + flist.sort() + return map(node.Entry, flist) diff --git a/src/engine/SCons/Scanner/DirTests.py b/src/engine/SCons/Scanner/DirTests.py new file mode 100644 index 0000000..e735ca2 --- /dev/null +++ b/src/engine/SCons/Scanner/DirTests.py @@ -0,0 +1,80 @@ +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os.path +import string +import sys +import types +import unittest + +import TestCmd +import SCons.Node.FS +import SCons.Scanner.Dir + +test = TestCmd.TestCmd(workdir = '') + +test.subdir('dir', ['dir', 'sub']) + +test.write(['dir', 'f1'], "dir/f1\n") +test.write(['dir', 'f2'], "dir/f2\n") +test.write(['dir', '.sconsign'], "dir/.sconsign\n") +test.write(['dir', '.sconsign.dblite'], "dir/.sconsign.dblite\n") +test.write(['dir', 'sub', 'f3'], "dir/sub/f3\n") +test.write(['dir', 'sub', 'f4'], "dir/sub/f4\n") +test.write(['dir', 'sub', '.sconsign'], "dir/.sconsign\n") +test.write(['dir', 'sub', '.sconsign.dblite'], "dir/.sconsign.dblite\n") + +class DummyNode: + def __init__(self, name): + self.name = name + self.abspath = test.workpath(name) + self.fs = SCons.Node.FS.default_fs + def __str__(self): + return self.name + def Entry(self, name): + return self.fs.Entry(name) + +class DirScannerTestCase1(unittest.TestCase): + def runTest(self): + s = SCons.Scanner.Dir.DirScanner() + + deps = s(DummyNode('dir'), {}, ()) + sss = map(str, deps) + assert sss == ['f1', 'f2', 'sub'], sss + + deps = s(DummyNode('dir/sub'), {}, ()) + sss = map(str, deps) + assert sss == ['f3', 'f4'], sss + +def suite(): + suite = unittest.TestSuite() + suite.addTest(DirScannerTestCase1()) + return suite + +if __name__ == "__main__": + runner = unittest.TextTestRunner() + result = runner.run(suite()) + if not result.wasSuccessful(): + sys.exit(1) diff --git a/src/engine/SCons/Scanner/ScannerTests.py b/src/engine/SCons/Scanner/ScannerTests.py index c38dc84..ce5411c 100644 --- a/src/engine/SCons/Scanner/ScannerTests.py +++ b/src/engine/SCons/Scanner/ScannerTests.py @@ -221,15 +221,29 @@ class BaseTestCase(unittest.TestCase): def test_recursive(self): """Test the Scanner.Base class recursive flag""" + nodes = [1, 2, 3, 4] + s = SCons.Scanner.Base(function = self.func) - self.failUnless(s.recursive == None, - "incorrect default recursive value") + n = s.recurse_nodes(nodes) + self.failUnless(n == [], + "default behavior returned nodes: %s" % n) + s = SCons.Scanner.Base(function = self.func, recursive = None) - self.failUnless(s.recursive == None, - "did not set recursive flag to None") + n = s.recurse_nodes(nodes) + self.failUnless(n == [], + "recursive = None returned nodes: %s" % n) + s = SCons.Scanner.Base(function = self.func, recursive = 1) - self.failUnless(s.recursive == 1, - "did not set recursive flag to 1") + n = s.recurse_nodes(nodes) + self.failUnless(n == n, + "recursive = 1 didn't return all nodes: %s" % n) + + def odd_only(nodes): + return filter(lambda n: n % 2, nodes) + s = SCons.Scanner.Base(function = self.func, recursive = odd_only) + n = s.recurse_nodes(nodes) + self.failUnless(n == [1, 3], + "recursive = 1 didn't return all nodes: %s" % n) def test_get_skeys(self): """Test the Scanner.Base get_skeys() method""" diff --git a/src/engine/SCons/Scanner/__init__.py b/src/engine/SCons/Scanner/__init__.py index 3f7ead4..cda156c 100644 --- a/src/engine/SCons/Scanner/__init__.py +++ b/src/engine/SCons/Scanner/__init__.py @@ -148,8 +148,12 @@ class Base: this node really needs to be scanned. 'recursive' - specifies that this scanner should be invoked - recursively on the implicit dependencies it returns (the - canonical example being #include lines in C source files). + recursively on all of the implicit dependencies it returns + (the canonical example being #include lines in C source files). + May be a callable, which will be called to filter the list + of nodes found to select a subset for recursive scanning + (the canonical example being only recursively scanning + subdirectories within a directory). The scanner function's first argument will be the a Node that should be scanned for dependencies, the second argument will @@ -182,7 +186,12 @@ class Base: self.node_class = node_class self.node_factory = node_factory self.scan_check = scan_check - self.recursive = recursive + if callable(recursive): + self.recurse_nodes = recursive + elif recursive: + self.recurse_nodes = self._recurse_all_nodes + else: + self.recurse_nodes = self._recurse_no_nodes def path(self, env, dir=None, target=None, source=None): if not self.path_function: @@ -241,6 +250,14 @@ class Base: def select(self, node): return self + def _recurse_all_nodes(self, nodes): + return nodes + + def _recurse_no_nodes(self, nodes): + return [] + + recurse_nodes = _recurse_no_nodes + if not SCons.Memoize.has_metaclass: _Base = Base class Base(SCons.Memoize.Memoizer, _Base): |