Commits

Anonymous committed a51bbae

add the C scanner

Comments (0)

Files changed (3)

 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

src/scons/Scanner/ScannerTests.py

+__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)
+
+

src/scons/Scanner/__init__.py

+"""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)
+        
+
+
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.