From a0dd8536429e6fc19e3edfe479c0fa3fb7e6fa7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 13 Apr 2019 20:01:40 +0200 Subject: [PATCH] analyzing one vs config (first debug config that matches platform) --- cli/cmdlineparser.cpp | 6 ++++-- cli/cppcheckexecutor.cpp | 35 +++++++++++++++++++---------------- gui/mainwindow.cpp | 26 +------------------------- lib/importproject.cpp | 33 ++++++++++++++++++++++++++++++++- lib/importproject.h | 3 +++ 5 files changed, 59 insertions(+), 44 deletions(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 26409e55d..9df82766a 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -556,8 +556,8 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) mSettings->platform(Settings::Unix64); else if (platform == "native") mSettings->platform(Settings::Native); - else if (platform == "unspecified") - mSettings->platform(Settings::Unspecified); + else if (platform == "unspecified" || platform == "Unspecified" || platform == "") + ; else if (!mSettings->loadPlatformFile(argv[0], platform)) { std::string message("cppcheck: error: unrecognized platform: \""); message += platform; @@ -570,6 +570,8 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) projType = mSettings->project.import(mSettings->project.guiProject.projectFile, mSettings); } if (projType == ImportProject::Type::VS_SLN || projType == ImportProject::Type::VS_VCXPROJ) { + if (mSettings->project.guiProject.analyzeAllVsConfigs == "false") + mSettings->project.selectOneVsConfig(mSettings->platformType); if (!CppCheckExecutor::tryLoadLibrary(mSettings->library, argv[0], "windows.cfg")) { // This shouldn't happen normally. printMessage("cppcheck: Failed to load 'windows.cfg'. Your Cppcheck installation is broken. Please re-install."); diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 95ec505c4..b808cc989 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -877,24 +877,27 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha std::size_t processedsize = 0; unsigned int c = 0; - for (std::map::const_iterator i = _files.begin(); i != _files.end(); ++i) { - if (!_settings->library.markupFile(i->first) - || !_settings->library.processMarkupAfterCode(i->first)) { - returnValue += cppcheck.check(i->first); - processedsize += i->second; - if (!settings.quiet) - reportStatus(c + 1, _files.size(), processedsize, totalfilesize); - c++; + if (settings.project.fileSettings.empty()) { + for (std::map::const_iterator i = _files.begin(); i != _files.end(); ++i) { + if (!_settings->library.markupFile(i->first) + || !_settings->library.processMarkupAfterCode(i->first)) { + returnValue += cppcheck.check(i->first); + processedsize += i->second; + if (!settings.quiet) + reportStatus(c + 1, _files.size(), processedsize, totalfilesize); + c++; + } } - } + } else { - // filesettings - c = 0; - for (const ImportProject::FileSettings &fs : settings.project.fileSettings) { - returnValue += cppcheck.check(fs); - ++c; - if (!settings.quiet) - reportStatus(c, settings.project.fileSettings.size(), c, settings.project.fileSettings.size()); + // filesettings + c = 0; + for (const ImportProject::FileSettings &fs : settings.project.fileSettings) { + returnValue += cppcheck.check(fs); + ++c; + if (!settings.quiet) + reportStatus(c, settings.project.fileSettings.size(), c, settings.project.fileSettings.size()); + } } // second loop to parse all markup files which may not work until all diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 2d61a6509..c2b8c8b13 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -405,32 +405,8 @@ void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLibrary, cons p.ignorePaths(v); if (!mProjectFile->getAnalyzeAllVsConfigs()) { - std::set filenames; Settings::PlatformType platform = (Settings::PlatformType) mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt(); - for (std::list::iterator it = p.fileSettings.begin(); it != p.fileSettings.end();) { - if (it->cfg.empty()) { - ++it; - continue; - } - const ImportProject::FileSettings &fs = *it; - bool remove = false; - if (fs.cfg.compare(0,5,"Debug") != 0) - remove = true; - if (platform == Settings::Win64 && fs.platformType != platform) - remove = true; - else if ((platform == Settings::Win32A || platform == Settings::Win32W) && fs.platformType == Settings::Win64) - remove = true; - else if (fs.platformType != Settings::Win64 && platform == Settings::Win64) - remove = true; - else if (filenames.find(fs.filename) != filenames.end()) - remove = true; - if (remove) { - it = p.fileSettings.erase(it); - } else { - filenames.insert(fs.filename); - ++it; - } - } + p.selectOneVsConfig(platform); } } else { enableProjectActions(false); diff --git a/lib/importproject.cpp b/lib/importproject.cpp index 5db57c2dc..dba25ed6b 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -1003,6 +1003,8 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti std::list suppressions; Settings temp; + guiProject.analyzeAllVsConfigs = false; + for (const tinyxml2::XMLElement *node = rootnode->FirstChildElement(); node; node = node->NextSiblingElement()) { if (strcmp(node->Name(), RootPathName) == 0 && node->Attribute(RootPathNameAttrib)) temp.basePaths.push_back(joinRelativePath(path, node->Attribute(RootPathNameAttrib))); @@ -1030,7 +1032,7 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti else if (strcmp(node->Name(), PlatformElementName) == 0) guiProject.platform = node->GetText(); else if (strcmp(node->Name(), AnalyzeAllVsConfigsElementName) == 0) - ; // FIXME: Write some warning + guiProject.analyzeAllVsConfigs = node->GetText(); else if (strcmp(node->Name(), AddonsElementName) == 0) temp.addons = readXmlStringList(node, "", AddonElementName, nullptr); else if (strcmp(node->Name(), TagsElementName) == 0) @@ -1061,3 +1063,32 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti settings->maxCtuDepth = temp.maxCtuDepth; return true; } + +void ImportProject::selectOneVsConfig(Settings::PlatformType platform) +{ + std::set filenames; + for (std::list::iterator it = fileSettings.begin(); it != fileSettings.end();) { + if (it->cfg.empty()) { + ++it; + continue; + } + const ImportProject::FileSettings &fs = *it; + bool remove = false; + if (fs.cfg.compare(0,5,"Debug") != 0) + remove = true; + if (platform == Settings::Win64 && fs.platformType != platform) + remove = true; + else if ((platform == Settings::Win32A || platform == Settings::Win32W) && fs.platformType == Settings::Win64) + remove = true; + else if (fs.platformType != Settings::Win64 && platform == Settings::Win64) + remove = true; + else if (filenames.find(fs.filename) != filenames.end()) + remove = true; + if (remove) { + it = fileSettings.erase(it); + } else { + filenames.insert(fs.filename); + ++it; + } + } +} diff --git a/lib/importproject.h b/lib/importproject.h index a3dc4ea72..bf311951c 100644 --- a/lib/importproject.h +++ b/lib/importproject.h @@ -82,8 +82,11 @@ public: }; std::list fileSettings; + void selectOneVsConfig(cppcheck::Platform::PlatformType platform); + // Cppcheck GUI output struct { + std::string analyzeAllVsConfigs; std::vector pathNames; std::list libraries; std::list excludedPaths;