add the C scanner
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Wed, 8 Aug 2001 11:57:38 +0000 (11:57 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Wed, 8 Aug 2001 11:57:38 +0000 (11:57 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@16 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/MANIFEST
src/scons/Scanner/ScannerTests.py [new file with mode: 0644]
src/scons/Scanner/__init__.py [new file with mode: 0644]

index 35c3b3cf3beae8d088271080e797ed9d80a8efed..c09fc4abb0d8571beacd5b9c5f39022aaf4e2e91 100644 (file)
@@ -6,6 +6,7 @@ scons/Environment.py
 scons/Job.py
 scons/Node/__init__.py
 scons/Node/FS.py
+scons/Scanner/__init__.py
 scons/Sig/__init__.py
 scons/Sig/MD5.py
 scons/Sig/TimeStamp.py
diff --git a/src/scons/Scanner/ScannerTests.py b/src/scons/Scanner/ScannerTests.py
new file mode 100644 (file)
index 0000000..0bcdcde
--- /dev/null
@@ -0,0 +1,57 @@
+__revision__ = "Scanner/ScannerTests.py __REVISION__ __DATE__ __DEVELOPER__"
+
+import unittest
+import scons.Scanner
+import sys
+
+class ScannerTestBase:
+    
+    def func(self, filename, env):
+        self.filename = filename
+        self.env = env
+        return self.deps
+
+    def error_func(self, filename, env):
+        self.fail("the wrong function was called")
+
+    def test(self, scanner, env, filename, deps):
+        self.deps = deps
+        deps = scanner.scan(filename, env)
+
+        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")
+
+class DummyEnvironment:
+    pass
+
+
+class ScannerPositionalTestCase(ScannerTestBase, unittest.TestCase):
+    "Test the Scanner class using the position argument"
+    def runTest(self):
+        s = scons.Scanner.Scanner(self.func)
+        env = DummyEnvironment()
+        env.ARGUMENT = "arg1"
+        self.test(s, env, 'f1.cpp', ['f1.h', 'f2.h'])
+
+class ScannerKeywordTestCase(ScannerTestBase, unittest.TestCase):
+    "Test the Scanner class using the keyword argument"
+    def runTest(self):
+        s = scons.Scanner.Scanner(function = self.func)
+        env = DummyEnvironment()
+        env.ARGUMENT = "arg1"
+        self.test(s, env, 'f1.cpp', ['f1.h', 'f2.h'])
+
+def suite():
+    suite = unittest.TestSuite()
+    suite.addTest(ScannerPositionalTestCase())
+    suite.addTest(ScannerKeywordTestCase())
+    return suite
+
+if __name__ == "__main__":
+    runner = unittest.TextTestRunner()
+    result = runner.run(suite())
+    if not result.wasSuccessful():
+        sys.exit(1)
+
+
diff --git a/src/scons/Scanner/__init__.py b/src/scons/Scanner/__init__.py
new file mode 100644 (file)
index 0000000..992179b
--- /dev/null
@@ -0,0 +1,51 @@
+"""scons.Scanner
+
+The Scanner package for the scons software construction utility.
+
+"""
+
+__revision__ = "Scanner/__init__.py __REVISION__ __DATE__ __DEVELOPER__"
+
+__version__ = "__VERSION__"
+
+class Scanner:
+
+    def __init__(self, function):
+        """
+        Construct a new scanner object given a scanner function.
+
+        The only argument to this method is a function taking two arguments
+        and returning a list of strings. The functions first argument will
+        be the name of a file that should be scanned for dependencies, the
+        second argument will be an Environment object and
+        the returned list of should contain the file names of all the
+        direct dependencies of this file.
+
+        Examples:
+
+        s = Scanner(my_scanner_function)
+        
+        s = Scanner(function = my_scanner_function)
+
+        """
+
+        # Note: this class could easily work with scanner functions that take
+        # something other than a filename as an argument (e.g. a database
+        # node) and a dependencies list that aren't file names. All that
+        # would need to be changed is the documentation.
+
+        self.function = function
+
+    def scan(self, filename, env):
+        """
+        This method does the actually scanning. 'filename' is the filename
+        that will be passed to the scanner function, and 'env' is the
+        environment that will be passed to the scanner function. A list of
+        dependencies will be returned.
+        """
+        
+        return self.function(filename, env)
+        
+
+
+