diff --git a/src/plugins/projectexplorer/runcontrol.cpp b/src/plugins/projectexplorer/runcontrol.cpp index b48643624be..f3bb8b3c474 100644 --- a/src/plugins/projectexplorer/runcontrol.cpp +++ b/src/plugins/projectexplorer/runcontrol.cpp @@ -1193,10 +1193,6 @@ SimpleTargetRunner::SimpleTargetRunner(RunControl *runControl) : RunWorker(runControl) { setId("SimpleTargetRunner"); - if (auto terminalAspect = runControl->aspect()) - m_useTerminal = terminalAspect->useTerminal; - if (auto runAsRootAspect = runControl->aspect()) - 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()) + useTerminal = terminalAspect->useTerminal; + + bool runAsRoot = false; + if (auto runAsRootAspect = runControl()->aspect()) + 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(); 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 &starter) diff --git a/src/plugins/projectexplorer/runcontrol.h b/src/plugins/projectexplorer/runcontrol.h index fc4189fd532..d0e443d1027 100644 --- a/src/plugins/projectexplorer/runcontrol.h +++ b/src/plugins/projectexplorer/runcontrol.h @@ -33,9 +33,10 @@ #include #include +#include #include #include -#include +#include #include #include @@ -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 m_starter; bool m_stopReported = false; - bool m_useTerminal = false; - bool m_runAsRoot = false; bool m_stopForced = false; };