diff options
| author | Steven Knight <knight@baldmt.com> | 2004-03-03 14:45:54 (GMT) |
|---|---|---|
| committer | Steven Knight <knight@baldmt.com> | 2004-03-03 14:45:54 (GMT) |
| commit | c6a5a383c8771988bc829ef90111afc4db03cc5f (patch) | |
| tree | f9f67f13e16ad2362292ac0c93a48ebdce7f7ab7 /src/engine/SCons/Scanner | |
| parent | 5174a3776049049f08a4812da16dfe03ede94a9e (diff) | |
| download | SCons-c6a5a383c8771988bc829ef90111afc4db03cc5f.zip SCons-c6a5a383c8771988bc829ef90111afc4db03cc5f.tar.gz SCons-c6a5a383c8771988bc829ef90111afc4db03cc5f.tar.bz2 | |
Refactor Scanner internals as a prelude to fixing use of '${TARGET.dir}'
in *PATH variables.
Diffstat (limited to 'src/engine/SCons/Scanner')
| -rw-r--r-- | src/engine/SCons/Scanner/Prog.py | 12 | ||||
| -rw-r--r-- | src/engine/SCons/Scanner/ScannerTests.py | 27 | ||||
| -rw-r--r-- | src/engine/SCons/Scanner/__init__.py | 36 |
3 files changed, 52 insertions, 23 deletions
diff --git a/src/engine/SCons/Scanner/Prog.py b/src/engine/SCons/Scanner/Prog.py index 5b3c935..0100b3d 100644 --- a/src/engine/SCons/Scanner/Prog.py +++ b/src/engine/SCons/Scanner/Prog.py @@ -33,18 +33,10 @@ import SCons.Util def ProgScan(fs = SCons.Node.FS.default_fs): """Return a prototype Scanner instance for scanning executable files for static-lib dependencies""" - ps = SCons.Scanner.Base(scan, "ProgScan", fs, path_function = path) + pf = SCons.Scanner.FindPathDirs('LIBPATH', fs) + ps = SCons.Scanner.Base(scan, "ProgScan", path_function = pf) return ps -def path(env, dir, fs = SCons.Node.FS.default_fs): - try: - libpath = env['LIBPATH'] - except KeyError: - return () - return tuple(fs.Rsearchall(SCons.Util.mapPaths(libpath, dir, env), - clazz = SCons.Node.FS.Dir, - must_exist = 0)) - def scan(node, env, libpath = (), fs = SCons.Node.FS.default_fs): """ This scanner scans program files for static-library diff --git a/src/engine/SCons/Scanner/ScannerTests.py b/src/engine/SCons/Scanner/ScannerTests.py index 8c8744d..3d72bd2 100644 --- a/src/engine/SCons/Scanner/ScannerTests.py +++ b/src/engine/SCons/Scanner/ScannerTests.py @@ -23,12 +23,32 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" +import sys import unittest +import UserDict + import SCons.Scanner -import sys -class DummyEnvironment: - pass +class DummyEnvironment(UserDict.UserDict): + def __init__(self, dict=None, **kw): + UserDict.UserDict.__init__(self, dict) + self.data.update(kw) + def subst(self, strSubst): + return strSubst + +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' ]) + + fpd = SCons.Scanner.FindPathDirs('LIBPATH', FS()) + result = fpd(env, dir) + assert result == ('xxx', 'foo'), result class ScannerTestCase(unittest.TestCase): @@ -297,6 +317,7 @@ class ClassicCPPTestCase(unittest.TestCase): def suite(): suite = unittest.TestSuite() tclasses = [ + FindPathDirsTestCase, ScannerTestCase, CurrentTestCase, ClassicTestCase, diff --git a/src/engine/SCons/Scanner/__init__.py b/src/engine/SCons/Scanner/__init__.py index 2146ebe..4bf8b6c 100644 --- a/src/engine/SCons/Scanner/__init__.py +++ b/src/engine/SCons/Scanner/__init__.py @@ -43,6 +43,31 @@ class _Null: # used as an actual argument value. _null = _Null +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): + self.variable = variable + self.fs = fs + def __call__(self, env, dir, argument=None): + try: + path = env[self.variable] + except KeyError: + return () + + if not SCons.Util.is_List(path): + path = [path] + r = [] + for p in path: + if SCons.Util.is_String(p): + p = env.subst(p) + r.append(p) + + return tuple(self.fs.Rsearchall(r, + must_exist = 0, + clazz = SCons.Node.FS.Dir, + cwd = dir)) + class Base: """ The base class for dependency scanners. This implements @@ -200,20 +225,11 @@ class Classic(Current): self.cre = re.compile(regex, re.M) self.fs = fs - def _path(env, dir, pv=path_variable, fs=fs): - try: - path = env[pv] - except KeyError: - return () - return tuple(fs.Rsearchall(SCons.Util.mapPaths(path, dir, env), - clazz = SCons.Node.FS.Dir, - must_exist = 0)) - def _scan(node, env, path, self=self, fs=fs): return self.scan(node, env, path) kw['function'] = _scan - kw['path_function'] = _path + kw['path_function'] = FindPathDirs(path_variable, fs) kw['recursive'] = 1 kw['skeys'] = suffixes |
