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