ProjectExplorer: Split RunControl constructor

Into a trivial bit and two setters. Plan is to use it only with information
that is truly there (e.g. kit/device only) at the user side without having
to invent a RunConfiguration "handle".

Also remove some dead code in the test runner.

Change-Id: I987881e41722178b14b91f973b84cbdb67a9f85e
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2019-03-12 15:53:54 +01:00
parent d6dfa7fa77
commit efb7d8deb7
13 changed files with 68 additions and 61 deletions
+2 -8
View File
@@ -541,14 +541,8 @@ void TestRunner::debugTests()
} }
QString errorMessage; QString errorMessage;
auto runControl = new ProjectExplorer::RunControl(config->runConfiguration(), auto runControl = new ProjectExplorer::RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE);
ProjectExplorer::Constants::DEBUG_RUN_MODE); runControl->setRunConfiguration(config->runConfiguration());
if (!runControl) {
emit testResultReady(TestResultPtr(new FaultyTestResult(Result::MessageFatal,
TestRunner::tr("Failed to create run configuration.\n%1").arg(errorMessage))));
onFinished();
return;
}
QStringList omitted; QStringList omitted;
ProjectExplorer::Runnable inferior = config->runnable(); ProjectExplorer::Runnable inferior = config->runnable();
@@ -364,7 +364,7 @@ static ClangDiagnosticConfig getDiagnosticConfig(Project *project)
void ClangTidyClazyTool::startTool(bool askUserForFileSelection) void ClangTidyClazyTool::startTool(bool askUserForFileSelection)
{ {
auto runControl = new RunControl(nullptr, Constants::CLANGTIDYCLAZY_RUN_MODE); auto runControl = new RunControl(Constants::CLANGTIDYCLAZY_RUN_MODE);
runControl->setDisplayName(tr("Clang-Tidy and Clazy")); runControl->setDisplayName(tr("Clang-Tidy and Clazy"));
runControl->setIcon(ProjectExplorer::Icons::ANALYZER_START_SMALL_TOOLBAR); runControl->setIcon(ProjectExplorer::Icons::ANALYZER_START_SMALL_TOOLBAR);
+1 -1
View File
@@ -405,7 +405,7 @@ void StartApplicationDialog::run(bool attachRemote)
Kit *k = dialog.d->kitChooser->currentKit(); Kit *k = dialog.d->kitChooser->currentKit();
IDevice::ConstPtr dev = DeviceKitAspect::device(k); IDevice::ConstPtr dev = DeviceKitAspect::device(k);
auto runControl = new RunControl(nullptr, ProjectExplorer::Constants::DEBUG_RUN_MODE); auto runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE);
auto debugger = new DebuggerRunTool(runControl, k); auto debugger = new DebuggerRunTool(runControl, k);
const StartApplicationParameters newParameters = dialog.parameters(); const StartApplicationParameters newParameters = dialog.parameters();
+15 -11
View File
@@ -887,7 +887,8 @@ bool DebuggerPluginPrivate::parseArgument(QStringList::const_iterator &it,
kit = guessKitFromAbis(Abi::abisOfBinary(FileName::fromString(executable))); kit = guessKitFromAbis(Abi::abisOfBinary(FileName::fromString(executable)));
IDevice::ConstPtr device = DeviceKitAspect::device(kit); IDevice::ConstPtr device = DeviceKitAspect::device(kit);
auto runControl = new RunControl(device, ProjectExplorer::Constants::DEBUG_RUN_MODE); auto runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE);
runControl->setDevice(device);
auto debugger = new DebuggerRunTool(runControl, kit); auto debugger = new DebuggerRunTool(runControl, kit);
debugger->setInferiorExecutable(executable); debugger->setInferiorExecutable(executable);
if (pid) { if (pid) {
@@ -929,7 +930,7 @@ bool DebuggerPluginPrivate::parseArgument(QStringList::const_iterator &it,
return false; return false;
} }
qint64 pid = it->section(':', 1, 1).toULongLong(); qint64 pid = it->section(':', 1, 1).toULongLong();
auto runControl = new RunControl(nullptr, ProjectExplorer::Constants::DEBUG_RUN_MODE); auto runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE);
auto debugger = new DebuggerRunTool(runControl, findUniversalCdbKit()); auto debugger = new DebuggerRunTool(runControl, findUniversalCdbKit());
debugger->setStartMode(AttachCrashedExternal); debugger->setStartMode(AttachCrashedExternal);
debugger->setCrashParameter(it->section(':', 0, 0)); debugger->setCrashParameter(it->section(':', 0, 0));
@@ -1583,8 +1584,8 @@ void DebuggerPluginPrivate::attachCore()
setConfigValue("LastExternalStartScript", dlg.overrideStartScript()); setConfigValue("LastExternalStartScript", dlg.overrideStartScript());
setConfigValue("LastForceLocalCoreFile", dlg.forcesLocalCoreFile()); setConfigValue("LastForceLocalCoreFile", dlg.forcesLocalCoreFile());
IDevice::ConstPtr device = DeviceKitAspect::device(dlg.kit()); auto runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE);
auto runControl = new RunControl(device, ProjectExplorer::Constants::DEBUG_RUN_MODE); runControl->setDevice(DeviceKitAspect::device(dlg.kit()));
auto debugger = new DebuggerRunTool(runControl, dlg.kit()); auto debugger = new DebuggerRunTool(runControl, dlg.kit());
debugger->setInferiorExecutable(dlg.symbolFile()); debugger->setInferiorExecutable(dlg.symbolFile());
debugger->setCoreFileName(dlg.localCoreFile()); debugger->setCoreFileName(dlg.localCoreFile());
@@ -1611,8 +1612,8 @@ void DebuggerPluginPrivate::startRemoteCdbSession()
return; return;
setConfigValue(connectionKey, dlg.connection()); setConfigValue(connectionKey, dlg.connection());
IDevice::ConstPtr device = DeviceKitAspect::device(kit); auto runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE);
auto runControl = new RunControl(device, ProjectExplorer::Constants::DEBUG_RUN_MODE); runControl->setDevice(DeviceKitAspect::device(kit));
auto debugger = new DebuggerRunTool(runControl, kit); auto debugger = new DebuggerRunTool(runControl, kit);
debugger->setStartMode(AttachToRemoteServer); debugger->setStartMode(AttachToRemoteServer);
debugger->setCloseMode(KillAtClose); debugger->setCloseMode(KillAtClose);
@@ -1670,7 +1671,8 @@ void DebuggerPluginPrivate::attachToRunningApplication()
if (device->type() == PE::DESKTOP_DEVICE_TYPE) { if (device->type() == PE::DESKTOP_DEVICE_TYPE) {
attachToRunningProcess(kit, process, false); attachToRunningProcess(kit, process, false);
} else { } else {
auto runControl = new RunControl(device, ProjectExplorer::Constants::DEBUG_RUN_MODE); auto runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE);
runControl->setDevice(device);
auto debugger = new RemoteAttachRunner(runControl, kit, process.pid); auto debugger = new RemoteAttachRunner(runControl, kit, process.pid);
debugger->startRunControl(); debugger->startRunControl();
} }
@@ -1723,7 +1725,7 @@ RunControl *DebuggerPluginPrivate::attachToRunningProcess(Kit *kit,
return nullptr; return nullptr;
} }
auto runControl = new RunControl(nullptr, ProjectExplorer::Constants::DEBUG_RUN_MODE); auto runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE);
auto debugger = new DebuggerRunTool(runControl, kit); auto debugger = new DebuggerRunTool(runControl, kit);
debugger->setAttachPid(ProcessHandle(process.pid)); debugger->setAttachPid(ProcessHandle(process.pid));
debugger->setRunControlName(tr("Process %1").arg(process.pid)); debugger->setRunControlName(tr("Process %1").arg(process.pid));
@@ -1745,7 +1747,8 @@ void DebuggerPlugin::attachExternalApplication(RunControl *rc)
QTC_ASSERT(runConfig, return); QTC_ASSERT(runConfig, return);
Target *target = runConfig->target(); Target *target = runConfig->target();
QTC_ASSERT(target, return); QTC_ASSERT(target, return);
auto runControl = new RunControl(runConfig, ProjectExplorer::Constants::DEBUG_RUN_MODE); auto runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE);
runControl->setRunConfiguration(runConfig);
auto debugger = new DebuggerRunTool(runControl, target->kit(), false); auto debugger = new DebuggerRunTool(runControl, target->kit(), false);
debugger->setAttachPid(pid); debugger->setAttachPid(pid);
debugger->setRunControlName(tr("Process %1").arg(pid.pid())); debugger->setRunControlName(tr("Process %1").arg(pid.pid()));
@@ -1804,7 +1807,7 @@ void DebuggerPluginPrivate::attachToQmlPort()
IDevice::ConstPtr device = DeviceKitAspect::device(kit); IDevice::ConstPtr device = DeviceKitAspect::device(kit);
QTC_ASSERT(device, return); QTC_ASSERT(device, return);
auto runControl = new RunControl(nullptr, ProjectExplorer::Constants::DEBUG_RUN_MODE); auto runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE);
auto debugger = new DebuggerRunTool(runControl, kit); auto debugger = new DebuggerRunTool(runControl, kit);
QUrl qmlServer = device->toolControlChannel(IDevice::QmlControlChannel); QUrl qmlServer = device->toolControlChannel(IDevice::QmlControlChannel);
@@ -2505,7 +2508,8 @@ void DebuggerUnitTests::testStateMachine()
RunConfiguration *rc = t->activeRunConfiguration(); RunConfiguration *rc = t->activeRunConfiguration();
QVERIFY(rc); QVERIFY(rc);
auto runControl = new RunControl(rc, ProjectExplorer::Constants::DEBUG_RUN_MODE); auto runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE);
runControl->setRunConfiguration(rc);
auto debugger = new DebuggerRunTool(runControl); auto debugger = new DebuggerRunTool(runControl);
debugger->setInferior(rc->runnable()); debugger->setInferior(rc->runnable());
+2 -1
View File
@@ -637,7 +637,8 @@ void DebuggerRunTool::start()
connect(m_engine, &DebuggerEngine::attachToCoreRequested, this, [this](const QString &coreFile) { connect(m_engine, &DebuggerEngine::attachToCoreRequested, this, [this](const QString &coreFile) {
auto runConfig = runControl()->runConfiguration(); auto runConfig = runControl()->runConfiguration();
QTC_ASSERT(runConfig, return); QTC_ASSERT(runConfig, return);
auto rc = new RunControl(runConfig, ProjectExplorer::Constants::DEBUG_RUN_MODE); auto rc = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE);
rc->setRunConfiguration(runConfig);
auto name = QString(tr("%1 - Snapshot %2").arg(runControl()->displayName()).arg(++d->snapshotCounter)); auto name = QString(tr("%1 - Snapshot %2").arg(runControl()->displayName()).arg(++d->snapshotCounter));
auto debugger = new DebuggerRunTool(rc); auto debugger = new DebuggerRunTool(rc);
debugger->setStartMode(AttachCore); debugger->setStartMode(AttachCore);
@@ -2191,7 +2191,8 @@ void ProjectExplorerPluginPrivate::executeRunConfiguration(RunConfiguration *run
RunControl::WorkerCreator producer = RunControl::producer(runConfiguration, runMode); RunControl::WorkerCreator producer = RunControl::producer(runConfiguration, runMode);
QTC_ASSERT(producer, return); QTC_ASSERT(producer, return);
auto runControl = new RunControl(runConfiguration, runMode); auto runControl = new RunControl(runMode);
runControl->setRunConfiguration(runConfiguration);
// A user needed interaction may have cancelled the run // A user needed interaction may have cancelled the run
// (by example asking for a process pid or server url). // (by example asking for a process pid or server url).
@@ -799,21 +799,11 @@ static QString stateName(RunControlState s)
class RunControlPrivate : public QObject class RunControlPrivate : public QObject
{ {
public: public:
RunControlPrivate(RunControl *parent, RunConfiguration *runConfiguration, Core::Id mode) RunControlPrivate(RunControl *parent, Core::Id mode)
: q(parent), runMode(mode), runConfiguration(runConfiguration) : q(parent), runMode(mode)
{ {
icon = Icons::RUN_SMALL_TOOLBAR; icon = Icons::RUN_SMALL_TOOLBAR;
if (runConfiguration) { outputFormatter = new OutputFormatter();
runnable = runConfiguration->runnable();
displayName = runConfiguration->displayName();
outputFormatter = runConfiguration->createOutputFormatter();
device = runnable.device;
target = runConfiguration->target();
if (!device)
device = DeviceKitAspect::device(target->kit());
} else {
outputFormatter = new OutputFormatter();
}
} }
~RunControlPrivate() override ~RunControlPrivate() override
@@ -856,7 +846,7 @@ public:
IDevice::ConstPtr device; IDevice::ConstPtr device;
Core::Id runMode; Core::Id runMode;
Utils::Icon icon; Utils::Icon icon;
const QPointer<RunConfiguration> runConfiguration; // Not owned. QPointer<RunConfiguration> runConfiguration; // Not owned. Avoid use.
QPointer<Target> target; // Not owned. QPointer<Target> target; // Not owned.
QPointer<Utils::OutputFormatter> outputFormatter = nullptr; QPointer<Utils::OutputFormatter> outputFormatter = nullptr;
std::function<bool(bool*)> promptToStop; std::function<bool(bool*)> promptToStop;
@@ -874,11 +864,33 @@ public:
using namespace Internal; using namespace Internal;
RunControl::RunControl(RunConfiguration *runConfiguration, Core::Id mode) : RunControl::RunControl(Core::Id mode) :
d(std::make_unique<RunControlPrivate>(this, runConfiguration, mode)) d(std::make_unique<RunControlPrivate>(this, mode))
{ {
}
void RunControl::setRunConfiguration(RunConfiguration *runConfig)
{
QTC_ASSERT(runConfig, return);
d->runConfiguration = runConfig;
d->runnable = runConfig->runnable();
d->displayName = runConfig->displayName();
if (auto outputFormatter = runConfig->createOutputFormatter()) {
delete d->outputFormatter;
d->outputFormatter = outputFormatter;
}
d->target = runConfig->target();
if (d->runnable.device)
setDevice(d->runnable.device);
else
setDevice(DeviceKitAspect::device(d->target->kit()));
}
void RunControl::setDevice(const IDevice::ConstPtr &device)
{
d->device = device;
#ifdef WITH_JOURNALD #ifdef WITH_JOURNALD
if (!device().isNull() && device()->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) { if (!device.isNull() && device->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) {
JournaldWatcher::instance()->subscribe(this, [this](const JournaldWatcher::LogEntry &entry) { JournaldWatcher::instance()->subscribe(this, [this](const JournaldWatcher::LogEntry &entry) {
if (entry.value("_MACHINE_ID") != JournaldWatcher::instance()->machineId()) if (entry.value("_MACHINE_ID") != JournaldWatcher::instance()->machineId())
@@ -899,12 +911,6 @@ RunControl::RunControl(RunConfiguration *runConfiguration, Core::Id mode) :
#endif #endif
} }
RunControl::RunControl(const IDevice::ConstPtr &device, Core::Id mode)
: RunControl(nullptr, mode)
{
d->device = device;
}
RunControl::~RunControl() RunControl::~RunControl()
{ {
#ifdef WITH_JOURNALD #ifdef WITH_JOURNALD
@@ -412,10 +412,12 @@ class PROJECTEXPLORER_EXPORT RunControl : public QObject
Q_OBJECT Q_OBJECT
public: public:
RunControl(RunConfiguration *runConfiguration, Core::Id mode); explicit RunControl(Core::Id mode);
RunControl(const IDevice::ConstPtr &device, Core::Id mode);
~RunControl() override; ~RunControl() override;
void setRunConfiguration(RunConfiguration *runConfig);
void setDevice(const IDevice::ConstPtr &device);
void initiateStart(); void initiateStart();
void initiateReStart(); void initiateReStart();
void initiateStop(); void initiateStop();
+2 -2
View File
@@ -552,8 +552,8 @@ ProjectExplorer::RunControl *QmlProfilerTool::attachToWaitingApplication()
d->m_viewContainer->perspective()->select(); d->m_viewContainer->perspective()->select();
auto runConfig = RunConfiguration::startupRunConfiguration(); auto runControl = new RunControl(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
auto runControl = new RunControl(runConfig, ProjectExplorer::Constants::QML_PROFILER_RUN_MODE); runControl->setRunConfiguration(RunConfiguration::startupRunConfiguration());
auto profiler = new QmlProfilerRunner(runControl); auto profiler = new QmlProfilerRunner(runControl);
profiler->setServerUrl(serverUrl); profiler->setServerUrl(serverUrl);
connect(profiler, &QmlProfilerRunner::starting, this, &QmlProfilerTool::finalizeRunControl); connect(profiler, &QmlProfilerRunner::starting, this, &QmlProfilerTool::finalizeRunControl);
@@ -64,8 +64,7 @@ void LocalQmlProfilerRunnerTest::testRunner()
serverUrl.setScheme(Utils::urlSocketScheme()); serverUrl.setScheme(Utils::urlSocketScheme());
serverUrl.setPath("invalid"); serverUrl.setPath("invalid");
runControl = new ProjectExplorer::RunControl(nullptr, runControl = new ProjectExplorer::RunControl(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
runControl->setRunnable(debuggee); runControl->setRunnable(debuggee);
profiler = new LocalQmlProfilerSupport(&tool, runControl, serverUrl); profiler = new LocalQmlProfilerSupport(&tool, runControl, serverUrl);
@@ -115,8 +114,7 @@ void LocalQmlProfilerRunnerTest::testRunner()
// comma is used to specify a test function. In this case, an invalid one. // comma is used to specify a test function. In this case, an invalid one.
debuggee.commandLineArguments = QString("-test QmlProfiler,"); debuggee.commandLineArguments = QString("-test QmlProfiler,");
runControl = new ProjectExplorer::RunControl(nullptr, runControl = new ProjectExplorer::RunControl(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
runControl->setRunnable(debuggee); runControl->setRunnable(debuggee);
profiler = new LocalQmlProfilerSupport(&tool, runControl, serverUrl); profiler = new LocalQmlProfilerSupport(&tool, runControl, serverUrl);
connectRunner(); connectRunner();
@@ -135,8 +133,7 @@ void LocalQmlProfilerRunnerTest::testRunner()
debuggee.commandLineArguments.clear(); debuggee.commandLineArguments.clear();
serverUrl.clear(); serverUrl.clear();
serverUrl = Utils::urlFromLocalHostAndFreePort(); serverUrl = Utils::urlFromLocalHostAndFreePort();
runControl = new ProjectExplorer::RunControl(nullptr, runControl = new ProjectExplorer::RunControl(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
runControl->setRunnable(debuggee); runControl->setRunnable(debuggee);
profiler = new LocalQmlProfilerSupport(&tool, runControl, serverUrl); profiler = new LocalQmlProfilerSupport(&tool, runControl, serverUrl);
connectRunner(); connectRunner();
@@ -161,8 +158,7 @@ void LocalQmlProfilerRunnerTest::testRunner()
serverUrl.setPath(file.fileName()); serverUrl.setPath(file.fileName());
} }
runControl = new ProjectExplorer::RunControl(nullptr, runControl = new ProjectExplorer::RunControl(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
runControl->setRunnable(debuggee); runControl->setRunnable(debuggee);
profiler = new LocalQmlProfilerSupport(&tool, runControl, serverUrl); profiler = new LocalQmlProfilerSupport(&tool, runControl, serverUrl);
connectRunner(); connectRunner();
+2 -1
View File
@@ -266,7 +266,8 @@ void QnxAttachDebugSupport::showProcessesDialog()
localExecutable = aspect->fileName().toString(); localExecutable = aspect->fileName().toString();
} }
auto runControl = new RunControl(runConfig, ProjectExplorer::Constants::DEBUG_RUN_MODE); auto runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE);
runControl->setRunConfiguration(runConfig);
auto debugger = new QnxAttachDebugSupport(runControl); auto debugger = new QnxAttachDebugSupport(runControl);
debugger->setStartMode(AttachToRemoteServer); debugger->setStartMode(AttachToRemoteServer);
debugger->setCloseMode(DetachAtClose); debugger->setCloseMode(DetachAtClose);
+2 -1
View File
@@ -280,7 +280,8 @@ CallgrindTool::CallgrindTool()
if (dlg.exec() != QDialog::Accepted) if (dlg.exec() != QDialog::Accepted)
return; return;
m_perspective.select(); m_perspective.select();
auto runControl = new RunControl(runConfig, CALLGRIND_RUN_MODE); auto runControl = new RunControl(CALLGRIND_RUN_MODE);
runControl->setRunConfiguration(runConfig);
if (auto creator = RunControl::producer(runConfig, CALLGRIND_RUN_MODE)) if (auto creator = RunControl::producer(runConfig, CALLGRIND_RUN_MODE))
creator(runControl); creator(runControl);
const auto runnable = dlg.runnable(); const auto runnable = dlg.runnable();
+2 -1
View File
@@ -671,7 +671,8 @@ MemcheckTool::MemcheckTool()
return; return;
TaskHub::clearTasks(Debugger::Constants::ANALYZERTASK_ID); TaskHub::clearTasks(Debugger::Constants::ANALYZERTASK_ID);
m_perspective.select(); m_perspective.select();
RunControl *rc = new RunControl(runConfig, MEMCHECK_RUN_MODE); RunControl *rc = new RunControl(MEMCHECK_RUN_MODE);
rc->setRunConfiguration(runConfig);
if (auto creator = RunControl::producer(runConfig, MEMCHECK_RUN_MODE)) if (auto creator = RunControl::producer(runConfig, MEMCHECK_RUN_MODE))
creator(rc); creator(rc);
const auto runnable = dlg.runnable(); const auto runnable = dlg.runnable();