From: stevenknight Date: Tue, 4 Dec 2001 06:42:41 +0000 (+0000) Subject: Speed up and generalize SCons.Util.find_files(). X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=fdbc53839fc7347048977245d7ae903ed09ee4c6;p=scons.git Speed up and generalize SCons.Util.find_files(). git-svn-id: http://scons.tigris.org/svn/scons/trunk@130 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/src/engine/SCons/Scanner/C.py b/src/engine/SCons/Scanner/C.py index 73961252..ab48342b 100644 --- a/src/engine/SCons/Scanner/C.py +++ b/src/engine/SCons/Scanner/C.py @@ -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 [] diff --git a/src/engine/SCons/Scanner/Prog.py b/src/engine/SCons/Scanner/Prog.py index 0f8acff3..cbbfb42f 100644 --- a/src/engine/SCons/Scanner/Prog.py +++ b/src/engine/SCons/Scanner/Prog.py @@ -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 = [] diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index 1d42d180..9108f146 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -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()): diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py index e8a6ecad..58e81b5f 100644 --- a/src/engine/SCons/UtilTests.py +++ b/src/engine/SCons/UtilTests.py @@ -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