forked from qt-creator/qt-creator
Ensure that project configuration did not change
Otherwise we might try to analyze invalid or vanished files. Change-Id: I387dfb127618f2db21a538b07e1c152dbd026ca6 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
@@ -121,10 +121,9 @@ bool ClangStaticAnalyzerPlugin::initializeEnterpriseFeatures(const QStringList &
|
|||||||
Q_UNUSED(arguments);
|
Q_UNUSED(arguments);
|
||||||
Q_UNUSED(errorString);
|
Q_UNUSED(errorString);
|
||||||
|
|
||||||
addAutoReleasedObject(new ClangStaticAnalyzerOptionsPage);
|
|
||||||
addAutoReleasedObject(new ClangStaticAnalyzerRunControlFactory);
|
|
||||||
|
|
||||||
m_analyzerTool = new ClangStaticAnalyzerTool(this);
|
m_analyzerTool = new ClangStaticAnalyzerTool(this);
|
||||||
|
addAutoReleasedObject(new ClangStaticAnalyzerRunControlFactory(m_analyzerTool));
|
||||||
|
addAutoReleasedObject(new ClangStaticAnalyzerOptionsPage);
|
||||||
|
|
||||||
const QString toolTip = tr("Clang Static Analyzer uses the analyzer from the clang project "
|
const QString toolTip = tr("Clang Static Analyzer uses the analyzer from the clang project "
|
||||||
"to find bugs.");
|
"to find bugs.");
|
||||||
|
@@ -49,9 +49,11 @@ namespace ClangStaticAnalyzer {
|
|||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
ClangStaticAnalyzerRunControl::ClangStaticAnalyzerRunControl(
|
ClangStaticAnalyzerRunControl::ClangStaticAnalyzerRunControl(
|
||||||
const Analyzer::AnalyzerStartParameters &startParams,
|
const Analyzer::AnalyzerStartParameters &startParams,
|
||||||
ProjectExplorer::RunConfiguration *runConfiguration)
|
ProjectExplorer::RunConfiguration *runConfiguration,
|
||||||
|
const ProjectInfo &projectInfo)
|
||||||
: AnalyzerRunControl(startParams, runConfiguration)
|
: AnalyzerRunControl(startParams, runConfiguration)
|
||||||
|
, m_projectInfo(projectInfo)
|
||||||
, m_initialFilesToProcessSize(0)
|
, m_initialFilesToProcessSize(0)
|
||||||
, m_filesAnalyzed(0)
|
, m_filesAnalyzed(0)
|
||||||
, m_filesNotAnalyzed(0)
|
, m_filesNotAnalyzed(0)
|
||||||
@@ -145,10 +147,9 @@ static QList<ClangStaticAnalyzerRunControl::AnalyzeUnit> unitsToAnalyzeFromProje
|
|||||||
return unitsToAnalyze;
|
return unitsToAnalyze;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QList<ClangStaticAnalyzerRunControl::AnalyzeUnit> unitsToAnalyze(Project *project)
|
static QList<ClangStaticAnalyzerRunControl::AnalyzeUnit> unitsToAnalyze(
|
||||||
|
const CppTools::ProjectInfo &projectInfo)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(project, return QList<ClangStaticAnalyzerRunControl::AnalyzeUnit>());
|
|
||||||
ProjectInfo projectInfo = CppModelManager::instance()->projectInfo(project);
|
|
||||||
QTC_ASSERT(projectInfo.isValid(), return QList<ClangStaticAnalyzerRunControl::AnalyzeUnit>());
|
QTC_ASSERT(projectInfo.isValid(), return QList<ClangStaticAnalyzerRunControl::AnalyzeUnit>());
|
||||||
|
|
||||||
const ProjectInfo::CompilerCallData compilerCallData = projectInfo.compilerCallData();
|
const ProjectInfo::CompilerCallData compilerCallData = projectInfo.compilerCallData();
|
||||||
@@ -161,14 +162,8 @@ bool ClangStaticAnalyzerRunControl::startEngine()
|
|||||||
{
|
{
|
||||||
emit starting(this);
|
emit starting(this);
|
||||||
|
|
||||||
RunConfiguration *runConfig = runConfiguration();
|
QTC_ASSERT(m_projectInfo.isValid(), emit finished(); return false);
|
||||||
QTC_ASSERT(runConfig, emit finished(); return false);
|
const QString projectFile = m_projectInfo.project()->projectFilePath().toString();
|
||||||
Target *target = runConfig->target();
|
|
||||||
QTC_ASSERT(target, emit finished(); return false);
|
|
||||||
Project *project = target->project();
|
|
||||||
QTC_ASSERT(project, emit finished(); return false);
|
|
||||||
|
|
||||||
const QString projectFile = project->projectFilePath().toString();
|
|
||||||
appendMessage(tr("Running Clang Static Analyzer on %1").arg(projectFile) + QLatin1Char('\n'),
|
appendMessage(tr("Running Clang Static Analyzer on %1").arg(projectFile) + QLatin1Char('\n'),
|
||||||
Utils::NormalMessageFormat);
|
Utils::NormalMessageFormat);
|
||||||
|
|
||||||
@@ -196,7 +191,7 @@ bool ClangStaticAnalyzerRunControl::startEngine()
|
|||||||
m_clangLogFileDir = temporaryDir.path();
|
m_clangLogFileDir = temporaryDir.path();
|
||||||
|
|
||||||
// Collect files
|
// Collect files
|
||||||
const QList<AnalyzeUnit> filesToProcess = unitsToAnalyze(project);
|
const QList<AnalyzeUnit> filesToProcess = unitsToAnalyze(m_projectInfo);
|
||||||
qCDebug(LOG) << "Files to process:";
|
qCDebug(LOG) << "Files to process:";
|
||||||
foreach (const AnalyzeUnit &fileConfig, filesToProcess)
|
foreach (const AnalyzeUnit &fileConfig, filesToProcess)
|
||||||
qCDebug(LOG) << fileConfig.file;
|
qCDebug(LOG) << fileConfig.file;
|
||||||
|
@@ -46,7 +46,8 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ClangStaticAnalyzerRunControl(const Analyzer::AnalyzerStartParameters &startParams,
|
explicit ClangStaticAnalyzerRunControl(const Analyzer::AnalyzerStartParameters &startParams,
|
||||||
ProjectExplorer::RunConfiguration *runConfiguration);
|
ProjectExplorer::RunConfiguration *runConfiguration,
|
||||||
|
const CppTools::ProjectInfo &projectInfo);
|
||||||
|
|
||||||
bool startEngine();
|
bool startEngine();
|
||||||
void stopEngine();
|
void stopEngine();
|
||||||
@@ -66,6 +67,8 @@ private:
|
|||||||
void updateProgressValue();
|
void updateProgressValue();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
const CppTools::ProjectInfo m_projectInfo;
|
||||||
|
|
||||||
QString m_clangExecutable;
|
QString m_clangExecutable;
|
||||||
QString m_clangLogFileDir;
|
QString m_clangLogFileDir;
|
||||||
QFutureInterface<void> m_progress;
|
QFutureInterface<void> m_progress;
|
||||||
|
@@ -22,21 +22,31 @@
|
|||||||
#include <analyzerbase/analyzerruncontrol.h>
|
#include <analyzerbase/analyzerruncontrol.h>
|
||||||
#include <analyzerbase/analyzerstartparameters.h>
|
#include <analyzerbase/analyzerstartparameters.h>
|
||||||
|
|
||||||
|
#include <cpptools/cppmodelmanager.h>
|
||||||
|
#include <cpptools/cppprojects.h>
|
||||||
|
|
||||||
#include <projectexplorer/gcctoolchain.h>
|
#include <projectexplorer/gcctoolchain.h>
|
||||||
#include <projectexplorer/kit.h>
|
#include <projectexplorer/kit.h>
|
||||||
#include <projectexplorer/kitinformation.h>
|
#include <projectexplorer/kitinformation.h>
|
||||||
|
#include <projectexplorer/session.h>
|
||||||
#include <projectexplorer/target.h>
|
#include <projectexplorer/target.h>
|
||||||
#include <projectexplorer/toolchain.h>
|
#include <projectexplorer/toolchain.h>
|
||||||
|
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
using namespace Analyzer;
|
using namespace Analyzer;
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
|
|
||||||
namespace ClangStaticAnalyzer {
|
namespace ClangStaticAnalyzer {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
ClangStaticAnalyzerRunControlFactory::ClangStaticAnalyzerRunControlFactory(QObject *parent)
|
ClangStaticAnalyzerRunControlFactory::ClangStaticAnalyzerRunControlFactory(
|
||||||
|
ClangStaticAnalyzerTool *tool,
|
||||||
|
QObject *parent)
|
||||||
: IRunControlFactory(parent)
|
: IRunControlFactory(parent)
|
||||||
|
, m_tool(tool)
|
||||||
{
|
{
|
||||||
|
QTC_CHECK(m_tool);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClangStaticAnalyzerRunControlFactory::canRun(RunConfiguration *runConfiguration,
|
bool ClangStaticAnalyzerRunControlFactory::canRun(RunConfiguration *runConfiguration,
|
||||||
@@ -58,9 +68,30 @@ RunControl *ClangStaticAnalyzerRunControlFactory::create(RunConfiguration *runCo
|
|||||||
RunMode runMode,
|
RunMode runMode,
|
||||||
QString *errorMessage)
|
QString *errorMessage)
|
||||||
{
|
{
|
||||||
Q_UNUSED(errorMessage);
|
|
||||||
Q_UNUSED(runMode);
|
Q_UNUSED(runMode);
|
||||||
|
|
||||||
|
using namespace CppTools;
|
||||||
|
const ProjectInfo projectInfoAtAnalyzerStart = m_tool->projectInfo();
|
||||||
|
QTC_ASSERT(projectInfoAtAnalyzerStart.isValid(), return 0);
|
||||||
|
|
||||||
|
Project *project = SessionManager::startupProject();
|
||||||
|
QTC_ASSERT(project, return 0);
|
||||||
|
const ProjectInfo projectInfoNow = CppModelManager::instance()->projectInfo(project);
|
||||||
|
|
||||||
|
if (projectInfoNow.configurationOrFilesChanged(projectInfoAtAnalyzerStart)) {
|
||||||
|
// If it's more than a release/debug build configuration change, e.g.
|
||||||
|
// a version control checkout, files might be not valid C++ anymore
|
||||||
|
// or even gone, so better stop here.
|
||||||
|
|
||||||
|
m_tool->resetCursorAndProjectInfo();
|
||||||
|
if (errorMessage) {
|
||||||
|
*errorMessage = tr(
|
||||||
|
"The project configuration changed since the start of the Clang Static Analyzer. "
|
||||||
|
"Please re-run with current configuration.");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
AnalyzerStartParameters sp;
|
AnalyzerStartParameters sp;
|
||||||
sp.runMode = runMode;
|
sp.runMode = runMode;
|
||||||
sp.startMode = StartLocal;
|
sp.startMode = StartLocal;
|
||||||
|
@@ -19,6 +19,8 @@
|
|||||||
#ifndef CLANGSTATICANALYZERRUNCONTROLFACTORY_H
|
#ifndef CLANGSTATICANALYZERRUNCONTROLFACTORY_H
|
||||||
#define CLANGSTATICANALYZERRUNCONTROLFACTORY_H
|
#define CLANGSTATICANALYZERRUNCONTROLFACTORY_H
|
||||||
|
|
||||||
|
#include "clangstaticanalyzertool.h"
|
||||||
|
|
||||||
#include <projectexplorer/runconfiguration.h>
|
#include <projectexplorer/runconfiguration.h>
|
||||||
|
|
||||||
namespace ClangStaticAnalyzer {
|
namespace ClangStaticAnalyzer {
|
||||||
@@ -29,7 +31,8 @@ class ClangStaticAnalyzerRunControlFactory : public ProjectExplorer::IRunControl
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ClangStaticAnalyzerRunControlFactory(QObject *parent = 0);
|
explicit ClangStaticAnalyzerRunControlFactory(ClangStaticAnalyzerTool *tool,
|
||||||
|
QObject *parent = 0);
|
||||||
|
|
||||||
bool canRun(ProjectExplorer::RunConfiguration *runConfiguration,
|
bool canRun(ProjectExplorer::RunConfiguration *runConfiguration,
|
||||||
ProjectExplorer::RunMode runMode) const;
|
ProjectExplorer::RunMode runMode) const;
|
||||||
@@ -37,6 +40,9 @@ public:
|
|||||||
ProjectExplorer::RunControl *create(ProjectExplorer::RunConfiguration *runConfiguration,
|
ProjectExplorer::RunControl *create(ProjectExplorer::RunConfiguration *runConfiguration,
|
||||||
ProjectExplorer::RunMode runMode,
|
ProjectExplorer::RunMode runMode,
|
||||||
QString *errorMessage);
|
QString *errorMessage);
|
||||||
|
|
||||||
|
private:
|
||||||
|
ClangStaticAnalyzerTool *m_tool;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -25,6 +25,7 @@
|
|||||||
#include <analyzerbase/analyzermanager.h>
|
#include <analyzerbase/analyzermanager.h>
|
||||||
#include <coreplugin/coreconstants.h>
|
#include <coreplugin/coreconstants.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
#include <cpptools/cppmodelmanager.h>
|
||||||
#include <projectexplorer/buildconfiguration.h>
|
#include <projectexplorer/buildconfiguration.h>
|
||||||
#include <projectexplorer/projectexplorer.h>
|
#include <projectexplorer/projectexplorer.h>
|
||||||
#include <projectexplorer/projectexplorerconstants.h>
|
#include <projectexplorer/projectexplorerconstants.h>
|
||||||
@@ -133,7 +134,11 @@ AnalyzerRunControl *ClangStaticAnalyzerTool::createRunControl(
|
|||||||
const AnalyzerStartParameters &sp,
|
const AnalyzerStartParameters &sp,
|
||||||
ProjectExplorer::RunConfiguration *runConfiguration)
|
ProjectExplorer::RunConfiguration *runConfiguration)
|
||||||
{
|
{
|
||||||
ClangStaticAnalyzerRunControl *engine = new ClangStaticAnalyzerRunControl(sp, runConfiguration);
|
QTC_ASSERT(runConfiguration, return 0);
|
||||||
|
QTC_ASSERT(m_projectInfo.isValid(), return 0);
|
||||||
|
|
||||||
|
ClangStaticAnalyzerRunControl *engine = new ClangStaticAnalyzerRunControl(sp, runConfiguration,
|
||||||
|
m_projectInfo);
|
||||||
connect(engine, &ClangStaticAnalyzerRunControl::starting,
|
connect(engine, &ClangStaticAnalyzerRunControl::starting,
|
||||||
this, &ClangStaticAnalyzerTool::onEngineIsStarting);
|
this, &ClangStaticAnalyzerTool::onEngineIsStarting);
|
||||||
connect(engine, &ClangStaticAnalyzerRunControl::newDiagnosticsAvailable,
|
connect(engine, &ClangStaticAnalyzerRunControl::newDiagnosticsAvailable,
|
||||||
@@ -192,6 +197,18 @@ void ClangStaticAnalyzerTool::startTool(StartMode mode)
|
|||||||
Project *project = SessionManager::startupProject();
|
Project *project = SessionManager::startupProject();
|
||||||
QTC_ASSERT(project, return);
|
QTC_ASSERT(project, return);
|
||||||
ProjectExplorerPlugin::instance()->runProject(project, runMode());
|
ProjectExplorerPlugin::instance()->runProject(project, runMode());
|
||||||
|
m_projectInfo = CppTools::CppModelManager::instance()->projectInfo(project);
|
||||||
|
}
|
||||||
|
|
||||||
|
CppTools::ProjectInfo ClangStaticAnalyzerTool::projectInfo() const
|
||||||
|
{
|
||||||
|
return m_projectInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClangStaticAnalyzerTool::resetCursorAndProjectInfo()
|
||||||
|
{
|
||||||
|
setBusyCursor(false);
|
||||||
|
m_projectInfo = CppTools::ProjectInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClangStaticAnalyzerTool::onEngineIsStarting()
|
void ClangStaticAnalyzerTool::onEngineIsStarting()
|
||||||
@@ -210,10 +227,12 @@ void ClangStaticAnalyzerTool::onEngineFinished()
|
|||||||
QTC_ASSERT(m_goBack, return);
|
QTC_ASSERT(m_goBack, return);
|
||||||
QTC_ASSERT(m_goNext, return);
|
QTC_ASSERT(m_goNext, return);
|
||||||
QTC_ASSERT(m_diagnosticModel, return);
|
QTC_ASSERT(m_diagnosticModel, return);
|
||||||
|
|
||||||
|
resetCursorAndProjectInfo();
|
||||||
|
|
||||||
const int issuesFound = m_diagnosticModel->rowCount();
|
const int issuesFound = m_diagnosticModel->rowCount();
|
||||||
m_goBack->setEnabled(issuesFound > 1);
|
m_goBack->setEnabled(issuesFound > 1);
|
||||||
m_goNext->setEnabled(issuesFound > 1);
|
m_goNext->setEnabled(issuesFound > 1);
|
||||||
setBusyCursor(false);
|
|
||||||
|
|
||||||
AnalyzerManager::showStatusMessage(issuesFound > 0
|
AnalyzerManager::showStatusMessage(issuesFound > 0
|
||||||
? AnalyzerManager::tr("Clang Static Analyzer finished, %n issues were found.", 0, issuesFound)
|
? AnalyzerManager::tr("Clang Static Analyzer finished, %n issues were found.", 0, issuesFound)
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
#define CLANGSTATICANALYZERTOOL_H
|
#define CLANGSTATICANALYZERTOOL_H
|
||||||
|
|
||||||
#include <analyzerbase/ianalyzertool.h>
|
#include <analyzerbase/ianalyzertool.h>
|
||||||
|
#include <cpptools/cppprojects.h>
|
||||||
|
|
||||||
namespace Analyzer { class DetailedErrorView; }
|
namespace Analyzer { class DetailedErrorView; }
|
||||||
|
|
||||||
@@ -36,6 +37,8 @@ class ClangStaticAnalyzerTool : public Analyzer::IAnalyzerTool
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ClangStaticAnalyzerTool(QObject *parent = 0);
|
explicit ClangStaticAnalyzerTool(QObject *parent = 0);
|
||||||
|
CppTools::ProjectInfo projectInfo() const;
|
||||||
|
void resetCursorAndProjectInfo();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QWidget *createWidgets();
|
QWidget *createWidgets();
|
||||||
@@ -50,6 +53,8 @@ private:
|
|||||||
void setBusyCursor(bool busy);
|
void setBusyCursor(bool busy);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
CppTools::ProjectInfo m_projectInfo;
|
||||||
|
|
||||||
ClangStaticAnalyzerDiagnosticModel *m_diagnosticModel;
|
ClangStaticAnalyzerDiagnosticModel *m_diagnosticModel;
|
||||||
Analyzer::DetailedErrorView *m_diagnosticView;
|
Analyzer::DetailedErrorView *m_diagnosticView;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user