forked from qt-creator/qt-creator
CppCheck: Use new settings pattern
Change-Id: Ia2de8e684690ab7bfbdcf7ba417df1f2174433de Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/variablechooser.h>
|
||||
|
||||
#include <coreplugin/dialogs/ioptionspage.h>
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <debugger/analyzer/analyzericons.h>
|
||||
@@ -25,14 +26,16 @@ using namespace Utils;
|
||||
|
||||
namespace Cppcheck::Internal {
|
||||
|
||||
CppcheckOptions::CppcheckOptions()
|
||||
CppcheckSettings &settings()
|
||||
{
|
||||
static CppcheckSettings theSettings;
|
||||
return theSettings;
|
||||
}
|
||||
|
||||
CppcheckSettings::CppcheckSettings()
|
||||
{
|
||||
setId(Constants::OPTIONS_PAGE_ID);
|
||||
setDisplayName(Tr::tr("Cppcheck"));
|
||||
setCategory("T.Analyzer");
|
||||
setDisplayCategory(::Debugger::Tr::tr("Analyzer"));
|
||||
setCategoryIconPath(Analyzer::Icons::SETTINGSCATEGORY_ANALYZER);
|
||||
setSettingsGroup("Cppcheck");
|
||||
setAutoApply(false);
|
||||
|
||||
binary.setSettingsKey("binary");
|
||||
binary.setExpectedKind(PathChooser::ExistingCommand);
|
||||
@@ -108,7 +111,7 @@ CppcheckOptions::CppcheckOptions()
|
||||
readSettings();
|
||||
}
|
||||
|
||||
std::function<Layouting::LayoutItem()> CppcheckOptions::layouter()
|
||||
std::function<Layouting::LayoutItem()> CppcheckSettings::layouter()
|
||||
{
|
||||
return [this] {
|
||||
using namespace Layouting;
|
||||
@@ -136,4 +139,20 @@ std::function<Layouting::LayoutItem()> CppcheckOptions::layouter()
|
||||
};
|
||||
}
|
||||
|
||||
class CppCheckSettingsPage final : public Core::IOptionsPage
|
||||
{
|
||||
public:
|
||||
CppCheckSettingsPage()
|
||||
{
|
||||
setId(Constants::OPTIONS_PAGE_ID);
|
||||
setDisplayName(Tr::tr("Cppcheck"));
|
||||
setCategory("T.Analyzer");
|
||||
setDisplayCategory(::Debugger::Tr::tr("Analyzer"));
|
||||
setCategoryIconPath(Analyzer::Icons::SETTINGSCATEGORY_ANALYZER);
|
||||
setSettingsProvider([] { return &settings(); });
|
||||
}
|
||||
};
|
||||
|
||||
const CppCheckSettingsPage settingsPage;
|
||||
|
||||
} // Cppcheck::Internal
|
||||
|
||||
@@ -3,14 +3,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <coreplugin/dialogs/ioptionspage.h>
|
||||
#include <utils/aspects.h>
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace Cppcheck::Internal {
|
||||
|
||||
class CppcheckOptions final : public Core::PagedSettings
|
||||
class CppcheckSettings final : public Utils::AspectContainer
|
||||
{
|
||||
public:
|
||||
CppcheckOptions();
|
||||
CppcheckSettings();
|
||||
|
||||
std::function<Layouting::LayoutItem()> layouter();
|
||||
|
||||
@@ -32,4 +34,7 @@ public:
|
||||
Utils::BoolAspect guessArguments{this};
|
||||
};
|
||||
|
||||
CppcheckSettings &settings();
|
||||
|
||||
|
||||
} // Cppcheck::Internal
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "cppcheckconstants.h"
|
||||
#include "cppcheckdiagnosticview.h"
|
||||
#include "cppcheckoptions.h"
|
||||
#include "cppchecktextmarkmanager.h"
|
||||
#include "cppchecktool.h"
|
||||
#include "cppchecktr.h"
|
||||
@@ -39,11 +40,10 @@ public:
|
||||
explicit CppcheckPluginPrivate();
|
||||
|
||||
CppcheckTextMarkManager marks;
|
||||
CppcheckOptions options;
|
||||
CppcheckTool tool{options, marks, Constants::CHECK_PROGRESS_ID};
|
||||
CppcheckTool tool{marks, Constants::CHECK_PROGRESS_ID};
|
||||
CppcheckTrigger trigger{marks, tool};
|
||||
DiagnosticsModel manualRunModel;
|
||||
CppcheckTool manualRunTool{options, manualRunModel, Constants::MANUAL_CHECK_PROGRESS_ID};
|
||||
CppcheckTool manualRunTool{manualRunModel, Constants::MANUAL_CHECK_PROGRESS_ID};
|
||||
Utils::Perspective perspective{Constants::PERSPECTIVE_ID, ::Cppcheck::Tr::tr("Cppcheck")};
|
||||
|
||||
QAction *manualRunAction;
|
||||
@@ -55,7 +55,7 @@ public:
|
||||
CppcheckPluginPrivate::CppcheckPluginPrivate()
|
||||
{
|
||||
tool.updateOptions();
|
||||
connect(&options, &AspectContainer::changed, [this] {
|
||||
connect(&settings(), &AspectContainer::changed, [this] {
|
||||
tool.updateOptions();
|
||||
trigger.recheck();
|
||||
});
|
||||
@@ -112,7 +112,7 @@ void CppcheckPluginPrivate::startManualRun()
|
||||
|
||||
manualRunTool.updateOptions();
|
||||
|
||||
auto optionsWidget = options.layouter()().emerge();
|
||||
auto optionsWidget = settings().layouter()().emerge();
|
||||
|
||||
ManualRunDialog dialog(optionsWidget, project);
|
||||
if (dialog.exec() == ManualRunDialog::Rejected)
|
||||
|
||||
@@ -26,8 +26,7 @@ using namespace Utils;
|
||||
|
||||
namespace Cppcheck::Internal {
|
||||
|
||||
CppcheckTool::CppcheckTool(CppcheckOptions &options, CppcheckDiagnosticManager &manager, const Id &progressId) :
|
||||
m_options(options),
|
||||
CppcheckTool::CppcheckTool(CppcheckDiagnosticManager &manager, const Id &progressId) :
|
||||
m_manager(manager),
|
||||
m_progressRegexp("^.* checked (\\d+)% done$"),
|
||||
m_messageRegexp("^(.+),(\\d+),(\\w+),(\\w+),(.*)$"),
|
||||
@@ -43,7 +42,7 @@ CppcheckTool::~CppcheckTool() = default;
|
||||
void CppcheckTool::updateOptions()
|
||||
{
|
||||
m_filters.clear();
|
||||
for (const QString &pattern : m_options.ignoredPatterns().split(',')) {
|
||||
for (const QString &pattern : settings().ignoredPatterns().split(',')) {
|
||||
const QString trimmedPattern = pattern.trimmed();
|
||||
if (trimmedPattern.isEmpty())
|
||||
continue;
|
||||
@@ -69,45 +68,47 @@ void CppcheckTool::updateArguments()
|
||||
|
||||
m_cachedAdditionalArguments.clear();
|
||||
|
||||
CppcheckSettings &s = settings();
|
||||
|
||||
QStringList arguments;
|
||||
if (!m_options.customArguments().isEmpty()) {
|
||||
if (!s.customArguments().isEmpty()) {
|
||||
Utils::MacroExpander *expander = Utils::globalMacroExpander();
|
||||
const QString expanded = expander->expand(m_options.customArguments());
|
||||
const QString expanded = expander->expand(s.customArguments());
|
||||
arguments.push_back(expanded);
|
||||
}
|
||||
|
||||
if (m_options.warning())
|
||||
if (s.warning())
|
||||
arguments.push_back("--enable=warning");
|
||||
if (m_options.style())
|
||||
if (s.style())
|
||||
arguments.push_back("--enable=style");
|
||||
if (m_options.performance())
|
||||
if (s.performance())
|
||||
arguments.push_back("--enable=performance");
|
||||
if (m_options.portability())
|
||||
if (s.portability())
|
||||
arguments.push_back("--enable=portability");
|
||||
if (m_options.information())
|
||||
if (s.information())
|
||||
arguments.push_back("--enable=information");
|
||||
if (m_options.unusedFunction())
|
||||
if (s.unusedFunction())
|
||||
arguments.push_back("--enable=unusedFunction");
|
||||
if (m_options.missingInclude())
|
||||
if (s.missingInclude())
|
||||
arguments.push_back("--enable=missingInclude");
|
||||
if (m_options.inconclusive())
|
||||
if (s.inconclusive())
|
||||
arguments.push_back("--inconclusive");
|
||||
if (m_options.forceDefines())
|
||||
if (s.forceDefines())
|
||||
arguments.push_back("--force");
|
||||
|
||||
if (!m_options.unusedFunction() && !m_options.customArguments().contains("-j "))
|
||||
if (!s.unusedFunction() && !s.customArguments().contains("-j "))
|
||||
arguments.push_back("-j " + QString::number(QThread::idealThreadCount()));
|
||||
|
||||
arguments.push_back("--template=\"{file},{line},{severity},{id},{message}\"");
|
||||
|
||||
m_runner->reconfigure(m_options.binary(), arguments.join(' '));
|
||||
m_runner->reconfigure(s.binary(), arguments.join(' '));
|
||||
}
|
||||
|
||||
QStringList CppcheckTool::additionalArguments(const CppEditor::ProjectPart &part) const
|
||||
{
|
||||
QStringList result;
|
||||
|
||||
if (m_options.addIncludePaths()) {
|
||||
if (settings().addIncludePaths()) {
|
||||
for (const ProjectExplorer::HeaderPath &path : part.headerPaths) {
|
||||
const QString projectDir = m_project->projectDirectory().toString();
|
||||
if (path.type == ProjectExplorer::HeaderPathType::User
|
||||
@@ -116,7 +117,7 @@ QStringList CppcheckTool::additionalArguments(const CppEditor::ProjectPart &part
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_options.guessArguments())
|
||||
if (!settings().guessArguments())
|
||||
return result;
|
||||
|
||||
using Version = Utils::LanguageVersion;
|
||||
@@ -221,7 +222,7 @@ void CppcheckTool::stop(const Utils::FilePaths &files)
|
||||
|
||||
void CppcheckTool::startParsing()
|
||||
{
|
||||
if (m_options.showOutput()) {
|
||||
if (settings().showOutput()) {
|
||||
const QString message = Tr::tr("Cppcheck started: \"%1\".").arg(m_runner->currentCommand());
|
||||
Core::MessageManager::writeSilently(message);
|
||||
}
|
||||
@@ -240,7 +241,7 @@ void CppcheckTool::parseOutputLine(const QString &line)
|
||||
if (line.isEmpty())
|
||||
return;
|
||||
|
||||
if (m_options.showOutput())
|
||||
if (settings().showOutput())
|
||||
Core::MessageManager::writeSilently(line);
|
||||
|
||||
enum Matches { Percentage = 1 };
|
||||
@@ -271,7 +272,7 @@ void CppcheckTool::parseErrorLine(const QString &line)
|
||||
if (line.isEmpty())
|
||||
return;
|
||||
|
||||
if (m_options.showOutput())
|
||||
if (settings().showOutput())
|
||||
Core::MessageManager::writeSilently(line);
|
||||
|
||||
enum Matches { File = 1, Line, Severity, Id, Message };
|
||||
@@ -296,7 +297,7 @@ void CppcheckTool::parseErrorLine(const QString &line)
|
||||
|
||||
void CppcheckTool::finishParsing()
|
||||
{
|
||||
if (m_options.showOutput())
|
||||
if (settings().showOutput())
|
||||
Core::MessageManager::writeSilently(Tr::tr("Cppcheck finished."));
|
||||
|
||||
QTC_ASSERT(m_progress, return);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cppcheck/cppcheckoptions.h>
|
||||
#include <utils/id.h>
|
||||
|
||||
#include <QFutureInterface>
|
||||
#include <QPointer>
|
||||
@@ -24,14 +24,13 @@ namespace Cppcheck::Internal {
|
||||
|
||||
class CppcheckRunner;
|
||||
class CppcheckDiagnosticManager;
|
||||
class CppcheckOptions;
|
||||
|
||||
class CppcheckTool final : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CppcheckTool(CppcheckOptions &options, CppcheckDiagnosticManager &manager, const Utils::Id &progressId);
|
||||
CppcheckTool(CppcheckDiagnosticManager &manager, const Utils::Id &progressId);
|
||||
~CppcheckTool() override;
|
||||
|
||||
void updateOptions();
|
||||
@@ -49,7 +48,6 @@ private:
|
||||
void addToQueue(const Utils::FilePaths &files, const CppEditor::ProjectPart &part);
|
||||
QStringList additionalArguments(const CppEditor::ProjectPart &part) const;
|
||||
|
||||
CppcheckOptions &m_options;
|
||||
CppcheckDiagnosticManager &m_manager;
|
||||
QPointer<ProjectExplorer::Project> m_project;
|
||||
std::unique_ptr<CppcheckRunner> m_runner;
|
||||
|
||||
Reference in New Issue
Block a user