diff options
| author | Steven Knight <knight@baldmt.com> | 2005-03-01 20:58:36 (GMT) |
|---|---|---|
| committer | Steven Knight <knight@baldmt.com> | 2005-03-01 20:58:36 (GMT) |
| commit | 101ccb287767fbe9509726a4af66f46d4caf2ea9 (patch) | |
| tree | 3640dcfc6a60d84b7bec0b1283cf4b074190766b /src/engine/SCons/Node | |
| parent | fe606cd36331a41959d57fa41f7e8fe139f31f3f (diff) | |
| download | SCons-101ccb287767fbe9509726a4af66f46d4caf2ea9.zip SCons-101ccb287767fbe9509726a4af66f46d4caf2ea9.tar.gz SCons-101ccb287767fbe9509726a4af66f46d4caf2ea9.tar.bz2 | |
Checkpoint refactoring of the find_file() interface.
Diffstat (limited to 'src/engine/SCons/Node')
| -rw-r--r-- | src/engine/SCons/Node/FS.py | 73 | ||||
| -rw-r--r-- | src/engine/SCons/Node/FSTests.py | 16 |
2 files changed, 42 insertions, 47 deletions
diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py index d15043c..52f19f5 100644 --- a/src/engine/SCons/Node/FS.py +++ b/src/engine/SCons/Node/FS.py @@ -999,15 +999,11 @@ class FS(LocalFS): self.__setTopLevelDir() self.Top.addRepository(d) - def do_Rsearch(self, path, func, clazz=_classEntry, cwd=None, verbose=lambda x: x): + def do_Rsearch(self, path, dir, func, clazz=_classEntry): """Search for something in a Repository. Returns the first one found in the list, or None if there isn't one. __cacheable__ """ - if isinstance(path, SCons.Node.Node): - return path - - path, dir = self.__transformPath(path, cwd) d, name = os.path.split(path) norm_name = _my_normcase(name) if d: @@ -1021,8 +1017,7 @@ class FS(LocalFS): if node: dir = node.get_dir() if node: - verbose("... FOUND '%s' in '%s'\n" % (name, dir)) - return node + return node, dir fname = '.' while dir: for rep in dir.getRepositories(): @@ -1034,19 +1029,21 @@ class FS(LocalFS): else: node = func(node) if node: - verbose("... FOUND '%s' in '%s'\n" % (name, dir)) - return node + return node, dir fname = dir.name + os.sep + fname dir = dir.get_dir() - return None + return None, None def Rsearch(self, path, clazz=_classEntry, cwd=None): + if isinstance(path, SCons.Node.Node): + return path def func(node): if node.exists() and \ (isinstance(node, Dir) or not node.is_derived()): return node return None - return self.do_Rsearch(path, func, clazz, cwd) + path, dir = self.__transformPath(path, cwd) + return self.do_Rsearch(path, dir, func, clazz)[0] def Rsearchall(self, pathlist, must_exist=1, clazz=_classEntry, cwd=None): """Search for a list of somethings in the Repository list. @@ -1848,7 +1845,7 @@ class File(Base): default_fs = FS() -def find_file(filename, paths, node_factory=default_fs.File, verbose=None): +def find_file(filename, paths, verbose=None): """ find_file(str, [Dir()]) -> [nodes] @@ -1874,36 +1871,35 @@ def find_file(filename, paths, node_factory=default_fs.File, verbose=None): else: verbose = lambda x: x - filedir, filename = os.path.split(filename) - if filedir: - lookup_dir = lambda d, fd=filedir: d.Dir(fd) - else: - lookup_dir = lambda d: d - if callable(paths): paths = paths() # Give Entries a chance to morph into Dirs. paths = map(lambda p: p.must_be_a_Dir(), paths) - for pathdir in paths: - verbose("looking for '%s' in '%s' ...\n" % (filename, pathdir)) - - try: dir = lookup_dir(pathdir) - except TypeError: dir = None - if not dir: - # We tried to look up a directory, but it seems there's - # already a file node (or something else) there. No big. - continue + filedir, filename = os.path.split(filename) + if filedir: + def filedir_lookup(p, fd=filedir): + try: + return p.Dir(fd) + except TypeError: + # We tried to look up a Dir, but it seems there's already + # a File (or something else) there. No big. + return None + paths = filter(None, map(filedir_lookup, paths)) + + def func(node): + if isinstance(node, SCons.Node.FS.File) and \ + (node.is_derived() or node.is_pseudo_derived() or node.exists()): + return node + return None - def func(node): - if isinstance(node, SCons.Node.FS.File) and \ - (node.is_derived() or node.is_pseudo_derived() or node.exists()): - return node - return None + for dir in paths: + verbose("looking for '%s' in '%s' ...\n" % (filename, dir)) - node = default_fs.do_Rsearch(filename, func, File, dir, verbose) + node, d = default_fs.do_Rsearch(filename, dir, func, File) if node: + verbose("... FOUND '%s' in '%s'\n" % (filename, d)) return node dirname = '.' @@ -1915,15 +1911,16 @@ def find_file(filename, paths, node_factory=default_fs.File, verbose=None): # build_dir is probably under src_dir, in which case # we are reflecting. break - node = dir.fs.do_Rsearch(filename, func, File, d, verbose) + node, d = dir.fs.do_Rsearch(filename, d, func, File) if node: + verbose("... FOUND '%s' in '%s'\n" % (filename, d)) return File(filename, dir.Dir(dirname), dir.fs) dirname = dir.name + os.sep + dirname dir = dir.get_dir() return None -def find_files(filenames, paths, node_factory = default_fs.File): +def find_files(filenames, paths): """ find_files([str], [Dir()]) -> [nodes] @@ -1938,7 +1935,5 @@ def find_files(filenames, paths, node_factory = default_fs.File): Only the first file found is returned for each filename, and any files that aren't found are ignored. """ - nodes = map(lambda x, paths=paths, node_factory=node_factory: - find_file(x, paths, node_factory), - filenames) - return filter(lambda x: x != None, nodes) + nodes = map(lambda x, paths=paths: find_file(x, paths), filenames) + return filter(None, nodes) diff --git a/src/engine/SCons/Node/FSTests.py b/src/engine/SCons/Node/FSTests.py index f841d32..c3f87bc 100644 --- a/src/engine/SCons/Node/FSTests.py +++ b/src/engine/SCons/Node/FSTests.py @@ -1443,10 +1443,10 @@ class find_fileTestCase(unittest.TestCase): node_pseudo.set_src_builder(1) # Any non-zero value. paths = map(fs.Dir, ['.', 'same', './bar']) - nodes = [SCons.Node.FS.find_file('foo', paths, fs.File)] - nodes.append(SCons.Node.FS.find_file('baz', paths, fs.File)) - nodes.append(SCons.Node.FS.find_file('pseudo', paths, fs.File)) - nodes.append(SCons.Node.FS.find_file('same', paths, fs.File)) + nodes = [SCons.Node.FS.find_file('foo', paths)] + nodes.append(SCons.Node.FS.find_file('baz', paths)) + nodes.append(SCons.Node.FS.find_file('pseudo', paths)) + nodes.append(SCons.Node.FS.find_file('same', paths)) file_names = map(str, nodes) file_names = map(os.path.normpath, file_names) @@ -1458,7 +1458,7 @@ class find_fileTestCase(unittest.TestCase): # of a directory that we'd otherwise try to search. If this # is broken, we'll see an exception like "Tried to lookup File # 'bar/baz' as a Dir. - SCons.Node.FS.find_file('baz/no_file_here', paths, fs.File) + SCons.Node.FS.find_file('baz/no_file_here', paths) import StringIO save_sys_stdout = sys.stdout @@ -1466,7 +1466,7 @@ class find_fileTestCase(unittest.TestCase): try: sio = StringIO.StringIO() sys.stdout = sio - SCons.Node.FS.find_file('foo', paths, fs.File, verbose="xyz") + SCons.Node.FS.find_file('foo', paths, verbose="xyz") expect = " xyz: looking for 'foo' in '.' ...\n" + \ " xyz: ... FOUND 'foo' in '.'\n" c = sio.getvalue() @@ -1474,7 +1474,7 @@ class find_fileTestCase(unittest.TestCase): sio = StringIO.StringIO() sys.stdout = sio - SCons.Node.FS.find_file('baz', paths, fs.File, verbose=1) + SCons.Node.FS.find_file('baz', paths, verbose=1) expect = " find_file: looking for 'baz' in '.' ...\n" + \ " find_file: looking for 'baz' in 'same' ...\n" + \ " find_file: looking for 'baz' in 'bar' ...\n" + \ @@ -1484,7 +1484,7 @@ class find_fileTestCase(unittest.TestCase): sio = StringIO.StringIO() sys.stdout = sio - SCons.Node.FS.find_file('on_disk', paths, fs.File, verbose=1) + SCons.Node.FS.find_file('on_disk', paths, verbose=1) expect = " find_file: looking for 'on_disk' in '.' ...\n" + \ " find_file: looking for 'on_disk' in 'same' ...\n" + \ " find_file: looking for 'on_disk' in 'bar' ...\n" + \ |
