Add runConfiguration to remote tool starters

Most of them need a run configuration. It's better to pass the
right one than to use various hacky ways to work around it.

Change-Id: Ic21b0ef33bdd79b526b1e1a1ead5ca87d9f32c4d
Reviewed-by: hjk <hjk@theqtcompany.com>
This commit is contained in:
Ulf Hermann
2016-01-22 17:08:50 +01:00
parent 0f4db8a32f
commit a1dd1e4c5b
9 changed files with 26 additions and 52 deletions

View File

@@ -89,23 +89,25 @@ void AnalyzerAction::startTool()
if (m_toolPreparer && !m_toolPreparer()) if (m_toolPreparer && !m_toolPreparer())
return; return;
// Custom start.
if (m_customToolStarter) {
m_customToolStarter();
return;
}
// ### not sure if we're supposed to check if the RunConFiguration isEnabled // ### not sure if we're supposed to check if the RunConFiguration isEnabled
Project *pro = SessionManager::startupProject(); Project *pro = SessionManager::startupProject();
RunConfiguration *rc = 0;
BuildConfiguration::BuildType buildType = BuildConfiguration::Unknown; BuildConfiguration::BuildType buildType = BuildConfiguration::Unknown;
if (pro) { if (pro) {
if (const Target *target = pro->activeTarget()) { if (const Target *target = pro->activeTarget()) {
// Build configuration is 0 for QML projects. // Build configuration is 0 for QML projects.
if (const BuildConfiguration *buildConfig = target->activeBuildConfiguration()) if (const BuildConfiguration *buildConfig = target->activeBuildConfiguration())
buildType = buildConfig->buildType(); buildType = buildConfig->buildType();
rc = target->activeRunConfiguration();
} }
} }
// Custom start.
if (m_customToolStarter) {
m_customToolStarter(rc);
return;
}
// Check the project for whether the build config is in the correct mode // Check the project for whether the build config is in the correct mode
// if not, notify the user and urge him to use the correct mode. // if not, notify the user and urge him to use the correct mode.
if (!buildTypeAccepted(m_toolMode, buildType)) { if (!buildTypeAccepted(m_toolMode, buildType)) {

View File

@@ -110,7 +110,7 @@ public:
void startTool(); void startTool();
/// This is only used for setups not using the startup project. /// This is only used for setups not using the startup project.
typedef std::function<void()> ToolStarter; typedef std::function<void(ProjectExplorer::RunConfiguration *runConfiguration)> ToolStarter;
void setCustomToolStarter(const ToolStarter &toolStarter) { m_customToolStarter = toolStarter; } void setCustomToolStarter(const ToolStarter &toolStarter) { m_customToolStarter = toolStarter; }
protected: protected:

View File

@@ -141,7 +141,9 @@ bool ClangStaticAnalyzerPlugin::initialize(const QStringList &arguments, QString
action->setActionId("ClangStaticAnalyzer"); action->setActionId("ClangStaticAnalyzer");
action->setWidgetCreator(widgetCreator); action->setWidgetCreator(widgetCreator);
action->setRunControlCreator(runControlCreator); action->setRunControlCreator(runControlCreator);
action->setCustomToolStarter([tool] { tool->startTool(); }); action->setCustomToolStarter([tool](ProjectExplorer::RunConfiguration *rc) {
tool->startTool(rc);
});
action->setText(tr("Clang Static Analyzer")); action->setText(tr("Clang Static Analyzer"));
action->setToolTip(toolTip); action->setToolTip(toolTip);
action->setMenuGroup(Analyzer::Constants::G_ANALYZER_TOOLS); action->setMenuGroup(Analyzer::Constants::G_ANALYZER_TOOLS);

View File

@@ -58,22 +58,6 @@ using namespace ProjectExplorer;
namespace ClangStaticAnalyzer { namespace ClangStaticAnalyzer {
namespace Internal { 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() override { return 0; }
};
ClangStaticAnalyzerTool::ClangStaticAnalyzerTool(QObject *parent) ClangStaticAnalyzerTool::ClangStaticAnalyzerTool(QObject *parent)
: QObject(parent) : QObject(parent)
, m_diagnosticModel(0) , m_diagnosticModel(0)
@@ -225,7 +209,7 @@ static bool dontStartAfterHintForDebugMode(Project *project)
return false; return false;
} }
void ClangStaticAnalyzerTool::startTool() void ClangStaticAnalyzerTool::startTool(ProjectExplorer::RunConfiguration *runConfiguration)
{ {
AnalyzerManager::showMode(); AnalyzerManager::showMode();
@@ -243,21 +227,8 @@ void ClangStaticAnalyzerTool::startTool()
m_running = true; m_running = true;
handleStateUpdate(); handleStateUpdate();
Target * const target = project->activeTarget(); ProjectExplorerPlugin::runRunConfiguration(runConfiguration,
QTC_ASSERT(target, return); Constants::CLANGSTATICANALYZER_RUN_MODE);
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, Constants::CLANGSTATICANALYZER_RUN_MODE);
} }
CppTools::ProjectInfo ClangStaticAnalyzerTool::projectInfoBeforeBuild() const CppTools::ProjectInfo ClangStaticAnalyzerTool::projectInfoBeforeBuild() const
@@ -328,5 +299,3 @@ void ClangStaticAnalyzerTool::handleStateUpdate()
} // namespace Internal } // namespace Internal
} // namespace ClangStaticAnalyzer } // namespace ClangStaticAnalyzer
#include "clangstaticanalyzertool.moc"

View File

@@ -61,7 +61,7 @@ public:
QWidget *createWidgets(); QWidget *createWidgets();
Analyzer::AnalyzerRunControl *createRunControl(ProjectExplorer::RunConfiguration *runConfiguration, Analyzer::AnalyzerRunControl *createRunControl(ProjectExplorer::RunConfiguration *runConfiguration,
Core::Id runMode); Core::Id runMode);
void startTool(); void startTool(ProjectExplorer::RunConfiguration *rc);
signals: signals:
void finished(bool success); // For testing. void finished(bool success); // For testing.
@@ -83,7 +83,6 @@ private:
QAction *m_goBack; QAction *m_goBack;
QAction *m_goNext; QAction *m_goNext;
QHash<ProjectExplorer::Target *, DummyRunConfiguration *> m_runConfigs;
bool m_running; bool m_running;
}; };

View File

@@ -81,7 +81,9 @@ bool QmlProfilerPlugin::initialize(const QStringList &arguments, QString *errorS
action->setToolId(Constants::QmlProfilerToolId); action->setToolId(Constants::QmlProfilerToolId);
action->setWidgetCreator(widgetCreator); action->setWidgetCreator(widgetCreator);
action->setRunControlCreator(runControlCreator); action->setRunControlCreator(runControlCreator);
action->setCustomToolStarter([tool] { tool->startRemoteTool(); }); action->setCustomToolStarter([tool](ProjectExplorer::RunConfiguration *rc) {
tool->startRemoteTool(rc);
});
action->setToolPreparer([tool] { return tool->prepareTool(); }); action->setToolPreparer([tool] { return tool->prepareTool(); });
action->setRunMode(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE); action->setRunMode(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
action->setText(tr("QML Profiler (External)")); action->setText(tr("QML Profiler (External)"));

View File

@@ -487,7 +487,7 @@ bool QmlProfilerTool::prepareTool()
return true; return true;
} }
void QmlProfilerTool::startRemoteTool() void QmlProfilerTool::startRemoteTool(ProjectExplorer::RunConfiguration *rc)
{ {
AnalyzerManager::showMode(); AnalyzerManager::showMode();
@@ -525,7 +525,7 @@ void QmlProfilerTool::startRemoteTool()
} }
connection.analyzerPort = port; connection.analyzerPort = port;
auto runControl = qobject_cast<QmlProfilerRunControl *>(createRunControl(0)); auto runControl = qobject_cast<QmlProfilerRunControl *>(createRunControl(rc));
runControl->setConnection(connection); runControl->setConnection(connection);
ProjectExplorerPlugin::startRunControl(runControl, ProjectExplorer::Constants::QML_PROFILER_RUN_MODE); ProjectExplorerPlugin::startRunControl(runControl, ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);

View File

@@ -56,7 +56,7 @@ public:
QWidget *createWidgets(); QWidget *createWidgets();
bool prepareTool(); bool prepareTool();
void startRemoteTool(); void startRemoteTool(ProjectExplorer::RunConfiguration *rc);
static QList <QAction *> profilerContextMenuActions(); static QList <QAction *> profilerContextMenuActions();

View File

@@ -187,11 +187,11 @@ void ValgrindPlugin::extensionsInitialized()
action->setActionId("Memcheck.Remote"); action->setActionId("Memcheck.Remote");
action->setToolId("Memcheck"); action->setToolId("Memcheck");
action->setWidgetCreator(mcWidgetCreator); action->setWidgetCreator(mcWidgetCreator);
action->setCustomToolStarter([mcTool] { action->setCustomToolStarter([mcTool](ProjectExplorer::RunConfiguration *runConfig) {
StartRemoteDialog dlg; StartRemoteDialog dlg;
if (dlg.exec() != QDialog::Accepted) if (dlg.exec() != QDialog::Accepted)
return; return;
ValgrindRunControl *rc = mcTool->createRunControl(0, MEMCHECK_RUN_MODE); ValgrindRunControl *rc = mcTool->createRunControl(runConfig, MEMCHECK_RUN_MODE);
QTC_ASSERT(rc, return); QTC_ASSERT(rc, return);
AnalyzerRunnable runnable; AnalyzerRunnable runnable;
runnable.debuggee = dlg.executable(); runnable.debuggee = dlg.executable();
@@ -214,11 +214,11 @@ void ValgrindPlugin::extensionsInitialized()
action->setActionId(CallgrindRemoteActionId); action->setActionId(CallgrindRemoteActionId);
action->setToolId(CallgrindToolId); action->setToolId(CallgrindToolId);
action->setWidgetCreator(cgWidgetCreator); action->setWidgetCreator(cgWidgetCreator);
action->setCustomToolStarter([cgTool] { action->setCustomToolStarter([cgTool](ProjectExplorer::RunConfiguration *runConfig) {
StartRemoteDialog dlg; StartRemoteDialog dlg;
if (dlg.exec() != QDialog::Accepted) if (dlg.exec() != QDialog::Accepted)
return; return;
ValgrindRunControl *rc = cgTool->createRunControl(0); ValgrindRunControl *rc = cgTool->createRunControl(runConfig);
QTC_ASSERT(rc, return); QTC_ASSERT(rc, return);
AnalyzerRunnable runnable; AnalyzerRunnable runnable;
runnable.debuggee = dlg.executable(); runnable.debuggee = dlg.executable();