Boot2Qt: Replace two more uses of ApplicationLauncher

Change-Id: I2fda5afccfd2e6f9daf81b299dd9b18aa6535338
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
hjk
2022-05-05 11:38:26 +02:00
parent 88fac2b9c7
commit 4d48c4cb5e

View File

@@ -31,7 +31,6 @@
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <projectexplorer/applicationlauncher.h>
#include <projectexplorer/devicesupport/idevice.h> #include <projectexplorer/devicesupport/idevice.h>
#include <projectexplorer/runcontrol.h> #include <projectexplorer/runcontrol.h>
@@ -61,6 +60,7 @@ public:
QdbProcessImpl(const LinuxDevice *linuxDevice) QdbProcessImpl(const LinuxDevice *linuxDevice)
: LinuxProcessInterface(linuxDevice) {} : LinuxProcessInterface(linuxDevice) {}
~QdbProcessImpl() { killIfRunning(); } ~QdbProcessImpl() { killIfRunning(); }
private: private:
void sendControlSignal(ControlSignal controlSignal) final void sendControlSignal(ControlSignal controlSignal) final
{ {
@@ -70,61 +70,50 @@ private:
} }
}; };
class DeviceApplicationObserver : public ApplicationLauncher class DeviceApplicationObserver : public QObject
{ {
public: public:
DeviceApplicationObserver(const IDevice::ConstPtr &device, const CommandLine &command) DeviceApplicationObserver(const IDevice::ConstPtr &device, const CommandLine &command)
{ {
connect(&m_appRunner, &ApplicationLauncher::appendMessage, this, connect(&m_appRunner, &QtcProcess::done, this, &DeviceApplicationObserver::handleDone);
&DeviceApplicationObserver::handleAppendMessage);
connect(&m_appRunner, &ApplicationLauncher::errorOccurred, this,
[this] { m_error = m_appRunner.errorString(); });
connect(&m_appRunner, &ApplicationLauncher::finished, this,
&DeviceApplicationObserver::handleFinished);
QTC_ASSERT(device, return); QTC_ASSERT(device, return);
m_deviceName = device->displayName(); m_deviceName = device->displayName();
Runnable r; CommandLine cmd;
r.command = command; cmd.setExecutable(device->mapToGlobalPath(command.executable()));
r.device = device; m_appRunner.setCommand(cmd);
m_appRunner.setRunnable(r);
m_appRunner.start(); m_appRunner.start();
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));
} }
private: private:
void handleAppendMessage(const QString &data, Utils::OutputFormat format) void handleDone()
{ {
if (format == Utils::StdOutFormat) const QString stdOut = m_appRunner.stdOut();
m_stdout += data; const QString stdErr = m_appRunner.stdErr();
else if (format == Utils::StdErrFormat)
m_stderr += data;
}
void handleFinished()
{
// FIXME: Needed in a post-adb world? // FIXME: Needed in a post-adb world?
// adb does not forward exit codes and all stderr goes to stdout. // adb does not forward exit codes and all stderr goes to stdout.
const bool failure = m_appRunner.exitStatus() == QProcess::CrashExit const bool failure = m_appRunner.result() != ProcessResult::FinishedWithSuccess
|| m_stdout.contains("fail") || stdOut.contains("fail")
|| m_stdout.contains("error") || stdOut.contains("error")
|| m_stdout.contains("not found"); || stdOut.contains("not found");
if (failure) { if (failure) {
QString errorString; QString errorString;
if (!m_error.isEmpty()) { if (!m_appRunner.errorString().isEmpty()) {
errorString = QdbDevice::tr("Command failed on device \"%1\": %2") errorString = QdbDevice::tr("Command failed on device \"%1\": %2")
.arg(m_deviceName, m_error); .arg(m_deviceName, m_appRunner.errorString());
} else { } else {
errorString = QdbDevice::tr("Command failed on device \"%1\".").arg(m_deviceName); errorString = QdbDevice::tr("Command failed on device \"%1\".").arg(m_deviceName);
} }
showMessage(errorString, true); showMessage(errorString, true);
if (!m_stdout.isEmpty()) if (!stdOut.isEmpty())
showMessage(QdbDevice::tr("stdout was: \"%1\"").arg(m_stdout)); showMessage(QdbDevice::tr("stdout was: \"%1\"").arg(stdOut));
if (!m_stderr.isEmpty()) if (!stdErr.isEmpty())
showMessage(QdbDevice::tr("stderr was: \"%1\"").arg(m_stderr)); showMessage(QdbDevice::tr("stderr was: \"%1\"").arg(stdErr));
} else { } else {
showMessage(QdbDevice::tr("Commands on device \"%1\" finished successfully.") showMessage(QdbDevice::tr("Commands on device \"%1\" finished successfully.")
.arg(m_deviceName)); .arg(m_deviceName));
@@ -132,11 +121,8 @@ private:
deleteLater(); deleteLater();
} }
QString m_stdout; QtcProcess m_appRunner;
QString m_stderr;
ProjectExplorer::ApplicationLauncher m_appRunner;
QString m_deviceName; QString m_deviceName;
QString m_error;
}; };