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):
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():
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):
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):
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"))