Replace ApplicationLauncher in SimpleTargetRunner

Change-Id: I9f258dc0c085fd5d4e7c57a7abb724e91a32060d
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2022-05-05 13:34:30 +02:00
parent 94e2fa7df0
commit b05fc053ef
2 changed files with 31 additions and 18 deletions

View File

@@ -1193,10 +1193,6 @@ SimpleTargetRunner::SimpleTargetRunner(RunControl *runControl)
: RunWorker(runControl) : RunWorker(runControl)
{ {
setId("SimpleTargetRunner"); setId("SimpleTargetRunner");
if (auto terminalAspect = runControl->aspect<TerminalAspect>())
m_useTerminal = terminalAspect->useTerminal;
if (auto runAsRootAspect = runControl->aspect<RunAsRootAspect>())
m_runAsRoot = runAsRootAspect->value;
} }
void SimpleTargetRunner::start() void SimpleTargetRunner::start()
@@ -1212,16 +1208,30 @@ void SimpleTargetRunner::start()
void SimpleTargetRunner::doStart(const Runnable &runnable) void SimpleTargetRunner::doStart(const Runnable &runnable)
{ {
bool useTerminal = false;
if (auto terminalAspect = runControl()->aspect<TerminalAspect>())
useTerminal = terminalAspect->useTerminal;
bool runAsRoot = false;
if (auto runAsRootAspect = runControl()->aspect<RunAsRootAspect>())
runAsRoot = runAsRootAspect->value;
m_stopForced = false; m_stopForced = false;
m_stopReported = false; m_stopReported = false;
m_launcher.disconnect(this); m_launcher.disconnect(this);
m_launcher.setUseTerminal(m_useTerminal);
m_launcher.setRunAsRoot(m_runAsRoot); m_launcher.setTerminalMode(useTerminal ? TerminalMode::On : TerminalMode::Off);
m_launcher.setRunAsRoot(runAsRoot);
m_launcher.setCommand(runnable.command);
m_launcher.setWorkingDirectory(runnable.workingDirectory);
m_launcher.setEnvironment(runnable.environment);
m_launcher.setExtraData(runnable.extraData);
const QString msg = RunControl::tr("Starting %1...").arg(runnable.command.toUserOutput()); const QString msg = RunControl::tr("Starting %1...").arg(runnable.command.toUserOutput());
appendMessage(msg, Utils::NormalMessageFormat); appendMessage(msg, Utils::NormalMessageFormat);
connect(&m_launcher, &ApplicationLauncher::done, this, [this, runnable] { connect(&m_launcher, &QtcProcess::done, this, [this, runnable] {
if (m_stopReported) if (m_stopReported)
return; return;
const QString executable = runnable.command.executable().toUserOutput(); const QString executable = runnable.command.executable().toUserOutput();
@@ -1238,14 +1248,19 @@ void SimpleTargetRunner::doStart(const Runnable &runnable)
reportStopped(); reportStopped();
}); });
connect(&m_launcher, &ApplicationLauncher::appendMessage, this, &RunWorker::appendMessage); connect(&m_launcher, &QtcProcess::readyReadStandardOutput, this, [this] {
appendMessage(QString::fromUtf8(m_launcher.readAllStandardOutput()), StdOutFormat);
});
connect(&m_launcher, &QtcProcess::readyReadStandardError, this, [this] {
appendMessage(QString::fromUtf8(m_launcher.readAllStandardError()), StdErrFormat);
});
const bool isDesktop = runnable.device.isNull() const bool isDesktop = runnable.device.isNull()
|| runnable.device.dynamicCast<const DesktopDevice>(); || runnable.device.dynamicCast<const DesktopDevice>();
if (isDesktop) { if (isDesktop) {
connect(&m_launcher, &ApplicationLauncher::started, this, [this] { connect(&m_launcher, &QtcProcess::started, this, [this] {
// Console processes only know their pid after being started // Console processes only know their pid after being started
ProcessHandle pid = m_launcher.applicationPID(); ProcessHandle pid = ProcessHandle(m_launcher.processId());
runControl()->setApplicationProcessHandle(pid); runControl()->setApplicationProcessHandle(pid);
pid.activate(); pid.activate();
reportStarted(); reportStarted();
@@ -1256,16 +1271,15 @@ void SimpleTargetRunner::doStart(const Runnable &runnable)
return; return;
} }
} else { } else {
connect(&m_launcher, &ApplicationLauncher::started, this, &RunWorker::reportStarted); connect(&m_launcher, &QtcProcess::started, this, &RunWorker::reportStarted);
} }
m_launcher.setRunnable(runnable);
m_launcher.start(); m_launcher.start();
} }
void SimpleTargetRunner::stop() void SimpleTargetRunner::stop()
{ {
m_stopForced = true; m_stopForced = true;
m_launcher.stop(); m_launcher.kill();
} }
void SimpleTargetRunner::setStarter(const std::function<void ()> &starter) void SimpleTargetRunner::setStarter(const std::function<void ()> &starter)

View File

@@ -33,9 +33,10 @@
#include <utils/commandline.h> #include <utils/commandline.h>
#include <utils/environment.h> #include <utils/environment.h>
#include <utils/icon.h>
#include <utils/processhandle.h> #include <utils/processhandle.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/icon.h> #include <utils/qtcprocess.h>
#include <QHash> #include <QHash>
#include <QVariant> #include <QVariant>
@@ -284,7 +285,7 @@ private:
/** /**
* A simple TargetRunner for cases where a plain ApplicationLauncher is * A simple TargetRunner for cases where a plain QtcProcess is
* sufficient for running purposes. * sufficient for running purposes.
*/ */
@@ -305,12 +306,10 @@ private:
const Runnable &runnable() const = delete; const Runnable &runnable() const = delete;
ApplicationLauncher m_launcher; Utils::QtcProcess m_launcher;
std::function<void()> m_starter; std::function<void()> m_starter;
bool m_stopReported = false; bool m_stopReported = false;
bool m_useTerminal = false;
bool m_runAsRoot = false;
bool m_stopForced = false; bool m_stopForced = false;
}; };