Speed up and generalize SCons.Util.find_files().
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 4 Dec 2001 06:42:41 +0000 (06:42 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 4 Dec 2001 06:42:41 +0000 (06:42 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@130 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/Scanner/C.py
src/engine/SCons/Scanner/Prog.py
src/engine/SCons/Util.py
src/engine/SCons/UtilTests.py

index 739612523f01796ffbf90bdee340447ee8a0dd6f..ab48342b81c20bf754e0e1e11d9c036494af0c79 100644 (file)
@@ -66,8 +66,10 @@ def scan(filename, env, node_factory):
     dependencies.
     """
 
+    fs = SCons.Node.FS.default_fs
     try:
-        paths = env.Dictionary("CPPPATH")
+        paths = map(lambda x, dir=fs.Dir: dir(x),
+                    env.Dictionary("CPPPATH"))
     except KeyError:
         paths = []
 
@@ -79,11 +81,15 @@ def scan(filename, env, node_factory):
         angle_includes = angle_re.findall(contents)
         quote_includes = quote_re.findall(contents)
 
-        source_dir = os.path.dirname(filename)
+        dir = os.path.dirname(filename)
+        if dir:
+            source_dir = [fs.Dir(dir)]
+        else:
+            source_dir = []
         
-        return (SCons.Util.find_files(angle_includes, paths + [source_dir],
+        return (SCons.Util.find_files(angle_includes, paths + source_dir,
                                       node_factory)
-                + SCons.Util.find_files(quote_includes, [source_dir] + paths,
+                + SCons.Util.find_files(quote_includes, source_dir + paths,
                                         node_factory))
     except OSError:
         return []
index 0f8acff302d5554b208f565540d2ef60bc770d69..cbbfb42f759b3704a2f8544f4be1652f18f315ba 100644 (file)
@@ -40,8 +40,10 @@ def scan(filename, env, node_factory):
     files it finds as dependencies.
     """
 
+    fs = SCons.Node.FS.default_fs
     try:
-        paths = env.Dictionary("LIBPATH")
+        paths = map(lambda x, dir=fs.Dir: dir(x),
+                    env.Dictionary("LIBPATH"))
     except KeyError:
         paths = []
 
index 1d42d1800ee4b0a656bf791f9263f7a9bec21b87..9108f1465e3651ecd8e4b890a9be311d4b0cbd7a 100644 (file)
@@ -228,22 +228,21 @@ def find_files(filenames, paths,
     find_files([str], [str]) -> [nodes]
 
     filenames - a list of filenames to find
-    paths - a list of paths to search in
+    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 fullname found is returned for each filename, and any
-    file that aren't found are ignored.
+    Only the first file found is returned for each filename,
+    and any files that aren't found are ignored.
     """
     nodes = []
     for filename in filenames:
-        for path in paths:
-            fullname = os.path.join(path, filename)
+        for dir in paths:
             try:
-                node = node_factory(fullname)
+                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.exists()):
index e8a6ecade011b1f42758b4abf8e2c68df045ceb4..58e81b5fc676111534ae36bc7bfd281993bb39f6 100644 (file)
@@ -167,8 +167,8 @@ class UtilTestCase(unittest.TestCase):
         fs = SCons.Node.FS.FS(test.workpath(""))
         node_derived = fs.File(test.workpath('./bar/baz'))
         node_derived.builder_set(1) # Any non-zero value.
-        nodes = find_files(['foo', 'baz'],
-                           map(test.workpath, ['./', './bar' ]), fs.File)
+        paths = map(lambda x, fs=fs: fs.Dir(x), ['./', './bar'])
+        nodes = find_files(['foo', '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