ProjectExplorer: Use simpler signature for ApplicationLauncher::processExited()

And rename it to finished().

Maps better to what QtcProcess uses.

Change-Id: Ibfa018549f436b27638a791c0b4937c4459c9452
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2022-02-15 14:43:18 +01:00
parent ccb42b3c74
commit 6942c58d65
12 changed files with 49 additions and 43 deletions

View File

@@ -83,7 +83,7 @@ public:
&DeviceApplicationObserver::handleAppendMessage);
connect(&m_appRunner, &ApplicationLauncher::error, this,
[this] { m_error = m_appRunner.errorString(); });
connect(&m_appRunner, &ApplicationLauncher::processExited, this,
connect(&m_appRunner, &ApplicationLauncher::finished, this,
&DeviceApplicationObserver::handleFinished);
QTC_ASSERT(device, return);
@@ -106,13 +106,15 @@ private:
m_stderr += data;
}
void handleFinished(int exitCode, QProcess::ExitStatus exitStatus)
void handleFinished()
{
Q_UNUSED(exitCode)
// FIXME: Needed in a post-adb world?
// adb does not forward exit codes and all stderr goes to stdout.
const bool failure = exitStatus == QProcess::CrashExit || m_stdout.contains("fail")
|| m_stdout.contains("error") || m_stdout.contains("not found");
const bool failure = m_appRunner.exitStatus() == QProcess::CrashExit
|| m_stdout.contains("fail")
|| m_stdout.contains("error")
|| m_stdout.contains("not found");
if (failure) {
QString errorString;
if (!m_error.isEmpty()) {

View File

@@ -57,7 +57,7 @@ public:
connect(&m_launcher, &ApplicationLauncher::processStarted,
this, &RunWorker::reportStarted);
connect(&m_launcher, &ApplicationLauncher::processExited,
connect(&m_launcher, &ApplicationLauncher::finished,
this, &RunWorker::reportStopped);
connect(&m_launcher, &ApplicationLauncher::appendMessage,
this, &RunWorker::appendMessage);

View File

@@ -57,11 +57,10 @@ QdbStopApplicationService::~QdbStopApplicationService()
delete d;
}
void QdbStopApplicationService::handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
void QdbStopApplicationService::handleProcessFinished()
{
Q_UNUSED(exitCode)
const auto failureMessage = tr("Could not check and possibly stop running application.");
if (exitStatus == QProcess::CrashExit) {
const QString failureMessage = tr("Could not check and possibly stop running application.");
if (d->applicationLauncher.exitStatus() == QProcess::CrashExit) {
emit errorMessage(failureMessage);
stopDeployment();
return;
@@ -91,7 +90,7 @@ void QdbStopApplicationService::doDeploy()
{
connect(&d->applicationLauncher, &ProjectExplorer::ApplicationLauncher::error,
this, [this] { emit stdErrData(d->applicationLauncher.errorString()); });
connect(&d->applicationLauncher, &ProjectExplorer::ApplicationLauncher::processExited,
connect(&d->applicationLauncher, &ProjectExplorer::ApplicationLauncher::finished,
this, &QdbStopApplicationService::handleProcessFinished);
connect(&d->applicationLauncher, &ProjectExplorer::ApplicationLauncher::appendMessage,
this, &QdbStopApplicationService::handleAppendMessage);

View File

@@ -28,8 +28,6 @@
#include <remotelinux/abstractremotelinuxdeployservice.h>
#include <utils/outputformat.h>
#include <QProcess>
namespace Qdb {
namespace Internal {
@@ -43,7 +41,7 @@ public:
~QdbStopApplicationService();
private:
void handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
void handleProcessFinished();
void handleAppendMessage(const QString &message, Utils::OutputFormat format);
bool isDeploymentNecessary() const final { return true; }

View File

@@ -269,7 +269,7 @@ QmlEngine::QmlEngine()
connect(stackHandler(), &StackHandler::currentIndexChanged,
this, &QmlEngine::updateCurrentContext);
connect(&d->applicationLauncher, &ApplicationLauncher::processExited,
connect(&d->applicationLauncher, &ApplicationLauncher::finished,
this, &QmlEngine::disconnected);
connect(&d->applicationLauncher, &ApplicationLauncher::appendMessage,
this, &QmlEngine::appMessage);
@@ -515,7 +515,7 @@ void QmlEngine::startApplicationLauncher()
void QmlEngine::stopApplicationLauncher()
{
if (d->applicationLauncher.isRunning()) {
disconnect(&d->applicationLauncher, &ApplicationLauncher::processExited,
disconnect(&d->applicationLauncher, &ApplicationLauncher::finished,
this, &QmlEngine::disconnected);
d->applicationLauncher.stop();
}

View File

@@ -116,11 +116,13 @@ public:
// Remote
QString m_remoteErrorString;
QProcess::ProcessError m_remoteError = QProcess::UnknownError;
QProcess::ExitStatus m_remoteExitStatus = QProcess::CrashExit;
State m_state = Inactive;
bool m_stopRequested = false;
Runnable m_runnable;
int m_exitCode = 0;
QProcess::ExitStatus m_exitStatus = QProcess::NormalExit;
};
} // Internal
@@ -188,7 +190,7 @@ void ApplicationLauncherPrivate::stop()
if (m_stopRequested)
return;
m_stopRequested = true;
m_remoteExitStatus = QProcess::CrashExit;
m_exitStatus = QProcess::CrashExit;
emit q->appendMessage(ApplicationLauncher::tr("User requested stop. Shutting down..."),
Utils::NormalMessageFormat);
switch (m_state) {
@@ -252,17 +254,17 @@ void ApplicationLauncherPrivate::localProcessError(QProcess::ProcessError error)
emit q->appendMessage(m_process->errorString(), ErrorMessageFormat);
if (m_processRunning && m_process->processId() == 0) {
m_processRunning = false;
emit q->processExited(-1, QProcess::NormalExit);
m_exitCode = -1;
emit q->finished();
}
} else {
QString error;
QProcess::ExitStatus status = QProcess::NormalExit;
switch (m_process->error()) {
case QProcess::FailedToStart:
error = ApplicationLauncher::tr("Failed to start program. Path or permissions wrong?");
break;
case QProcess::Crashed:
status = QProcess::CrashExit;
m_exitStatus = QProcess::CrashExit;
break;
default:
error = ApplicationLauncher::tr("Some error has occurred while running the program.");
@@ -271,7 +273,8 @@ void ApplicationLauncherPrivate::localProcessError(QProcess::ProcessError error)
emit q->appendMessage(error, ErrorMessageFormat);
if (m_processRunning && !isRunning()) {
m_processRunning = false;
emit q->processExited(-1, status);
m_exitCode = -1;
emit q->finished();
}
}
emit q->error(error);
@@ -311,7 +314,9 @@ void ApplicationLauncherPrivate::localProcessDone(int exitCode, QProcess::ExitSt
{
QTimer::singleShot(100, this, [this, exitCode, status]() {
m_listeningPid = 0;
emit q->processExited(exitCode, status);
m_exitCode = exitCode;
m_exitStatus = status;
emit q->finished();
});
}
@@ -340,6 +345,9 @@ void ApplicationLauncherPrivate::start(const IDevice::ConstPtr &device, bool loc
{
m_isLocal = local;
m_exitCode = 0;
m_exitStatus = QProcess::NormalExit;
if (m_isLocal) {
m_process.reset(new QtcProcess(this));
m_process->setProcessChannelMode(m_processChannelMode);
@@ -411,7 +419,6 @@ void ApplicationLauncherPrivate::start(const IDevice::ConstPtr &device, bool loc
}
m_stopRequested = false;
m_remoteExitStatus = QProcess::NormalExit;
m_process.reset(device->createProcess(this));
connect(m_process.get(), &QtcProcess::started,
@@ -448,12 +455,10 @@ void ApplicationLauncherPrivate::setFinished()
if (m_state == Inactive)
return;
int exitCode = 0;
if (m_process)
exitCode = m_process->exitCode();
m_exitCode = m_process ? m_exitCode = m_process->exitCode() : 0;
m_state = Inactive;
emit q->processExited(exitCode, m_remoteExitStatus);
emit q->finished();
}
void ApplicationLauncherPrivate::handleApplicationFinished()
@@ -483,7 +488,7 @@ void ApplicationLauncherPrivate::doReportError(const QString &message, QProcess:
{
m_remoteErrorString = message;
m_remoteError = error;
m_remoteExitStatus = QProcess::CrashExit;
m_exitStatus = QProcess::CrashExit;
emit q->error(error);
}

View File

@@ -69,10 +69,13 @@ public:
static QString msgWinCannotRetrieveDebuggingOutput();
int exitCode() const;
QProcess::ExitStatus exitStatus() const;
signals:
void appendMessage(const QString &message, Utils::OutputFormat format, bool appendNewLine = true);
void processStarted();
void processExited(int exitCode, QProcess::ExitStatus exitStatus);
void finished();
void error(QProcess::ProcessError error);
private:

View File

@@ -1202,16 +1202,14 @@ void SimpleTargetRunner::doStart(const Runnable &runnable, const IDevice::ConstP
m_launcher.setUseTerminal(m_useTerminal);
m_launcher.setRunAsRoot(m_runAsRoot);
const bool isDesktop = device.isNull() || device.dynamicCast<const DesktopDevice>();
const QString msg = RunControl::tr("Starting %1...").arg(runnable.command.toUserOutput());
appendMessage(msg, Utils::NormalMessageFormat);
connect(&m_launcher, &ApplicationLauncher::processExited,
this, [this, runnable](int exitCode, QProcess::ExitStatus status) {
connect(&m_launcher, &ApplicationLauncher::finished, this, [this, runnable]() {
if (m_stopReported)
return;
const QString msg = (status == QProcess::CrashExit)
? tr("%1 crashed.") : tr("%2 exited with code %1").arg(exitCode);
const QString msg = (m_launcher.exitStatus() == QProcess::CrashExit)
? tr("%1 crashed.") : tr("%2 exited with code %1").arg(m_launcher.exitCode());
const QString displayName = runnable.command.executable().toUserOutput();
appendMessage(msg.arg(displayName), Utils::NormalMessageFormat);
m_stopReported = true;
@@ -1233,6 +1231,7 @@ void SimpleTargetRunner::doStart(const Runnable &runnable, const IDevice::ConstP
connect(&m_launcher, &ApplicationLauncher::appendMessage, this, &RunWorker::appendMessage);
const bool isDesktop = device.isNull() || device.dynamicCast<const DesktopDevice>();
if (isDesktop) {
connect(&m_launcher, &ApplicationLauncher::processStarted, this, [this] {
// Console processes only know their pid after being started

View File

@@ -117,7 +117,7 @@ void CallgrindController::run(Option option)
#if CALLGRIND_CONTROL_DEBUG
m_controllerProcess->setProcessChannelMode(QProcess::ForwardedChannels);
#endif
connect(m_controllerProcess, &ApplicationLauncher::processExited,
connect(m_controllerProcess, &ApplicationLauncher::finished,
this, &CallgrindController::controllerProcessFinished);
connect(m_controllerProcess, &ApplicationLauncher::error,
this, &CallgrindController::handleControllerProcessError);
@@ -149,7 +149,7 @@ void CallgrindController::handleControllerProcessError(QProcess::ProcessError)
m_controllerProcess = nullptr;
}
void CallgrindController::controllerProcessFinished(int rc, QProcess::ExitStatus status)
void CallgrindController::controllerProcessFinished()
{
QTC_ASSERT(m_controllerProcess, return);
const QString error = m_controllerProcess->errorString();
@@ -157,7 +157,7 @@ void CallgrindController::controllerProcessFinished(int rc, QProcess::ExitStatus
m_controllerProcess->deleteLater(); // Called directly from finished() signal in m_process
m_controllerProcess = nullptr;
if (rc != 0 || status != QProcess::NormalExit) {
if (m_controllerProcess->exitCode() != 0 || m_controllerProcess->exitStatus() != QProcess::NormalExit) {
qWarning() << "Controller exited abnormally:" << error;
return;
}

View File

@@ -76,7 +76,7 @@ private:
void sftpJobFinished(QSsh::SftpJobId job, const QString &error);
void cleanupTempFile();
void controllerProcessFinished(int, QProcess::ExitStatus);
void controllerProcessFinished();
void controllerProcessError(QProcess::ProcessError);
ProjectExplorer::ApplicationLauncher *m_controllerProcess = nullptr;

View File

@@ -114,7 +114,7 @@ bool ValgrindRunner::Private::run()
// consider appending our options last so they override any interfering user-supplied options
// -q as suggested by valgrind manual
connect(&m_valgrindProcess, &ApplicationLauncher::processExited,
connect(&m_valgrindProcess, &ApplicationLauncher::finished,
q, &ValgrindRunner::processFinished);
connect(&m_valgrindProcess, &ApplicationLauncher::processStarted,
this, &ValgrindRunner::Private::processStarted);
@@ -295,7 +295,7 @@ void ValgrindRunner::processError(QProcess::ProcessError e)
emit finished();
}
void ValgrindRunner::processFinished(int ret, QProcess::ExitStatus status)
void ValgrindRunner::processFinished()
{
emit extraProcessFinished();
@@ -307,7 +307,7 @@ void ValgrindRunner::processFinished(int ret, QProcess::ExitStatus status)
// make sure we don't wait for the connection anymore
emit finished();
if (ret != 0 || status == QProcess::CrashExit)
if (d->m_valgrindProcess.exitCode() != 0 || d->m_valgrindProcess.exitStatus() == QProcess::CrashExit)
emit processErrorReceived(errorString(), d->m_valgrindProcess.processError());
}

View File

@@ -72,7 +72,7 @@ signals:
private:
bool startServers();
void processError(QProcess::ProcessError);
void processFinished(int, QProcess::ExitStatus);
void processFinished();
void xmlSocketConnected();
void logSocketConnected();