forked from qt-creator/qt-creator
Create a dummy run configuration to create our run control from.
The Clang Static Analyzer differs from other analyzers in that it does not run a binary produced by the build process, but looks at source files instead. It is therefore completely unrelated to any run configurations that may or may not exist for the project. This has been ignored so far, with these two main consequences: - When running the analyzer, the name of some random run configuration appears in the application output pane, which makes it look to the user as if the corresponding executable has been run, which it has not. - For projects without run configurations (e.g. libraries), analyzing does not work out of the box, which makes no sense conceptually. So we now create our own run special run configuration (not visible in the UI) and run it directly via runRunConfiguration() instead of using the currently active run configuration via runProject(). This fixes both issues listed above. Change-Id: Icc839816f4a1e6f02a0eb2328c536b44f7304807 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
@@ -48,6 +48,22 @@ using namespace ProjectExplorer;
|
||||
namespace ClangStaticAnalyzer {
|
||||
namespace Internal {
|
||||
|
||||
class DummyRunConfiguration : public RunConfiguration
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DummyRunConfiguration(Target *parent)
|
||||
: RunConfiguration(parent, "ClangStaticAnalyzer.DummyRunConfig")
|
||||
{
|
||||
setDefaultDisplayName(tr("Clang Static Analyzer"));
|
||||
addExtraAspects();
|
||||
}
|
||||
|
||||
private:
|
||||
QWidget *createConfigurationWidget() { return 0; }
|
||||
};
|
||||
|
||||
ClangStaticAnalyzerTool::ClangStaticAnalyzerTool(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_diagnosticModel(0)
|
||||
@@ -218,7 +234,22 @@ void ClangStaticAnalyzerTool::startTool()
|
||||
QTC_ASSERT(m_projectInfoBeforeBuild.isValid(), return);
|
||||
m_running = true;
|
||||
handleStateUpdate();
|
||||
ProjectExplorerPlugin::runProject(project, ProjectExplorer::ClangStaticAnalyzerMode);
|
||||
|
||||
Target * const target = project->activeTarget();
|
||||
QTC_ASSERT(target, return);
|
||||
DummyRunConfiguration *& rc = m_runConfigs[target];
|
||||
if (!rc) {
|
||||
rc = new DummyRunConfiguration(target);
|
||||
connect(project, &Project::aboutToRemoveTarget, this,
|
||||
[this](Target *t) { m_runConfigs.remove(t); });
|
||||
const auto onProjectRemoved = [this](Project *p) {
|
||||
foreach (Target * const t, p->targets())
|
||||
m_runConfigs.remove(t);
|
||||
};
|
||||
connect(SessionManager::instance(), &SessionManager::aboutToRemoveProject, this,
|
||||
onProjectRemoved, Qt::UniqueConnection);
|
||||
}
|
||||
ProjectExplorerPlugin::runRunConfiguration(rc, ProjectExplorer::ClangStaticAnalyzerMode);
|
||||
}
|
||||
|
||||
CppTools::ProjectInfo ClangStaticAnalyzerTool::projectInfoBeforeBuild() const
|
||||
@@ -289,3 +320,5 @@ void ClangStaticAnalyzerTool::handleStateUpdate()
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ClangStaticAnalyzer
|
||||
|
||||
#include "clangstaticanalyzertool.moc"
|
||||
|
@@ -22,7 +22,10 @@
|
||||
#include <analyzerbase/ianalyzertool.h>
|
||||
#include <cpptools/cppprojects.h>
|
||||
|
||||
#include <QHash>
|
||||
|
||||
namespace Analyzer { class DetailedErrorView; }
|
||||
namespace ProjectExplorer { class Target; }
|
||||
|
||||
namespace ClangStaticAnalyzer {
|
||||
namespace Internal {
|
||||
@@ -31,6 +34,7 @@ class ClangStaticAnalyzerDiagnosticFilterModel;
|
||||
class ClangStaticAnalyzerDiagnosticModel;
|
||||
class ClangStaticAnalyzerDiagnosticView;
|
||||
class Diagnostic;
|
||||
class DummyRunConfiguration;
|
||||
|
||||
const char ClangStaticAnalyzerToolId[] = "ClangStaticAnalyzer";
|
||||
|
||||
@@ -72,6 +76,7 @@ private:
|
||||
|
||||
QAction *m_goBack;
|
||||
QAction *m_goNext;
|
||||
QHash<ProjectExplorer::Target *, DummyRunConfiguration *> m_runConfigs;
|
||||
bool m_running;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user