From aa98ee27559dc79ac874755f190e2cbe9d817dfe Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Fri, 31 Oct 2014 15:55:32 +0100 Subject: [PATCH] Tool: Warn on run in Release mode Change-Id: I3443ccc8daf37a1b10b43df3736fcf24c7ae2fea Reviewed-by: Nikolai Kosjar --- .../clangstaticanalyzertool.cpp | 49 +++++++++++++++++-- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/plugins/clangstaticanalyzer/clangstaticanalyzertool.cpp b/plugins/clangstaticanalyzer/clangstaticanalyzertool.cpp index bc7b60d7e6f..c2b663074ef 100644 --- a/plugins/clangstaticanalyzer/clangstaticanalyzertool.cpp +++ b/plugins/clangstaticanalyzer/clangstaticanalyzertool.cpp @@ -24,10 +24,14 @@ #include #include +#include +#include #include #include #include +#include +#include #include #include @@ -139,23 +143,60 @@ AnalyzerRunControl *ClangStaticAnalyzerTool::createRunControl( return engine; } +static bool dontStartAfterHintForDebugMode() +{ + const Project *project = SessionManager::startupProject(); + BuildConfiguration::BuildType buildType = BuildConfiguration::Unknown; + if (project) { + if (const Target *target = project->activeTarget()) { + if (const BuildConfiguration *buildConfig = target->activeBuildConfiguration()) + buildType = buildConfig->buildType(); + } + } + + if (buildType == BuildConfiguration::Release) { + const QString wrongMode = ClangStaticAnalyzerTool::tr("Release"); + const QString toolName = ClangStaticAnalyzerTool::tr("Clang Static Analyzer"); + const QString title = ClangStaticAnalyzerTool::tr("Run %1 in %2 Mode?").arg(toolName) + .arg(wrongMode); + const QString message = ClangStaticAnalyzerTool::tr( + "" + "

You are trying to run the tool \"%1\" on an application in %2 mode. The tool is " + "designed to be used in Debug mode since enabled assertions can reduce the number of " + "false positives.

" + "

Do you want to continue and run the tool in %2 mode?

" + "") + .arg(toolName).arg(wrongMode); + if (Utils::CheckableMessageBox::doNotAskAgainQuestion(Core::ICore::mainWindow(), + title, message, Core::ICore::settings(), + QLatin1String("ClangStaticAnalyzerCorrectModeWarning"), + QDialogButtonBox::Yes|QDialogButtonBox::Cancel, + QDialogButtonBox::Cancel, QDialogButtonBox::Yes) != QDialogButtonBox::Yes) + return true; + } + + return false; +} + void ClangStaticAnalyzerTool::startTool(StartMode mode) { QTC_ASSERT(mode == Analyzer::StartLocal, return); AnalyzerManager::showMode(); + if (dontStartAfterHintForDebugMode()) + return; + m_diagnosticModel->clear(); setBusyCursor(true); - Project *pro = SessionManager::startupProject(); - QTC_ASSERT(pro, return); - ProjectExplorerPlugin::instance()->runProject(pro, runMode()); + Project *project = SessionManager::startupProject(); + QTC_ASSERT(project, return); + ProjectExplorerPlugin::instance()->runProject(project, runMode()); } void ClangStaticAnalyzerTool::onEngineIsStarting() { QTC_ASSERT(m_diagnosticModel, return); - } void ClangStaticAnalyzerTool::onNewDiagnosticsAvailable(const QList &diagnostics)