summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2022-05-05 13:34:30 +0200
committerhjk <hjk@qt.io>2022-05-23 08:21:20 +0000
commitb05fc053ef08352a951baa4667b215ddc98620cc (patch)
tree52add6937c5e95d73c5dbf17e4fc953bb7648202
parent94e2fa7df0864ec20fbb033bbf68f5e62bfbdbf3 (diff)
downloadqt-creator-b05fc053ef08352a951baa4667b215ddc98620cc.tar.gz
Replace ApplicationLauncher in SimpleTargetRunner
Change-Id: I9f258dc0c085fd5d4e7c57a7abb724e91a32060d Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
-rw-r--r--src/plugins/projectexplorer/runcontrol.cpp40
-rw-r--r--src/plugins/projectexplorer/runcontrol.h9
2 files changed, 31 insertions, 18 deletions
diff --git a/src/plugins/projectexplorer/runcontrol.cpp b/src/plugins/projectexplorer/runcontrol.cpp
index b48643624b..f3bb8b3c47 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<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)
diff --git a/src/plugins/projectexplorer/runcontrol.h b/src/plugins/projectexplorer/runcontrol.h
index fc4189fd53..d0e443d102 100644
--- a/src/plugins/projectexplorer/runcontrol.h
+++ b/src/plugins/projectexplorer/runcontrol.h
@@ -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;
};