Skip to content

Commit c790d43

Browse files
committed
refactor importing of visual studio files
1 parent 2e19539 commit c790d43

31 files changed

Lines changed: 1122 additions & 566 deletions

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ test/testfunctions.o: test/testfunctions.cpp lib/check.h lib/checkers.h lib/chec
819819
test/testgarbage.o: test/testgarbage.cpp lib/check.h lib/checkers.h lib/checks.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/smallvector.h lib/standards.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h
820820
$(CXX) ${INCLUDE_FOR_TEST} ${CFLAGS_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testgarbage.cpp
821821

822-
test/testimportproject.o: test/testimportproject.cpp externals/tinyxml2/tinyxml2.h lib/check.h lib/checkers.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h lib/xml.h test/fixture.h test/redirect.h
822+
test/testimportproject.o: test/testimportproject.cpp lib/check.h lib/checkers.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h test/fixture.h test/redirect.h
823823
$(CXX) ${INCLUDE_FOR_TEST} ${CFLAGS_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testimportproject.cpp
824824

825825
test/testincompletestatement.o: test/testincompletestatement.cpp lib/check.h lib/checkers.h lib/checkimpl.h lib/checkother.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/standards.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h test/helpers.h

lib/importproject.cpp

Lines changed: 566 additions & 488 deletions
Large diffs are not rendered by default.

lib/importproject.h

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636

3737
class Settings;
3838
struct Suppressions;
39-
namespace tinyxml2 {
40-
class XMLDocument;
41-
}
4239

4340
/// @addtogroup Core
4441
/// @{
@@ -56,11 +53,14 @@ namespace cppcheck {
5653
}
5754
}
5855

56+
using VariablesMap = std::map<std::string, std::string, cppcheck::stricmp>;
57+
5958
/**
6059
* @brief Importing project settings.
6160
*/
6261
class CPPCHECKLIB WARN_UNUSED ImportProject {
6362
public:
63+
6464
enum class Type : std::uint8_t {
6565
NONE,
6666
UNKNOWN,
@@ -76,7 +76,7 @@ class CPPCHECKLIB WARN_UNUSED ImportProject {
7676

7777
protected:
7878
static void fsSetDefines(FileSettings& fs, std::string defs);
79-
static void fsSetIncludePaths(FileSettings& fs, const std::string &basepath, const std::list<std::string> &in, std::map<std::string, std::string, cppcheck::stricmp> &variables);
79+
static void fsSetIncludePaths(FileSettings& fs, const std::string &basepath, const std::list<std::string> &in, VariablesMap &variables);
8080

8181
public:
8282
std::list<FileSettings> fileSettings;
@@ -106,28 +106,22 @@ class CPPCHECKLIB WARN_UNUSED ImportProject {
106106
void ignoreOtherConfigs(const std::string &cfg);
107107

108108
Type import(const std::string &filename, Settings *settings=nullptr, Suppressions *supprs=nullptr);
109+
109110
protected:
110111
bool importCompileCommands(std::istream &istr);
111112
bool importCppcheckGuiProject(std::istream &istr, Settings &settings, Suppressions &supprs);
112113
static std::string collectArgs(const std::string &cmd, std::vector<std::string> &args);
113114
void setRelativePaths(const std::string &filename);
114115

115-
struct SharedItemsProject {
116-
bool successful = false;
117-
std::string pathToProjectFile;
118-
std::vector<std::string> includePaths;
119-
std::vector<std::string> sourceFiles;
120-
};
116+
VariablesMap mVariables;
121117

122-
bool importVcxproj(const std::string &filename, std::map<std::string, std::string, cppcheck::stricmp> &variables, const std::string &additionalIncludeDirectories, const std::vector<std::string> &fileFilters, std::vector<SharedItemsProject> &cache);
123-
bool importVcxproj(const std::string &filename, const tinyxml2::XMLDocument &doc, std::map<std::string, std::string, cppcheck::stricmp> &variables, const std::string &additionalIncludeDirectories, const std::vector<std::string> &fileFilters, std::vector<SharedItemsProject> &cache);
118+
bool importVcxproj(const std::string &filename, VariablesMap &variables, const std::vector<std::string> &fileFilters);
124119

125120
private:
126121
static void parseArgs(FileSettings &fs, const std::vector<std::string> &args);
127122

128123
bool importSln(std::istream &istr, const std::string &path, const std::vector<std::string> &fileFilters);
129124
bool importSlnx(const std::string& filename, const std::vector<std::string>& fileFilters);
130-
SharedItemsProject importVcxitems(const std::string &filename, const std::vector<std::string> &fileFilters, std::vector<SharedItemsProject> &cache);
131125
bool importBcb6Prj(const std::string &projectFilename);
132126

133127
std::string mPath;

test/cli/proj2_test.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
'x = 3 / 0;\n' +
1919
' ^\n') % os.path.join('b', 'b.c')
2020

21+
def __get_lines(s):
22+
# file order is not guaranteed when multiple jobs are used (TEST_CPPCHECK_INJECT_J) so
23+
# compare output order-independently
24+
return sorted(s.split('\n'))
25+
2126
def __create_compile_commands(proj_dir):
2227
proj_dir = str(proj_dir)
2328
j = [{'directory': os.path.join(proj_dir, 'a'), 'command': 'gcc -c a.c', 'file': 'a.c'},
@@ -152,7 +157,7 @@ def test_gui_project_loads_relative_vs_solution_2(tmp_path):
152157
create_gui_project_file(os.path.join(tmp_path, 'test.cppcheck'), root_path='proj2', import_project='proj2/proj2.sln')
153158
ret, stdout, stderr = cppcheck(['--project=test.cppcheck'], cwd=tmp_path)
154159
assert ret == 0, stdout
155-
assert stderr == __ERR_A + __ERR_B
160+
assert __get_lines(stderr) == __get_lines(__ERR_A + __ERR_B)
156161

157162
def test_gui_project_loads_relative_vs_solution_with_exclude(tmp_path):
158163
proj_dir = tmp_path / 'proj2'
@@ -170,4 +175,4 @@ def test_gui_project_loads_absolute_vs_solution_2(tmp_path):
170175
import_project=os.path.join(proj_dir, 'proj2.sln'))
171176
ret, stdout, stderr = cppcheck(['--project=test.cppcheck'], cwd=tmp_path)
172177
assert ret == 0, stdout
173-
assert stderr == __ERR_A + __ERR_B
178+
assert __get_lines(stderr) == __get_lines(__ERR_A + __ERR_B)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|x64">
5+
<Configuration>Debug</Configuration>
6+
<Platform>x64</Platform>
7+
</ProjectConfiguration>
8+
</ItemGroup>
9+
<PropertyGroup Label="Globals">
10+
<ProjectGuid>{a1a1a1a1-a1a1-a1a1-a1a1-a1a1a1a1a1a1}</ProjectGuid>
11+
<RootNamespace>ProjA</RootNamespace>
12+
</PropertyGroup>
13+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
14+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
15+
<ConfigurationType>Application</ConfigurationType>
16+
<PlatformToolset>v143</PlatformToolset>
17+
</PropertyGroup>
18+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
19+
<!-- Pulls in shared/shared.props, which itself pulls in common/common.props -->
20+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
21+
<Import Project="$(MSBuildThisFileDirectory)..\shared\shared.props" />
22+
</ImportGroup>
23+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
24+
<ClCompile>
25+
<PreprocessorDefinitions>PROJA_DEFINE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
26+
</ClCompile>
27+
</ItemDefinitionGroup>
28+
<ItemGroup>
29+
<ClCompile Include="a.cpp" />
30+
</ItemGroup>
31+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
32+
</Project>

test/cli/props-dirs/ProjA/a.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "common.h"
2+
3+
#ifndef COMMON_H_INCLUDED_MARKER
4+
#error "common.h was not found - AdditionalIncludeDirectories from common.props did not resolve"
5+
#endif
6+
7+
int main()
8+
{
9+
int x = 1;
10+
return x / 0;
11+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|x64">
5+
<Configuration>Debug</Configuration>
6+
<Platform>x64</Platform>
7+
</ProjectConfiguration>
8+
</ItemGroup>
9+
<PropertyGroup Label="Globals">
10+
<ProjectGuid>{b2b2b2b2-b2b2-b2b2-b2b2-b2b2b2b2b2b2}</ProjectGuid>
11+
<RootNamespace>ProjB</RootNamespace>
12+
</PropertyGroup>
13+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
14+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
15+
<ConfigurationType>Application</ConfigurationType>
16+
<PlatformToolset>v143</PlatformToolset>
17+
</PropertyGroup>
18+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
19+
<!-- Imports common/common.props DIRECTLY - does NOT go through shared/shared.props.
20+
Must NOT see PROJA_DEFINE or SHARED_DEFINE from ProjA, which is processed first
21+
in the same solution (regression coverage for the mVariables cross-project leak). -->
22+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
23+
<Import Project="$(MSBuildThisFileDirectory)..\common\common.props" />
24+
</ImportGroup>
25+
<ItemGroup>
26+
<ClCompile Include="b.cpp" />
27+
</ItemGroup>
28+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
29+
</Project>

test/cli/props-dirs/ProjB/b.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "common.h"
2+
3+
#ifndef COMMON_H_INCLUDED_MARKER
4+
#error "common.h was not found - AdditionalIncludeDirectories from common.props did not resolve"
5+
#endif
6+
7+
int main()
8+
{
9+
int y = 2;
10+
return y / 0;
11+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#ifndef COMMON_H_INCLUDED_MARKER
2+
#define COMMON_H_INCLUDED_MARKER
3+
#endif
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<!-- Imported from both ProjA (indirectly, via shared/shared.props) and ProjB (directly).
4+
AdditionalIncludeDirectories uses $(MSBuildThisFileDirectory) to prove it resolves to
5+
this file's own directory (common/) rather than to whichever project imported it. -->
6+
<ItemDefinitionGroup>
7+
<ClCompile>
8+
<PreprocessorDefinitions>COMMON_DEFINE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
9+
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
10+
<LanguageStandard>stdcpp17</LanguageStandard>
11+
</ClCompile>
12+
</ItemDefinitionGroup>
13+
</Project>

0 commit comments

Comments
 (0)