diff options
author | Ivan Kravets <me@ikravets.com> | 2018-03-08 14:25:09 (GMT) |
---|---|---|
committer | Ivan Kravets <me@ikravets.com> | 2018-03-08 14:25:09 (GMT) |
commit | e2312b8dfb4b993e8abbb1cf1043906d4bf31b14 (patch) | |
tree | 04ba9b5bf3f1038de0203d537836cc9d193e3cf2 | |
parent | 80e62ede63890d52fb7395c7588758bc07f8fba6 (diff) | |
download | SCons-e2312b8dfb4b993e8abbb1cf1043906d4bf31b14.zip SCons-e2312b8dfb4b993e8abbb1cf1043906d4bf31b14.tar.gz SCons-e2312b8dfb4b993e8abbb1cf1043906d4bf31b14.tar.bz2 |
Allow to control maximum depth of nested includes for conditional PreProcessor
-rw-r--r-- | src/engine/SCons/Scanner/C.py | 4 | ||||
-rw-r--r-- | src/engine/SCons/cpp.py | 28 |
2 files changed, 25 insertions, 7 deletions
diff --git a/src/engine/SCons/Scanner/C.py b/src/engine/SCons/Scanner/C.py index 0d18879..bd75bc9 100644 --- a/src/engine/SCons/Scanner/C.py +++ b/src/engine/SCons/Scanner/C.py @@ -96,11 +96,11 @@ class SConsCPPScannerWrapper(object): def __init__(self, name, variable): self.name = name self.path = SCons.Scanner.FindPathDirs(variable) - def __call__(self, node, env, path = (), all=False): + def __call__(self, node, env, path = (), depth=-1): cpp = SConsCPPScanner(current = node.get_dir(), cpppath = path, dict = dictify_CPPDEFINES(env), - all = all) + depth = depth) result = cpp(node) for included, includer in cpp.missing: fmt = "No dependency generated for file: %s (included from: %s) -- file not found" diff --git a/src/engine/SCons/cpp.py b/src/engine/SCons/cpp.py index 22b7a7b..cfff053 100644 --- a/src/engine/SCons/cpp.py +++ b/src/engine/SCons/cpp.py @@ -245,7 +245,7 @@ class PreProcessor(object): """ The main workhorse class for handling C pre-processing. """ - def __init__(self, current=os.curdir, cpppath=(), dict={}, all=False): + def __init__(self, current=os.curdir, cpppath=(), dict={}, all=0, depth=-1): global Table cpppath = tuple(cpppath) @@ -263,8 +263,15 @@ class PreProcessor(object): self.cpp_namespace = dict.copy() self.cpp_namespace['__dict__'] = self.cpp_namespace - # IF all=True, return all found includes without nested parsing - self.all = all + # Return all includes without resolving + if all: + self.do_include = self.all_include + + # Max depth of nested includes: + # -1 = unlimited + # 0 - disabled nesting + # >0 - number of allowed nested includes + self.depth = depth # For efficiency, a dispatch table maps each C preprocessor # directive (#if, #define, etc.) to the method that should be @@ -564,8 +571,14 @@ class PreProcessor(object): self.result.append(include_file) # print include_file, len(self.tuples) - if self.all: - return + # Handle maximum depth of nested includes + if self.depth != -1: + current_depth = 0 + for t in self.tuples: + if t[0] != "scons_current_file": + current_depth += 1 + if current_depth >= self.depth: + return new_tuples = [('scons_current_file', include_file)] + \ self.tupleize(self.read_file(include_file)) + \ @@ -623,6 +636,11 @@ class PreProcessor(object): return None return (t[0], s[0], s[1:-1]) + def all_include(self, t): + """ + """ + self.result.append(self.resolve_include(t)) + class DumbPreProcessor(PreProcessor): """A preprocessor that ignores all #if/#elif/#else/#endif directives |