diff --git a/cxx-squid/src/main/java/org/sonar/cxx/CxxVCppBuildLogParser.java b/cxx-squid/src/main/java/org/sonar/cxx/CxxVCppBuildLogParser.java index ad1abcd59b..306855fe0f 100644 --- a/cxx-squid/src/main/java/org/sonar/cxx/CxxVCppBuildLogParser.java +++ b/cxx-squid/src/main/java/org/sonar/cxx/CxxVCppBuildLogParser.java @@ -138,27 +138,24 @@ private void parseVCppCompilerCLLine(String line, String projectPath, String fil ParseInclude(includeElem, projectPath, fileElement); } - for (String includeElem : getMatches(Pattern.compile("/I([^\\s\"]+) "), - line)) { + for (String includeElem : getMatches(Pattern.compile("/I([^\\s\"]+) "), line)) { ParseInclude(includeElem, projectPath, fileElement); } - for (String macroElem : getMatches(Pattern.compile("[/-]D\\s([^\\s]+)"), - line)) { + for (String macroElem : getMatches(Pattern.compile("[/-]D\\s([^\\s]+)"), line)) { AddMacro(macroElem, fileElement); } - for (String macroElem : getMatches(Pattern.compile("[/-]D([^\\s]+)"), - line)) { + for (String macroElem : getMatches(Pattern.compile("[/-]D([^\\s]+)"), line)) { AddMacro(macroElem, fileElement); } - + // https://msdn.microsoft.com/en-us/library/vstudio/b0084kay(v=vs.100).aspx // https://msdn.microsoft.com/en-us/library/vstudio/b0084kay(v=vs.110).aspx // https://msdn.microsoft.com/en-us/library/vstudio/b0084kay(v=vs.120).aspx // https://msdn.microsoft.com/en-us/library/vstudio/b0084kay(v=vs.140).aspx ParseCommonCompilerOptions(line, fileElement); - + if (platformToolset.equals(VSVersion.V100)) { ParseV100CompilerOptions(line, fileElement); } else if (platformToolset.equals(VSVersion.V110)) { @@ -167,7 +164,7 @@ private void parseVCppCompilerCLLine(String line, String projectPath, String fil ParseV120CompilerOptions(line, fileElement); } else if (platformToolset.equals(VSVersion.V140)) { ParseV140CompilerOptions(line, fileElement); - } + } } private List getMatches(Pattern pattern, String text) { @@ -391,10 +388,6 @@ else if(platform.equals("Win32")||line.contains("/D WIN32")) { //This is not defined for x64 processors. AddMacro("_M_IX86", fileElement); } - // VC++ 16.0 - if (line.contains("/GX ")) { - AddMacro("_CPPUNWIND", fileElement); - } // VC++ 17.0, 18.0, 19.0 // _CPPUNWIND Defined for code compiled by using one of the /EH (Exception Handling Model) flags. if (line.contains("/EHs ") || @@ -418,6 +411,10 @@ private void ParseV100CompilerOptions(String line, String fileElement) { //_MFC_VER Defines the MFC version. For example, in Visual Studio 2010, _MFC_VER is defined as 0x0C00. AddMacro("_MFC_VER=0x0A00", fileElement); AddMacro("_ATL_VER=0x0A00", fileElement); + // VC++ 16.0 + if (line.contains("/GX ")) { + AddMacro("_CPPUNWIND", fileElement); + } } private void ParseV110CompilerOptions(String line, String fileElement) { diff --git a/cxx-squid/src/test/java/org/sonar/cxx/CxxConfigurationTest.java b/cxx-squid/src/test/java/org/sonar/cxx/CxxConfigurationTest.java index c2b2a0853c..ecbfcccc24 100644 --- a/cxx-squid/src/test/java/org/sonar/cxx/CxxConfigurationTest.java +++ b/cxx-squid/src/test/java/org/sonar/cxx/CxxConfigurationTest.java @@ -32,7 +32,6 @@ public class CxxConfigurationTest { private static final String vcKey = "Visual C++"; private static final String vcCharSet = "UTF8"; - private static final int commonDefines = 14; @Test public void emptyValueShouldReturnNoDirsOrDefines() { @@ -68,11 +67,11 @@ public void correctlyCreatesConfiguration1() { config.setCompilationPropertiesWithBuildLog(files, vcKey, vcCharSet); assertThat(config.getIncludeDirectories().size()).isEqualTo(13); - assertThat(config.getDefines().size()).isEqualTo(commonDefines + 17); + assertThat(config.getDefines().size()).isEqualTo(26 + 5); } @Test - public void shouldHandleSpeciificCommonOptionsCorrectly() { + public void shouldHandleSpecificCommonOptionsCorrectly() { CxxConfiguration config = new CxxConfiguration(); config.setBaseDir("."); List files = new ArrayList<>(); @@ -81,7 +80,7 @@ public void shouldHandleSpeciificCommonOptionsCorrectly() { assertThat(config.getIncludeDirectories().size()).isEqualTo(0); List defines = config.getDefines(); - assertThat(defines.size()).isEqualTo(commonDefines + 11); + assertThat(defines.size()).isEqualTo(20 + 5); ValidateDefaultAsserts(defines); Assertions.assertThat(defines).as("_OPENMP"); Assertions.assertThat(defines).as("_WIN32"); @@ -97,13 +96,13 @@ public void shouldHandleSpeciificCommonOptionsCorrectly() { Assertions.assertThat(defines).as("_VC_NODEFAULTLIB"); } - public void shouldHandleSpeciificCommonWin32OptionsCorrectly() { + public void shouldHandleSpecificCommonWin32OptionsCorrectly() { CxxConfiguration config = new CxxConfiguration(); List files = new ArrayList<>(); files.add(new File("src/test/resources/compiler/platformCommonWin32.txt")); config.setCompilationPropertiesWithBuildLog(files, vcKey, vcCharSet); - assertThat(config.getIncludeDirectories().size()).isEqualTo(0); + assertThat(config.getIncludeDirectories().size()).isEqualTo(0); List defines = config.getDefines(); assertThat(defines.size()).isEqualTo(3); ValidateDefaultAsserts(defines); @@ -111,16 +110,16 @@ public void shouldHandleSpeciificCommonWin32OptionsCorrectly() { } @Test - public void shouldHandleSpeciificCommonx64OptionsCorrectly() { + public void shouldHandleSpecificCommonx64OptionsCorrectly() { CxxConfiguration config = new CxxConfiguration(); config.setBaseDir("."); List files = new ArrayList<>(); files.add(new File("src/test/resources/compiler/platformCommonX64.txt")); config.setCompilationPropertiesWithBuildLog(files, vcKey, vcCharSet); - assertThat(config.getIncludeDirectories().size()).isEqualTo(0); + assertThat(config.getIncludeDirectories().size()).isEqualTo(0); List defines = config.getDefines(); - assertThat(defines.size()).isEqualTo(commonDefines + 6); + assertThat(defines.size()).isEqualTo(15 + 5); ValidateDefaultAsserts(defines); Assertions.assertThat(defines).as("_Wp64"); Assertions.assertThat(defines).as("_WIN32"); @@ -131,7 +130,7 @@ public void shouldHandleSpeciificCommonx64OptionsCorrectly() { } @Test - public void shouldHandleSpeciificV100OptionsCorrectly() { + public void shouldHandleSpecificV100OptionsCorrectly() { CxxConfiguration config = new CxxConfiguration(); config.setBaseDir("."); List files = new ArrayList(); @@ -140,7 +139,7 @@ public void shouldHandleSpeciificV100OptionsCorrectly() { assertThat(config.getIncludeDirectories().size()).isEqualTo(0); List defines = config.getDefines(); - assertThat(defines.size()).isEqualTo(commonDefines + 4); + assertThat(defines.size()).isEqualTo(12 + 6); ValidateDefaultAsserts(defines); Assertions.assertThat(defines).as("_CPPUNWIND"); Assertions.assertThat(defines).as("_M_IX86"); @@ -149,7 +148,7 @@ public void shouldHandleSpeciificV100OptionsCorrectly() { } @Test - public void shouldHandleSpeciificV110OptionsCorrectly() { + public void shouldHandleSpecificV110OptionsCorrectly() { CxxConfiguration config = new CxxConfiguration(); config.setBaseDir("."); List files = new ArrayList(); @@ -158,7 +157,7 @@ public void shouldHandleSpeciificV110OptionsCorrectly() { assertThat(config.getIncludeDirectories().size()).isEqualTo(0); List defines = config.getDefines(); - assertThat(defines.size()).isEqualTo(commonDefines + 5); + assertThat(defines.size()).isEqualTo(13 + 6); ValidateDefaultAsserts(defines); Assertions.assertThat(defines).as("__cplusplus_winrt"); Assertions.assertThat(defines).as("_CPPUNWIND"); @@ -168,7 +167,7 @@ public void shouldHandleSpeciificV110OptionsCorrectly() { } @Test - public void shouldHandleSpeciificV120OptionsCorrectly() { + public void shouldHandleSpecificV120OptionsCorrectly() { CxxConfiguration config = new CxxConfiguration(); config.setBaseDir("."); List files = new ArrayList<>(); @@ -177,7 +176,7 @@ public void shouldHandleSpeciificV120OptionsCorrectly() { assertThat(config.getIncludeDirectories().size()).isEqualTo(0); List defines = config.getDefines(); - assertThat(defines.size()).isEqualTo(commonDefines + 7); + assertThat(defines.size()).isEqualTo(15 + 6); ValidateDefaultAsserts(defines); Assertions.assertThat(defines).as("__AVX2__"); Assertions.assertThat(defines).as("__AVX__"); @@ -190,7 +189,7 @@ public void shouldHandleSpeciificV120OptionsCorrectly() { } @Test - public void shouldHandleSpeciificV140OptionsCorrectly() { + public void shouldHandleSpecificV140OptionsCorrectly() { CxxConfiguration config = new CxxConfiguration(); config.setBaseDir("."); List files = new ArrayList<>(); @@ -199,7 +198,7 @@ public void shouldHandleSpeciificV140OptionsCorrectly() { assertThat(config.getIncludeDirectories().size()).isEqualTo(0); List defines = config.getDefines(); - assertThat(defines.size()).isEqualTo(commonDefines + 7); + assertThat(defines.size()).isEqualTo(15 + 6); ValidateDefaultAsserts(defines); Assertions.assertThat(defines).as("__AVX2__"); Assertions.assertThat(defines).as("__AVX__");