From 0d2959feb33a2c7f8d19f7bcad718af10866ce3f Mon Sep 17 00:00:00 2001 From: ArdaFu Date: Tue, 13 Nov 2018 16:56:40 +0800 Subject: Fix cpp scanner regex logic to treat ifndef. Previously it was not properly differentiating between if, ifdef, and ifndef --- src/CHANGES.txt | 3 +++ src/engine/SCons/cpp.py | 4 ++-- 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..6245f1a 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. 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 +#else +#include +#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 -- cgit v0.12 From 14fd1dfa719488b14ef2ba5ac3ff6cf84ce2e2ba Mon Sep 17 00:00:00 2001 From: ArdaFu Date: Wed, 14 Nov 2018 09:32:57 +0800 Subject: Modify changes.txt since this is a py3.5+ only issue. --- src/CHANGES.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 6245f1a..c9d4ceb 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -186,8 +186,8 @@ RELEASE 3.1.0.alpha.yyyymmdd - NEW DATE WILL BE INSERTED HERE - Replace usage of unittest.TestSuite with unittest.main() (fix #3113) From Arda Fu - - Fix cpp scanner regex logic to treat ifndef. Previously it was not properly - differentiating between if, ifdef, and ifndef + - 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 -- cgit v0.12