diff options
Diffstat (limited to 'src/engine/SCons/Scanner/C.py')
-rw-r--r-- | src/engine/SCons/Scanner/C.py | 122 |
1 files changed, 58 insertions, 64 deletions
diff --git a/src/engine/SCons/Scanner/C.py b/src/engine/SCons/Scanner/C.py index 6e7db58..cbcf1c6 100644 --- a/src/engine/SCons/Scanner/C.py +++ b/src/engine/SCons/Scanner/C.py @@ -48,10 +48,20 @@ def CScan(fs = SCons.Node.FS.default_fs): cs = SCons.Scanner.Recursive(scan, "CScan", fs, [".c", ".C", ".cxx", ".cpp", ".c++", ".cc", ".h", ".H", ".hxx", ".hpp", ".hh", - ".F", ".fpp", ".FPP"]) + ".F", ".fpp", ".FPP"], + path_function = path) return cs -def scan(node, env, target, fs = SCons.Node.FS.default_fs): +def path(env, dir, fs = SCons.Node.FS.default_fs): + try: + cpppath = env['CPPPATH'] + except KeyError: + return () + return tuple(fs.Rsearchall(SCons.Util.mapPaths(cpppath, dir, env), + clazz = SCons.Node.FS.Dir, + must_exist = 0)) + +def scan(node, env, cpppath = (), fs = SCons.Node.FS.default_fs): """ scan(node, Environment) -> [node] @@ -72,70 +82,54 @@ def scan(node, env, target, fs = SCons.Node.FS.default_fs): dependencies. """ - # This function caches various information in node and target: - # target.cpppath - env['CPPPATH'] converted to nodes - # node.found_includes - include files found by previous call to scan, - # keyed on cpppath - # node.includes - the result of include_re.findall() - - if not hasattr(target, 'cpppath'): - try: - target.cpppath = tuple(fs.Rsearchall(SCons.Util.mapPaths(env['CPPPATH'], target.cwd, env), clazz=SCons.Node.FS.Dir, must_exist=0)) - except KeyError: - target.cpppath = () - - cpppath = target.cpppath - node = node.rfile() - if not node.found_includes.has_key(cpppath): - if node.exists(): - - # cache the includes list in node so we only scan it once: - if node.includes != None: - includes = node.includes - else: - includes = include_re.findall(node.get_contents()) - node.includes = includes - - nodes = [] - source_dir = node.get_dir() - for include in includes: - if include[0] == '"': - n = SCons.Node.FS.find_file(include[1], - (source_dir,) + cpppath, - fs.File) - else: - n = SCons.Node.FS.find_file(include[1], - cpppath + (source_dir,), - fs.File) - - if not n is None: - nodes.append(n) - else: - SCons.Warnings.warn(SCons.Warnings.DependencyWarning, - "No dependency generated for file: %s (included from: %s) -- file not found" % (include[1], node)) - - # Schwartzian transform from the Python FAQ Wizard - def st(List, Metric): - def pairing(element, M = Metric): - return (M(element), element) - def stripit(pair): - return pair[1] - paired = map(pairing, List) - paired.sort() - return map(stripit, paired) - - def normalize(node): - # We don't want the order of includes to be - # modified by case changes on case insensitive OSes, so - # normalize the case of the filename here: - # (see test/win32pathmadness.py for a test of this) - return SCons.Node.FS._my_normcase(str(node)) - node.found_includes[cpppath] = st(nodes, normalize) + # This function caches the following information: + # node.includes - the result of include_re.findall() + if not node.exists(): + return [] + + # cache the includes list in node so we only scan it once: + if node.includes != None: + includes = node.includes + else: + includes = include_re.findall(node.get_contents()) + node.includes = includes + + nodes = [] + source_dir = node.get_dir() + for include in includes: + if include[0] == '"': + n = SCons.Node.FS.find_file(include[1], + (source_dir,) + cpppath, + fs.File) else: + n = SCons.Node.FS.find_file(include[1], + cpppath + (source_dir,), + fs.File) - node.found_includes[cpppath] = [] - - return node.found_includes[cpppath] + if not n is None: + nodes.append(n) + else: + SCons.Warnings.warn(SCons.Warnings.DependencyWarning, + "No dependency generated for file: %s (included from: %s) -- file not found" % (include[1], node)) + + # Schwartzian transform from the Python FAQ Wizard + def st(List, Metric): + def pairing(element, M = Metric): + return (M(element), element) + def stripit(pair): + return pair[1] + paired = map(pairing, List) + paired.sort() + return map(stripit, paired) + + def normalize(node): + # We don't want the order of includes to be + # modified by case changes on case insensitive OSes, so + # normalize the case of the filename here: + # (see test/win32pathmadness.py for a test of this) + return SCons.Node.FS._my_normcase(str(node)) + + return st(nodes, normalize) |