From 10acf6af840153b5b69e9dc32fa9ad671d8f8290 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Tue, 3 Mar 2015 15:09:27 +0100 Subject: [PATCH] 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 --- .../clangstaticanalyzertool.cpp | 35 ++++++++++++++++++- .../clangstaticanalyzertool.h | 5 +++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/plugins/clangstaticanalyzer/clangstaticanalyzertool.cpp b/plugins/clangstaticanalyzer/clangstaticanalyzertool.cpp index 37447c5f664..4e98a28ddd7 100644 --- a/plugins/clangstaticanalyzer/clangstaticanalyzertool.cpp +++ b/plugins/clangstaticanalyzer/clangstaticanalyzertool.cpp @@ -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" diff --git a/plugins/clangstaticanalyzer/clangstaticanalyzertool.h b/plugins/clangstaticanalyzer/clangstaticanalyzertool.h index 2f9b18efa7b..4334884c7e7 100644 --- a/plugins/clangstaticanalyzer/clangstaticanalyzertool.h +++ b/plugins/clangstaticanalyzer/clangstaticanalyzertool.h @@ -22,7 +22,10 @@ #include #include +#include + 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 m_runConfigs; bool m_running; };