From: stevenknight Date: Tue, 11 Dec 2001 03:22:06 +0000 (+0000) Subject: Add Scanner objects to source files when we first find them, not later when they... X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=c04e51f4a7c8a59116f2603e899b9eed46091b64;p=scons.git Add Scanner objects to source files when we first find them, not later when they're just going to be scanned. git-svn-id: http://scons.tigris.org/svn/scons/trunk@136 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py index 1525804c..60aafb10 100644 --- a/src/engine/SCons/Builder.py +++ b/src/engine/SCons/Builder.py @@ -188,6 +188,9 @@ class BuilderBase: for s in slist: s.env_set(env, 1) + scanner = env.get_scanner(os.path.splitext(s.name)[1]) + if scanner: + s.scanner_set(scanner.instance(env)) if len(tlist) == 1: tlist = tlist[0] diff --git a/src/engine/SCons/BuilderTests.py b/src/engine/SCons/BuilderTests.py index 9143a5f0..fd55f03a 100644 --- a/src/engine/SCons/BuilderTests.py +++ b/src/engine/SCons/BuilderTests.py @@ -62,10 +62,13 @@ outfile = test.workpath('outfile') show_string = None instanced = None +env_scanner = None class Environment: - def subst(self, s): - return s + def subst(self, s): + return s + def get_scanner(self, ext): + return env_scanner env = Environment() class BuilderTestCase(unittest.TestCase): @@ -388,6 +391,20 @@ class BuilderTestCase(unittest.TestCase): assert tgt.scanner == scn, tgt.scanner assert instanced + def test_src_scanner(slf): + """Testing ability to set a source file scanner through a builder.""" + global env_scanner + class TestScanner: + def key(self, env): + return 'TestScannerkey' + def instance(self, env): + return self + env_scanner = TestScanner() + builder = SCons.Builder.Builder(action='action') + tgt = builder(env, target='foo', source='bar') + assert not tgt.scanner == env_scanner + assert tgt.sources[0].scanner == env_scanner + if __name__ == "__main__": suite = unittest.makeSuite(BuilderTestCase, 'test_') if not unittest.TextTestRunner().run(suite).wasSuccessful(): diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py index a898f01b..b170ef62 100644 --- a/src/engine/SCons/Node/FS.py +++ b/src/engine/SCons/Node/FS.py @@ -468,11 +468,7 @@ class File(Entry): def scan(self): if not self.scanned and self.env: if self.scanner: - scanner = self.scanner - else: - scanner = self.env.get_scanner(os.path.splitext(self.name)[1]) - if scanner: - self.add_dependency(scanner.scan(self.path_, self.env)) + self.add_dependency(self.scanner.scan(self.path, self.env)) self.scanned = 1 def __createDir(self): diff --git a/src/engine/SCons/Node/FSTests.py b/src/engine/SCons/Node/FSTests.py index d9d128e9..fc58c4a9 100644 --- a/src/engine/SCons/Node/FSTests.py +++ b/src/engine/SCons/Node/FSTests.py @@ -38,9 +38,17 @@ class Builder: built_it = 1 return 0 +scanner_count = 0 + class Scanner: + def __init__(self): + global scanner_count + scanner_count = scanner_count + 1 + self.hash = scanner_count def scan(self, filename, env): return [SCons.Node.FS.default_fs.File(filename)] + def __hash__(self): + return self.hash class Environment: def __init__(self): @@ -296,11 +304,15 @@ class FSTestCase(unittest.TestCase): f1.scanner = Scanner() f1.scan() assert f1.depends[0].path_ == os.path.join("d1", "f1") - f1.scanner = None - f1.depends = [] - f1.scanned = 0 + f1.scanner = None + f1.scanned = None f1.scan() assert f1.depends[0].path_ == os.path.join("d1", "f1") + f1.scanner = None + f1.scanned = None + f1.depends = [] + f1.scan() + assert not f1.depends # Test building a file whose directory is not there yet... f1 = fs.File(test.workpath("foo/bar/baz/ack"))