Skip to content

fixed #13793 - added CLI option --{no-}analyze-all-vs-configs #7480

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 2 commits into from
May 6, 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: 18 additions & 2 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,9 @@ 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)
mSettings.analyzeAllVsConfigs = true;

// Check configuration
else if (std::strcmp(argv[i], "--check-config") == 0)
mSettings.checkConfiguration = true;
Expand Down Expand Up @@ -1018,6 +1021,9 @@ 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)
mSettings.analyzeAllVsConfigs = false;

else if (std::strcmp(argv[i], "--no-check-headers") == 0)
mSettings.checkHeaders = false;

Expand Down Expand Up @@ -1202,8 +1208,6 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
}
}
if (projectType == ImportProject::Type::VS_SLN || projectType == ImportProject::Type::VS_VCXPROJ) {
if (project.guiProject.analyzeAllVsConfigs == "false")
project.selectOneVsConfig(mSettings.platform.type);
mSettings.libraries.emplace_back("windows");
}
if (projectType == ImportProject::Type::MISSING) {
Expand Down Expand Up @@ -1605,10 +1609,22 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
return Result::Fail;
}

// TODO: conflicts with analyzeAllVsConfigs
Copy link
Collaborator Author

@firewave firewave Apr 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have like four different ways to select a Visual Studio configuration from the GUI and CLI. At least the code doing it should be unified (if possible). But something for later after the import/CLI handling has been cleaned up and has better test coverage.

Copy link
Owner

@danmar danmar May 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have like four different ways to select a Visual Studio configuration from the GUI and CLI.

ouch

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so as far as I see this will not be an "official" option to start with.. i.e. not shown in the --help output.. which will make it easier to unify later.

if (!vsConfig.empty()) {
// TODO: bail out when this does nothing
project.ignoreOtherConfigs(vsConfig);
}

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;
}

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

if (!mSettings.buildDir.empty() && !Path::isDirectory(mSettings.buildDir)) {
mLogger.printError("Directory '" + mSettings.buildDir + "' specified by --cppcheck-build-dir argument has to be existent.");
return Result::Fail;
Expand Down
2 changes: 1 addition & 1 deletion gui/projectfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void ProjectFile::clear()
mSuppressions.clear();
mAddons.clear();
mClangAnalyzer = mClangTidy = false;
mAnalyzeAllVsConfigs = false;
mAnalyzeAllVsConfigs = false; // TODO: defaults to true if loading a GUI project via CLI
mCheckHeaders = true;
mCheckUnusedTemplates = true;
mInlineSuppression = true;
Expand Down
5 changes: 2 additions & 3 deletions lib/importproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1262,8 +1262,6 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings &setti
// default to --check-level=normal for import for now
temp.setCheckLevel(Settings::CheckLevel::normal);

guiProject.analyzeAllVsConfigs.clear();

// TODO: this should support all available command-line options
for (const tinyxml2::XMLElement *node = rootnode->FirstChildElement(); node; node = node->NextSiblingElement()) {
const char* name = node->Name();
Expand Down Expand Up @@ -1318,7 +1316,7 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings &setti
else if (strcmp(name, CppcheckXml::PlatformElementName) == 0)
guiProject.platform = empty_if_null(node->GetText());
else if (strcmp(name, CppcheckXml::AnalyzeAllVsConfigsElementName) == 0)
guiProject.analyzeAllVsConfigs = empty_if_null(node->GetText());
temp.analyzeAllVsConfigs = std::string(empty_if_null(node->GetText())) != "false";
else if (strcmp(name, CppcheckXml::Parser) == 0)
temp.clang = true;
else if (strcmp(name, CppcheckXml::AddonsElementName) == 0) {
Expand Down Expand Up @@ -1399,6 +1397,7 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings &setti
settings.addons = temp.addons;
settings.clang = temp.clang;
settings.clangTidy = temp.clangTidy;
settings.analyzeAllVsConfigs = temp.analyzeAllVsConfigs;

if (!settings.premiumArgs.empty())
settings.premiumArgs += temp.premiumArgs;
Expand Down
1 change: 0 additions & 1 deletion lib/importproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class CPPCHECKLIB WARN_UNUSED ImportProject {

// Cppcheck GUI output
struct {
std::string analyzeAllVsConfigs;
std::vector<std::string> pathNames;
std::list<std::string> libraries;
std::list<std::string> excludedPaths;
Expand Down
3 changes: 3 additions & 0 deletions lib/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ class CPPCHECKLIB WARN_UNUSED Settings {
/** @brief Path to the python interpreter to be used to run addons. */
std::string addonPython;

/** @brief Analyze all configuration in Visual Studio project. */
bool analyzeAllVsConfigs{true};

/** @brief Paths used as base for conversion to relative paths. */
std::vector<std::string> basePaths;

Expand Down
6 changes: 6 additions & 0 deletions test/cli/helloworld_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ def test_vs_project_local_path_select_one():
def test_vs_project_local_path_select_one_multiple():
__test_vs_project_local_path(['--project-configuration=Debug|Win32', '--project-configuration=Release|Win32'], 'Release|Win32')

def test_vs_project_local_path_no_analyze_all():
__test_vs_project_local_path(['--no-analyze-all-vs-configs'], 'Debug|Win32')

def test_vs_project_relative_path():
args = [
'--template=cppcheck1',
Expand Down Expand Up @@ -214,6 +217,9 @@ def test_cppcheck_project_local_path_select_one():
def test_cppcheck_project_local_path_select_one_multiple():
__test_cppcheck_project_local_path(['--project-configuration=Debug|Win32', '--project-configuration=Release|Win32'], 'Release|Win32')

def test_cppcheck_project_local_path_analyze_all():
__test_cppcheck_project_local_path(['--analyze-all-vs-configs'], 'Debug|Win32 Debug|x64 Release|Win32 Release|x64')

def test_cppcheck_project_relative_path():
args = [
'--template=cppcheck1',
Expand Down
24 changes: 24 additions & 0 deletions test/testcmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,9 @@ class TestCmdlineParser : public TestFixture {
TEST_CASE(clangTidyCustom);
TEST_CASE(projectConfigurationNoProject);
TEST_CASE(projectConfigurationEmpty);
TEST_CASE(analyzeAllVsConfigs);
TEST_CASE(noAnalyzeAllVsConfigs);
TEST_CASE(noAnalyzeAllVsConfigs2);

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

void analyzeAllVsConfigs() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--analyze-all-vs-configs", "file.cpp"};
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
ASSERT_EQUALS(true, settings->analyzeAllVsConfigs);
}

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());
}

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());
}

void ignorepaths1() {
REDIRECT;
const char * const argv[] = {"cppcheck", "-isrc", "file.cpp"};
Expand Down
Loading