Skip to content

fix #13948: CmdLineParser: Don't warn when --no-analyze-all-vs-configs is set in Cppcheck project file. #7608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,10 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
else if (std::strncmp(argv[i],"--addon-python=", 15) == 0)
mSettings.addonPython.assign(argv[i]+15);

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

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

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

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

if (!mSettings.analyzeAllVsConfigs) {
if (projectType != ImportProject::Type::VS_SLN && projectType != ImportProject::Type::VS_VCXPROJ) {
mLogger.printError("--no-analyze-all-vs-configs has no effect - no Visual Studio project provided.");
return Result::Fail;
if (mAnalyzeAllVsConfigsSetOnCmdLine) {
mLogger.printError("--no-analyze-all-vs-configs has no effect - no Visual Studio project provided.");
return Result::Fail;
}
} else {
// TODO: bail out when this does nothing
project.selectOneVsConfig(mSettings.platform.type);
}

// TODO: bail out when this does nothing
project.selectOneVsConfig(mSettings.platform.type);
}

if (!mSettings.buildDir.empty() && !Path::isDirectory(mSettings.buildDir)) {
Expand Down
3 changes: 3 additions & 0 deletions cli/cmdlineparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ class CmdLineParser {
std::vector<std::string> mIgnoredPaths;
Settings &mSettings;
Suppressions &mSuppressions;
bool mAnalyzeAllVsConfigsSetOnCmdLine = false;

friend class TestCmdlineParser;
};

/// @}
Expand Down
22 changes: 21 additions & 1 deletion test/cli/more-projects_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,4 +896,24 @@ def test_project_file_nested(tmp_path):
'cppcheck: error: nested Cppcheck GUI projects are not supported.'
]

assert_cppcheck(args, ec_exp=1, err_exp=[], out_exp=out_lines)
assert_cppcheck(args, ec_exp=1, err_exp=[], out_exp=out_lines)


def test_project_file_no_analyze_all_vs_configs(tmp_path):
test_file = tmp_path / 'test.c'
with open(test_file, 'wt'):
pass

project_path = tmp_path / 'project.cppcheck'
with open(project_path, 'wt') as f:
f.write(
"""<project>
<analyze-all-vs-configs>false</analyze-all-vs-configs>
<paths>
<dir name="."/>
</paths>
</project>""")

ret, stdout, stderr = cppcheck(['--project=' + str(project_path)])
assert ret == 0, stdout
assert stderr == ''
3 changes: 3 additions & 0 deletions test/testcmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3138,20 +3138,23 @@ class TestCmdlineParser : public TestFixture {
const char * const argv[] = {"cppcheck", "--analyze-all-vs-configs", "file.cpp"};
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
ASSERT_EQUALS(true, settings->analyzeAllVsConfigs);
ASSERT(parser->mAnalyzeAllVsConfigsSetOnCmdLine);
}

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

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

void debugSymdb() {
Expand Down
Loading