summaryrefslogtreecommitdiffstats
path: root/src/engine/SCons/Scanner/C.py
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2003-04-23 22:27:58 (GMT)
committerSteven Knight <knight@baldmt.com>2003-04-23 22:27:58 (GMT)
commit9587e1d2dad1c532d86f664f5cbd6266ebd77808 (patch)
tree71ab8dbc059c0d16de3f5088427e288716d9dd43 /src/engine/SCons/Scanner/C.py
parent9c4ebd90350becd6ff9b1b4e4049546680c849b6 (diff)
downloadSCons-9587e1d2dad1c532d86f664f5cbd6266ebd77808.zip
SCons-9587e1d2dad1c532d86f664f5cbd6266ebd77808.tar.gz
SCons-9587e1d2dad1c532d86f664f5cbd6266ebd77808.tar.bz2
Add support for MIDL. (Greg Spencer)
Diffstat (limited to 'src/engine/SCons/Scanner/C.py')
-rw-r--r--src/engine/SCons/Scanner/C.py103
1 files changed, 7 insertions, 96 deletions
diff --git a/src/engine/SCons/Scanner/C.py b/src/engine/SCons/Scanner/C.py
index c06774d..44007f9 100644
--- a/src/engine/SCons/Scanner/C.py
+++ b/src/engine/SCons/Scanner/C.py
@@ -29,106 +29,17 @@ This module implements the depenency scanner for C/C++ code.
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-
-import re
-
-import SCons.Node
import SCons.Node.FS
import SCons.Scanner
-import SCons.Util
-import SCons.Warnings
-
-include_re = re.compile('^[ \t]*#[ \t]*(?:include|import)[ \t]+(<|")([^>"]+)(>|")', re.M)
def CScan(fs = SCons.Node.FS.default_fs):
"""Return a prototype Scanner instance for scanning source files
that use the C pre-processor"""
- cs = SCons.Scanner.Current(scan, "CScan", fs,
- [".c", ".C", ".cxx", ".cpp", ".c++", ".cc",
- ".h", ".H", ".hxx", ".hpp", ".hh",
- ".F", ".fpp", ".FPP"],
- path_function = path,
- recursive = 1)
+ cs = SCons.Scanner.ClassicCPP("CScan",
+ [".c", ".C", ".cxx", ".cpp", ".c++", ".cc",
+ ".h", ".H", ".hxx", ".hpp", ".hh",
+ ".F", ".fpp", ".FPP"],
+ "CPPPATH",
+ '^[ \t]*#[ \t]*(?:include|import)[ \t]+(<|")([^>"]+)(>|")',
+ fs = fs)
return cs
-
-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]
-
- the C/C++ dependency scanner function
-
- This function is intentionally simple. There are two rules it
- follows:
-
- 1) #include <foo.h> - search for foo.h in CPPPATH followed by the
- directory 'filename' is in
- 2) #include \"foo.h\" - search for foo.h in the directory 'filename' is
- in followed by CPPPATH
-
- These rules approximate the behaviour of most C/C++ compilers.
-
- This scanner also ignores #ifdef and other preprocessor conditionals, so
- it may find more depencies than there really are, but it never misses
- dependencies.
- """
-
- node = node.rfile()
-
- # 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)
-
- 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)