forked from qt-creator/qt-creator
Replace ApplicationLauncher in SimpleTargetRunner
Change-Id: I9f258dc0c085fd5d4e7c57a7abb724e91a32060d Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -1193,10 +1193,6 @@ SimpleTargetRunner::SimpleTargetRunner(RunControl *runControl)
|
||||
: RunWorker(runControl)
|
||||
{
|
||||
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()
|
||||
@@ -1212,16 +1208,30 @@ void SimpleTargetRunner::start()
|
||||
|
||||
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_stopReported = false;
|
||||
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());
|
||||
appendMessage(msg, Utils::NormalMessageFormat);
|
||||
|
||||
connect(&m_launcher, &ApplicationLauncher::done, this, [this, runnable] {
|
||||
connect(&m_launcher, &QtcProcess::done, this, [this, runnable] {
|
||||
if (m_stopReported)
|
||||
return;
|
||||
const QString executable = runnable.command.executable().toUserOutput();
|
||||
@@ -1238,14 +1248,19 @@ void SimpleTargetRunner::doStart(const Runnable &runnable)
|
||||
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()
|
||||
|| runnable.device.dynamicCast<const DesktopDevice>();
|
||||
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
|
||||
ProcessHandle pid = m_launcher.applicationPID();
|
||||
ProcessHandle pid = ProcessHandle(m_launcher.processId());
|
||||
runControl()->setApplicationProcessHandle(pid);
|
||||
pid.activate();
|
||||
reportStarted();
|
||||
@@ -1256,16 +1271,15 @@ void SimpleTargetRunner::doStart(const Runnable &runnable)
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
connect(&m_launcher, &ApplicationLauncher::started, this, &RunWorker::reportStarted);
|
||||
connect(&m_launcher, &QtcProcess::started, this, &RunWorker::reportStarted);
|
||||
}
|
||||
m_launcher.setRunnable(runnable);
|
||||
m_launcher.start();
|
||||
}
|
||||
|
||||
void SimpleTargetRunner::stop()
|
||||
{
|
||||
m_stopForced = true;
|
||||
m_launcher.stop();
|
||||
m_launcher.kill();
|
||||
}
|
||||
|
||||
void SimpleTargetRunner::setStarter(const std::function<void ()> &starter)
|
||||
|
@@ -33,9 +33,10 @@
|
||||
|
||||
#include <utils/commandline.h>
|
||||
#include <utils/environment.h>
|
||||
#include <utils/icon.h>
|
||||
#include <utils/processhandle.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/icon.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
|
||||
#include <QHash>
|
||||
#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.
|
||||
*/
|
||||
|
||||
@@ -305,12 +306,10 @@ private:
|
||||
|
||||
const Runnable &runnable() const = delete;
|
||||
|
||||
ApplicationLauncher m_launcher;
|
||||
Utils::QtcProcess m_launcher;
|
||||
std::function<void()> m_starter;
|
||||
|
||||
bool m_stopReported = false;
|
||||
bool m_useTerminal = false;
|
||||
bool m_runAsRoot = false;
|
||||
bool m_stopForced = false;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user