ProjectExplorer: Split ApplicationLauncher::start() parameters

There's traditionally an odd duplication of the runnable.device
and the passed device here. Start disentangling things.

Change-Id: I1cc1628c99cea04d761fc4d8dd0cb232127ce055
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
hjk
2022-02-15 12:44:04 +01:00
parent 13ed522d8d
commit 47957de2dc
9 changed files with 51 additions and 30 deletions

View File

@@ -67,7 +67,9 @@ public:
ProjectExplorer::Runnable r; ProjectExplorer::Runnable r;
r.command = {Constants::AppcontrollerFilepath, {"--stop"}}; r.command = {Constants::AppcontrollerFilepath, {"--stop"}};
(new ApplicationLauncher(this))->start(r, device()); auto launcher = new ApplicationLauncher(this);
launcher->setRunnable(r);
launcher->start(device());
} }
}; };
@@ -89,7 +91,8 @@ public:
Runnable r; Runnable r;
r.command = command; r.command = command;
m_appRunner.start(r, device); m_appRunner.setRunnable(r);
m_appRunner.start(device);
showMessage(QdbDevice::tr("Starting command \"%1\" on device \"%2\".") showMessage(QdbDevice::tr("Starting command \"%1\" on device \"%2\".")
.arg(command.toUserOutput(), m_deviceName)); .arg(command.toUserOutput(), m_deviceName));
} }

View File

@@ -118,7 +118,8 @@ public:
r.command.setArguments(args); r.command.setArguments(args);
r.command.setExecutable(FilePath::fromString(Constants::AppcontrollerFilepath)); r.command.setExecutable(FilePath::fromString(Constants::AppcontrollerFilepath));
m_launcher.start(r, device()); m_launcher.setRunnable(r);
m_launcher.start(device());
} }
void stop() override { m_launcher.stop(); } void stop() override { m_launcher.stop(); }

View File

@@ -100,8 +100,8 @@ void QdbStopApplicationService::doDeploy()
runnable.command = {Constants::AppcontrollerFilepath, {"--stop"}}; runnable.command = {Constants::AppcontrollerFilepath, {"--stop"}};
runnable.workingDirectory = "/usr/bin"; runnable.workingDirectory = "/usr/bin";
d->applicationLauncher.start(runnable, d->applicationLauncher.setRunnable(runnable);
ProjectExplorer::DeviceKitAspect::device(target()->kit())); d->applicationLauncher.start(ProjectExplorer::DeviceKitAspect::device(target()->kit()));
} }
void QdbStopApplicationService::stopDeployment() void QdbStopApplicationService::stopDeployment()

View File

@@ -507,7 +507,8 @@ void QmlEngine::startApplicationLauncher()
const Runnable runnable = runParameters().inferior; const Runnable runnable = runParameters().inferior;
showMessage(tr("Starting %1").arg(runnable.command.toUserOutput()), showMessage(tr("Starting %1").arg(runnable.command.toUserOutput()),
NormalMessageFormat); NormalMessageFormat);
d->applicationLauncher.start(runnable); d->applicationLauncher.setRunnable(runnable);
d->applicationLauncher.start();
} }
} }

View File

@@ -70,7 +70,7 @@ public:
explicit ApplicationLauncherPrivate(ApplicationLauncher *parent); explicit ApplicationLauncherPrivate(ApplicationLauncher *parent);
~ApplicationLauncherPrivate() override { setFinished(); } ~ApplicationLauncherPrivate() override { setFinished(); }
void start(const Runnable &runnable, const IDevice::ConstPtr &device, bool local); void start(const IDevice::ConstPtr &device, bool local);
void stop(); void stop();
// Local // Local
@@ -119,6 +119,8 @@ public:
QProcess::ExitStatus m_remoteExitStatus = QProcess::CrashExit; QProcess::ExitStatus m_remoteExitStatus = QProcess::CrashExit;
State m_state = Inactive; State m_state = Inactive;
bool m_stopRequested = false; bool m_stopRequested = false;
Runnable m_runnable;
}; };
} // Internal } // Internal
@@ -164,6 +166,11 @@ void ApplicationLauncher::setRunAsRoot(bool on)
d->m_runAsRoot = on; d->m_runAsRoot = on;
} }
void ApplicationLauncher::setRunnable(const Runnable &runnable)
{
d->m_runnable = runnable;
}
void ApplicationLauncher::stop() void ApplicationLauncher::stop()
{ {
d->stop(); d->stop();
@@ -319,17 +326,17 @@ void ApplicationLauncherPrivate::handleProcessStarted()
emit q->processStarted(); emit q->processStarted();
} }
void ApplicationLauncher::start(const Runnable &runnable) void ApplicationLauncher::start()
{ {
d->start(runnable, IDevice::ConstPtr(), true); d->start(IDevice::ConstPtr(), true);
} }
void ApplicationLauncher::start(const Runnable &runnable, const IDevice::ConstPtr &device) void ApplicationLauncher::start(const IDevice::ConstPtr &device)
{ {
d->start(runnable, device, false); d->start(device, false);
} }
void ApplicationLauncherPrivate::start(const Runnable &runnable, const IDevice::ConstPtr &device, bool local) void ApplicationLauncherPrivate::start(const IDevice::ConstPtr &device, bool local)
{ {
m_isLocal = local; m_isLocal = local;
@@ -358,10 +365,10 @@ void ApplicationLauncherPrivate::start(const Runnable &runnable, const IDevice::
// Work around QTBUG-17529 (QtDeclarative fails with 'File name case mismatch' ...) // Work around QTBUG-17529 (QtDeclarative fails with 'File name case mismatch' ...)
const FilePath fixedPath = runnable.workingDirectory.normalizedPathName(); const FilePath fixedPath = m_runnable.workingDirectory.normalizedPathName();
m_localProcess->setWorkingDirectory(fixedPath); m_localProcess->setWorkingDirectory(fixedPath);
Environment env = runnable.environment; Environment env = m_runnable.environment;
if (m_runAsRoot) if (m_runAsRoot)
RunControl::provideAskPassEntry(env); RunControl::provideAskPassEntry(env);
@@ -373,7 +380,7 @@ void ApplicationLauncherPrivate::start(const Runnable &runnable, const IDevice::
WinDebugInterface::instance()->start(); // Try to start listener again... WinDebugInterface::instance()->start(); // Try to start listener again...
#endif #endif
CommandLine cmdLine = runnable.command; CommandLine cmdLine = m_runnable.command;
if (HostOsInfo::isMacHost()) { if (HostOsInfo::isMacHost()) {
CommandLine disclaim(Core::ICore::libexecPath("disclaim")); CommandLine disclaim(Core::ICore::libexecPath("disclaim"));
@@ -400,7 +407,7 @@ void ApplicationLauncherPrivate::start(const Runnable &runnable, const IDevice::
return; return;
} }
if (!device->isEmptyCommandAllowed() && runnable.command.isEmpty()) { if (!device->isEmptyCommandAllowed() && m_runnable.command.isEmpty()) {
doReportError(ApplicationLauncher::tr("Cannot run: No command given.")); doReportError(ApplicationLauncher::tr("Cannot run: No command given."));
setFinished(); setFinished();
return; return;
@@ -422,10 +429,10 @@ void ApplicationLauncherPrivate::start(const Runnable &runnable, const IDevice::
this, &ApplicationLauncherPrivate::handleApplicationError); this, &ApplicationLauncherPrivate::handleApplicationError);
connect(m_deviceProcess, &DeviceProcess::finished, connect(m_deviceProcess, &DeviceProcess::finished,
this, &ApplicationLauncherPrivate::handleApplicationFinished); this, &ApplicationLauncherPrivate::handleApplicationFinished);
m_deviceProcess->setCommand(runnable.command); m_deviceProcess->setCommand(m_runnable.command);
m_deviceProcess->setWorkingDirectory(runnable.workingDirectory); m_deviceProcess->setWorkingDirectory(m_runnable.workingDirectory);
m_deviceProcess->setEnvironment(runnable.environment); m_deviceProcess->setEnvironment(m_runnable.environment);
m_deviceProcess->setExtraData(runnable.extraData); m_deviceProcess->setExtraData(m_runnable.extraData);
m_deviceProcess->start(); m_deviceProcess->start();
} }
} }

View File

@@ -55,8 +55,10 @@ public:
void setProcessChannelMode(QProcess::ProcessChannelMode mode); void setProcessChannelMode(QProcess::ProcessChannelMode mode);
void setUseTerminal(bool on); void setUseTerminal(bool on);
void setRunAsRoot(bool on); void setRunAsRoot(bool on);
void start(const Runnable &runnable); void setRunnable(const Runnable &runnable);
void start(const Runnable &runnable, const IDevice::ConstPtr &device);
void start();
void start(const IDevice::ConstPtr &device);
void stop(); void stop();
bool isRunning() const; bool isRunning() const;
Utils::ProcessHandle applicationPID() const; Utils::ProcessHandle applicationPID() const;

View File

@@ -1245,12 +1245,14 @@ void SimpleTargetRunner::doStart(const Runnable &runnable, const IDevice::ConstP
if (runnable.command.isEmpty()) { if (runnable.command.isEmpty()) {
reportFailure(RunControl::tr("No executable specified.")); reportFailure(RunControl::tr("No executable specified."));
} else { } else {
m_launcher.start(runnable); m_launcher.setRunnable(runnable);
m_launcher.start();
} }
} else { } else {
connect(&m_launcher, &ApplicationLauncher::processStarted, this, &RunWorker::reportStarted); connect(&m_launcher, &ApplicationLauncher::processStarted, this, &RunWorker::reportStarted);
m_launcher.start(runnable, device); m_launcher.setRunnable(runnable);
m_launcher.start(device);
} }
} }

View File

@@ -126,11 +126,12 @@ void CallgrindController::run(Option option)
controller.command.setExecutable(FilePath::fromString(CALLGRIND_CONTROL_BINARY)); controller.command.setExecutable(FilePath::fromString(CALLGRIND_CONTROL_BINARY));
controller.command.setArguments(QString("%1 %2").arg(toOptionString(option)).arg(m_pid)); controller.command.setArguments(QString("%1 %2").arg(toOptionString(option)).arg(m_pid));
m_controllerProcess->setRunnable(controller);
if (!m_valgrindRunnable.device if (!m_valgrindRunnable.device
|| m_valgrindRunnable.device->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) || m_valgrindRunnable.device->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE)
m_controllerProcess->start(controller); m_controllerProcess->start();
else else
m_controllerProcess->start(controller, m_valgrindRunnable.device); m_controllerProcess->start(m_valgrindRunnable.device);
} }
void CallgrindController::setValgrindPid(qint64 pid) void CallgrindController::setValgrindPid(qint64 pid)

View File

@@ -138,12 +138,15 @@ bool ValgrindRunner::Private::run()
valgrind.device = m_device; valgrind.device = m_device;
if (m_device->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) { if (m_device->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) {
m_valgrindProcess.start(valgrind); m_valgrindProcess.setRunnable(valgrind);
m_valgrindProcess.start();
} else if (m_device->type() == "DockerDeviceType") { } else if (m_device->type() == "DockerDeviceType") {
valgrind.device = {}; valgrind.device = {};
m_valgrindProcess.start(valgrind); m_valgrindProcess.setRunnable(valgrind);
m_valgrindProcess.start();
} else { } else {
m_valgrindProcess.start(valgrind, m_device); m_valgrindProcess.setRunnable(valgrind);
m_valgrindProcess.start(m_device);
} }
return true; return true;
@@ -193,7 +196,8 @@ void ValgrindRunner::Private::remoteProcessStarted()
// m_remote.m_findPID = m_remote.m_connection->createRemoteProcess(cmd.toUtf8()); // m_remote.m_findPID = m_remote.m_connection->createRemoteProcess(cmd.toUtf8());
connect(&m_findPID, &ApplicationLauncher::appendMessage, connect(&m_findPID, &ApplicationLauncher::appendMessage,
this, &ValgrindRunner::Private::findPidOutputReceived); this, &ValgrindRunner::Private::findPidOutputReceived);
m_findPID.start(findPid, m_device); m_findPID.setRunnable(findPid);
m_findPID.start(m_device);
} }
void ValgrindRunner::Private::findPidOutputReceived(const QString &out, Utils::OutputFormat format) void ValgrindRunner::Private::findPidOutputReceived(const QString &out, Utils::OutputFormat format)