diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index e7679a70c0c..00baa0b49b1 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -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; @@ -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; @@ -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) { @@ -1605,10 +1609,22 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a return Result::Fail; } + // TODO: conflicts with analyzeAllVsConfigs 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; diff --git a/gui/projectfile.cpp b/gui/projectfile.cpp index c6ffbea13d7..9b92f0d9184 100644 --- a/gui/projectfile.cpp +++ b/gui/projectfile.cpp @@ -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; diff --git a/lib/importproject.cpp b/lib/importproject.cpp index f7ff19e4141..51a4585e2f6 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -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(); @@ -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) { @@ -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; diff --git a/lib/importproject.h b/lib/importproject.h index 82a36cac234..68ded1a7f6d 100644 --- a/lib/importproject.h +++ b/lib/importproject.h @@ -83,7 +83,6 @@ class CPPCHECKLIB WARN_UNUSED ImportProject { // Cppcheck GUI output struct { - std::string analyzeAllVsConfigs; std::vector pathNames; std::list libraries; std::list excludedPaths; diff --git a/lib/settings.h b/lib/settings.h index deb5d094973..64e007b46ce 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -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 basePaths; diff --git a/test/cli/helloworld_test.py b/test/cli/helloworld_test.py index bef1456af6b..602cc1cb651 100644 --- a/test/cli/helloworld_test.py +++ b/test/cli/helloworld_test.py @@ -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', @@ -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', diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index 3d066e3bb77..fab73b838bb 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -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); @@ -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"};