summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2016-03-08 14:35:24 +0800
committerBernard Xiong <[email protected]>2016-03-08 14:35:24 +0800
commite0998e3c230a16fa1a60ff14fa52590bcce16eda (patch)
treee4a2ec2ebbdd67017ba30d36daf21d6de29bd9d8
parent10fd3d34ad04a9783643139ae5bc2bf8319a7c0a (diff)
parentaee3a1d4c51d0becfab37863696cf217ea054cd8 (diff)
Merge pull request #614 from onelife/upstream
SCons PreProcessor patch: Stop processing "#define" in false condition
-rw-r--r--tools/building.py44
1 files changed, 41 insertions, 3 deletions
diff --git a/tools/building.py b/tools/building.py
index 07f5e91fc9..c6555b1e63 100644
--- a/tools/building.py
+++ b/tools/building.py
@@ -36,6 +36,44 @@ Projects = []
Rtt_Root = ''
Env = None
+# SCons PreProcessor patch
+def start_handling_includes(self, t=None):
+ """
+ Causes the PreProcessor object to start processing #import,
+ #include and #include_next lines.
+
+ This method will be called when a #if, #ifdef, #ifndef or #elif
+ evaluates True, or when we reach the #else in a #if, #ifdef,
+ #ifndef or #elif block where a condition already evaluated
+ False.
+
+ """
+ d = self.dispatch_table
+ p = self.stack[-1] if self.stack else self.default_table
+
+ for k in ('import', 'include', 'include_next', 'define'):
+ d[k] = p[k]
+
+def stop_handling_includes(self, t=None):
+ """
+ Causes the PreProcessor object to stop processing #import,
+ #include and #include_next lines.
+
+ This method will be called when a #if, #ifdef, #ifndef or #elif
+ evaluates False, or when we reach the #else in a #if, #ifdef,
+ #ifndef or #elif block where a condition already evaluated True.
+ """
+ d = self.dispatch_table
+ d['import'] = self.do_nothing
+ d['include'] = self.do_nothing
+ d['include_next'] = self.do_nothing
+ d['define'] = self.do_nothing
+
+PatchedPreProcessor = SCons.cpp.PreProcessor
+PatchedPreProcessor.start_handling_includes = start_handling_includes
+PatchedPreProcessor.stop_handling_includes = stop_handling_includes
+
+
class Win32Spawn:
def spawn(self, sh, escape, cmd, args, env):
# deal with the cmd build-in commands which cannot be used in
@@ -123,7 +161,7 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
Env.Append(BUILDERS = {'BuildLib': bld})
# parse rtconfig.h to get used component
- PreProcessor = SCons.cpp.PreProcessor()
+ PreProcessor = PatchedPreProcessor()
f = file('rtconfig.h', 'r')
contents = f.read()
f.close()
@@ -277,7 +315,7 @@ def PrepareModuleBuilding(env, root_directory, bsp_directory):
Rtt_Root = root_directory
# parse bsp rtconfig.h to get used component
- PreProcessor = SCons.cpp.PreProcessor()
+ PreProcessor = PatchedPreProcessor()
f = file(bsp_directory + '/rtconfig.h', 'r')
contents = f.read()
f.close()
@@ -631,7 +669,7 @@ def GetVersion():
rtdef = os.path.join(Rtt_Root, 'include', 'rtdef.h')
# parse rtdef.h to get RT-Thread version
- prepcessor = SCons.cpp.PreProcessor()
+ prepcessor = PatchedPreProcessor()
f = file(rtdef, 'r')
contents = f.read()
f.close()