From: stevenknight Date: Thu, 8 Aug 2002 18:22:55 +0000 (+0000) Subject: Refactor the interface between Rsearch() and Rsearchall() and their supplied function... X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=c366ce19bc22babfa9b9b812b3a0a7bcf8cdc2e8;p=scons.git Refactor the interface between Rsearch() and Rsearchall() and their supplied functions' arguments to keep the repository and dir path portions separate. git-svn-id: http://scons.tigris.org/svn/scons/trunk@435 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index fea60c3f..4a86ae60 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -489,7 +489,9 @@ class DirVarInterp(VarInterpolator): def prepareSrc(self, dict): src = VarInterpolator.prepareSrc(self, dict) - def path_dirs(path, fs = self.fs, dir = self.dir): + def path_dirs(rep, path, fs=self.fs, dir=self.dir): + if rep: + path = os.path.join(rep, path) return fs.Dir(path, directory = dir) return self.fs.Rsearchall(src, path_dirs) diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py index d438cd04..1c90ea8f 100644 --- a/src/engine/SCons/Node/FS.py +++ b/src/engine/SCons/Node/FS.py @@ -84,9 +84,11 @@ else: return string.upper(x) -def exists_path(path): +def exists_path(rep, path): """Return a path if it's already a Node or it exists in the real filesystem.""" + if rep: + path = os.path.join(rep, path) if os.path.exists(path): return path return None @@ -317,11 +319,11 @@ class FS: if isinstance(path, SCons.Node.Node): return path else: - n = func(path) + n = func(None, path) if n: return n for dir in self.Repositories: - n = func(os.path.join(dir.path, path)) + n = func(dir.path, path) if n: return n return None @@ -337,14 +339,14 @@ class FS: if isinstance(path, SCons.Node.Node): ret.append(path) else: - n = func(path) + n = func(None, path) if n: ret.append(n) if not os.path.isabs(path): if path[0] == '#': path = path[1:] for dir in self.Repositories: - n = func(os.path.join(dir.path, path)) + n = func(dir.path, path) if n: ret.append(n) return ret @@ -778,7 +780,9 @@ class File(Entry): if not hasattr(self, '_rfile'): self._rfile = self if not os.path.isabs(self.path) and not os.path.isfile(self.path): - def file_node(path, fs = self.fs): + def file_node(dir, path, fs=self.fs): + if dir: + path = os.path.join(dir, path) if os.path.isfile(path): return fs.File(path) return None diff --git a/src/engine/SCons/Node/FSTests.py b/src/engine/SCons/Node/FSTests.py index b45cc4ba..5945f3f8 100644 --- a/src/engine/SCons/Node/FSTests.py +++ b/src/engine/SCons/Node/FSTests.py @@ -597,9 +597,14 @@ class RepositoryTestCase(unittest.TestCase): assert fs.Rsearch('f2') assert fs.Rsearch(f3) is f3 - assert not fs.Rsearch('f1', os.path.exists) - assert fs.Rsearch('f2', os.path.exists) - assert fs.Rsearch('f3', os.path.exists) + def my_exists(rep, path): + if rep: + path = os.path.join(rep, path) + return os.path.exists(path) + + assert not fs.Rsearch('f1', my_exists) + assert fs.Rsearch('f2', my_exists) + assert fs.Rsearch('f3', my_exists) list = fs.Rsearchall(fs.Dir('d1')) assert len(list) == 1, list diff --git a/src/engine/SCons/Scanner/C.py b/src/engine/SCons/Scanner/C.py index f388b630..f8715512 100644 --- a/src/engine/SCons/Scanner/C.py +++ b/src/engine/SCons/Scanner/C.py @@ -79,7 +79,10 @@ def scan(node, env, target, fs = SCons.Node.FS.default_fs): # node.includes - the result of include_re.findall() if not hasattr(target, 'cpppath'): - def Dir(x, dir=target.cwd, fs=fs): return fs.Dir(x,dir) + def Dir(rep, path, dir=target.cwd, fs=fs): + if rep: + path = os.path.join(rep, path) + return fs.Dir(path, dir) try: target.cpppath = tuple(fs.Rsearchall(env['CPPPATH'], Dir)) except KeyError: diff --git a/src/engine/SCons/Scanner/Fortran.py b/src/engine/SCons/Scanner/Fortran.py index e87b885d..954510ac 100644 --- a/src/engine/SCons/Scanner/Fortran.py +++ b/src/engine/SCons/Scanner/Fortran.py @@ -77,7 +77,10 @@ def scan(node, env, target, fs = SCons.Node.FS.default_fs): # node.includes - the result of include_re.findall() if not hasattr(target, 'f77path'): - def Dir(x, dir=target.cwd, fs=fs): return fs.Dir(x,dir) + def Dir(rep, path, dir=target.cwd, fs=fs): + if rep: + path = os.path.join(rep, path) + return fs.Dir(path, dir) try: target.f77path = tuple(fs.Rsearchall(env['F77PATH'], Dir)) except KeyError: