Skip to content

Commit b8245c6

Browse files
authored
fix #13948: CmdLineParser: Don't warn when --no-analyze-all-vs-configs is set in Cppcheck project file. (danmar#7608)
1 parent 47a9df5 commit b8245c6

File tree

4 files changed

+40
-8
lines changed

4 files changed

+40
-8
lines changed

cli/cmdlineparser.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,10 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
550550
else if (std::strncmp(argv[i],"--addon-python=", 15) == 0)
551551
mSettings.addonPython.assign(argv[i]+15);
552552

553-
else if (std::strcmp(argv[i],"--analyze-all-vs-configs") == 0)
553+
else if (std::strcmp(argv[i],"--analyze-all-vs-configs") == 0) {
554554
mSettings.analyzeAllVsConfigs = true;
555+
mAnalyzeAllVsConfigsSetOnCmdLine = true;
556+
}
555557

556558
// Check configuration
557559
else if (std::strcmp(argv[i], "--check-config") == 0)
@@ -1036,8 +1038,10 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
10361038
return Result::Fail;
10371039
}
10381040

1039-
else if (std::strcmp(argv[i],"--no-analyze-all-vs-configs") == 0)
1041+
else if (std::strcmp(argv[i],"--no-analyze-all-vs-configs") == 0) {
10401042
mSettings.analyzeAllVsConfigs = false;
1043+
mAnalyzeAllVsConfigsSetOnCmdLine = true;
1044+
}
10411045

10421046
else if (std::strcmp(argv[i], "--no-check-headers") == 0)
10431047
mSettings.checkHeaders = false;
@@ -1639,12 +1643,14 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
16391643

16401644
if (!mSettings.analyzeAllVsConfigs) {
16411645
if (projectType != ImportProject::Type::VS_SLN && projectType != ImportProject::Type::VS_VCXPROJ) {
1642-
mLogger.printError("--no-analyze-all-vs-configs has no effect - no Visual Studio project provided.");
1643-
return Result::Fail;
1646+
if (mAnalyzeAllVsConfigsSetOnCmdLine) {
1647+
mLogger.printError("--no-analyze-all-vs-configs has no effect - no Visual Studio project provided.");
1648+
return Result::Fail;
1649+
}
1650+
} else {
1651+
// TODO: bail out when this does nothing
1652+
project.selectOneVsConfig(mSettings.platform.type);
16441653
}
1645-
1646-
// TODO: bail out when this does nothing
1647-
project.selectOneVsConfig(mSettings.platform.type);
16481654
}
16491655

16501656
if (!mSettings.buildDir.empty() && !Path::isDirectory(mSettings.buildDir)) {

cli/cmdlineparser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ class CmdLineParser {
174174
std::vector<std::string> mIgnoredPaths;
175175
Settings &mSettings;
176176
Suppressions &mSuppressions;
177+
bool mAnalyzeAllVsConfigsSetOnCmdLine = false;
178+
179+
friend class TestCmdlineParser;
177180
};
178181

179182
/// @}

test/cli/more-projects_test.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,4 +896,24 @@ def test_project_file_nested(tmp_path):
896896
'cppcheck: error: nested Cppcheck GUI projects are not supported.'
897897
]
898898

899-
assert_cppcheck(args, ec_exp=1, err_exp=[], out_exp=out_lines)
899+
assert_cppcheck(args, ec_exp=1, err_exp=[], out_exp=out_lines)
900+
901+
902+
def test_project_file_no_analyze_all_vs_configs(tmp_path):
903+
test_file = tmp_path / 'test.c'
904+
with open(test_file, 'wt'):
905+
pass
906+
907+
project_path = tmp_path / 'project.cppcheck'
908+
with open(project_path, 'wt') as f:
909+
f.write(
910+
"""<project>
911+
<analyze-all-vs-configs>false</analyze-all-vs-configs>
912+
<paths>
913+
<dir name="."/>
914+
</paths>
915+
</project>""")
916+
917+
ret, stdout, stderr = cppcheck(['--project=' + str(project_path)])
918+
assert ret == 0, stdout
919+
assert stderr == ''

test/testcmdlineparser.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3138,20 +3138,23 @@ class TestCmdlineParser : public TestFixture {
31383138
const char * const argv[] = {"cppcheck", "--analyze-all-vs-configs", "file.cpp"};
31393139
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
31403140
ASSERT_EQUALS(true, settings->analyzeAllVsConfigs);
3141+
ASSERT(parser->mAnalyzeAllVsConfigsSetOnCmdLine);
31413142
}
31423143

31433144
void noAnalyzeAllVsConfigs() {
31443145
REDIRECT;
31453146
const char * const argv[] = {"cppcheck", "--no-analyze-all-vs-configs", "file.cpp"};
31463147
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Fail, parseFromArgs(argv));
31473148
ASSERT_EQUALS("cppcheck: error: --no-analyze-all-vs-configs has no effect - no Visual Studio project provided.\n", logger->str());
3149+
ASSERT(parser->mAnalyzeAllVsConfigsSetOnCmdLine);
31483150
}
31493151

31503152
void noAnalyzeAllVsConfigs2() {
31513153
REDIRECT;
31523154
const char * const argv[] = {"cppcheck", "--analyze-all-vs-configs", "--no-analyze-all-vs-configs", "file.cpp"};
31533155
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Fail, parseFromArgs(argv));
31543156
ASSERT_EQUALS("cppcheck: error: --no-analyze-all-vs-configs has no effect - no Visual Studio project provided.\n", logger->str());
3157+
ASSERT(parser->mAnalyzeAllVsConfigsSetOnCmdLine);
31553158
}
31563159

31573160
void debugSymdb() {

0 commit comments

Comments
 (0)