Skip to content

Commit 3d59c29

Browse files
authored
fixed #13793 - added CLI option --{no-}analyze-all-vs-configs (danmar#7480)
1 parent 3ed376a commit 3d59c29

File tree

7 files changed

+54
-7
lines changed

7 files changed

+54
-7
lines changed

cli/cmdlineparser.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,9 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
544544
else if (std::strncmp(argv[i],"--addon-python=", 15) == 0)
545545
mSettings.addonPython.assign(argv[i]+15);
546546

547+
else if (std::strcmp(argv[i],"--analyze-all-vs-configs") == 0)
548+
mSettings.analyzeAllVsConfigs = true;
549+
547550
// Check configuration
548551
else if (std::strcmp(argv[i], "--check-config") == 0)
549552
mSettings.checkConfiguration = true;
@@ -1018,6 +1021,9 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
10181021
return Result::Fail;
10191022
}
10201023

1024+
else if (std::strcmp(argv[i],"--no-analyze-all-vs-configs") == 0)
1025+
mSettings.analyzeAllVsConfigs = false;
1026+
10211027
else if (std::strcmp(argv[i], "--no-check-headers") == 0)
10221028
mSettings.checkHeaders = false;
10231029

@@ -1202,8 +1208,6 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
12021208
}
12031209
}
12041210
if (projectType == ImportProject::Type::VS_SLN || projectType == ImportProject::Type::VS_VCXPROJ) {
1205-
if (project.guiProject.analyzeAllVsConfigs == "false")
1206-
project.selectOneVsConfig(mSettings.platform.type);
12071211
mSettings.libraries.emplace_back("windows");
12081212
}
12091213
if (projectType == ImportProject::Type::MISSING) {
@@ -1605,10 +1609,22 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
16051609
return Result::Fail;
16061610
}
16071611

1612+
// TODO: conflicts with analyzeAllVsConfigs
16081613
if (!vsConfig.empty()) {
1614+
// TODO: bail out when this does nothing
16091615
project.ignoreOtherConfigs(vsConfig);
16101616
}
16111617

1618+
if (!mSettings.analyzeAllVsConfigs) {
1619+
if (projectType != ImportProject::Type::VS_SLN && projectType != ImportProject::Type::VS_VCXPROJ) {
1620+
mLogger.printError("--no-analyze-all-vs-configs has no effect - no Visual Studio project provided.");
1621+
return Result::Fail;
1622+
}
1623+
1624+
// TODO: bail out when this does nothing
1625+
project.selectOneVsConfig(mSettings.platform.type);
1626+
}
1627+
16121628
if (!mSettings.buildDir.empty() && !Path::isDirectory(mSettings.buildDir)) {
16131629
mLogger.printError("Directory '" + mSettings.buildDir + "' specified by --cppcheck-build-dir argument has to be existent.");
16141630
return Result::Fail;

gui/projectfile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void ProjectFile::clear()
7474
mSuppressions.clear();
7575
mAddons.clear();
7676
mClangAnalyzer = mClangTidy = false;
77-
mAnalyzeAllVsConfigs = false;
77+
mAnalyzeAllVsConfigs = false; // TODO: defaults to true if loading a GUI project via CLI
7878
mCheckHeaders = true;
7979
mCheckUnusedTemplates = true;
8080
mInlineSuppression = true;

lib/importproject.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,8 +1263,6 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings &setti
12631263
// default to --check-level=normal for import for now
12641264
temp.setCheckLevel(Settings::CheckLevel::normal);
12651265

1266-
guiProject.analyzeAllVsConfigs.clear();
1267-
12681266
// TODO: this should support all available command-line options
12691267
for (const tinyxml2::XMLElement *node = rootnode->FirstChildElement(); node; node = node->NextSiblingElement()) {
12701268
const char* name = node->Name();
@@ -1319,7 +1317,7 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings &setti
13191317
else if (strcmp(name, CppcheckXml::PlatformElementName) == 0)
13201318
guiProject.platform = empty_if_null(node->GetText());
13211319
else if (strcmp(name, CppcheckXml::AnalyzeAllVsConfigsElementName) == 0)
1322-
guiProject.analyzeAllVsConfigs = empty_if_null(node->GetText());
1320+
temp.analyzeAllVsConfigs = std::string(empty_if_null(node->GetText())) != "false";
13231321
else if (strcmp(name, CppcheckXml::Parser) == 0)
13241322
temp.clang = true;
13251323
else if (strcmp(name, CppcheckXml::AddonsElementName) == 0) {
@@ -1400,6 +1398,7 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings &setti
14001398
settings.addons = temp.addons;
14011399
settings.clang = temp.clang;
14021400
settings.clangTidy = temp.clangTidy;
1401+
settings.analyzeAllVsConfigs = temp.analyzeAllVsConfigs;
14031402

14041403
if (!settings.premiumArgs.empty())
14051404
settings.premiumArgs += temp.premiumArgs;

lib/importproject.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ class CPPCHECKLIB WARN_UNUSED ImportProject {
8383

8484
// Cppcheck GUI output
8585
struct {
86-
std::string analyzeAllVsConfigs;
8786
std::vector<std::string> pathNames;
8887
std::list<std::string> libraries;
8988
std::list<std::string> excludedPaths;

lib/settings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ class CPPCHECKLIB WARN_UNUSED Settings {
123123
/** @brief Path to the python interpreter to be used to run addons. */
124124
std::string addonPython;
125125

126+
/** @brief Analyze all configuration in Visual Studio project. */
127+
bool analyzeAllVsConfigs{true};
128+
126129
/** @brief Paths used as base for conversion to relative paths. */
127130
std::vector<std::string> basePaths;
128131

test/cli/helloworld_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ def test_vs_project_local_path_select_one():
168168
def test_vs_project_local_path_select_one_multiple():
169169
__test_vs_project_local_path(['--project-configuration=Debug|Win32', '--project-configuration=Release|Win32'], 'Release|Win32')
170170

171+
def test_vs_project_local_path_no_analyze_all():
172+
__test_vs_project_local_path(['--no-analyze-all-vs-configs'], 'Debug|Win32')
173+
171174
def test_vs_project_relative_path():
172175
args = [
173176
'--template=cppcheck1',
@@ -214,6 +217,9 @@ def test_cppcheck_project_local_path_select_one():
214217
def test_cppcheck_project_local_path_select_one_multiple():
215218
__test_cppcheck_project_local_path(['--project-configuration=Debug|Win32', '--project-configuration=Release|Win32'], 'Release|Win32')
216219

220+
def test_cppcheck_project_local_path_analyze_all():
221+
__test_cppcheck_project_local_path(['--analyze-all-vs-configs'], 'Debug|Win32 Debug|x64 Release|Win32 Release|x64')
222+
217223
def test_cppcheck_project_relative_path():
218224
args = [
219225
'--template=cppcheck1',

test/testcmdlineparser.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,9 @@ class TestCmdlineParser : public TestFixture {
452452
TEST_CASE(clangTidyCustom);
453453
TEST_CASE(projectConfigurationNoProject);
454454
TEST_CASE(projectConfigurationEmpty);
455+
TEST_CASE(analyzeAllVsConfigs);
456+
TEST_CASE(noAnalyzeAllVsConfigs);
457+
TEST_CASE(noAnalyzeAllVsConfigs2);
455458

456459
TEST_CASE(ignorepaths1);
457460
TEST_CASE(ignorepaths2);
@@ -3082,6 +3085,27 @@ class TestCmdlineParser : public TestFixture {
30823085
ASSERT_EQUALS("cppcheck: error: --project-configuration parameter is empty.\n", logger->str());
30833086
}
30843087

3088+
void analyzeAllVsConfigs() {
3089+
REDIRECT;
3090+
const char * const argv[] = {"cppcheck", "--analyze-all-vs-configs", "file.cpp"};
3091+
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
3092+
ASSERT_EQUALS(true, settings->analyzeAllVsConfigs);
3093+
}
3094+
3095+
void noAnalyzeAllVsConfigs() {
3096+
REDIRECT;
3097+
const char * const argv[] = {"cppcheck", "--no-analyze-all-vs-configs", "file.cpp"};
3098+
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Fail, parseFromArgs(argv));
3099+
ASSERT_EQUALS("cppcheck: error: --no-analyze-all-vs-configs has no effect - no Visual Studio project provided.\n", logger->str());
3100+
}
3101+
3102+
void noAnalyzeAllVsConfigs2() {
3103+
REDIRECT;
3104+
const char * const argv[] = {"cppcheck", "--analyze-all-vs-configs", "--no-analyze-all-vs-configs", "file.cpp"};
3105+
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Fail, parseFromArgs(argv));
3106+
ASSERT_EQUALS("cppcheck: error: --no-analyze-all-vs-configs has no effect - no Visual Studio project provided.\n", logger->str());
3107+
}
3108+
30853109
void ignorepaths1() {
30863110
REDIRECT;
30873111
const char * const argv[] = {"cppcheck", "-isrc", "file.cpp"};

0 commit comments

Comments
 (0)