diff options
author | Steven Knight <knight@baldmt.com> | 2005-04-02 19:50:33 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2005-04-02 19:50:33 (GMT) |
commit | 13dcf8c4ebad065d6296e7a3da24b21a1666a974 (patch) | |
tree | 6149e7e01cdfa22db3b3086c4b525526ac84fec2 /src/engine/SCons/Scanner | |
parent | c378212a5904028315760269a52272a3eb025dca (diff) | |
download | SCons-13dcf8c4ebad065d6296e7a3da24b21a1666a974.zip SCons-13dcf8c4ebad065d6296e7a3da24b21a1666a974.tar.gz SCons-13dcf8c4ebad065d6296e7a3da24b21a1666a974.tar.bz2 |
Remove widespread reliance on SCons.Node.FS.default_fs so we can initialize it once (later than we used to) and eliminate all the __setTopLevelDir() calls.
Diffstat (limited to 'src/engine/SCons/Scanner')
-rw-r--r-- | src/engine/SCons/Scanner/C.py | 5 | ||||
-rw-r--r-- | src/engine/SCons/Scanner/CTests.py | 77 | ||||
-rw-r--r-- | src/engine/SCons/Scanner/D.py | 5 | ||||
-rw-r--r-- | src/engine/SCons/Scanner/Dir.py | 12 | ||||
-rw-r--r-- | src/engine/SCons/Scanner/DirTests.py | 19 | ||||
-rw-r--r-- | src/engine/SCons/Scanner/Fortran.py | 12 | ||||
-rw-r--r-- | src/engine/SCons/Scanner/FortranTests.py | 100 | ||||
-rw-r--r-- | src/engine/SCons/Scanner/IDL.py | 5 | ||||
-rw-r--r-- | src/engine/SCons/Scanner/IDLTests.py | 85 | ||||
-rw-r--r-- | src/engine/SCons/Scanner/Prog.py | 6 | ||||
-rw-r--r-- | src/engine/SCons/Scanner/ProgTests.py | 18 | ||||
-rw-r--r-- | src/engine/SCons/Scanner/ScannerTests.py | 25 | ||||
-rw-r--r-- | src/engine/SCons/Scanner/__init__.py | 39 |
13 files changed, 222 insertions, 186 deletions
diff --git a/src/engine/SCons/Scanner/C.py b/src/engine/SCons/Scanner/C.py index 62a6842..276570e 100644 --- a/src/engine/SCons/Scanner/C.py +++ b/src/engine/SCons/Scanner/C.py @@ -32,12 +32,11 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import SCons.Node.FS import SCons.Scanner -def CScanner(fs = SCons.Node.FS.default_fs): +def CScanner(): """Return a prototype Scanner instance for scanning source files that use the C pre-processor""" cs = SCons.Scanner.ClassicCPP("CScanner", "$CPPSUFFIXES", "CPPPATH", - '^[ \t]*#[ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")', - fs = fs) + '^[ \t]*#[ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")') return cs diff --git a/src/engine/SCons/Scanner/CTests.py b/src/engine/SCons/Scanner/CTests.py index fd17ee1..138b788 100644 --- a/src/engine/SCons/Scanner/CTests.py +++ b/src/engine/SCons/Scanner/CTests.py @@ -174,6 +174,7 @@ class DummyEnvironment(UserDict.UserDict): def __init__(self, **kw): UserDict.UserDict.__init__(self) self.data.update(kw) + self.fs = SCons.Node.FS.FS(test.workpath('')) def Dictionary(self, *args): return self.data @@ -196,6 +197,15 @@ class DummyEnvironment(UserDict.UserDict): def get_calculator(self): return None + def get_factory(self, factory): + return factory or self.fs.File + + def Dir(self, filename): + return self.fs.Dir(test.workpath(filename)) + + def File(self, filename): + return self.fs.File(test.workpath(filename)) + if os.path.normcase('foo') == os.path.normcase('FOO'): my_normpath = os.path.normcase else: @@ -207,9 +217,6 @@ def deps_match(self, deps, headers): expect = map(my_normpath, headers) self.failUnless(scanned == expect, "expect %s != scanned %s" % (expect, scanned)) -def make_node(filename, fs=SCons.Node.FS.default_fs): - return fs.File(test.workpath(filename)) - # define some tests: class CScannerTestCase1(unittest.TestCase): @@ -217,36 +224,36 @@ class CScannerTestCase1(unittest.TestCase): env = DummyEnvironment(CPPPATH=[]) s = SCons.Scanner.C.CScanner() path = s.path(env) - deps = s(make_node('f1.cpp'), env, path) + deps = s(env.File('f1.cpp'), env, path) headers = ['f1.h', 'f2.h'] - deps_match(self, deps, map(test.workpath, headers)) + deps_match(self, deps, headers) class CScannerTestCase2(unittest.TestCase): def runTest(self): env = DummyEnvironment(CPPPATH=[test.workpath("d1")]) s = SCons.Scanner.C.CScanner() path = s.path(env) - deps = s(make_node('f1.cpp'), env, path) + deps = s(env.File('f1.cpp'), env, path) headers = ['f1.h', 'd1/f2.h'] - deps_match(self, deps, map(test.workpath, headers)) + deps_match(self, deps, headers) class CScannerTestCase3(unittest.TestCase): def runTest(self): env = DummyEnvironment(CPPPATH=[test.workpath("d1")]) s = SCons.Scanner.C.CScanner() path = s.path(env) - deps = s(make_node('f2.cpp'), env, path) + deps = s(env.File('f2.cpp'), env, path) headers = ['d1/f1.h', 'f1.h', 'd1/d2/f1.h'] - deps_match(self, deps, map(test.workpath, headers)) + deps_match(self, deps, headers) class CScannerTestCase4(unittest.TestCase): def runTest(self): env = DummyEnvironment(CPPPATH=[test.workpath("d1"), test.workpath("d1/d2")]) s = SCons.Scanner.C.CScanner() path = s.path(env) - deps = s(make_node('f2.cpp'), env, path) + deps = s(env.File('f2.cpp'), env, path) headers = ['d1/f1.h', 'f1.h', 'd1/d2/f1.h', 'd1/d2/f4.h'] - deps_match(self, deps, map(test.workpath, headers)) + deps_match(self, deps, headers) class CScannerTestCase5(unittest.TestCase): def runTest(self): @@ -254,7 +261,7 @@ class CScannerTestCase5(unittest.TestCase): s = SCons.Scanner.C.CScanner() path = s.path(env) - n = make_node('f3.cpp') + n = env.File('f3.cpp') def my_rexists(s=n): s.rexists_called = 1 return s.old_rexists() @@ -269,7 +276,7 @@ class CScannerTestCase5(unittest.TestCase): headers = ['f1.h', 'f2.h', 'f3-test.h', 'd1/f1.h', 'd1/f2.h', 'd1/f3-test.h'] - deps_match(self, deps, map(test.workpath, headers)) + deps_match(self, deps, headers) class CScannerTestCase6(unittest.TestCase): def runTest(self): @@ -278,25 +285,24 @@ class CScannerTestCase6(unittest.TestCase): s = SCons.Scanner.C.CScanner() path1 = s.path(env1) path2 = s.path(env2) - deps1 = s(make_node('f1.cpp'), env1, path1) - deps2 = s(make_node('f1.cpp'), env2, path2) + deps1 = s(env1.File('f1.cpp'), env1, path1) + deps2 = s(env2.File('f1.cpp'), env2, path2) headers1 = ['f1.h', 'd1/f2.h'] headers2 = ['f1.h', 'd1/d2/f2.h'] - deps_match(self, deps1, map(test.workpath, headers1)) - deps_match(self, deps2, map(test.workpath, headers2)) + deps_match(self, deps1, headers1) + deps_match(self, deps2, headers2) class CScannerTestCase8(unittest.TestCase): def runTest(self): - fs = SCons.Node.FS.FS(test.workpath('')) env = DummyEnvironment(CPPPATH=["include"]) - s = SCons.Scanner.C.CScanner(fs = fs) + s = SCons.Scanner.C.CScanner() path = s.path(env) - deps1 = s(fs.File('fa.cpp'), env, path) - fs.chdir(fs.Dir('subdir')) - dir = fs.getcwd() - fs.chdir(fs.Dir('..')) + deps1 = s(env.File('fa.cpp'), env, path) + env.fs.chdir(env.Dir('subdir')) + dir = env.fs.getcwd() + env.fs.chdir(env.Dir('')) path = s.path(env, dir) - deps2 = s(fs.File('#fa.cpp'), env, path) + deps2 = s(env.File('#fa.cpp'), env, path) headers1 = ['include/fa.h', 'include/fb.h'] headers2 = ['subdir/include/fa.h', 'subdir/include/fb.h'] deps_match(self, deps1, headers1) @@ -315,7 +321,8 @@ class CScannerTestCase9(unittest.TestCase): test.write('fa.h','\n') fs = SCons.Node.FS.FS(test.workpath('')) env = DummyEnvironment(CPPPATH=[]) - s = SCons.Scanner.C.CScanner(fs=fs) + env.fs = fs + s = SCons.Scanner.C.CScanner() path = s.path(env) deps = s(fs.File('fa.cpp'), env, path) @@ -330,7 +337,8 @@ class CScannerTestCase10(unittest.TestCase): fs = SCons.Node.FS.FS(test.workpath('')) fs.chdir(fs.Dir('include')) env = DummyEnvironment(CPPPATH=[]) - s = SCons.Scanner.C.CScanner(fs=fs) + env.fs = fs + s = SCons.Scanner.C.CScanner() path = s.path(env) test.write('include/fa.cpp', test.read('fa.cpp')) fs.chdir(fs.Dir('..')) @@ -349,10 +357,12 @@ class CScannerTestCase11(unittest.TestCase): f1=fs.File('include2/jjj.h') f1.builder=1 env = DummyEnvironment(CPPPATH=['include', 'include2']) - s = SCons.Scanner.C.CScanner(fs=fs) + env.fs = fs + s = SCons.Scanner.C.CScanner() 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' ]) + deps_match(self, deps, [ test.workpath('repository/include/iii.h'), + 'include2/jjj.h' ]) os.chdir(test.workpath('')) class CScannerTestCase12(unittest.TestCase): @@ -363,7 +373,8 @@ class CScannerTestCase12(unittest.TestCase): fs.BuildDir('build2', 'src', 0) fs.Repository(test.workpath('repository')) env = DummyEnvironment(CPPPATH=[]) - s = SCons.Scanner.C.CScanner(fs = fs) + env.fs = fs + s = SCons.Scanner.C.CScanner() path = s.path(env) deps1 = s(fs.File('build1/aaa.c'), env, path) deps_match(self, deps1, [ 'build1/bbb.h' ]) @@ -383,18 +394,18 @@ class CScannerTestCase13(unittest.TestCase): env = SubstEnvironment(CPPPATH=["blah"]) s = SCons.Scanner.C.CScanner() path = s.path(env) - deps = s(make_node('f1.cpp'), env, path) + deps = s(env.File('f1.cpp'), env, path) headers = ['f1.h', 'd1/f2.h'] - deps_match(self, deps, map(test.workpath, headers)) + deps_match(self, deps, headers) class CScannerTestCase14(unittest.TestCase): def runTest(self): env = DummyEnvironment(CPPPATH=[]) s = SCons.Scanner.C.CScanner() path = s.path(env) - deps = s(make_node('f5.c'), env, path) + deps = s(env.File('f5.c'), env, path) headers = ['f5a.h', 'f5b.h'] - deps_match(self, deps, map(test.workpath, headers)) + deps_match(self, deps, headers) class CScannerTestCase15(unittest.TestCase): def runTest(self): diff --git a/src/engine/SCons/Scanner/D.py b/src/engine/SCons/Scanner/D.py index cd93a69..2ea2614 100644 --- a/src/engine/SCons/Scanner/D.py +++ b/src/engine/SCons/Scanner/D.py @@ -36,13 +36,12 @@ import string import SCons.Scanner -def DScanner(fs = SCons.Node.FS.default_fs): +def DScanner(): """Return a prototype Scanner instance for scanning D source files""" ds = D(name = "DScanner", suffixes = '$DSUFFIXES', path_variable = 'DPATH', - regex = 'import\s+([^\;]*)\;', - fs = fs) + regex = 'import\s+([^\;]*)\;') return ds class D(SCons.Scanner.Classic): diff --git a/src/engine/SCons/Scanner/Dir.py b/src/engine/SCons/Scanner/Dir.py index 6161059..ae20749 100644 --- a/src/engine/SCons/Scanner/Dir.py +++ b/src/engine/SCons/Scanner/Dir.py @@ -28,14 +28,16 @@ import string import SCons.Node.FS import SCons.Scanner -def DirScanner(fs = SCons.Node.FS.default_fs, **kw): +def DirScanner(**kw): """Return a prototype Scanner instance for scanning directories for on-disk files""" - def only_dirs(nodes, fs=fs): - return filter(lambda n: isinstance(n.disambiguate(), SCons.Node.FS.Dir), nodes) - kw['node_factory'] = fs.Entry + def only_dirs(nodes): + return filter(lambda n: isinstance(n.disambiguate(), + SCons.Node.FS.Dir), + nodes) + kw['node_factory'] = SCons.Node.FS.Entry kw['recursive'] = only_dirs - ds = apply(SCons.Scanner.Base, [scan, "DirScanner"], kw) + ds = apply(SCons.Scanner.Base, (scan, "DirScanner"), kw) return ds skip_entry = { diff --git a/src/engine/SCons/Scanner/DirTests.py b/src/engine/SCons/Scanner/DirTests.py index e735ca2..257e76b 100644 --- a/src/engine/SCons/Scanner/DirTests.py +++ b/src/engine/SCons/Scanner/DirTests.py @@ -47,24 +47,35 @@ test.write(['dir', 'sub', '.sconsign'], "dir/.sconsign\n") test.write(['dir', 'sub', '.sconsign.dblite'], "dir/.sconsign.dblite\n") class DummyNode: - def __init__(self, name): + def __init__(self, name, fs): self.name = name self.abspath = test.workpath(name) - self.fs = SCons.Node.FS.default_fs + self.fs = fs def __str__(self): return self.name def Entry(self, name): return self.fs.Entry(name) +class DummyEnvironment: + def __init__(self): + self.fs = SCons.Node.FS.FS() + def Entry(self, name): + node = DummyNode(name, self.fs) + return node + def get_factory(self, factory): + return factory or self.fs.Entry + class DirScannerTestCase1(unittest.TestCase): def runTest(self): + env = DummyEnvironment() + s = SCons.Scanner.Dir.DirScanner() - deps = s(DummyNode('dir'), {}, ()) + deps = s(env.Entry('dir'), env, ()) sss = map(str, deps) assert sss == ['f1', 'f2', 'sub'], sss - deps = s(DummyNode('dir/sub'), {}, ()) + deps = s(env.Entry('dir/sub'), env, ()) sss = map(str, deps) assert sss == ['f3', 'f4'], sss diff --git a/src/engine/SCons/Scanner/Fortran.py b/src/engine/SCons/Scanner/Fortran.py index 4da0914..66bec0c 100644 --- a/src/engine/SCons/Scanner/Fortran.py +++ b/src/engine/SCons/Scanner/Fortran.py @@ -55,13 +55,12 @@ class F90Scanner(SCons.Scanner.Classic): """ def __init__(self, name, suffixes, path_variable, use_regex, - incl_regex, fs=SCons.Node.FS.default_fs, *args, **kw): + incl_regex, *args, **kw): self.cre_use = re.compile(use_regex, re.M) self.cre_incl = re.compile(incl_regex, re.M) - self.fs = fs - def _scan(node, env, path, self=self, fs=fs): + def _scan(node, env, path, self=self): node = node.rfile() if not node.exists(): @@ -70,7 +69,7 @@ class F90Scanner(SCons.Scanner.Classic): return self.scan(node, env, path) kw['function'] = _scan - kw['path_function'] = SCons.Scanner.FindPathDirs(path_variable, fs) + kw['path_function'] = SCons.Scanner.FindPathDirs(path_variable) kw['recursive'] = 1 kw['skeys'] = suffixes kw['name'] = name @@ -117,7 +116,7 @@ class F90Scanner(SCons.Scanner.Classic): nodes = map(lambda pair: pair[1], nodes) return nodes -def FortranScan(path_variable="FORTRANPATH", fs=SCons.Node.FS.default_fs): +def FortranScan(path_variable="FORTRANPATH"): """Return a prototype Scanner instance for scanning source files for Fortran USE & INCLUDE statements""" @@ -275,6 +274,5 @@ def FortranScan(path_variable="FORTRANPATH", fs=SCons.Node.FS.default_fs): "$FORTRANSUFFIXES", path_variable, use_regex, - include_regex, - fs = fs) + include_regex) return scanner diff --git a/src/engine/SCons/Scanner/FortranTests.py b/src/engine/SCons/Scanner/FortranTests.py index 4c82522..141f375 100644 --- a/src/engine/SCons/Scanner/FortranTests.py +++ b/src/engine/SCons/Scanner/FortranTests.py @@ -210,6 +210,7 @@ test.write(['modules', 'use.mod'], "\n") class DummyEnvironment: def __init__(self, listCppPath): self.path = listCppPath + self.fs = SCons.Node.FS.FS(test.workpath('')) def Dictionary(self, *args): if not args: @@ -244,14 +245,20 @@ class DummyEnvironment: def get_calculator(self): return None + def get_factory(self, factory): + return factory or self.fs.File + + def Dir(self, filename): + return self.fs.Dir(test.workpath(filename)) + + def File(self, filename): + return self.fs.File(test.workpath(filename)) + def deps_match(self, deps, headers): scanned = map(os.path.normpath, map(str, deps)) expect = map(os.path.normpath, headers) self.failUnless(scanned == expect, "expect %s != scanned %s" % (expect, scanned)) -def make_node(filename, fs=SCons.Node.FS.default_fs): - return fs.File(test.workpath(filename)) - # define some tests: class FortranScannerTestCase1(unittest.TestCase): @@ -261,10 +268,9 @@ class FortranScannerTestCase1(unittest.TestCase): env = DummyEnvironment([]) s = SCons.Scanner.Fortran.FortranScan() path = s.path(env) - fs = SCons.Node.FS.FS(original) - deps = s(make_node('fff1.f', fs), env, path) + deps = s(env.File('fff1.f'), env, path) headers = ['f1.f', 'f2.f'] - deps_match(self, deps, map(test.workpath, headers)) + deps_match(self, deps, headers) test.unlink('f1.f') test.unlink('f2.f') @@ -275,10 +281,9 @@ class FortranScannerTestCase2(unittest.TestCase): env = DummyEnvironment([test.workpath("d1")]) s = SCons.Scanner.Fortran.FortranScan() path = s.path(env) - fs = SCons.Node.FS.FS(original) - deps = s(make_node('fff1.f', fs), env, path) + deps = s(env.File('fff1.f'), env, path) headers = ['f1.f', 'f2.f'] - deps_match(self, deps, map(test.workpath, headers)) + deps_match(self, deps, headers) test.unlink('f1.f') test.unlink('f2.f') @@ -287,10 +292,9 @@ class FortranScannerTestCase3(unittest.TestCase): env = DummyEnvironment([test.workpath("d1")]) s = SCons.Scanner.Fortran.FortranScan() path = s.path(env) - fs = SCons.Node.FS.FS(original) - deps = s(make_node('fff1.f', fs), env, path) + deps = s(env.File('fff1.f'), env, path) headers = ['d1/f1.f', 'd1/f2.f'] - deps_match(self, deps, map(test.workpath, headers)) + deps_match(self, deps, headers) class FortranScannerTestCase4(unittest.TestCase): def runTest(self): @@ -298,10 +302,9 @@ class FortranScannerTestCase4(unittest.TestCase): env = DummyEnvironment([test.workpath("d1")]) s = SCons.Scanner.Fortran.FortranScan() path = s.path(env) - fs = SCons.Node.FS.FS(original) - deps = s(make_node('fff1.f', fs), env, path) + deps = s(env.File('fff1.f'), env, path) headers = ['d1/f1.f', 'd1/f2.f'] - deps_match(self, deps, map(test.workpath, headers)) + deps_match(self, deps, headers) test.write(['d1', 'f2.f'], "\n") class FortranScannerTestCase5(unittest.TestCase): @@ -309,10 +312,9 @@ class FortranScannerTestCase5(unittest.TestCase): env = DummyEnvironment([test.workpath("d1")]) s = SCons.Scanner.Fortran.FortranScan() path = s.path(env) - fs = SCons.Node.FS.FS(original) - deps = s(make_node('fff2.f', fs), env, path) + deps = s(env.File('fff2.f'), env, path) headers = ['d1/f2.f', 'd1/d2/f2.f', 'd1/f2.f'] - deps_match(self, deps, map(test.workpath, headers)) + deps_match(self, deps, headers) class FortranScannerTestCase6(unittest.TestCase): def runTest(self): @@ -320,10 +322,9 @@ class FortranScannerTestCase6(unittest.TestCase): env = DummyEnvironment([test.workpath("d1")]) s = SCons.Scanner.Fortran.FortranScan() path = s.path(env) - fs = SCons.Node.FS.FS(original) - deps = s(make_node('fff2.f', fs), env, path) + deps = s(env.File('fff2.f'), env, path) headers = ['d1/f2.f', 'd1/d2/f2.f', 'f2.f'] - deps_match(self, deps, map(test.workpath, headers)) + deps_match(self, deps, headers) test.unlink('f2.f') class FortranScannerTestCase7(unittest.TestCase): @@ -331,10 +332,9 @@ class FortranScannerTestCase7(unittest.TestCase): env = DummyEnvironment([test.workpath("d1/d2"), test.workpath("d1")]) s = SCons.Scanner.Fortran.FortranScan() path = s.path(env) - fs = SCons.Node.FS.FS(original) - deps = s(make_node('fff2.f', fs), env, path) + deps = s(env.File('fff2.f'), env, path) headers = ['d1/f2.f', 'd1/d2/f2.f', 'd1/d2/f2.f'] - deps_match(self, deps, map(test.workpath, headers)) + deps_match(self, deps, headers) class FortranScannerTestCase8(unittest.TestCase): def runTest(self): @@ -342,10 +342,9 @@ class FortranScannerTestCase8(unittest.TestCase): env = DummyEnvironment([test.workpath("d1/d2"), test.workpath("d1")]) s = SCons.Scanner.Fortran.FortranScan() path = s.path(env) - fs = SCons.Node.FS.FS(original) - deps = s(make_node('fff2.f', fs), env, path) + deps = s(env.File('fff2.f'), env, path) headers = ['d1/f2.f', 'd1/d2/f2.f', 'f2.f'] - deps_match(self, deps, map(test.workpath, headers)) + deps_match(self, deps, headers) test.unlink('f2.f') class FortranScannerTestCase9(unittest.TestCase): @@ -355,7 +354,7 @@ class FortranScannerTestCase9(unittest.TestCase): s = SCons.Scanner.Fortran.FortranScan() path = s.path(env) - n = make_node('fff3.f') + n = env.File('fff3.f') def my_rexists(s=n): s.rexists_called = 1 return s.old_rexists() @@ -369,21 +368,20 @@ class FortranScannerTestCase9(unittest.TestCase): assert n.rexists_called headers = ['d1/f3.f', 'f3.f'] - deps_match(self, deps, map(test.workpath, headers)) + deps_match(self, deps, headers) test.unlink('f3.f') class FortranScannerTestCase10(unittest.TestCase): def runTest(self): - fs = SCons.Node.FS.FS(test.workpath('')) env = DummyEnvironment(["include"]) - s = SCons.Scanner.Fortran.FortranScan(fs = fs) + s = SCons.Scanner.Fortran.FortranScan() path = s.path(env) - deps1 = s(fs.File('fff4.f'), env, path) - fs.chdir(fs.Dir('subdir')) - dir = fs.getcwd() - fs.chdir(fs.Dir('..')) + deps1 = s(env.File('fff4.f'), env, path) + env.fs.chdir(env.Dir('subdir')) + dir = env.fs.getcwd() + env.fs.chdir(env.Dir('')) path = s.path(env, dir) - deps2 = s(fs.File('#fff4.f'), env, path) + deps2 = s(env.File('#fff4.f'), env, path) headers1 = ['include/f4.f'] headers2 = ['subdir/include/f4.f'] deps_match(self, deps1, headers1) @@ -399,11 +397,10 @@ class FortranScannerTestCase11(unittest.TestCase): to = TestOut() to.out = None SCons.Warnings._warningOut = to - fs = SCons.Node.FS.FS(test.workpath('')) env = DummyEnvironment([]) - s = SCons.Scanner.Fortran.FortranScan(fs=fs) + s = SCons.Scanner.Fortran.FortranScan() path = s.path(env) - deps = s(fs.File('fff5.f'), env, path) + deps = s(env.File('fff5.f'), env, path) # Did we catch the warning from not finding not_there.f? assert to.out @@ -412,14 +409,13 @@ class FortranScannerTestCase11(unittest.TestCase): class FortranScannerTestCase12(unittest.TestCase): def runTest(self): - fs = SCons.Node.FS.FS(test.workpath('')) - fs.chdir(fs.Dir('include')) env = DummyEnvironment([]) - s = SCons.Scanner.Fortran.FortranScan(fs=fs) + env.fs.chdir(env.Dir('include')) + s = SCons.Scanner.Fortran.FortranScan() path = s.path(env) test.write('include/fff4.f', test.read('fff4.f')) - deps = s(fs.File('#include/fff4.f'), env, path) - fs.chdir(fs.Dir('..')) + deps = s(env.File('#include/fff4.f'), env, path) + env.fs.chdir(env.Dir('')) deps_match(self, deps, ['include/f4.f']) test.unlink('include/fff4.f') @@ -434,7 +430,8 @@ class FortranScannerTestCase13(unittest.TestCase): f1=fs.File('include2/jjj.f') f1.builder=1 env = DummyEnvironment(['include','include2']) - s = SCons.Scanner.Fortran.FortranScan(fs=fs) + env.fs = fs + s = SCons.Scanner.Fortran.FortranScan() path = s.path(env) deps = s(fs.File('src/fff.f'), env, path) deps_match(self, deps, [test.workpath('repository/include/iii.f'), 'include2/jjj.f']) @@ -448,7 +445,8 @@ class FortranScannerTestCase14(unittest.TestCase): fs.BuildDir('build2', 'src', 0) fs.Repository(test.workpath('repository')) env = DummyEnvironment([]) - s = SCons.Scanner.Fortran.FortranScan(fs = fs) + env.fs = fs + s = SCons.Scanner.Fortran.FortranScan() path = s.path(env) deps1 = s(fs.File('build1/aaa.f'), env, path) deps_match(self, deps1, [ 'build1/bbb.f' ]) @@ -469,10 +467,9 @@ class FortranScannerTestCase15(unittest.TestCase): env = SubstEnvironment(["junk"]) s = SCons.Scanner.Fortran.FortranScan() path = s.path(env) - fs = SCons.Node.FS.FS(original) - deps = s(make_node('fff1.f', fs), env, path) + deps = s(env.File('fff1.f'), env, path) headers = ['d1/f1.f', 'd1/f2.f'] - deps_match(self, deps, map(test.workpath, headers)) + deps_match(self, deps, headers) test.write(['d1', 'f2.f'], "\n") class FortranScannerTestCase16(unittest.TestCase): @@ -490,8 +487,7 @@ class FortranScannerTestCase16(unittest.TestCase): env = DummyEnvironment([test.workpath('modules')]) s = SCons.Scanner.Fortran.FortranScan() path = s.path(env) - fs = SCons.Node.FS.FS(original) - deps = s(make_node('fff90a.f90', fs), env, path) + deps = s(env.File('fff90a.f90'), env, path) headers = ['f1.f', 'f2.f', 'f3.f', 'f4.f', 'f5.f', 'f6.f', 'f7.f', 'f8.f', 'f9.f'] modules = ['mod01.mod', 'mod02.mod', 'mod03.mod', 'mod04.mod', 'mod05.mod', 'mod06.mod', 'mod07.mod', 'mod08.mod', 'mod09.mod', 'mod10.mod', @@ -499,7 +495,7 @@ class FortranScannerTestCase16(unittest.TestCase): 'mod16.mod', 'mod17.mod', 'mod18.mod', 'mod19.mod', 'mod20.mod', 'mod21.mod', 'mod22.mod', 'mod23.mod', 'mod24.mod', 'mod25.mod', 'modules/use.mod'] deps_expected = headers + modules - deps_match(self, deps, map(test.workpath, deps_expected)) + deps_match(self, deps, deps_expected) test.unlink('f1.f') test.unlink('f2.f') test.unlink('f3.f') diff --git a/src/engine/SCons/Scanner/IDL.py b/src/engine/SCons/Scanner/IDL.py index 8c4f68d..b0fd8ed 100644 --- a/src/engine/SCons/Scanner/IDL.py +++ b/src/engine/SCons/Scanner/IDL.py @@ -33,11 +33,10 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import SCons.Node.FS import SCons.Scanner -def IDLScan(fs = SCons.Node.FS.default_fs): +def IDLScan(): """Return a prototype Scanner instance for scanning IDL source files""" cs = SCons.Scanner.ClassicCPP("IDLScan", "$IDLSUFFIXES", "CPPPATH", - '^[ \t]*(?:#[ \t]*include|[ \t]*import)[ \t]+(<|")([^>"]+)(>|")', - fs = fs) + '^[ \t]*(?:#[ \t]*include|[ \t]*import)[ \t]+(<|")([^>"]+)(>|")') return cs diff --git a/src/engine/SCons/Scanner/IDLTests.py b/src/engine/SCons/Scanner/IDLTests.py index db842c3..d1a0941 100644 --- a/src/engine/SCons/Scanner/IDLTests.py +++ b/src/engine/SCons/Scanner/IDLTests.py @@ -189,6 +189,7 @@ test.write([ 'repository', 'src', 'ddd.idl'], "\n") class DummyEnvironment: def __init__(self, listCppPath): self.path = listCppPath + self.fs = SCons.Node.FS.FS(test.workpath('')) def Dictionary(self, *args): if not args: @@ -221,6 +222,15 @@ class DummyEnvironment: def get_calculator(self): return None + def get_factory(self, factory): + return factory or self.fs.File + + def Dir(self, filename): + return self.fs.Dir(test.workpath(filename)) + + def File(self, filename): + return self.fs.File(test.workpath(filename)) + global my_normpath my_normpath = os.path.normpath @@ -232,9 +242,6 @@ def deps_match(self, deps, headers): expect = map(my_normpath, headers) self.failUnless(scanned == expect, "expect %s != scanned %s" % (expect, scanned)) -def make_node(filename, fs=SCons.Node.FS.default_fs): - return fs.File(test.workpath(filename)) - # define some tests: class IDLScannerTestCase1(unittest.TestCase): @@ -242,36 +249,36 @@ class IDLScannerTestCase1(unittest.TestCase): env = DummyEnvironment([]) s = SCons.Scanner.IDL.IDLScan() path = s.path(env) - deps = s(make_node('t1.idl'), env, path) + deps = s(env.File('t1.idl'), env, path) headers = ['f1.idl', 'f3.idl', 'f2.idl'] - deps_match(self, deps, map(test.workpath, headers)) + deps_match(self, deps, headers) class IDLScannerTestCase2(unittest.TestCase): def runTest(self): env = DummyEnvironment([test.workpath("d1")]) s = SCons.Scanner.IDL.IDLScan() path = s.path(env) - deps = s(make_node('t1.idl'), env, path) + deps = s(env.File('t1.idl'), env, path) headers = ['f1.idl', 'f3.idl', 'd1/f2.idl'] - deps_match(self, deps, map(test.workpath, headers)) + deps_match(self, deps, headers) class IDLScannerTestCase3(unittest.TestCase): def runTest(self): env = DummyEnvironment([test.workpath("d1")]) s = SCons.Scanner.IDL.IDLScan() path = s.path(env) - deps = s(make_node('t2.idl'), env, path) + deps = s(env.File('t2.idl'), env, path) headers = ['d1/f1.idl', 'f1.idl', 'd1/d2/f1.idl', 'f3.idl'] - deps_match(self, deps, map(test.workpath, headers)) + deps_match(self, deps, headers) class IDLScannerTestCase4(unittest.TestCase): def runTest(self): env = DummyEnvironment([test.workpath("d1"), test.workpath("d1/d2")]) s = SCons.Scanner.IDL.IDLScan() path = s.path(env) - deps = s(make_node('t2.idl'), env, path) + deps = s(env.File('t2.idl'), env, path) headers = ['d1/f1.idl', 'f1.idl', 'd1/d2/f1.idl', 'f3.idl'] - deps_match(self, deps, map(test.workpath, headers)) + deps_match(self, deps, headers) class IDLScannerTestCase5(unittest.TestCase): def runTest(self): @@ -279,7 +286,7 @@ class IDLScannerTestCase5(unittest.TestCase): s = SCons.Scanner.IDL.IDLScan() path = s.path(env) - n = make_node('t3.idl') + n = env.File('t3.idl') def my_rexists(s=n): s.rexists_called = 1 return s.old_rexists() @@ -295,7 +302,7 @@ class IDLScannerTestCase5(unittest.TestCase): headers = ['d1/f1.idl', 'd1/f2.idl', 'f1.idl', 'f2.idl', 'f3-test.idl', 'd1/f1.idl', 'd1/f2.idl', 'd1/f3-test.idl'] - deps_match(self, deps, map(test.workpath, headers)) + deps_match(self, deps, headers) class IDLScannerTestCase6(unittest.TestCase): def runTest(self): @@ -304,25 +311,24 @@ class IDLScannerTestCase6(unittest.TestCase): s = SCons.Scanner.IDL.IDLScan() path1 = s.path(env1) path2 = s.path(env2) - deps1 = s(make_node('t1.idl'), env1, path1) - deps2 = s(make_node('t1.idl'), env2, path2) + deps1 = s(env1.File('t1.idl'), env1, path1) + deps2 = s(env2.File('t1.idl'), env2, path2) headers1 = ['f1.idl', 'f3.idl', 'd1/f2.idl'] headers2 = ['f1.idl', 'f3.idl', 'd1/d2/f2.idl'] - deps_match(self, deps1, map(test.workpath, headers1)) - deps_match(self, deps2, map(test.workpath, headers2)) + deps_match(self, deps1, headers1) + deps_match(self, deps2, headers2) class IDLScannerTestCase7(unittest.TestCase): def runTest(self): - fs = SCons.Node.FS.FS(test.workpath('')) env = DummyEnvironment(["include"]) - s = SCons.Scanner.IDL.IDLScan(fs = fs) + s = SCons.Scanner.IDL.IDLScan() path = s.path(env) - deps1 = s(fs.File('t4.idl'), env, path) - fs.chdir(fs.Dir('subdir')) - dir = fs.getcwd() - fs.chdir(fs.Dir('..')) + deps1 = s(env.File('t4.idl'), env, path) + env.fs.chdir(env.Dir('subdir')) + dir = env.fs.getcwd() + env.fs.chdir(env.Dir('')) path = s.path(env, dir) - deps2 = s(fs.File('#t4.idl'), env, path) + deps2 = s(env.File('#t4.idl'), env, path) headers1 = ['include/fa.idl', 'include/fb.idl'] headers2 = ['subdir/include/fa.idl', 'subdir/include/fb.idl'] deps_match(self, deps1, headers1) @@ -339,11 +345,10 @@ class IDLScannerTestCase8(unittest.TestCase): to.out = None SCons.Warnings._warningOut = to test.write('fa.idl','\n') - fs = SCons.Node.FS.FS(test.workpath('')) env = DummyEnvironment([]) - s = SCons.Scanner.IDL.IDLScan(fs=fs) + s = SCons.Scanner.IDL.IDLScan() path = s.path(env) - deps = s(fs.File('t4.idl'), env, path) + deps = s(env.File('t4.idl'), env, path) # Did we catch the warning associated with not finding fb.idl? assert to.out @@ -353,14 +358,13 @@ class IDLScannerTestCase8(unittest.TestCase): class IDLScannerTestCase9(unittest.TestCase): def runTest(self): - fs = SCons.Node.FS.FS(test.workpath('')) - fs.chdir(fs.Dir('include')) env = DummyEnvironment([]) - s = SCons.Scanner.IDL.IDLScan(fs=fs) + env.fs.chdir(env.Dir('include')) + s = SCons.Scanner.IDL.IDLScan() path = s.path(env) test.write('include/t4.idl', test.read('t4.idl')) - deps = s(fs.File('#include/t4.idl'), env, path) - fs.chdir(fs.Dir('..')) + deps = s(env.File('#include/t4.idl'), env, path) + env.fs.chdir(env.Dir('')) deps_match(self, deps, [ 'include/fa.idl', 'include/fb.idl' ]) test.unlink('include/t4.idl') @@ -372,13 +376,15 @@ class IDLScannerTestCase10(unittest.TestCase): # Create a derived file in a directory that does not exist yet. # This was a bug at one time. - f1=fs.File('include2/jjj.idl') - f1.builder=1 env = DummyEnvironment(['include', 'include2']) - s = SCons.Scanner.IDL.IDLScan(fs=fs) + env.fs = fs + f1 = fs.File('include2/jjj.idl') + f1.builder = 1 + s = SCons.Scanner.IDL.IDLScan() path = s.path(env) deps = s(fs.File('src/fff.c'), env, path) - deps_match(self, deps, [ test.workpath('repository/include/iii.idl'), 'include2/jjj.idl' ]) + deps_match(self, deps, [ test.workpath('repository/include/iii.idl'), + 'include2/jjj.idl' ]) os.chdir(test.workpath('')) class IDLScannerTestCase11(unittest.TestCase): @@ -389,7 +395,8 @@ class IDLScannerTestCase11(unittest.TestCase): fs.BuildDir('build2', 'src', 0) fs.Repository(test.workpath('repository')) env = DummyEnvironment([]) - s = SCons.Scanner.IDL.IDLScan(fs = fs) + env.fs = fs + s = SCons.Scanner.IDL.IDLScan() path = s.path(env) deps1 = s(fs.File('build1/aaa.c'), env, path) deps_match(self, deps1, [ 'build1/bbb.idl' ]) @@ -409,9 +416,9 @@ class IDLScannerTestCase12(unittest.TestCase): env = SubstEnvironment(["blah"]) s = SCons.Scanner.IDL.IDLScan() path = s.path(env) - deps = s(make_node('t1.idl'), env, path) + deps = s(env.File('t1.idl'), env, path) headers = ['f1.idl', 'f3.idl', 'd1/f2.idl'] - deps_match(self, deps, map(test.workpath, headers)) + deps_match(self, deps, headers) def suite(): diff --git a/src/engine/SCons/Scanner/Prog.py b/src/engine/SCons/Scanner/Prog.py index 206c6de..54db9a8 100644 --- a/src/engine/SCons/Scanner/Prog.py +++ b/src/engine/SCons/Scanner/Prog.py @@ -33,14 +33,14 @@ import SCons.Util # global, set by --debug=findlibs print_find_libs = None -def ProgramScanner(fs = SCons.Node.FS.default_fs, **kw): +def ProgramScanner(**kw): """Return a prototype Scanner instance for scanning executable files for static-lib dependencies""" - kw['path_function'] = SCons.Scanner.FindPathDirs('LIBPATH', fs) + kw['path_function'] = SCons.Scanner.FindPathDirs('LIBPATH') ps = apply(SCons.Scanner.Base, [scan, "ProgramScanner"], kw) return ps -def scan(node, env, libpath = (), fs = SCons.Node.FS.default_fs): +def scan(node, env, libpath = ()): """ This scanner scans program files for static-library dependencies. It will search the LIBPATH environment variable diff --git a/src/engine/SCons/Scanner/ProgTests.py b/src/engine/SCons/Scanner/ProgTests.py index ec25f24..bac10b7 100644 --- a/src/engine/SCons/Scanner/ProgTests.py +++ b/src/engine/SCons/Scanner/ProgTests.py @@ -49,6 +49,7 @@ class DummyEnvironment: def __init__(self, **kw): self._dict = {'LIBSUFFIXES' : '.lib'} self._dict.update(kw) + self.fs = SCons.Node.FS.FS(test.workpath('')) def Dictionary(self, *args): if not args: @@ -83,6 +84,15 @@ class DummyEnvironment: path = [path] return map(self.subst, path) + def get_factory(self, factory): + return factory or self.fs.File + + def Dir(self, filename): + return self.fs.Dir(test.workpath(filename)) + + def File(self, filename): + return self.fs.File(test.workpath(filename)) + class DummyNode: def __init__(self, name): self.name = name @@ -95,9 +105,7 @@ def deps_match(deps, libs): deps=map(str, deps) deps.sort() libs.sort() - return map(os.path.normpath, deps) == \ - map(os.path.normpath, - map(test.workpath, libs)) + return map(os.path.normpath, deps) == map(os.path.normpath, libs) # define some tests: @@ -117,7 +125,7 @@ class ProgramScannerTestCase1(unittest.TestCase): deps = s(DummyNode('dummy'), env, path) assert deps_match(deps, ['l1.lib']), map(str, deps) - f1 = SCons.Node.FS.default_fs.File(test.workpath('f1')) + f1 = env.fs.File(test.workpath('f1')) env = DummyEnvironment(LIBPATH=[ test.workpath("") ], LIBS=[f1]) s = SCons.Scanner.Prog.ProgramScanner() @@ -125,7 +133,7 @@ class ProgramScannerTestCase1(unittest.TestCase): deps = s(DummyNode('dummy'), env, path) assert deps[0] is f1, deps - f2 = SCons.Node.FS.default_fs.File(test.workpath('f1')) + f2 = env.fs.File(test.workpath('f1')) env = DummyEnvironment(LIBPATH=[ test.workpath("") ], LIBS=f2) s = SCons.Scanner.Prog.ProgramScanner() diff --git a/src/engine/SCons/Scanner/ScannerTests.py b/src/engine/SCons/Scanner/ScannerTests.py index ef836bc..0d0ccec 100644 --- a/src/engine/SCons/Scanner/ScannerTests.py +++ b/src/engine/SCons/Scanner/ScannerTests.py @@ -30,10 +30,19 @@ import SCons.Sig import SCons.Scanner +class DummyFS: + def __init__(self, search_result=[]): + self.search_result = search_result + def File(self, name): + return DummyNode(name) + def Rsearchall(self, nodes, must_exist=0, clazz=None, cwd=dir): + return self.search_result + nodes + class DummyEnvironment(UserDict.UserDict): def __init__(self, dict=None, **kw): UserDict.UserDict.__init__(self, dict) self.data.update(kw) + self.fs = DummyFS() def subst(self, strSubst): if strSubst[0] == '$': return self.data[strSubst[1:]] @@ -48,6 +57,8 @@ class DummyEnvironment(UserDict.UserDict): return map(self.subst, path) def get_calculator(self): return SCons.Sig.default_calc + def get_factory(self, factory): + return factory or self.fs.File class DummyNode: def __init__(self, name): @@ -56,18 +67,15 @@ class DummyNode: return 1 def __str__(self): return self.name - + class FindPathDirsTestCase(unittest.TestCase): def test_FindPathDirs(self): """Test the FindPathDirs callable class""" - class FS: - def Rsearchall(self, nodes, must_exist=0, clazz=None, cwd=dir): - return ['xxx'] + nodes - env = DummyEnvironment(LIBPATH = [ 'foo' ]) + env.fs = DummyFS(['xxx']) - fpd = SCons.Scanner.FindPathDirs('LIBPATH', FS()) + fpd = SCons.Scanner.FindPathDirs('LIBPATH') result = fpd(env, dir) assert str(result) == "('xxx', 'foo')", result @@ -308,11 +316,12 @@ class SelectorTestCase(unittest.TestCase): s2 = SCons.Scanner.Base(s2func) selector = SCons.Scanner.Selector({'.x' : s1, '.y' : s2}) nx = self.skey_node('.x') - selector(nx, None, []) + env = DummyEnvironment() + selector(nx, env, []) assert called == ['s1func', nx], called del called[:] ny = self.skey_node('.y') - selector(ny, None, []) + selector(ny, env, []) assert called == ['s2func', ny], called def test_select(self): diff --git a/src/engine/SCons/Scanner/__init__.py b/src/engine/SCons/Scanner/__init__.py index 247eafb..504b6df 100644 --- a/src/engine/SCons/Scanner/__init__.py +++ b/src/engine/SCons/Scanner/__init__.py @@ -75,11 +75,10 @@ def Binder(path): class FindPathDirs: - """A class to bind a specific *PATH variable name and the fs object - to a function that will return all of the *path directories.""" - def __init__(self, variable, fs): + """A class to bind a specific *PATH variable name to a function that + will return all of the *path directories.""" + def __init__(self, variable): self.variable = variable - self.fs = fs def __call__(self, env, dir, target=None, source=None, argument=None): # The goal is that we've made caching this unnecessary # because the caching takes place at higher layers. @@ -89,10 +88,10 @@ class FindPathDirs: return () path = env.subst_path(path, target=target, source=source) - path_tuple = tuple(self.fs.Rsearchall(path, - must_exist = 0, #kwq! - clazz = SCons.Node.FS.Dir, - cwd = dir)) + path_tuple = tuple(env.fs.Rsearchall(path, + must_exist = 0, #kwq! + clazz = SCons.Node.FS.Dir, + cwd = dir)) return Binder(path_tuple) class Base: @@ -110,7 +109,7 @@ class Base: skeys = [], path_function = None, node_class = SCons.Node.FS.Entry, - node_factory = SCons.Node.FS.default_fs.File, + node_factory = None, scan_check = None, recursive = None): """ @@ -155,13 +154,12 @@ class Base: (the canonical example being only recursively scanning subdirectories within a directory). - The scanner function's first argument will be the a Node that - should be scanned for dependencies, the second argument will - be an Environment object, the third argument will be the tuple - of paths returned by the path_function, and the fourth - argument will be the value passed into 'argument', and the - returned list should contain the Nodes for all the direct - dependencies of the file. + The scanner function's first argument will be a Node that should + be scanned for dependencies, the second argument will be an + Environment object, the third argument will be the tuple of paths + returned by the path_function, and the fourth argument will be + the value passed into 'argument', and the returned list should + contain the Nodes for all the direct dependencies of the file. Examples: @@ -218,10 +216,11 @@ class Base: kw = {} if hasattr(node, 'dir'): kw['directory'] = node.dir + node_factory = env.get_factory(self.node_factory) nodes = [] for l in list: if self.node_class and not isinstance(l, self.node_class): - l = apply(self.node_factory, (l,), kw) + l = apply(node_factory, (l,), kw) nodes.append(l) return nodes @@ -315,11 +314,9 @@ class Classic(Current): include file in group 0. """ - def __init__(self, name, suffixes, path_variable, regex, - fs=SCons.Node.FS.default_fs, *args, **kw): + def __init__(self, name, suffixes, path_variable, regex, *args, **kw): self.cre = re.compile(regex, re.M) - self.fs = fs def _scan(node, env, path=(), self=self): node = node.rfile() @@ -328,7 +325,7 @@ class Classic(Current): return self.scan(node, path) kw['function'] = _scan - kw['path_function'] = FindPathDirs(path_variable, fs) + kw['path_function'] = FindPathDirs(path_variable) kw['recursive'] = 1 kw['skeys'] = suffixes kw['name'] = name |