ProjectExplorer: Reduce use of Runnable in SimpleTargetRunner

Runnable functionality is nowadays mostly accessed more directly
in QtcProcess and its setup functions.

Change-Id: I2a2b5433aef1d464dc58d5a35069376dee051d57
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2022-05-23 16:09:43 +02:00
parent ae42604904
commit f79a71df7b
13 changed files with 123 additions and 110 deletions

View File

@@ -199,11 +199,9 @@ RunWorker *GdbServerProvider::targetRunner(RunControl *runControl) const
if (m_startupMode != GdbServerProvider::StartupOnNetwork) if (m_startupMode != GdbServerProvider::StartupOnNetwork)
return nullptr; return nullptr;
Runnable r;
r.command = command();
// Command arguments are in host OS style as the bare metal's GDB servers are launched // Command arguments are in host OS style as the bare metal's GDB servers are launched
// on the host, not on that target. // on the host, not on that target.
return new GdbServerProviderRunner(runControl, r); return new GdbServerProviderRunner(runControl, command());
} }
bool GdbServerProvider::fromMap(const QVariantMap &data) bool GdbServerProvider::fromMap(const QVariantMap &data)
@@ -341,14 +339,15 @@ QString GdbServerProviderConfigWidget::defaultResetCommandsTooltip()
// GdbServerProviderRunner // GdbServerProviderRunner
GdbServerProviderRunner::GdbServerProviderRunner(ProjectExplorer::RunControl *runControl, GdbServerProviderRunner::GdbServerProviderRunner(ProjectExplorer::RunControl *runControl,
const ProjectExplorer::Runnable &runnable) const Utils::CommandLine &commandLine)
: SimpleTargetRunner(runControl) : SimpleTargetRunner(runControl)
{ {
setId("BareMetalGdbServer"); setId("BareMetalGdbServer");
// Baremetal's GDB servers are launched on the host, not on the target. // Baremetal's GDB servers are launched on the host, not on the target.
Runnable devicelessRunnable = runnable; setStartModifier([this, commandLine] {
devicelessRunnable.device.reset(); setCommandLine(commandLine);
setStarter([this, devicelessRunnable] { doStart(devicelessRunnable); }); forceRunOnHost();
});
} }
} // namespace Internal } // namespace Internal

View File

@@ -126,7 +126,7 @@ class GdbServerProviderRunner final : public ProjectExplorer::SimpleTargetRunner
{ {
public: public:
explicit GdbServerProviderRunner(ProjectExplorer::RunControl *runControl, explicit GdbServerProviderRunner(ProjectExplorer::RunControl *runControl,
const ProjectExplorer::Runnable &runnable); const Utils::CommandLine &commandLine);
}; };
} // namespace Internal } // namespace Internal

View File

@@ -142,13 +142,11 @@ public:
QdbDeviceRunSupport(RunControl *runControl) QdbDeviceRunSupport(RunControl *runControl)
: SimpleTargetRunner(runControl) : SimpleTargetRunner(runControl)
{ {
setStarter([this, runControl] { setStartModifier([this] {
Runnable r = runControl->runnable(); CommandLine cmd;
// FIXME: Spaces! cmd.setExecutable(FilePath::fromString(Constants::AppcontrollerFilepath));
r.command.setArguments(r.command.executable().toString() + ' ' + r.command.arguments()); cmd.addCommandLineAsArgs(commandLine());
r.command.setExecutable(FilePath::fromString(Constants::AppcontrollerFilepath)); setCommandLine(cmd);
r.device = runControl->device();
doStart(r);
}); });
} }
}; };

View File

@@ -1042,35 +1042,31 @@ DebugServerRunner::DebugServerRunner(RunControl *runControl, DebugServerPortsGat
: SimpleTargetRunner(runControl) : SimpleTargetRunner(runControl)
{ {
setId("DebugServerRunner"); setId("DebugServerRunner");
const Runnable mainRunnable = runControl->runnable();
addStartDependency(portsGatherer); addStartDependency(portsGatherer);
QTC_ASSERT(portsGatherer, reportFailure(); return); QTC_ASSERT(portsGatherer, reportFailure(); return);
setStarter([this, runControl, mainRunnable, portsGatherer] { setStartModifier([this, runControl, portsGatherer] {
QTC_ASSERT(portsGatherer, reportFailure(); return); QTC_ASSERT(portsGatherer, reportFailure(); return);
Runnable debugServer;
debugServer.environment = mainRunnable.environment;
debugServer.workingDirectory = mainRunnable.workingDirectory;
QStringList args = ProcessArgs::splitArgs(mainRunnable.command.arguments(), OsTypeLinux);
const bool isQmlDebugging = portsGatherer->useQmlServer(); const bool isQmlDebugging = portsGatherer->useQmlServer();
const bool isCppDebugging = portsGatherer->useGdbServer(); const bool isCppDebugging = portsGatherer->useGdbServer();
CommandLine cmd;
QStringList args = ProcessArgs::splitArgs(commandLine().arguments(), OsTypeLinux);
if (isQmlDebugging) { if (isQmlDebugging) {
args.prepend(QmlDebug::qmlDebugTcpArguments(QmlDebug::QmlDebuggerServices, args.prepend(QmlDebug::qmlDebugTcpArguments(QmlDebug::QmlDebuggerServices,
portsGatherer->qmlServer())); portsGatherer->qmlServer()));
} }
if (isQmlDebugging && !isCppDebugging) { if (isQmlDebugging && !isCppDebugging) {
debugServer.command.setExecutable(mainRunnable.command.executable()); // FIXME: Case should not happen? cmd.setExecutable(commandLine().executable()); // FIXME: Case should not happen?
} else { } else {
debugServer.command.setExecutable(runControl->device()->debugServerPath()); cmd.setExecutable(runControl->device()->debugServerPath());
if (debugServer.command.isEmpty()) if (cmd.isEmpty())
debugServer.command.setExecutable("gdbserver"); cmd.setExecutable("gdbserver");
args.clear(); args.clear();
if (debugServer.command.executable().toString().contains("lldb-server")) { if (cmd.executable().toString().contains("lldb-server")) {
args.append("platform"); args.append("platform");
args.append("--listen"); args.append("--listen");
args.append(QString("*:%1").arg(portsGatherer->gdbServer().port())); args.append(QString("*:%1").arg(portsGatherer->gdbServer().port()));
@@ -1086,9 +1082,9 @@ DebugServerRunner::DebugServerRunner(RunControl *runControl, DebugServerPortsGat
args.append(QString::number(m_pid.pid())); args.append(QString::number(m_pid.pid()));
} }
} }
debugServer.command.setArguments(ProcessArgs::joinArgs(args, OsTypeLinux)); cmd.setArguments(ProcessArgs::joinArgs(args, OsTypeLinux));
debugServer.device = runControl->device();
doStart(debugServer); setCommandLine(cmd);
}); });
} }

View File

@@ -88,15 +88,12 @@ public:
FlashAndRunWorker(RunControl *runControl) FlashAndRunWorker(RunControl *runControl)
: SimpleTargetRunner(runControl) : SimpleTargetRunner(runControl)
{ {
setStarter([this, runControl] { setStartModifier([this, runControl] {
const Target *target = runControl->target(); const Target *target = runControl->target();
Runnable r; setCommandLine({cmakeFilePath(target), runControl->aspect<StringAspect>()->value,
r.command = {cmakeFilePath(target), CommandLine::Raw});
runControl->aspect<StringAspect>()->value, setWorkingDirectory(target->activeBuildConfiguration()->buildDirectory());
CommandLine::Raw}; setEnvironment(target->activeBuildConfiguration()->environment());
r.workingDirectory = target->activeBuildConfiguration()->buildDirectory();
r.environment = target->activeBuildConfiguration()->environment();
SimpleTargetRunner::doStart(r);
}); });
} }
}; };

View File

@@ -1246,7 +1246,7 @@ public:
ProcessResultData m_resultData; ProcessResultData m_resultData;
std::function<void()> m_starter; std::function<void()> m_startModifier;
bool m_stopReported = false; bool m_stopReported = false;
bool m_stopForced = false; bool m_stopForced = false;
@@ -1481,17 +1481,6 @@ SimpleTargetRunner::SimpleTargetRunner(RunControl *runControl)
SimpleTargetRunner::~SimpleTargetRunner() = default; SimpleTargetRunner::~SimpleTargetRunner() = default;
void SimpleTargetRunner::start()
{
if (d->m_starter) {
d->m_starter();
} else {
Runnable runnable = runControl()->runnable();
runnable.device = runControl()->device();
doStart(runnable);
}
}
void SimpleTargetRunnerPrivate::forwardDone() void SimpleTargetRunnerPrivate::forwardDone()
{ {
if (m_stopReported) if (m_stopReported)
@@ -1523,8 +1512,14 @@ void SimpleTargetRunnerPrivate::forwardStarted()
q->reportStarted(); q->reportStarted();
} }
void SimpleTargetRunner::doStart(const Runnable &runnable) void SimpleTargetRunner::start()
{ {
d->m_runnable = runControl()->runnable();
d->m_runnable.device = runControl()->device();
if (d->m_startModifier)
d->m_startModifier();
bool useTerminal = false; bool useTerminal = false;
if (auto terminalAspect = runControl()->aspect<TerminalAspect>()) if (auto terminalAspect = runControl()->aspect<TerminalAspect>())
useTerminal = terminalAspect->useTerminal; useTerminal = terminalAspect->useTerminal;
@@ -1539,16 +1534,15 @@ void SimpleTargetRunner::doStart(const Runnable &runnable)
d->m_process.setTerminalMode(useTerminal ? Utils::TerminalMode::On : Utils::TerminalMode::Off); d->m_process.setTerminalMode(useTerminal ? Utils::TerminalMode::On : Utils::TerminalMode::Off);
d->m_runAsRoot = runAsRoot; d->m_runAsRoot = runAsRoot;
const QString msg = RunControl::tr("Starting %1...").arg(runnable.command.toUserOutput()); const QString msg = RunControl::tr("Starting %1...").arg(d->m_runnable.command.toUserOutput());
appendMessage(msg, Utils::NormalMessageFormat); appendMessage(msg, Utils::NormalMessageFormat);
const bool isDesktop = runnable.device.isNull() const bool isDesktop = d->m_runnable.device.isNull()
|| runnable.device.dynamicCast<const DesktopDevice>(); || d->m_runnable.device.dynamicCast<const DesktopDevice>();
if (isDesktop && runnable.command.isEmpty()) { if (isDesktop && d->m_runnable.command.isEmpty()) {
reportFailure(RunControl::tr("No executable specified.")); reportFailure(RunControl::tr("No executable specified."));
return; return;
} }
d->m_runnable = runnable;
d->start(); d->start();
} }
@@ -1558,11 +1552,40 @@ void SimpleTargetRunner::stop()
d->stop(); d->stop();
} }
void SimpleTargetRunner::setStarter(const std::function<void ()> &starter) void SimpleTargetRunner::setStartModifier(const std::function<void ()> &startModifier)
{ {
d->m_starter = starter; d->m_startModifier = startModifier;
} }
CommandLine SimpleTargetRunner::commandLine() const
{
return d->m_runnable.command;
}
void SimpleTargetRunner::setCommandLine(const Utils::CommandLine &commandLine)
{
d->m_runnable.command = commandLine;
}
void SimpleTargetRunner::setEnvironment(const Environment &environment)
{
d->m_runnable.environment = environment;
}
void SimpleTargetRunner::setWorkingDirectory(const FilePath &workingDirectory)
{
d->m_runnable.workingDirectory = workingDirectory;
}
void SimpleTargetRunner::forceRunOnHost()
{
d->m_runnable.device = {};
const FilePath executable = d->m_runnable.command.executable();
if (executable.needsDevice()) {
QTC_CHECK(false);
d->m_runnable.command.setExecutable(FilePath::fromString(executable.path()));
}
}
// RunWorkerPrivate // RunWorkerPrivate

View File

@@ -298,14 +298,22 @@ public:
~SimpleTargetRunner() override; ~SimpleTargetRunner() override;
protected: protected:
void setStarter(const std::function<void()> &starter); void setStartModifier(const std::function<void()> &startModifier);
void doStart(const Runnable &runnable);
Utils::CommandLine commandLine() const;
void setCommandLine(const Utils::CommandLine &commandLine);
void setEnvironment(const Utils::Environment &environment);
void setWorkingDirectory(const Utils::FilePath &workingDirectory);
void forceRunOnHost();
private: private:
void start() final; void start() final;
void stop() final; void stop() final;
const Runnable &runnable() const = delete; const Runnable &runnable() const = delete;
void setRunnable(const Runnable &) = delete;
const std::unique_ptr<Internal::SimpleTargetRunnerPrivate> d; const std::unique_ptr<Internal::SimpleTargetRunnerPrivate> d;
}; };

View File

@@ -41,6 +41,8 @@
#include <utils/url.h> #include <utils/url.h>
#include <utils/fileutils.h> #include <utils/fileutils.h>
using namespace Utils;
namespace QmlPreview { namespace QmlPreview {
static const QString QmlServerUrl = "QmlServerUrl"; static const QString QmlServerUrl = "QmlServerUrl";
@@ -126,9 +128,10 @@ LocalQmlPreviewSupport::LocalQmlPreviewSupport(ProjectExplorer::RunControl *runC
addStopDependency(preview); addStopDependency(preview);
addStartDependency(preview); addStartDependency(preview);
setStarter([this, runControl, serverUrl] { setStartModifier([this, runControl, serverUrl] {
ProjectExplorer::Runnable runnable = runControl->runnable(); CommandLine cmd = commandLine();
QStringList qmlProjectRunConfigurationArguments = runnable.command.splitArguments();
QStringList qmlProjectRunConfigurationArguments = cmd.splitArguments();
const auto currentTarget = runControl->target(); const auto currentTarget = runControl->target();
const auto *qmlBuildSystem = qobject_cast<QmlProjectManager::QmlBuildSystem *>(currentTarget->buildSystem()); const auto *qmlBuildSystem = qobject_cast<QmlProjectManager::QmlBuildSystem *>(currentTarget->buildSystem());
@@ -142,15 +145,15 @@ LocalQmlPreviewSupport::LocalQmlPreviewSupport(ProjectExplorer::RunControl *runC
if (!currentFile.isEmpty() && qmlProjectRunConfigurationArguments.last().contains(mainScriptFromProject)) { if (!currentFile.isEmpty() && qmlProjectRunConfigurationArguments.last().contains(mainScriptFromProject)) {
qmlProjectRunConfigurationArguments.removeLast(); qmlProjectRunConfigurationArguments.removeLast();
runnable.command = Utils::CommandLine(runnable.command.executable(), qmlProjectRunConfigurationArguments); cmd = Utils::CommandLine(cmd.executable(), qmlProjectRunConfigurationArguments);
runnable.command.addArg(currentFile); cmd.addArg(currentFile);
} }
} }
runnable.command.addArg(QmlDebug::qmlDebugLocalArguments(QmlDebug::QmlPreviewServices, cmd.addArg(QmlDebug::qmlDebugLocalArguments(QmlDebug::QmlPreviewServices, serverUrl.path()));
serverUrl.path())); setCommandLine(cmd);
runnable.device.reset();
doStart(runnable); forceRunOnHost();
}); });
} }

View File

@@ -25,7 +25,6 @@
#include "qmlprofilerruncontrol.h" #include "qmlprofilerruncontrol.h"
#include "qmlprofilerclientmanager.h"
#include "qmlprofilertool.h" #include "qmlprofilertool.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
@@ -236,8 +235,7 @@ LocalQmlProfilerSupport::LocalQmlProfilerSupport(RunControl *runControl, const Q
// In the TCP case, it doesn't hurt either to start the profiler before. // In the TCP case, it doesn't hurt either to start the profiler before.
addStartDependency(profiler); addStartDependency(profiler);
setStarter([this, runControl, profiler, serverUrl] { setStartModifier([this, profiler, serverUrl] {
Runnable debuggee = runControl->runnable();
QUrl serverUrl = profiler->serverUrl(); QUrl serverUrl = profiler->serverUrl();
QString code; QString code;
@@ -251,12 +249,13 @@ LocalQmlProfilerSupport::LocalQmlProfilerSupport(RunControl *runControl, const Q
QString arguments = Utils::ProcessArgs::quoteArg( QString arguments = Utils::ProcessArgs::quoteArg(
QmlDebug::qmlDebugCommandLineArguments(QmlDebug::QmlProfilerServices, code, true)); QmlDebug::qmlDebugCommandLineArguments(QmlDebug::QmlProfilerServices, code, true));
if (!debuggee.command.arguments().isEmpty()) Utils::CommandLine cmd = commandLine();
arguments += ' ' + debuggee.command.arguments(); const QString oldArgs = cmd.arguments();
cmd.setArguments(arguments);
cmd.addArgs(oldArgs, Utils::CommandLine::Raw);
setCommandLine(cmd);
debuggee.command.setArguments(arguments); forceRunOnHost();
debuggee.device.reset();
doStart(debuggee);
}); });
} }

View File

@@ -56,14 +56,13 @@ QnxQmlProfilerSupport::QnxQmlProfilerSupport(RunControl *runControl)
profiler->addStartDependency(this); profiler->addStartDependency(this);
addStopDependency(profiler); addStopDependency(profiler);
setStarter([this, runControl, portsGatherer, profiler] { setStartModifier([this, portsGatherer, profiler] {
const QUrl serverUrl = portsGatherer->findEndPoint(); const QUrl serverUrl = portsGatherer->findEndPoint();
profiler->recordData("QmlServerUrl", serverUrl); profiler->recordData("QmlServerUrl", serverUrl);
Runnable r = runControl->runnable(); CommandLine cmd = commandLine();
r.command.addArg(QmlDebug::qmlDebugTcpArguments(QmlDebug::QmlProfilerServices, serverUrl)); cmd.addArg(QmlDebug::qmlDebugTcpArguments(QmlDebug::QmlProfilerServices, serverUrl));
r.device = runControl->device(); setCommandLine(cmd);
doStart(r);
}); });
} }

View File

@@ -26,11 +26,9 @@
#include "qnxdebugsupport.h" #include "qnxdebugsupport.h"
#include "qnxconstants.h" #include "qnxconstants.h"
#include "qnxdevice.h"
#include "qnxrunconfiguration.h" #include "qnxrunconfiguration.h"
#include "slog2inforunner.h" #include "slog2inforunner.h"
#include "qnxqtversion.h" #include "qnxqtversion.h"
#include "qnxutils.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
@@ -103,21 +101,21 @@ public:
{ {
setId("QnxDebuggeeRunner"); setId("QnxDebuggeeRunner");
setStarter([this, runControl, portsGatherer] { setStartModifier([this, portsGatherer] {
Runnable r = runControl->runnable(); CommandLine cmd = commandLine();
QStringList arguments; QStringList arguments;
if (portsGatherer->useGdbServer()) { if (portsGatherer->useGdbServer()) {
int pdebugPort = portsGatherer->gdbServer().port(); int pdebugPort = portsGatherer->gdbServer().port();
r.command.setExecutable(FilePath::fromString(QNX_DEBUG_EXECUTABLE)); cmd.setExecutable(FilePath::fromString(QNX_DEBUG_EXECUTABLE));
arguments.append(QString::number(pdebugPort)); arguments.append(QString::number(pdebugPort));
} }
if (portsGatherer->useQmlServer()) { if (portsGatherer->useQmlServer()) {
arguments.append(QmlDebug::qmlDebugTcpArguments(QmlDebug::QmlDebuggerServices, arguments.append(QmlDebug::qmlDebugTcpArguments(QmlDebug::QmlDebuggerServices,
portsGatherer->qmlServer())); portsGatherer->qmlServer()));
} }
r.command.setArguments(ProcessArgs::joinArgs(arguments)); cmd.setArguments(ProcessArgs::joinArgs(arguments));
r.device = runControl->device(); setCommandLine(cmd);
doStart(r);
}); });
} }
}; };
@@ -197,13 +195,9 @@ public:
setId("PDebugRunner"); setId("PDebugRunner");
addStartDependency(portsGatherer); addStartDependency(portsGatherer);
setStarter([this, runControl, portsGatherer] { setStartModifier([this, portsGatherer] {
const int pdebugPort = portsGatherer->gdbServer().port(); const int pdebugPort = portsGatherer->gdbServer().port();
setCommandLine({QNX_DEBUG_EXECUTABLE, {QString::number(pdebugPort)}});
Runnable r;
r.command = {QNX_DEBUG_EXECUTABLE, {QString::number(pdebugPort)}};
r.device = runControl->device();
doStart(r);
}); });
} }
}; };

View File

@@ -51,16 +51,15 @@ RemoteLinuxQmlToolingSupport::RemoteLinuxQmlToolingSupport(RunControl *runContro
runworker->addStartDependency(this); runworker->addStartDependency(this);
addStopDependency(runworker); addStopDependency(runworker);
setStarter([this, runControl, portsGatherer, runworker] { setStartModifier([this, runControl, portsGatherer, runworker] {
const QUrl serverUrl = portsGatherer->findEndPoint(); const QUrl serverUrl = portsGatherer->findEndPoint();
runworker->recordData("QmlServerUrl", serverUrl); runworker->recordData("QmlServerUrl", serverUrl);
QmlDebug::QmlDebugServicesPreset services = QmlDebug::servicesForRunMode(runControl->runMode()); QmlDebug::QmlDebugServicesPreset services = QmlDebug::servicesForRunMode(runControl->runMode());
Runnable r = runControl->runnable(); CommandLine cmd = commandLine();
r.command.addArg(QmlDebug::qmlDebugTcpArguments(services, serverUrl)); cmd.addArg(QmlDebug::qmlDebugTcpArguments(services, serverUrl));
r.device = runControl->device(); setCommandLine(cmd);
doStart(r);
}); });
} }

View File

@@ -120,16 +120,14 @@ public:
auto portsGatherer = new PortsGatherer(runControl); auto portsGatherer = new PortsGatherer(runControl);
addStartDependency(portsGatherer); addStartDependency(portsGatherer);
setStarter([this, runControl, portsGatherer] { setStartModifier([this, runControl, portsGatherer] {
Runnable r;
const QString browserId = const QString browserId =
runControl->aspect<WebBrowserSelectionAspect>()->currentBrowser; runControl->aspect<WebBrowserSelectionAspect>()->currentBrowser;
r.command = emrunCommand(runControl->target(), setCommandLine(emrunCommand(runControl->target(),
runControl->buildKey(), runControl->buildKey(),
browserId, browserId,
QString::number(portsGatherer->findEndPoint().port())); QString::number(portsGatherer->findEndPoint().port())));
r.environment = runControl->buildEnvironment(); setEnvironment(runControl->buildEnvironment());
SimpleTargetRunner::doStart(r);
}); });
} }
}; };