Move find_file() and find_files() from SCons.Util to SCons.Node.FS.
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 12 Mar 2002 15:57:38 +0000 (15:57 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 12 Mar 2002 15:57:38 +0000 (15:57 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@291 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/Node/FS.py
src/engine/SCons/Node/FSTests.py
src/engine/SCons/Scanner/C.py
src/engine/SCons/Scanner/Prog.py
src/engine/SCons/Util.py
src/engine/SCons/UtilTests.py

index 3167005d673a73a5299dc0d5ce042ff65b70400f..f7e1f44884d31313636aecd869b2678c72b8c5bf 100644 (file)
@@ -573,5 +573,56 @@ class File(Entry):
         else:
             self.__createDir()
 
+
 default_fs = FS()
 
+
+def find_file(filename, paths, node_factory = default_fs.File):
+    """
+    find_file(str, [Dir()]) -> [nodes]
+
+    filename - a filename to find
+    paths - a list of directory path *nodes* to search in
+
+    returns - the node created from the found file.
+
+    Find a node corresponding to either a derived file or a file
+    that exists already.
+
+    Only the first file found is returned, and none is returned
+    if no file is found.
+    """
+    retval = None
+    for dir in paths:
+        try:
+            node = node_factory(filename, dir)
+            # Return true of the node exists or is a derived node.
+            if node.builder or \
+               (isinstance(node, SCons.Node.FS.Entry) and node.cached_exists()):
+                retval = node
+                break
+        except TypeError:
+            # If we find a directory instead of a file, we don't care
+            pass
+
+    return retval
+
+def find_files(filenames, paths, node_factory = default_fs.File):
+    """
+    find_files([str], [Dir()]) -> [nodes]
+
+    filenames - a list of filenames to find
+    paths - a list of directory path *nodes* to search in
+
+    returns - the nodes created from the found files.
+
+    Finds nodes corresponding to either derived files or files
+    that exist already.
+
+    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)
index 94f81fdfb33963a61de7d3d8ca8ffd7dde33d013..b132b1232ca302908777ff530dff9029fd21a093 100644 (file)
@@ -469,10 +469,29 @@ class FSTestCase(unittest.TestCase):
         #XXX test get_prevsiginfo()
 
 
+class find_fileTestCase(unittest.TestCase):
+    def runTest(self):
+        """Testing find_file function"""
+        test = TestCmd(workdir = '')
+        test.write('./foo', 'Some file\n')
+        fs = SCons.Node.FS.FS(test.workpath(""))
+        os.chdir(test.workpath("")) # FS doesn't like the cwd to be something other than it's root
+        node_derived = fs.File(test.workpath('bar/baz'))
+        node_derived.builder_set(1) # Any non-zero value.
+        paths = map(fs.Dir, ['.', './bar'])
+        nodes = [SCons.Node.FS.find_file('foo', paths, fs.File), 
+                 SCons.Node.FS.find_file('baz', paths, fs.File)] 
+        file_names = map(str, nodes)
+        file_names = map(os.path.normpath, file_names)
+        assert os.path.normpath('./foo') in file_names, file_names
+        assert os.path.normpath('./bar/baz') in file_names, file_names
+
+
 
 if __name__ == "__main__":
     suite = unittest.TestSuite()
     suite.addTest(FSTestCase())
     suite.addTest(BuildDirTestCase())
+    suite.addTest(find_fileTestCase())
     if not unittest.TextTestRunner().run(suite).wasSuccessful():
         sys.exit(1)
index 6b5b6c647d8257835b3f7f9433d2d677ff5f0a57..7a9a4bad1b516d207674419e81773f679029dae7 100644 (file)
@@ -114,10 +114,12 @@ def scan(node, env, args = [SCons.Node.FS.default_fs, ()]):
             
             for include in includes:
                 if include[0] == '"':
-                    n = SCons.Util.find_file(include[1], (source_dir,) + cpppath,
+                    n = SCons.Node.FS.find_file(include[1],
+                                                (source_dir,) + cpppath,
                                                 fs.File)
                 else:
-                    n = SCons.Util.find_file(include[1], cpppath + (source_dir,),
+                    n = SCons.Node.FS.find_file(include[1],
+                                                cpppath + (source_dir,),
                                                 fs.File)
 
                 if not n is None:
index d77ca324b59797f52085a589467617a712904acf..d8fb22c06faf170d9f2b2150176f1474e116bda6 100644 (file)
@@ -66,4 +66,4 @@ def scan(node, env, node_factory):
         suffix=''
 
     libs = map(lambda x, s=suffix, p=prefix: p + x + s, libs)
-    return SCons.Util.find_files(libs, paths, node_factory)
+    return SCons.Node.FS.find_files(libs, paths, node_factory)
index 2202abd15e53b544545aa7c7ca69c2c8cec7a68d..d7a025376a60fdb8c5710e2ed8e963b8fe91579f 100644 (file)
@@ -232,56 +232,6 @@ def scons_subst(strSubst, locals, globals, remove=None):
     cmd_list = scons_subst_list(strSubst, locals, globals, remove)
     return string.join(map(string.join, cmd_list), '\n')
 
-def find_files(filenames, paths,
-              node_factory = SCons.Node.FS.default_fs.File):
-    """
-    find_files([str], [Dir()]) -> [nodes]
-
-    filenames - a list of filenames to find
-    paths - a list of directory path *nodes* to search in
-
-    returns - the nodes created from the found files.
-
-    Finds nodes corresponding to either derived files or files
-    that exist already.
-
-    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)
-
-def find_file(filename, paths,
-              node_factory = SCons.Node.FS.default_fs.File):
-    """
-    find_file(str, [Dir()]) -> [nodes]
-
-    filename - a filename to find
-    paths - a list of directory path *nodes* to search in
-
-    returns - the node created from the found file.
-
-    Find a node corresponding to either a derived file or a file
-    that exists already.
-
-    Only the first file found is returned, and none is returned
-    if no file is found.
-    """
-    retval = None
-    for dir in paths:
-        try:
-            node = node_factory(filename, dir)
-            # Return true of the node exists or is a derived node.
-            if node.builder or \
-               (isinstance(node, SCons.Node.FS.Entry) and node.cached_exists()):
-                retval = node
-                break
-        except TypeError:
-            # If we find a directory instead of a file, we don't care
-            pass
-
-    return retval
-
 class VarInterpolator:
     def __init__(self, dest, src, prefix, suffix):
         self.dest = dest
index bcb93d09044e07ec7f65fe9734c99753e025e2b6..aa58c8ea5cf1ad67221460f1a13f927d8ae29227 100644 (file)
@@ -188,22 +188,6 @@ class UtilTestCase(unittest.TestCase):
         assert cmd_list[1][0] == 'after', cmd_list[1][0]
         assert cmd_list[0][2] == cvt('../foo/ack.cbefore'), cmd_list[0][2]
 
-    def test_find_file(self):
-        """Testing find_file function."""
-        test = TestCmd.TestCmd(workdir = '')
-        test.write('./foo', 'Some file\n')
-        fs = SCons.Node.FS.FS(test.workpath(""))
-        os.chdir(test.workpath("")) # FS doesn't like the cwd to be something other than it's root
-        node_derived = fs.File(test.workpath('bar/baz'))
-        node_derived.builder_set(1) # Any non-zero value.
-        paths = map(fs.Dir, ['.', './bar'])
-        nodes = [find_file('foo', paths, fs.File), 
-                 find_file('baz', paths, fs.File)] 
-        file_names = map(str, nodes)
-        file_names = map(os.path.normpath, file_names)
-        assert os.path.normpath('./foo') in file_names, file_names
-        assert os.path.normpath('./bar/baz') in file_names, file_names
-
     def test_autogenerate(dict):
         """Test autogenerating variables in a dictionary."""
         dict = {'LIBS'          : [ 'foo', 'bar', 'baz' ],