From: stevenknight Date: Mon, 14 Feb 2005 00:40:40 +0000 (+0000) Subject: Move the canned Scanner objects out of Defaults.py and document how to add Scanners... X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=14846b57dc5acc8d24be52993b8d4e3faf102b70;p=scons.git Move the canned Scanner objects out of Defaults.py and document how to add Scanners that env.Object() can use. git-svn-id: http://scons.tigris.org/svn/scons/trunk@1228 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/doc/man/scons.1 b/doc/man/scons.1 index be4f9449..db1da8c5 100644 --- a/doc/man/scons.1 +++ b/doc/man/scons.1 @@ -1999,6 +1999,13 @@ env.SharedObject(target = 'eee.o', source = 'eee.cpp') env.SharedObject(target = 'fff.obj', source = 'fff.for') .EE +Note that the source files will be scanned +according to the suffix mappings in +.B SourceFileScanner +object. +See the section "Scanner Objects," +below, for a more information. + '\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" .IP StaticLibrary() .IP env.StaticLibrary() @@ -2080,6 +2087,13 @@ env.StaticObject(target = 'bbb.o', source = 'bbb.c++') env.StaticObject(target = 'ccc.obj', source = 'ccc.f') .EE +Note that the source files will be scanned +according to the suffix mappings in +.B SourceFileScanner +object. +See the section "Scanner Objects," +below, for a more information. + '\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" .IP Tar() .IP env.Tar() @@ -2169,9 +2183,21 @@ env.Zip('stuff', ['subdir1', 'subdir2']) env.Zip('stuff', 'another') .EE +All +targets of builder methods automatically depend on their sources. +An explicit dependency can +be specified using the +.B Depends +method of a construction environment (see below). + +In addition, .B scons automatically scans -C source files, C++ source files, +source files for various programming languages, +so the dependencies do not need to be specified explicitly. +By default, SCons can +C source files, +C++ source files, Fortran source files with .B .F (POSIX systems only), @@ -2186,14 +2212,26 @@ and assembly language files with or .B .SPP files extensions -for C preprocessor dependencies, -so the dependencies do not need to be specified explicitly. -In addition, all -targets of builder methods automatically depend on their sources. -An explicit dependency can -be specified using the -.B Depends -method of a construction environment (see below). +for C preprocessor dependencies. +SCons also has default support +for scanning D source files, +You can also write your own Scanners +to add support for additional source file types. +These can be added to the default +Scanner object used by +the +.BR Object () +.BR StaticObject () +and +.BR SharedObject () +Builders by adding them +to the +.B SourceFileScanner +object as follows: + +See the section "Scanner Objects," +below, for a more information about +defining your own Scanner objects. .SS Methods and Functions to Do Things In addition to Builder methods, @@ -9185,6 +9223,41 @@ and not (for example) also on the files specified by the #include lines in the file being scanned. +Note that +.B scons +has a global +.B SourceFileScanner +object that is used by +the +.BR Object (), +.BR SharedObject (), +and +.BR StaticObject () +builders to decide +which scanner should be used +for different file extensions. +You can using the +.BR SourceFileScanner.add_scanner () +method to add your own Scanner object +to the +.B scons +infrastructure +that builds target programs or +libraries from a list of +source files of different types: + +.ES +def xyz_scan(node, env, path): + contents = node.get_contents() + # Scan the contents and return the included files. + +XYZScanner = Scanner(xyz_scan) + +SourceFileScanner.add_scanner('.xyx', XYZScanner) + +env.Program('my_prog', ['file1.c', 'file2.f', 'file3.xyz']) +.EE + .SH SYSTEM-SPECIFIC BEHAVIOR SCons and its configuration files are very portable, due largely to its implementation in Python. diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 8f198602..dbd06853 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -193,6 +193,11 @@ RELEASE 0.97 - XXX - When scanning, don't create Nodes for include files that don't actually exist on disk. + - Make supported global variables CScanner, DScanner, ProgramScanner and + SourceFileScanner. Make SourceFileScanner.add_scanner() a supported + part of the public interface. Keep the old SCons.Defaults.*Scan names + around for a while longer since some people were already using them. + From Wayne Lee: - Avoid "maximum recursion limit" errors when removing $(-$) pairs diff --git a/src/RELEASE.txt b/src/RELEASE.txt index 2ace3c5d..2592f5cd 100644 --- a/src/RELEASE.txt +++ b/src/RELEASE.txt @@ -164,6 +164,27 @@ RELEASE 0.97 - XXX changed. This change *only* affects any cases where you explicitly use UserList objects to initialize or append to a variable. + Please note the following planned, future changes: + + - Several internal variable names in SCons.Defaults for various + pre-made default Scanner objects have been deprecated and will + be removed in a future revision. In their place are several new + global variable names that are now part of the publicly-supported + interface: + + NEW NAME DEPRECATED NAME + -------- ---------------------------- + CScanner SCons.Defaults.CScan + DSCanner SCons.Defaults.DScan + SourceFileScanner SCons.Defaults.ObjSourceScan + ProgramScanner SCons.Defaults.ProgScan + + Of these, only ObjSourceScan was probably used at all, to add + new mappings of file suffixes to other scanners for use by the + Object() Builder. This should now be done as follows: + + SourceFileScanner.add_scanner('.x', XScanner) + SCons is developed with an extensive regression test suite, and a rigorous development methodology for continually improving that suite. Because of this, SCons is of sufficient quality that you can use it diff --git a/src/engine/SCons/Defaults.py b/src/engine/SCons/Defaults.py index 26e22361..032a067d 100644 --- a/src/engine/SCons/Defaults.py +++ b/src/engine/SCons/Defaults.py @@ -48,9 +48,7 @@ import sys import SCons.Action import SCons.Builder import SCons.Environment -import SCons.Scanner.C -import SCons.Scanner.D -import SCons.Scanner.Prog +import SCons.Tool import SCons.Sig # A placeholder for a default Environment (for fetching source files @@ -95,30 +93,14 @@ def SharedFlagChecker(source, target, env): SharedCheck = SCons.Action.Action(SharedFlagChecker, None) -# Scanners and suffixes for common languages. -ObjSourceScan = SCons.Scanner.Scanner({}, name='ObjSrcScanner') - -CScan = SCons.Scanner.C.CScan() - -CSuffixes = [".c", ".C", ".cxx", ".cpp", ".c++", ".cc", - ".h", ".H", ".hxx", ".hpp", ".hh", - ".F", ".fpp", ".FPP", - ".S", ".spp", ".SPP"] - -for suffix in CSuffixes: - ObjSourceScan.add_scanner(suffix, CScan) - -DScan = SCons.Scanner.D.DScan() - -DSuffixes = ['.d'] - -for suffix in DSuffixes: - ObjSourceScan.add_scanner(suffix, DScan) - -IDLSuffixes = [".idl", ".IDL"] - -# cleanup -del suffix +# Some people were using these variable name before we made +# SourceFileScanner part of the public interface. Don't break their +# SConscript files until we've given them some fair warning and a +# transition period. +CScan = SCons.Tool.CScanner +DScan = SCons.Tool.DScanner +ObjSourceScan = SCons.Tool.SourceFileScanner +ProgScan = SCons.Tool.ProgramScanner # Actions for common languages. CAction = SCons.Action.Action("$CCCOM", "$CCCOMSTR") @@ -138,8 +120,6 @@ ArAction = SCons.Action.Action("$ARCOM", "$ARCOMSTR") LexAction = SCons.Action.Action("$LEXCOM", "$LEXCOMSTR") YaccAction = SCons.Action.Action("$YACCCOM", "$YACCCOMSTR") -ProgScan = SCons.Scanner.Prog.ProgScan() - def DVI(): """Common function to generate a DVI file Builder.""" return SCons.Builder.Builder(action = {}, @@ -364,9 +344,9 @@ class Variable_Method_Caller: ConstructionEnvironment = { 'BUILDERS' : {}, 'SCANNERS' : [], - 'CPPSUFFIXES' : CSuffixes, - 'DSUFFIXES' : DSuffixes, - 'IDLSUFFIXES' : IDLSuffixes, + 'CPPSUFFIXES' : SCons.Tool.CSuffixes, + 'DSUFFIXES' : SCons.Tool.DSuffixes, + 'IDLSUFFIXES' : SCons.Tool.IDLSuffixes, 'PDFPREFIX' : '', 'PDFSUFFIX' : '.pdf', 'PSPREFIX' : '', diff --git a/src/engine/SCons/Scanner/C.py b/src/engine/SCons/Scanner/C.py index a5c2331e..62a6842e 100644 --- a/src/engine/SCons/Scanner/C.py +++ b/src/engine/SCons/Scanner/C.py @@ -32,10 +32,10 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import SCons.Node.FS import SCons.Scanner -def CScan(fs = SCons.Node.FS.default_fs): +def CScanner(fs = SCons.Node.FS.default_fs): """Return a prototype Scanner instance for scanning source files that use the C pre-processor""" - cs = SCons.Scanner.ClassicCPP("CScan", + cs = SCons.Scanner.ClassicCPP("CScanner", "$CPPSUFFIXES", "CPPPATH", '^[ \t]*#[ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")', diff --git a/src/engine/SCons/Scanner/CTests.py b/src/engine/SCons/Scanner/CTests.py index 4c21fe9e..fd17ee1e 100644 --- a/src/engine/SCons/Scanner/CTests.py +++ b/src/engine/SCons/Scanner/CTests.py @@ -215,7 +215,7 @@ def make_node(filename, fs=SCons.Node.FS.default_fs): class CScannerTestCase1(unittest.TestCase): def runTest(self): env = DummyEnvironment(CPPPATH=[]) - s = SCons.Scanner.C.CScan() + s = SCons.Scanner.C.CScanner() path = s.path(env) deps = s(make_node('f1.cpp'), env, path) headers = ['f1.h', 'f2.h'] @@ -224,7 +224,7 @@ class CScannerTestCase1(unittest.TestCase): class CScannerTestCase2(unittest.TestCase): def runTest(self): env = DummyEnvironment(CPPPATH=[test.workpath("d1")]) - s = SCons.Scanner.C.CScan() + s = SCons.Scanner.C.CScanner() path = s.path(env) deps = s(make_node('f1.cpp'), env, path) headers = ['f1.h', 'd1/f2.h'] @@ -233,7 +233,7 @@ class CScannerTestCase2(unittest.TestCase): class CScannerTestCase3(unittest.TestCase): def runTest(self): env = DummyEnvironment(CPPPATH=[test.workpath("d1")]) - s = SCons.Scanner.C.CScan() + s = SCons.Scanner.C.CScanner() path = s.path(env) deps = s(make_node('f2.cpp'), env, path) headers = ['d1/f1.h', 'f1.h', 'd1/d2/f1.h'] @@ -242,7 +242,7 @@ class CScannerTestCase3(unittest.TestCase): class CScannerTestCase4(unittest.TestCase): def runTest(self): env = DummyEnvironment(CPPPATH=[test.workpath("d1"), test.workpath("d1/d2")]) - s = SCons.Scanner.C.CScan() + s = SCons.Scanner.C.CScanner() path = s.path(env) deps = s(make_node('f2.cpp'), env, path) headers = ['d1/f1.h', 'f1.h', 'd1/d2/f1.h', 'd1/d2/f4.h'] @@ -251,7 +251,7 @@ class CScannerTestCase4(unittest.TestCase): class CScannerTestCase5(unittest.TestCase): def runTest(self): env = DummyEnvironment(CPPPATH=[]) - s = SCons.Scanner.C.CScan() + s = SCons.Scanner.C.CScanner() path = s.path(env) n = make_node('f3.cpp') @@ -275,7 +275,7 @@ class CScannerTestCase6(unittest.TestCase): def runTest(self): env1 = DummyEnvironment(CPPPATH=[test.workpath("d1")]) env2 = DummyEnvironment(CPPPATH=[test.workpath("d1/d2")]) - s = SCons.Scanner.C.CScan() + s = SCons.Scanner.C.CScanner() path1 = s.path(env1) path2 = s.path(env2) deps1 = s(make_node('f1.cpp'), env1, path1) @@ -289,7 +289,7 @@ class CScannerTestCase8(unittest.TestCase): def runTest(self): fs = SCons.Node.FS.FS(test.workpath('')) env = DummyEnvironment(CPPPATH=["include"]) - s = SCons.Scanner.C.CScan(fs = fs) + s = SCons.Scanner.C.CScanner(fs = fs) path = s.path(env) deps1 = s(fs.File('fa.cpp'), env, path) fs.chdir(fs.Dir('subdir')) @@ -315,7 +315,7 @@ class CScannerTestCase9(unittest.TestCase): test.write('fa.h','\n') fs = SCons.Node.FS.FS(test.workpath('')) env = DummyEnvironment(CPPPATH=[]) - s = SCons.Scanner.C.CScan(fs=fs) + s = SCons.Scanner.C.CScanner(fs=fs) path = s.path(env) deps = s(fs.File('fa.cpp'), env, path) @@ -330,7 +330,7 @@ class CScannerTestCase10(unittest.TestCase): fs = SCons.Node.FS.FS(test.workpath('')) fs.chdir(fs.Dir('include')) env = DummyEnvironment(CPPPATH=[]) - s = SCons.Scanner.C.CScan(fs=fs) + s = SCons.Scanner.C.CScanner(fs=fs) path = s.path(env) test.write('include/fa.cpp', test.read('fa.cpp')) fs.chdir(fs.Dir('..')) @@ -349,7 +349,7 @@ class CScannerTestCase11(unittest.TestCase): f1=fs.File('include2/jjj.h') f1.builder=1 env = DummyEnvironment(CPPPATH=['include', 'include2']) - s = SCons.Scanner.C.CScan(fs=fs) + s = SCons.Scanner.C.CScanner(fs=fs) path = s.path(env) deps = s(fs.File('src/fff.c'), env, path) deps_match(self, deps, [ test.workpath('repository/include/iii.h'), 'include2/jjj.h' ]) @@ -363,7 +363,7 @@ class CScannerTestCase12(unittest.TestCase): fs.BuildDir('build2', 'src', 0) fs.Repository(test.workpath('repository')) env = DummyEnvironment(CPPPATH=[]) - s = SCons.Scanner.C.CScan(fs = fs) + s = SCons.Scanner.C.CScanner(fs = fs) path = s.path(env) deps1 = s(fs.File('build1/aaa.c'), env, path) deps_match(self, deps1, [ 'build1/bbb.h' ]) @@ -381,7 +381,7 @@ class CScannerTestCase13(unittest.TestCase): def subst(self, arg, test=test): return test.workpath("d1") env = SubstEnvironment(CPPPATH=["blah"]) - s = SCons.Scanner.C.CScan() + s = SCons.Scanner.C.CScanner() path = s.path(env) deps = s(make_node('f1.cpp'), env, path) headers = ['f1.h', 'd1/f2.h'] @@ -390,7 +390,7 @@ class CScannerTestCase13(unittest.TestCase): class CScannerTestCase14(unittest.TestCase): def runTest(self): env = DummyEnvironment(CPPPATH=[]) - s = SCons.Scanner.C.CScan() + s = SCons.Scanner.C.CScanner() path = s.path(env) deps = s(make_node('f5.c'), env, path) headers = ['f5a.h', 'f5b.h'] @@ -403,7 +403,7 @@ class CScannerTestCase15(unittest.TestCase): ".F", ".fpp", ".FPP", ".S", ".spp", ".SPP"] env = DummyEnvironment(CPPSUFFIXES = suffixes) - s = SCons.Scanner.C.CScan() + s = SCons.Scanner.C.CScanner() for suffix in suffixes: assert suffix in s.get_skeys(env), "%s not in skeys" % suffix diff --git a/src/engine/SCons/Scanner/D.py b/src/engine/SCons/Scanner/D.py index fba973f1..b80912d1 100644 --- a/src/engine/SCons/Scanner/D.py +++ b/src/engine/SCons/Scanner/D.py @@ -36,16 +36,16 @@ import string import SCons.Scanner -def DScan(fs = SCons.Node.FS.default_fs): +def DScanner(fs = SCons.Node.FS.default_fs): """Return a prototype Scanner instance for scanning D source files""" - ds = DScanner(name = "DScan", - suffixes = '$DSUFFIXES', - path_variable = 'DPATH', - regex = 'import\s+([^\;]*)\;', - fs = fs) + ds = D(name = "DScanner", + suffixes = '$DSUFFIXES', + path_variable = 'DPATH', + regex = 'import\s+([^\;]*)\;', + fs = fs) return ds -class DScanner(SCons.Scanner.Classic): +class D(SCons.Scanner.Classic): def find_include(self, include, source_dir, path): if callable(path): path=path() # translate dots (package separators) to slashes diff --git a/src/engine/SCons/Scanner/Prog.py b/src/engine/SCons/Scanner/Prog.py index d9b57b90..f2f3bbf6 100644 --- a/src/engine/SCons/Scanner/Prog.py +++ b/src/engine/SCons/Scanner/Prog.py @@ -33,11 +33,11 @@ import SCons.Util # global, set by --debug=findlibs print_find_libs = None -def ProgScan(fs = SCons.Node.FS.default_fs, **kw): +def ProgramScanner(fs = SCons.Node.FS.default_fs, **kw): """Return a prototype Scanner instance for scanning executable files for static-lib dependencies""" kw['path_function'] = SCons.Scanner.FindPathDirs('LIBPATH', fs) - ps = apply(SCons.Scanner.Base, [scan, "ProgScan"], kw) + ps = apply(SCons.Scanner.Base, [scan, "ProgramScanner"], kw) return ps def scan(node, env, libpath = (), fs = SCons.Node.FS.default_fs): diff --git a/src/engine/SCons/Scanner/ProgTests.py b/src/engine/SCons/Scanner/ProgTests.py index c31b3922..ec25f244 100644 --- a/src/engine/SCons/Scanner/ProgTests.py +++ b/src/engine/SCons/Scanner/ProgTests.py @@ -101,18 +101,18 @@ def deps_match(deps, libs): # define some tests: -class ProgScanTestCase1(unittest.TestCase): +class ProgramScannerTestCase1(unittest.TestCase): def runTest(self): env = DummyEnvironment(LIBPATH=[ test.workpath("") ], LIBS=[ 'l1', 'l2', 'l3' ]) - s = SCons.Scanner.Prog.ProgScan() + s = SCons.Scanner.Prog.ProgramScanner() path = s.path(env) deps = s(DummyNode('dummy'), env, path) assert deps_match(deps, ['l1.lib']), map(str, deps) env = DummyEnvironment(LIBPATH=[ test.workpath("") ], LIBS='l1') - s = SCons.Scanner.Prog.ProgScan() + s = SCons.Scanner.Prog.ProgramScanner() path = s.path(env) deps = s(DummyNode('dummy'), env, path) assert deps_match(deps, ['l1.lib']), map(str, deps) @@ -120,7 +120,7 @@ class ProgScanTestCase1(unittest.TestCase): f1 = SCons.Node.FS.default_fs.File(test.workpath('f1')) env = DummyEnvironment(LIBPATH=[ test.workpath("") ], LIBS=[f1]) - s = SCons.Scanner.Prog.ProgScan() + s = SCons.Scanner.Prog.ProgramScanner() path = s.path(env) deps = s(DummyNode('dummy'), env, path) assert deps[0] is f1, deps @@ -128,33 +128,33 @@ class ProgScanTestCase1(unittest.TestCase): f2 = SCons.Node.FS.default_fs.File(test.workpath('f1')) env = DummyEnvironment(LIBPATH=[ test.workpath("") ], LIBS=f2) - s = SCons.Scanner.Prog.ProgScan() + s = SCons.Scanner.Prog.ProgramScanner() path = s.path(env) deps = s(DummyNode('dummy'), env, path) assert deps[0] is f2, deps -class ProgScanTestCase2(unittest.TestCase): +class ProgramScannerTestCase2(unittest.TestCase): def runTest(self): env = DummyEnvironment(LIBPATH=map(test.workpath, ["", "d1", "d1/d2" ]), LIBS=[ 'l1', 'l2', 'l3' ]) - s = SCons.Scanner.Prog.ProgScan() + s = SCons.Scanner.Prog.ProgramScanner() path = s.path(env) deps = s(DummyNode('dummy'), env, path) assert deps_match(deps, ['l1.lib', 'd1/l2.lib', 'd1/d2/l3.lib' ]), map(str, deps) -class ProgScanTestCase3(unittest.TestCase): +class ProgramScannerTestCase3(unittest.TestCase): def runTest(self): env = DummyEnvironment(LIBPATH=[test.workpath("d1/d2"), test.workpath("d1")], LIBS=string.split('l2 l3')) - s = SCons.Scanner.Prog.ProgScan() + s = SCons.Scanner.Prog.ProgramScanner() path = s.path(env) deps = s(DummyNode('dummy'), env, path) assert deps_match(deps, ['d1/l2.lib', 'd1/d2/l3.lib']), map(str, deps) -class ProgScanTestCase5(unittest.TestCase): +class ProgramScannerTestCase5(unittest.TestCase): def runTest(self): class SubstEnvironment(DummyEnvironment): def subst(self, arg, path=test.workpath("d1")): @@ -164,23 +164,23 @@ class ProgScanTestCase5(unittest.TestCase): return arg env = SubstEnvironment(LIBPATH=[ "blah" ], LIBS=string.split('l2 l3')) - s = SCons.Scanner.Prog.ProgScan() + s = SCons.Scanner.Prog.ProgramScanner() path = s.path(env) deps = s(DummyNode('dummy'), env, path) assert deps_match(deps, [ 'd1/l2.lib' ]), map(str, deps) -class ProgScanTestCase6(unittest.TestCase): +class ProgramScannerTestCase6(unittest.TestCase): def runTest(self): env = DummyEnvironment(LIBPATH=[ test.workpath("dir") ], LIBS=['foo', 'sub/libbar', 'xyz.other'], LIBPREFIXES=['lib'], LIBSUFFIXES=['.a']) - s = SCons.Scanner.Prog.ProgScan() + s = SCons.Scanner.Prog.ProgramScanner() path = s.path(env) deps = s(DummyNode('dummy'), env, path) assert deps_match(deps, ['dir/libfoo.a', 'dir/sub/libbar.a', 'dir/libxyz.other']), map(str, deps) -class ProgScanTestCase7(unittest.TestCase): +class ProgramScannerTestCase7(unittest.TestCase): def runTest(self): env = DummyEnvironment(LIBPATH=[ test.workpath("dir") ], LIBS=['foo', '$LIBBAR', '$XYZ'], @@ -188,12 +188,12 @@ class ProgScanTestCase7(unittest.TestCase): LIBSUFFIXES=['.a'], LIBBAR='sub/libbar', XYZ='xyz.other') - s = SCons.Scanner.Prog.ProgScan() + s = SCons.Scanner.Prog.ProgramScanner() path = s.path(env) deps = s(DummyNode('dummy'), env, path) assert deps_match(deps, ['dir/libfoo.a', 'dir/sub/libbar.a', 'dir/libxyz.other']), map(str, deps) -class ProgScanTestCase8(unittest.TestCase): +class ProgramScannerTestCase8(unittest.TestCase): def runTest(self): n1 = DummyNode('n1') @@ -201,7 +201,7 @@ class ProgScanTestCase8(unittest.TestCase): LIBS=[n1], LIBPREFIXES=['p1-', 'p2-'], LIBSUFFIXES=['.1', '2']) - s = SCons.Scanner.Prog.ProgScan(node_class = DummyNode) + s = SCons.Scanner.Prog.ProgramScanner(node_class = DummyNode) path = s.path(env) deps = s(DummyNode('dummy'), env, path) assert deps == [n1], deps @@ -211,32 +211,32 @@ class ProgScanTestCase8(unittest.TestCase): LIBS=[n1, [n2]], LIBPREFIXES=['p1-', 'p2-'], LIBSUFFIXES=['.1', '2']) - s = SCons.Scanner.Prog.ProgScan(node_class = DummyNode) + s = SCons.Scanner.Prog.ProgramScanner(node_class = DummyNode) path = s.path(env) deps = s(DummyNode('dummy'), env, path) assert deps == [n1, n2], deps def suite(): suite = unittest.TestSuite() - suite.addTest(ProgScanTestCase1()) - suite.addTest(ProgScanTestCase2()) - suite.addTest(ProgScanTestCase3()) - suite.addTest(ProgScanTestCase5()) - suite.addTest(ProgScanTestCase6()) - suite.addTest(ProgScanTestCase7()) - suite.addTest(ProgScanTestCase8()) + suite.addTest(ProgramScannerTestCase1()) + suite.addTest(ProgramScannerTestCase2()) + suite.addTest(ProgramScannerTestCase3()) + suite.addTest(ProgramScannerTestCase5()) + suite.addTest(ProgramScannerTestCase6()) + suite.addTest(ProgramScannerTestCase7()) + suite.addTest(ProgramScannerTestCase8()) if hasattr(types, 'UnicodeType'): code = """if 1: - class ProgScanTestCase4(unittest.TestCase): + class ProgramScannerTestCase4(unittest.TestCase): def runTest(self): env = DummyEnvironment(LIBPATH=[test.workpath("d1/d2"), test.workpath("d1")], LIBS=string.split(u'l2 l3')) - s = SCons.Scanner.Prog.ProgScan() + s = SCons.Scanner.Prog.ProgramScanner() path = s.path(env) deps = s(DummyNode('dummy'), env, path) assert deps_match(deps, ['d1/l2.lib', 'd1/d2/l3.lib']), map(str, deps) - suite.addTest(ProgScanTestCase4()) + suite.addTest(ProgramScannerTestCase4()) \n""" exec code return suite diff --git a/src/engine/SCons/Script/__init__.py b/src/engine/SCons/Script/__init__.py index 7368c8c8..6e27ab43 100644 --- a/src/engine/SCons/Script/__init__.py +++ b/src/engine/SCons/Script/__init__.py @@ -105,6 +105,12 @@ Mkdir = SCons.Defaults.Mkdir Move = SCons.Defaults.Move Touch = SCons.Defaults.Touch +# Pre-made, public scanners. +CScanner = SCons.Tool.CScanner +DScanner = SCons.Tool.DScanner +ProgramScanner = SCons.Tool.ProgramScanner +SourceFileScanner = SCons.Tool.SourceFileScanner + # Functions we might still convert to Environment methods. CScan = SCons.Defaults.CScan DefaultEnvironment = SCons.Defaults.DefaultEnvironment diff --git a/src/engine/SCons/Tool/__init__.py b/src/engine/SCons/Tool/__init__.py index 1cfe6eff..7ef2ea0c 100644 --- a/src/engine/SCons/Tool/__init__.py +++ b/src/engine/SCons/Tool/__init__.py @@ -42,7 +42,30 @@ import imp import sys import SCons.Errors -import SCons.Defaults +import SCons.Scanner +import SCons.Scanner.C +import SCons.Scanner.D +import SCons.Scanner.Prog + +CScanner = SCons.Scanner.C.CScanner() +DScanner = SCons.Scanner.D.DScanner() +ProgramScanner = SCons.Scanner.Prog.ProgramScanner() +SourceFileScanner = SCons.Scanner.Scanner({}, name='SourceFileScanner') + +CSuffixes = [".c", ".C", ".cxx", ".cpp", ".c++", ".cc", + ".h", ".H", ".hxx", ".hpp", ".hh", + ".F", ".fpp", ".FPP", + ".S", ".spp", ".SPP"] + +DSuffixes = ['.d'] + +IDLSuffixes = [".idl", ".IDL"] + +for suffix in CSuffixes: + SourceFileScanner.add_scanner(suffix, CScanner) + +for suffix in DSuffixes: + SourceFileScanner.add_scanner(suffix, DScanner) class ToolSpec: def __init__(self, name, **kw): @@ -116,13 +139,14 @@ def createProgBuilder(env): try: program = env['BUILDERS']['Program'] except KeyError: + import SCons.Defaults program = SCons.Builder.Builder(action = SCons.Defaults.LinkAction, emitter = '$PROGEMITTER', prefix = '$PROGPREFIX', suffix = '$PROGSUFFIX', src_suffix = '$OBJSUFFIX', src_builder = 'Object', - target_scanner = SCons.Defaults.ProgScan) + target_scanner = ProgramScanner) env['BUILDERS']['Program'] = program return program @@ -137,6 +161,7 @@ def createStaticLibBuilder(env): try: static_lib = env['BUILDERS']['StaticLibrary'] except KeyError: + import SCons.Defaults static_lib = SCons.Builder.Builder(action = SCons.Defaults.ArAction, emitter = '$LIBEMITTER', prefix = '$LIBPREFIX', @@ -158,13 +183,14 @@ def createSharedLibBuilder(env): try: shared_lib = env['BUILDERS']['SharedLibrary'] except KeyError: + import SCons.Defaults action_list = [ SCons.Defaults.SharedCheck, SCons.Defaults.ShLinkAction ] shared_lib = SCons.Builder.Builder(action = action_list, emitter = "$SHLIBEMITTER", prefix = '$SHLIBPREFIX', suffix = '$SHLIBSUFFIX', - target_scanner = SCons.Defaults.ProgScan, + target_scanner = ProgramScanner, src_suffix = '$SHOBJSUFFIX', src_builder = 'SharedObject') env['BUILDERS']['SharedLibrary'] = shared_lib @@ -181,13 +207,14 @@ def createLoadableModuleBuilder(env): try: ld_module = env['BUILDERS']['LoadableModule'] except KeyError: + import SCons.Defaults action_list = [ SCons.Defaults.SharedCheck, SCons.Defaults.LdModuleLinkAction ] ld_module = SCons.Builder.Builder(action = action_list, emitter = "$SHLIBEMITTER", prefix = '$LDMODULEPREFIX', suffix = '$LDMODULESUFFIX', - target_scanner = SCons.Defaults.ProgScan, + target_scanner = ProgramScanner, src_suffix = '$SHOBJSUFFIX', src_builder = 'SharedObject') env['BUILDERS']['LoadableModule'] = ld_module @@ -207,6 +234,7 @@ def createObjBuilders(env): The return is a 2-tuple of (StaticObject, SharedObject) """ + try: static_obj = env['BUILDERS']['StaticObject'] except KeyError: @@ -215,7 +243,8 @@ def createObjBuilders(env): prefix = '$OBJPREFIX', suffix = '$OBJSUFFIX', src_builder = ['CFile', 'CXXFile'], - source_scanner = SCons.Defaults.ObjSourceScan, single_source=1) + source_scanner = SourceFileScanner, + single_source = 1) env['BUILDERS']['StaticObject'] = static_obj env['BUILDERS']['Object'] = static_obj @@ -227,7 +256,8 @@ def createObjBuilders(env): prefix = '$SHOBJPREFIX', suffix = '$SHOBJSUFFIX', src_builder = ['CFile', 'CXXFile'], - source_scanner = SCons.Defaults.ObjSourceScan, single_source=1) + source_scanner = SourceFileScanner, + single_source = 1) env['BUILDERS']['SharedObject'] = shared_obj return (static_obj, shared_obj) diff --git a/src/engine/SCons/Tool/f77.py b/src/engine/SCons/Tool/f77.py index 5650e97b..d5acbb3c 100644 --- a/src/engine/SCons/Tool/f77.py +++ b/src/engine/SCons/Tool/f77.py @@ -53,7 +53,7 @@ else: F77Scan = SCons.Scanner.Fortran.FortranScan("F77PATH") for suffix in F77Suffixes + F77PPSuffixes: - SCons.Defaults.ObjSourceScan.add_scanner(suffix, F77Scan) + SCons.Tool.SourceFileScanner.add_scanner(suffix, F77Scan) # fVLG = fortran.VariableListGenerator diff --git a/src/engine/SCons/Tool/f90.py b/src/engine/SCons/Tool/f90.py index 9c3b0a3c..447497f6 100644 --- a/src/engine/SCons/Tool/f90.py +++ b/src/engine/SCons/Tool/f90.py @@ -53,7 +53,7 @@ else: F90Scan = SCons.Scanner.Fortran.FortranScan("F90PATH") for suffix in F90Suffixes + F90PPSuffixes: - SCons.Defaults.ObjSourceScan.add_scanner(suffix, F90Scan) + SCons.Tool.SourceFileScanner.add_scanner(suffix, F90Scan) # fVLG = fortran.VariableListGenerator diff --git a/src/engine/SCons/Tool/f95.py b/src/engine/SCons/Tool/f95.py index 2d5a0b5e..bc3ece30 100644 --- a/src/engine/SCons/Tool/f95.py +++ b/src/engine/SCons/Tool/f95.py @@ -52,7 +52,7 @@ else: F95Scan = SCons.Scanner.Fortran.FortranScan("F95PATH") for suffix in F95Suffixes + F95PPSuffixes: - SCons.Defaults.ObjSourceScan.add_scanner(suffix, F95Scan) + SCons.Tool.SourceFileScanner.add_scanner(suffix, F95Scan) # fVLG = fortran.VariableListGenerator diff --git a/src/engine/SCons/Tool/fortran.py b/src/engine/SCons/Tool/fortran.py index 770a45eb..180c8111 100644 --- a/src/engine/SCons/Tool/fortran.py +++ b/src/engine/SCons/Tool/fortran.py @@ -62,7 +62,7 @@ else: FortranScan = SCons.Scanner.Fortran.FortranScan("FORTRANPATH") for suffix in FortranSuffixes + FortranPPSuffixes: - SCons.Defaults.ObjSourceScan.add_scanner(suffix, FortranScan) + SCons.Tool.SourceFileScanner.add_scanner(suffix, FortranScan) # def _fortranEmitter(target, source, env): diff --git a/src/engine/SCons/Tool/ifl.py b/src/engine/SCons/Tool/ifl.py index 923e5ef3..b8b20124 100644 --- a/src/engine/SCons/Tool/ifl.py +++ b/src/engine/SCons/Tool/ifl.py @@ -39,7 +39,7 @@ import fortran def generate(env): """Add Builders and construction variables for ifl to an Environment.""" - SCons.Defaults.ObjSourceScan.add_scanner('.i90', fortran.FortranScan) + SCons.Tool.SourceFileScanner.add_scanner('.i90', fortran.FortranScan) fortran.FortranSuffixes.extend(['.i90']) fortran.generate(env) diff --git a/src/engine/SCons/Tool/ifort.py b/src/engine/SCons/Tool/ifort.py index 519f266c..181078af 100644 --- a/src/engine/SCons/Tool/ifort.py +++ b/src/engine/SCons/Tool/ifort.py @@ -42,8 +42,8 @@ def generate(env): """Add Builders and construction variables for ifort to an Environment.""" # ifort supports Fortran 90 and Fortran 95 # Additionally, ifort recognizes more file extensions. - SCons.Defaults.ObjSourceScan.add_scanner('.i', fortran.FortranScan) - SCons.Defaults.ObjSourceScan.add_scanner('.i90', fortran.FortranScan) + SCons.Tool.SourceFileScanner.add_scanner('.i', fortran.FortranScan) + SCons.Tool.SourceFileScanner.add_scanner('.i90', fortran.FortranScan) fortran.FortranSuffixes.extend(['.i', '.i90']) fortran.generate(env) diff --git a/src/engine/SCons/Tool/mingw.py b/src/engine/SCons/Tool/mingw.py index f1bc91ac..78cffde4 100644 --- a/src/engine/SCons/Tool/mingw.py +++ b/src/engine/SCons/Tool/mingw.py @@ -99,8 +99,8 @@ shlib_action = SCons.Action.CommandGenerator(shlib_generator) res_action = SCons.Action.Action('$RCCOM', '$RCCOMSTR') res_builder = SCons.Builder.Builder(action=res_action, suffix='.o', - source_scanner=SCons.Defaults.ObjSourceScan) -SCons.Defaults.ObjSourceScan.add_scanner('.rc', SCons.Defaults.CScan) + source_scanner=SCons.Tool.SourceFileScanner) +SCons.Tool.SourceFileScanner.add_scanner('.rc', SCons.Defaults.CScan) def generate(env): mingw = find(env) diff --git a/src/engine/SCons/Tool/msvc.py b/src/engine/SCons/Tool/msvc.py index e0ed26d3..b47f331a 100644 --- a/src/engine/SCons/Tool/msvc.py +++ b/src/engine/SCons/Tool/msvc.py @@ -400,11 +400,11 @@ def shared_object_emitter(target, source, env): pch_action = SCons.Action.Action('$PCHCOM', '$PCHCOMSTR') pch_builder = SCons.Builder.Builder(action=pch_action, suffix='.pch', emitter=pch_emitter, - source_scanner=SCons.Defaults.ObjSourceScan) + source_scanner=SCons.Tool.SourceFileScanner) res_action = SCons.Action.Action('$RCCOM', '$RCCOMSTR') res_builder = SCons.Builder.Builder(action=res_action, suffix='.res', - source_scanner=SCons.Defaults.ObjSourceScan) -SCons.Defaults.ObjSourceScan.add_scanner('.rc', SCons.Defaults.CScan) + source_scanner=SCons.Tool.SourceFileScanner) +SCons.Tool.SourceFileScanner.add_scanner('.rc', SCons.Defaults.CScan) def generate(env): """Add Builders and construction variables for MSVC++ to an Environment."""