class CScanner(SCons.Scanner.Recursive):
def __init__(self, *args, **kw):
apply(SCons.Scanner.Recursive.__init__, (self,) + args, kw)
+ self.hash = None
self.pathscanners = {}
def instance(self, env):
dirs = ()
if not self.pathscanners.has_key(dirs):
clone = copy.copy(self)
- clone.argument = [self.fs, dirs] # XXX reaching into object
+ clone.hash = dirs
+ clone.argument = [self.fs, dirs] # XXX reaching into object
self.pathscanners[dirs] = clone
return self.pathscanners[dirs]
+ def __hash__(self):
+ return hash(self.hash)
+
def scan(filename, env, args = [SCons.Node.FS.default_fs, ()]):
"""
scan(str, Environment) -> [str]
def runTest(self):
env1 = DummyEnvironment([test.workpath("d1")])
env2 = DummyEnvironment([test.workpath("d1/d2")])
+ env3 = DummyEnvironment([test.workpath("d1/../d1")])
s = SCons.Scanner.C.CScan()
- s1 = s.instance(env1)
- s2 = s.instance(env2)
- s3 = s.instance(env1)
- assert not s1 is s2
- assert s1 is s3
+ s1 = s.instance(env1)
+ s2 = s.instance(env2)
+ s3 = s.instance(env3)
+ assert not s1 is s2
+ assert s1 is s3
deps1 = s1.scan(test.workpath('f1.cpp'), None)
deps2 = s2.scan(test.workpath('f1.cpp'), None)
headers1 = ['f1.h', 'd1/f2.h']
deps_match(self, deps1, headers1)
deps_match(self, deps2, headers2)
+class CScannerTestCase7(unittest.TestCase):
+ def runTest(self):
+ s = SCons.Scanner.C.CScan()
+ s1 = s.instance(DummyEnvironment([test.workpath("d1")]))
+ s2 = s.instance(DummyEnvironment([test.workpath("d1/../d1")]))
+ dict = {}
+ dict[s1] = 777
+ assert dict[s2] == 777
+
def suite():
suite = unittest.TestSuite()
suite.addTest(CScannerTestCase1())
suite.addTest(CScannerTestCase4())
suite.addTest(CScannerTestCase5())
suite.addTest(CScannerTestCase6())
+ suite.addTest(CScannerTestCase7())
return suite
if __name__ == "__main__":
i = s.instance(env)
self.test(i, env, 'i4.cpp', ['i4.h', 'i4.hpp'], arg)
+class ScannerHashTestCase(ScannerTestBase, unittest.TestCase):
+ "Test the Scanner.Base class __hash__() method"
+ def runTest(self):
+ s = SCons.Scanner.Base(self.func, "Hash")
+ dict = {}
+ dict[s] = 777
+ self.failUnless(hash(dict.keys()[0]) == hash(None),
+ "did not hash Scanner base class as expected")
+
def suite():
suite = unittest.TestSuite()
suite.addTest(ScannerPositionalTestCase())
suite.addTest(ScannerKeywordTestCase())
suite.addTest(ScannerPositionalArgumentTestCase())
suite.addTest(ScannerKeywordArgumentTestCase())
+ suite.addTest(ScannerHashTestCase())
return suite
if __name__ == "__main__":
def __cmp__(self, other):
return cmp(self.__dict__, other.__dict__)
+ def __hash__(self):
+ return hash(None)
+
class Recursive(Base):
"""
The class for recursive dependency scanning. This will
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)
+ if d:
+ deps.extend(d)
+ s = map(str, d)
+ seen.extend(s)
+ files.extend(s)
return deps