From 0bb3690b121a1f5aee280570e9b19c3a4947f3d0 Mon Sep 17 00:00:00 2001 From: stevenknight Date: Wed, 8 Aug 2001 11:57:38 +0000 Subject: [PATCH] add the C scanner git-svn-id: http://scons.tigris.org/svn/scons/trunk@16 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/MANIFEST | 1 + src/scons/Scanner/ScannerTests.py | 57 +++++++++++++++++++++++++++++++ src/scons/Scanner/__init__.py | 51 +++++++++++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 src/scons/Scanner/ScannerTests.py create mode 100644 src/scons/Scanner/__init__.py diff --git a/src/MANIFEST b/src/MANIFEST index 35c3b3cf..c09fc4ab 100644 --- a/src/MANIFEST +++ b/src/MANIFEST @@ -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 index 00000000..0bcdcde8 --- /dev/null +++ b/src/scons/Scanner/ScannerTests.py @@ -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 index 00000000..992179ba --- /dev/null +++ b/src/scons/Scanner/__init__.py @@ -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) + + + + -- 2.26.2