-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1668 from rudolfgrauberger/vc-log-improvements
Improves Visual studio/MSBUILD log file analysis
- Loading branch information
Showing
6 changed files
with
131 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
cxx-squid/src/test/java/org/sonar/cxx/CxxVCppBuildLogParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* Sonar C++ Plugin (Community) | ||
* Copyright (C) 2010-2019 SonarOpenCommunity | ||
* http://github.com/SonarOpenCommunity/sonar-cxx | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
package org.sonar.cxx; | ||
|
||
import org.assertj.core.api.SoftAssertions; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.sonar.api.internal.apachecommons.lang.SystemUtils; | ||
|
||
import java.io.File; | ||
import java.util.*; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* These tests ensure that the relative paths in the INCLUDES are correctly converted to absolute paths. | ||
* The project directory is used as the base directory. | ||
* The project directory is extracted regardless of the language of the log file. | ||
* | ||
* @author rudolfgrauberger | ||
*/ | ||
public class CxxVCppBuildLogParserTest { | ||
|
||
private static final String VC_CHARSET = "UTF8"; | ||
|
||
public static final String OVERALLINCLUDEKEY = "CxxOverallInclude"; | ||
public static final String OVERALLDEFINEKEY = "CxxOverallDefine"; | ||
public static final String REFERENCE_DETAILED_LOG = "src/test/resources/logfile/msbuild-detailed-en.txt"; | ||
public static final String UNIQUE_FILE = "D:\\Development\\Source\\Cpp\\Dummy\\src\\main.cpp"; | ||
|
||
@BeforeClass | ||
public static void init() | ||
{ | ||
org.junit.Assume.assumeTrue(SystemUtils.IS_OS_WINDOWS); | ||
} | ||
|
||
@Test | ||
public void relativeIncludesFromReferenceLog() { | ||
|
||
List<String> includes = getIncludesForReferenceLogFile(); | ||
|
||
SoftAssertions softly = new SoftAssertions(); | ||
|
||
// Absolute path | ||
softly.assertThat(includes).contains("D:\\Development\\Source\\ThirdParty\\VS2017\\Firebird-2.5.8\\include"); | ||
// Relative paths | ||
softly.assertThat(includes).contains("D:\\Development\\Source\\ThirdParty\\VS2017\\Boost-1.67.0"); | ||
softly.assertThat(includes).contains("D:\\Development\\Source\\Cpp\\Dummy\\includes"); | ||
softly.assertThat(includes).contains("D:\\Development\\Source\\Cpp\\Dummy\\release"); | ||
softly.assertThat(includes).hasSize(4); | ||
softly.assertAll(); | ||
} | ||
|
||
@Test | ||
public void relativeIncludesFromGermanLog() { | ||
|
||
List<String> refIncludes = getIncludesForReferenceLogFile(); | ||
List<String> includes = getIncludesForUniqueFile("src/test/resources/logfile/msbuild-detailed-de.txt"); | ||
|
||
SoftAssertions softly = new SoftAssertions(); | ||
|
||
softly.assertThat(includes).containsExactlyInAnyOrderElementsOf(refIncludes); | ||
softly.assertAll(); | ||
} | ||
|
||
@Test | ||
public void relativeIncludesFromFrenchLog() { | ||
|
||
List<String> refIncludes = getIncludesForReferenceLogFile(); | ||
List<String> includes = getIncludesForUniqueFile("src/test/resources/logfile/msbuild-detailed-fr.txt"); | ||
|
||
SoftAssertions softly = new SoftAssertions(); | ||
|
||
softly.assertThat(includes).containsExactlyInAnyOrderElementsOf(refIncludes); | ||
softly.assertAll(); | ||
} | ||
|
||
private List<String> getIncludesForReferenceLogFile() { | ||
return getIncludesForUniqueFile(REFERENCE_DETAILED_LOG); | ||
} | ||
|
||
private List<String> getIncludesForUniqueFile(String log) { | ||
Map<String, List<String>> uniqueIncludes = new HashMap<>(); | ||
uniqueIncludes.put(OVERALLINCLUDEKEY, new ArrayList<>()); | ||
Map<String, Set<String>> uniqueDefines = new HashMap<>(); | ||
uniqueDefines.put(OVERALLDEFINEKEY, new HashSet<>()); | ||
|
||
File logFile = new File(log); | ||
|
||
CxxVCppBuildLogParser parser = new CxxVCppBuildLogParser(uniqueIncludes, uniqueDefines); | ||
parser.parseVCppLog(logFile, ".", VC_CHARSET); | ||
|
||
List<String> includes = uniqueIncludes.get(UNIQUE_FILE); | ||
return includes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Ziel "ClCompile" in Datei "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets" aus Projekt "D:\Development\Source\Cpp\Dummy\MyProject.vcxproj" (Ziel "_ClCompile" ist davon abhängig): | ||
CL-Aufgabe | ||
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\CL.exe /c /I"D:\Development\Source\ThirdParty\VS2017\Firebird-2.5.8\include" /I"..\..\ThirdParty\VS2017\Boost-1.67.0" /Iincludes /Irelease /Zi /nologo /W3 /WX- /diagnostics:classic /MP4 /Ox /Oy- /GL /D _CONSOLE /D UNICODE /D WIN32 /D _SCL_SECURE_NO_WARNINGS /D _CRT_SECURE_NO_WARNINGS /D _WIN32_WINNT=0x0600 /D WIN32_LEAN_AND_MEAN /D VC_EXTRALEAN /D BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE /D NDEBUG /Gm- /EHsc /MD /GS /Gy /arch:SSE2 /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /Fo"release\\" /Fd"release\vc141.pdb" /Gd /TP /analyze- /FC /errorReport:queue /we4700 /we4715 /we4150 -Zm200 /std:c++17 /w14265 /Zc:rvalueCast /Gw -w34100 -w34189 src\MyClass.cpp src\main.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Target "ClCompile" in file "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets" from project "D:\Development\Source\Cpp\Dummy\MyProject.vcxproj" (target "_ClCompile" depends on it): | ||
Task "CL" | ||
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\CL.exe /c /I"D:\Development\Source\ThirdParty\VS2017\Firebird-2.5.8\include" /I"..\..\ThirdParty\VS2017\Boost-1.67.0" /Iincludes /Irelease /Zi /nologo /W3 /WX- /diagnostics:classic /MP4 /Ox /Oy- /GL /D _CONSOLE /D UNICODE /D WIN32 /D _SCL_SECURE_NO_WARNINGS /D _CRT_SECURE_NO_WARNINGS /D _WIN32_WINNT=0x0600 /D WIN32_LEAN_AND_MEAN /D VC_EXTRALEAN /D BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE /D NDEBUG /Gm- /EHsc /MD /GS /Gy /arch:SSE2 /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /Fo"release\\" /Fd"release\vc141.pdb" /Gd /TP /analyze- /FC /errorReport:queue /we4700 /we4715 /we4150 -Zm200 /std:c++17 /w14265 /Zc:rvalueCast /Gw -w34100 -w34189 src\MyClass.cpp src\main.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Cible "ClCompile" dans le fichier "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets" du projet "D:\Development\Source\Cpp\Dummy\MyProject.vcxproj" (la cible "_ClCompile" en dépend) : | ||
Tâche "CL" | ||
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\CL.exe /c /I"D:\Development\Source\ThirdParty\VS2017\Firebird-2.5.8\include" /I"..\..\ThirdParty\VS2017\Boost-1.67.0" /Iincludes /Irelease /Zi /nologo /W3 /WX- /diagnostics:classic /MP4 /Ox /Oy- /GL /D _CONSOLE /D UNICODE /D WIN32 /D _SCL_SECURE_NO_WARNINGS /D _CRT_SECURE_NO_WARNINGS /D _WIN32_WINNT=0x0600 /D WIN32_LEAN_AND_MEAN /D VC_EXTRALEAN /D BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE /D NDEBUG /Gm- /EHsc /MD /GS /Gy /arch:SSE2 /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /Fo"release\\" /Fd"release\vc141.pdb" /Gd /TP /analyze- /FC /errorReport:queue /we4700 /we4715 /we4150 -Zm200 /std:c++17 /w14265 /Zc:rvalueCast /Gw -w34100 -w34189 src\MyClass.cpp src\main.cpp |