summaryrefslogtreecommitdiffstats
path: root/src/engine/SCons
diff options
context:
space:
mode:
authorArdaFu <pengfei.fu@gmail.com>2018-11-13 08:56:40 (GMT)
committerArdaFu <pengfei.fu@gmail.com>2018-11-14 01:31:10 (GMT)
commit0d2959feb33a2c7f8d19f7bcad718af10866ce3f (patch)
treee510992b5ce09e7e620dfbf4d3c07848444c26d4 /src/engine/SCons
parent857e0221af6d5ee2fc1d2e4bfbe581b867ba31a4 (diff)
downloadSCons-0d2959feb33a2c7f8d19f7bcad718af10866ce3f.zip
SCons-0d2959feb33a2c7f8d19f7bcad718af10866ce3f.tar.gz
SCons-0d2959feb33a2c7f8d19f7bcad718af10866ce3f.tar.bz2
Fix cpp scanner regex logic to treat ifndef. Previously it was not properly differentiating between if, ifdef, and ifndef
Diffstat (limited to 'src/engine/SCons')
-rw-r--r--src/engine/SCons/cpp.py4
-rw-r--r--src/engine/SCons/cppTests.py35
2 files changed, 37 insertions, 2 deletions
diff --git a/src/engine/SCons/cpp.py b/src/engine/SCons/cpp.py
index 161f070..d2178a7 100644
--- a/src/engine/SCons/cpp.py
+++ b/src/engine/SCons/cpp.py
@@ -82,9 +82,9 @@ del op_list
# Create a list of the expressions we'll use to match all of the
# preprocessor directives. These are the same as the directives
# themselves *except* that we must use a negative lookahead assertion
-# when matching "if" so it doesn't match the "if" in "ifdef."
+# when matching "if" so it doesn't match the "if" in "ifdef" or "ifndef".
override = {
- 'if' : 'if(?!def)',
+ 'if' : 'if(?!n?def)',
}
l = [override.get(x, x) for x in list(Table.keys())]
diff --git a/src/engine/SCons/cppTests.py b/src/engine/SCons/cppTests.py
index 40236e4..d496273 100644
--- a/src/engine/SCons/cppTests.py
+++ b/src/engine/SCons/cppTests.py
@@ -346,6 +346,24 @@ nested_ifs_input = """
+ifndef_input = """
+#define DEFINED 0
+
+#ifndef DEFINED
+#include "file45-no"
+#else
+#include "file45-yes"
+#endif
+
+#ifndef NOT_DEFINED
+#include <file46-yes>
+#else
+#include <file46-no>
+#endif
+"""
+
+
+
# pp_class = PreProcessor
# #pp_class = DumbPreProcessor
@@ -426,6 +444,12 @@ class cppTestCase(unittest.TestCase):
result = self.cpp.process_contents(nested_ifs_input)
assert expect == result, (expect, result)
+ def test_ifndef(self):
+ """Test basic #ifndef processing"""
+ expect = self.ifndef_expect
+ result = self.cpp.process_contents(ifndef_input)
+ assert expect == result, (expect, result)
+
class cppAllTestCase(cppTestCase):
def setUp(self):
self.cpp = self.cpp_class(current = ".",
@@ -513,6 +537,11 @@ class PreProcessorTestCase(cppAllTestCase):
('include', '"', 'file7-yes'),
]
+ ifndef_expect = [
+ ('include', '"', 'file45-yes'),
+ ('include', '<', 'file46-yes'),
+ ]
+
class DumbPreProcessorTestCase(cppAllTestCase):
cpp_class = cpp.DumbPreProcessor
@@ -626,6 +655,12 @@ class DumbPreProcessorTestCase(cppAllTestCase):
]
+ ifndef_expect = [
+ ('include', '"', 'file45-no'),
+ ('include', '"', 'file45-yes'),
+ ('include', '<', 'file46-yes'),
+ ('include', '<', 'file46-no'),
+ ]
import os
import re