Skip to content

Commit

Permalink
Merge pull request #997 from Bertk/log-parser
Browse files Browse the repository at this point in the history
enhance VC log file parser to support VS2017 RC
  • Loading branch information
guwirth authored Nov 20, 2016
2 parents b1e0841 + 1424f2d commit 0b18596
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 32 deletions.
74 changes: 56 additions & 18 deletions cxx-squid/src/main/java/org/sonar/cxx/CxxVCppBuildLogParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,20 @@ public void parseVCppLog(File buildLog, String baseDir, String charsetName) {
platformToolset = "V110";
} else if (line.contains("\\V120\\Microsoft.CppBuild.targets") || line.contains("Microsoft Visual Studio 12.0\\VC\\bin\\CL.exe")) {
platformToolset = "V120";
} else if (line.contains("\\V140\\Microsoft.CppBuild.targets") || line.contains("Microsoft Visual Studio 14.0\\VC\\bin\\CL.exe")) {
} else if (line.contains("\\V140\\Microsoft.CppBuild.targets") ||
line.contains("Microsoft Visual Studio 14.0\\VC\\bin\\CL.exe") ||
line.contains("Microsoft Visual Studio 14.0\\VC\\bin\\amd64\\cl.exe")) {
platformToolset = "V140";
} else if (line.contains("\\V141\\Microsoft.CppBuild.targets") ||
line.matches("^.*VC\\\\Tools\\\\MSVC\\\\14.10.*\\\\bin\\\\HostX..\\\\x..\\\\CL.exe.*$")) {
platformToolset = "V141";
}

// 1>Task "Message"
// 1> Configuration=Debug
// 1>Done executing task "Message".
// 1>Task "Message"
//1> Platform=Win32
if (line.trim().endsWith("Platform=x64")) {
if (line.trim().endsWith("Platform=x64") || line.trim().matches("Building solution configuration \".*\\|x64\".")) {
platform = "x64";
}
// match "bin\CL.exe", "bin\amd64\CL.exe", "bin\x86_amd64\CL.exe"
Expand Down Expand Up @@ -191,6 +195,8 @@ private void parseVCppCompilerCLLine(String line, String projectPath, String fil
ParseV120CompilerOptions(line, fileElement);
} else if ("V140".equals(platformToolset)) {
ParseV140CompilerOptions(line, fileElement);
} else if ("V141".equals(platformToolset)) {
ParseV141CompilerOptions(line, fileElement);
}
}

Expand Down Expand Up @@ -240,6 +246,12 @@ private void addMacro(String macroElem, String file) {
}
}

private boolean existMacro(String macroElem, String file) {
Set<String> definesPerUnit = uniqueDefines.get(file);
String macro = macroElem.replace('=', ' ');
return definesPerUnit.contains(macro);
}

private void ParseCommonCompilerOptions(String line, String fileElement) {
// Always Defined //
//_INTEGRAL_MAX_BITS Reports the maximum size (in bits) for an integral type.
Expand Down Expand Up @@ -288,11 +300,13 @@ private void ParseCommonCompilerOptions(String line, String fileElement) {
if (line.contains("/arch:SSE")) {
addMacro("_M_IX86_FP=1", fileElement);
}
if (line.contains("/arch:AVX")) {
addMacro("__AVX__", fileElement);
//arch:ARMv7VE or /arch:VFPv4
if (line.contains("/arch:ARMv7VE")) {
addMacro("_M_ARM=7", fileElement);
addMacro("_M_ARM_ARMV7VE=1", fileElement);
}
if (line.contains("/arch:AVX2")) {
addMacro("__AVX2__", fileElement);
if (line.contains("/arch:VFPv4")) {
addMacro("_M_ARM=7", fileElement);
}
// WinCE and WinRT
// see https://en.wikipedia.org/wiki/ARM_architecture
Expand All @@ -314,7 +328,7 @@ private void ParseCommonCompilerOptions(String line, String fileElement) {

//_CHAR_UNSIGNED Default char type is unsigned. Defined when /J is specified.
if (line.contains("/J ")) {
addMacro("_CHAR_UNSIGNED", fileElement);
addMacro("_CHAR_UNSIGNED=1", fileElement);
}

//_CPPRTTI Defined for code compiled with /GR (Enable Run-Time Type Information).
Expand Down Expand Up @@ -410,14 +424,14 @@ private void ParseCommonCompilerOptions(String line, String fileElement) {
addMacro("_WIN32", fileElement);
// This is not defined for x86 processors.
addMacro("_WIN64", fileElement);
addMacro("_M_X64", fileElement);
addMacro("_M_X64=100", fileElement);
addMacro("_M_IA64", fileElement);
addMacro("_M_AMD64", fileElement);
} else if ("Win32".equals(platform) || line.contains("/D WIN32")) {
} else if ("Win32".equals(platform)) {
// Defined for compilations that target x86 processors.
addMacro("_WIN32", fileElement);
//This is not defined for x64 processors.
addMacro("_M_IX86", fileElement);
addMacro("_M_IX86=600", fileElement);
}
// VC++ 17.0, 18.0, 19.0
// _CPPUNWIND Defined for code compiled by using one of the /EH (Exception Handling Model) flags.
Expand All @@ -427,6 +441,15 @@ private void ParseCommonCompilerOptions(String line, String fileElement) {
|| line.contains("/EHac ")) {
addMacro("_CPPUNWIND", fileElement);
}
if (line.contains("/favor:ATOM") && (existMacro("_M_X64 100", fileElement) || existMacro("_M_IX86 600", fileElement))) {
addMacro("__ATOM__=1", fileElement);
}
if (line.contains("/arch:AVX") && (existMacro("_M_X64 100", fileElement) || existMacro("_M_IX86 600", fileElement))) {
addMacro("__AVX__=1", fileElement);
}
if (line.contains("/arch:AVX2") && (existMacro("_M_X64 100", fileElement) || existMacro("_M_IX86 600", fileElement))) {
addMacro("__AVX2__=1", fileElement);
}
}

private void ParseV100CompilerOptions(String line, String fileElement) {
Expand Down Expand Up @@ -458,7 +481,7 @@ private void ParseV110CompilerOptions(String line, String fileElement) {
addMacro("_MSC_VER=1700", fileElement);
// VS2012 Update 4
addMacro("_MSC_FULL_VER=1700610301", fileElement);
//_MFC_VER Defines the MFC version. For example, in Visual Studio 2013, _MFC_VER is defined as 0x0C00.
//_MFC_VER Defines the MFC version (see afxver_.h)
addMacro("_MFC_VER=0x0B00", fileElement);
addMacro("_ATL_VER=0x0B00", fileElement);
}
Expand All @@ -473,7 +496,7 @@ private void ParseV120CompilerOptions(String line, String fileElement) {
addMacro("_MSC_VER=1800", fileElement);
// VS2013 Update 4
addMacro("_MSC_FULL_VER=180031101", fileElement);
//_MFC_VER Defines the MFC version. For example, in Visual Studio 2013, _MFC_VER is defined as 0x0C00.
//_MFC_VER Defines the MFC version (see afxver_.h)
addMacro("_MFC_VER=0x0C00", fileElement);
addMacro("_ATL_VER=0x0C00", fileElement);
}
Expand All @@ -486,11 +509,26 @@ private void ParseV140CompilerOptions(String line, String fileElement) {
addMacro(CPPWINRTVERSION, fileElement);
}
addMacro("_MSC_VER=1900", fileElement);
// VS2015 RC
addMacro("_MSC_FULL_VER=190022816", fileElement);
//_MFC_VER Defines the MFC version. For example, in Visual Studio 2013, _MFC_VER is defined as 0x0C00.
addMacro("_MFC_VER=0x0C00", fileElement);
addMacro("_ATL_VER=0x0C00", fileElement);
// VS2015 Update 3 V19.00.24215.1
addMacro("_MSC_FULL_VER=190024215", fileElement);
//_MFC_VER Defines the MFC version (see afxver_.h)
addMacro("_MFC_VER=0x0E00", fileElement);
addMacro("_ATL_VER=0x0E00", fileElement);
}

private void ParseV141CompilerOptions(String line, String fileElement) {
// VC++ V19.1 - VS2017 (V15.0)
addMacro(CPPVERSION, fileElement);
// __cplusplus_winrt Defined when you use the /ZW option to compile. The value of __cplusplus_winrt is 201009.
if (line.contains("/ZW ")) {
addMacro(CPPWINRTVERSION, fileElement);
}
addMacro("_MSC_VER=1910", fileElement);
// VS2017 RC
addMacro("_MSC_FULL_VER=191024629", fileElement);
//_MFC_VER Defines the MFC version (see afxver_.h)
addMacro("_MFC_VER=0x0E00", fileElement);
addMacro("_ATL_VER=0x0E00", fileElement);
}
}

67 changes: 53 additions & 14 deletions cxx-squid/src/test/java/org/sonar/cxx/CxxConfigurationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void shouldHandleSpecificCommonOptionsCorrectly() {
ValidateDefaultAsserts(defines);
Assertions.assertThat(defines.contains("_OPENMP 200203")).isTrue();
Assertions.assertThat(defines.contains("_WIN32")).isTrue();
Assertions.assertThat(defines.contains("_M_IX86")).isTrue();
Assertions.assertThat(defines.contains("_M_IX86 600")).isTrue();
Assertions.assertThat(defines.contains("_M_IX86_FP 2")).isTrue();
Assertions.assertThat(defines.contains("_WCHAR_T_DEFINED 1")).isTrue();
Assertions.assertThat(defines.contains("_NATIVE_WCHAR_T_DEFINED 1")).isTrue();
Expand Down Expand Up @@ -123,7 +123,7 @@ public void shouldHandleSpecificCommonx64OptionsCorrectly() {
Assertions.assertThat(defines.contains("_Wp64")).isTrue();
Assertions.assertThat(defines.contains("_WIN32")).isTrue();
Assertions.assertThat(defines.contains("_WIN64")).isTrue();
Assertions.assertThat(defines.contains("_M_X64")).isTrue();
Assertions.assertThat(defines.contains("_M_X64 100")).isTrue();
Assertions.assertThat(defines.contains("_M_IX86")).isFalse();
Assertions.assertThat(defines.contains("_M_IX86_FP 2")).isTrue();
}
Expand All @@ -141,7 +141,7 @@ public void shouldHandleSpecificV100OptionsCorrectly() {
assertThat(defines.size()).isEqualTo(12 + 6);
ValidateDefaultAsserts(defines);
Assertions.assertThat(defines.contains("_CPPUNWIND")).isTrue();
Assertions.assertThat(defines.contains("_M_IX86")).isTrue();
Assertions.assertThat(defines.contains("_M_IX86 600")).isTrue();
Assertions.assertThat(defines.contains("_WIN32")).isTrue();
Assertions.assertThat(defines.contains("_M_IX86_FP 2")).isTrue();
}
Expand All @@ -156,11 +156,11 @@ public void shouldHandleSpecificV110OptionsCorrectly() {

assertThat(config.getIncludeDirectories().size()).isEqualTo(0);
List<String> defines = config.getDefines();
assertThat(defines.size()).isEqualTo(13 + 6);
assertThat(defines.size()).isEqualTo(13 + 5);
ValidateDefaultAsserts(defines);
Assertions.assertThat(defines.contains("__cplusplus_winrt 201009")).isTrue();
Assertions.assertThat(defines.contains("_CPPUNWIND")).isTrue();
Assertions.assertThat(defines.contains("_M_IX86")).isTrue();
Assertions.assertThat(defines.contains("_M_IX86 600")).isTrue();
Assertions.assertThat(defines.contains("_WIN32")).isTrue();
Assertions.assertThat(defines.contains("_M_IX86_FP 2")).isTrue();
Assertions.assertThat(defines.contains("_MSC_VER 1700")).isTrue();
Expand All @@ -180,13 +180,13 @@ public void shouldHandleSpecificV120OptionsCorrectly() {
List<String> defines = config.getDefines();
assertThat(defines.size()).isEqualTo(15 + 6);
ValidateDefaultAsserts(defines);
Assertions.assertThat(defines.contains("__AVX2__")).isTrue();
Assertions.assertThat(defines.contains("__AVX__")).isTrue();
Assertions.assertThat(defines.contains("__AVX2__ 1")).isTrue();
Assertions.assertThat(defines.contains("__AVX__ 1")).isTrue();
Assertions.assertThat(defines.contains("__cplusplus_winrt 201009")).isTrue();
Assertions.assertThat(defines.contains("_CPPUNWIND")).isTrue();
Assertions.assertThat(defines.contains("_M_ARM_FP")).isTrue();
Assertions.assertThat(defines.contains("_WIN32")).isTrue();
Assertions.assertThat(defines.contains("_M_IX86")).isTrue();
Assertions.assertThat(defines.contains("_M_IX86 600")).isTrue();
Assertions.assertThat(defines.contains("_M_IX86_FP 2")).isTrue();
Assertions.assertThat(defines.contains("_MSC_VER 1800")).isTrue();
Assertions.assertThat(defines.contains("_MSC_FULL_VER 180031101")).isTrue();
Expand All @@ -205,18 +205,57 @@ public void shouldHandleSpecificV140OptionsCorrectly() {
List<String> defines = config.getDefines();
assertThat(defines.size()).isEqualTo(15 + 6);
ValidateDefaultAsserts(defines);
Assertions.assertThat(defines.contains("__AVX2__")).isTrue();
Assertions.assertThat(defines.contains("__AVX__")).isTrue();
Assertions.assertThat(defines.contains("__AVX2__ 1")).isTrue();
Assertions.assertThat(defines.contains("__AVX__ 1")).isTrue();
Assertions.assertThat(defines.contains("__cplusplus_winrt 201009")).isTrue();
Assertions.assertThat(defines.contains("_CPPUNWIND")).isTrue();
Assertions.assertThat(defines.contains("_M_ARM_FP")).isTrue();
Assertions.assertThat(defines.contains("_M_IX86")).isTrue();
Assertions.assertThat(defines.contains("_M_IX86 600")).isTrue();
Assertions.assertThat(defines.contains("_M_IX86_FP 2")).isTrue();
Assertions.assertThat(defines.contains("_MSC_VER 1900")).isTrue();
Assertions.assertThat(defines.contains("_MSC_FULL_VER 190022816")).isTrue();
Assertions.assertThat(defines.contains("_ATL_VER 0x0C00")).isTrue();
Assertions.assertThat(defines.contains("_MSC_FULL_VER 190024215")).isTrue();
Assertions.assertThat(defines.contains("_ATL_VER 0x0E00")).isTrue();
}

@Test
public void shouldHandleSpecificV141x86OptionsCorrectly() {
CxxConfiguration config = new CxxConfiguration();
config.setBaseDir(".");
List<File> files = new ArrayList<>();
files.add(new File("src/test/resources/compiler/platformToolsetv141x86.txt"));
config.setCompilationPropertiesWithBuildLog(files, vcKey, vcCharSet);

assertThat(config.getIncludeDirectories().size()).isEqualTo(0);
List<String> defines = config.getDefines();
assertThat(defines.size()).isEqualTo(15 + 12);
ValidateDefaultAsserts(defines);
Assertions.assertThat(defines.contains("_M_IX86 600")).isTrue();
Assertions.assertThat(defines.contains("__cplusplus 199711L")).isTrue();
Assertions.assertThat(defines.contains("_MSC_VER 1910")).isTrue();
Assertions.assertThat(defines.contains("_MSC_FULL_VER 191024629")).isTrue();
// check atldef.h for _ATL_VER
Assertions.assertThat(defines.contains("_ATL_VER 0x0E00")).isTrue();
}

@Test
public void shouldHandleSpecificV141x64OptionsCorrectly() {
CxxConfiguration config = new CxxConfiguration();
config.setBaseDir(".");
List<File> files = new ArrayList<>();
files.add(new File("src/test/resources/compiler/platformToolsetv141x64.txt"));
config.setCompilationPropertiesWithBuildLog(files, vcKey, vcCharSet);

assertThat(config.getIncludeDirectories().size()).isEqualTo(0);
List<String> defines = config.getDefines();
assertThat(defines.size()).isEqualTo(15 + 14);
ValidateDefaultAsserts(defines);
Assertions.assertThat(defines.contains("_M_IX86 600")).isFalse();
Assertions.assertThat(defines.contains("__cplusplus 199711L")).isTrue();
Assertions.assertThat(defines.contains("_MSC_VER 1910")).isTrue();
Assertions.assertThat(defines.contains("_MSC_FULL_VER 191024629")).isTrue();
// check atldef.h for _ATL_VER
Assertions.assertThat(defines.contains("_ATL_VER 0x0E00")).isTrue();
}

@Test
public void shouldHandleBuildLog() {
CxxConfiguration config = new CxxConfiguration();
Expand Down
38 changes: 38 additions & 0 deletions cxx-squid/src/test/resources/compiler/platformToolsetv141x64.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Build started 11/20/2016 10:00:15 AM.
Project "C:\visual studio 2017\Projects\test_VS2017\test_VS2017.sln" on node 1 (rebuild target(s)).
ValidateSolutionConfiguration:
Building solution configuration "Release|x64".
Project "C:\visual studio 2017\Projects\test_VS2017\test_VS2017.sln" (1) is building "C:\visual studio 2017\Projects\test_VS2017\test_VS2017\test_VS2017.vcxproj" (2) on node 1 (Rebuild target(s)).
_PrepareForClean:
Deleting file "x64\Release\test_VS2017.tlog\test_VS2017.lastbuildstate".
InitializeBuildStatus:
Touching "x64\Release\test_VS2017.tlog\unsuccessfulbuild".
ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.10.24629\bin\HostX86\x64\CL.exe /c /Zi /nologo /W3 /WX- /diagnostics:classic /O2 /Oi /GL /D NDEBUG /D _CONSOLE /D _UNICODE /D UNICODE /D _AFXDLL /Gm- /EHsc /MD /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Yc"stdafx.h" /Fp"x64\Release\test_VS2017.pch" /Fo"x64\Release\\" /Fd"x64\Release\vc141.pdb" /Gd /TP /errorReport:queue stdafx.cpp
stdafx.cpp
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.10.24629\bin\HostX86\x64\CL.exe /c /Zi /nologo /W3 /WX- /diagnostics:classic /O2 /Oi /GL /D NDEBUG /D _CONSOLE /D _UNICODE /D UNICODE /D _AFXDLL /Gm- /EHsc /MD /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Yu"stdafx.h" /Fp"x64\Release\test_VS2017.pch" /Fo"x64\Release\\" /Fd"x64\Release\vc141.pdb" /Gd /TP /errorReport:queue test_VS2017.cpp
test_VS2017.cpp
ResourceCompile:
C:\Program Files (x86)\Windows Kits\10\bin\x86\rc.exe /D _UNICODE /D UNICODE /D _AFXDLL /l"0x0409" /nologo /fo"x64\Release\test_VS2017.res" test_VS2017.rc
Link:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.10.24629\bin\HostX86\x64\link.exe /ERRORREPORT:QUEUE /OUT:"C:\visual studio 2017\Projects\test_VS2017\x64\Release\test_VS2017.exe" /INCREMENTAL:NO /NOLOGO /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /manifestinput:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\\Common7\IDE\VC\VCTargets\..\..\..\..\VC\Tools\MSVC\14.10.24629\Include\Manifest\dpiaware.manifest" /DEBUG /PDB:"C:\visual studio 2017\Projects\test_VS2017\x64\Release\test_VS2017.pdb" /SUBSYSTEM:CONSOLE /OPT:REF /OPT:ICF /LTCG:incremental /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\visual studio 2017\Projects\test_VS2017\x64\Release\test_VS2017.lib" /MACHINE:X64 x64\Release\test_VS2017.res
x64\Release\stdafx.obj
x64\Release\test_VS2017.obj
Generating code
All 118 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
Finished generating code
test_VS2017.vcxproj -> C:\visual studio 2017\Projects\test_VS2017\x64\Release\test_VS2017.exe
test_VS2017.vcxproj -> C:\visual studio 2017\Projects\test_VS2017\x64\Release\test_VS2017.pdb (Full PDB)
FinalizeBuildStatus:
Deleting file "x64\Release\test_VS2017.tlog\unsuccessfulbuild".
Touching "x64\Release\test_VS2017.tlog\test_VS2017.lastbuildstate".
Done Building Project "C:\visual studio 2017\Projects\test_VS2017\test_VS2017\test_VS2017.vcxproj" (Rebuild target(s)).

Done Building Project "C:\visual studio 2017\Projects\test_VS2017\test_VS2017.sln" (rebuild target(s)).


Build succeeded.
0 Warning(s)
0 Error(s)

Time Elapsed 00:00:11.23
Loading

0 comments on commit 0b18596

Please sign in to comment.