diff options
author | William Deegan <bill@baddogconsulting.com> | 2018-11-14 03:15:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-14 03:15:37 (GMT) |
commit | ba1566949a4d18f2a032fdb400a1da749cd16225 (patch) | |
tree | 41d743833d9a0276cd18af7ebb186ffcbb014e9a | |
parent | 857e0221af6d5ee2fc1d2e4bfbe581b867ba31a4 (diff) | |
parent | 14fd1dfa719488b14ef2ba5ac3ff6cf84ce2e2ba (diff) | |
download | SCons-ba1566949a4d18f2a032fdb400a1da749cd16225.zip SCons-ba1566949a4d18f2a032fdb400a1da749cd16225.tar.gz SCons-ba1566949a4d18f2a032fdb400a1da749cd16225.tar.bz2 |
Merge pull request #3240 from ArdaFu/master
Fix cpp scanner regex logic to treat ifndef. This is a PY3.5+ only issue.
-rw-r--r-- | src/CHANGES.txt | 3 | ||||
-rw-r--r-- | src/engine/SCons/cpp.py | 4 | ||||
-rw-r--r-- | src/engine/SCons/cppTests.py | 35 |
3 files changed, 40 insertions, 2 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt index bb9ff98..c9d4ceb 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -185,6 +185,9 @@ RELEASE 3.1.0.alpha.yyyymmdd - NEW DATE WILL BE INSERTED HERE - Typo in customized decider example in user guide - Replace usage of unittest.TestSuite with unittest.main() (fix #3113) + From Arda Fu + - Fix cpp scanner regex logic to treat ifndef for py3.5+. Previously it was + not properly differentiating between if, ifdef, and ifndef. RELEASE 3.0.1 - Mon, 12 Nov 2017 15:31:33 -0700 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 |