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); &DeviceApplicationObserver::handleAppendMessage);
connect(&m_appRunner, &ApplicationLauncher::error, this, connect(&m_appRunner, &ApplicationLauncher::error, this,
[this] { m_error = m_appRunner.errorString(); }); [this] { m_error = m_appRunner.errorString(); });
connect(&m_appRunner, &ApplicationLauncher::processExited, this, connect(&m_appRunner, &ApplicationLauncher::finished, this,
&DeviceApplicationObserver::handleFinished); &DeviceApplicationObserver::handleFinished);
QTC_ASSERT(device, return); QTC_ASSERT(device, return);
@@ -106,13 +106,15 @@ private:
m_stderr += data; m_stderr += data;
} }
void handleFinished(int exitCode, QProcess::ExitStatus exitStatus) void handleFinished()
{ {
Q_UNUSED(exitCode)
// 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 = exitStatus == QProcess::CrashExit || m_stdout.contains("fail") const bool failure = m_appRunner.exitStatus() == QProcess::CrashExit
|| m_stdout.contains("error") || m_stdout.contains("not found"); || m_stdout.contains("fail")
|| m_stdout.contains("error")
|| m_stdout.contains("not found");
if (failure) { if (failure) {
QString errorString; QString errorString;
if (!m_error.isEmpty()) { if (!m_error.isEmpty()) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -76,7 +76,7 @@ private:
void sftpJobFinished(QSsh::SftpJobId job, const QString &error); void sftpJobFinished(QSsh::SftpJobId job, const QString &error);
void cleanupTempFile(); void cleanupTempFile();
void controllerProcessFinished(int, QProcess::ExitStatus); void controllerProcessFinished();
void controllerProcessError(QProcess::ProcessError); void controllerProcessError(QProcess::ProcessError);
ProjectExplorer::ApplicationLauncher *m_controllerProcess = nullptr; 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 // consider appending our options last so they override any interfering user-supplied options
// -q as suggested by valgrind manual // -q as suggested by valgrind manual
connect(&m_valgrindProcess, &ApplicationLauncher::processExited, connect(&m_valgrindProcess, &ApplicationLauncher::finished,
q, &ValgrindRunner::processFinished); q, &ValgrindRunner::processFinished);
connect(&m_valgrindProcess, &ApplicationLauncher::processStarted, connect(&m_valgrindProcess, &ApplicationLauncher::processStarted,
this, &ValgrindRunner::Private::processStarted); this, &ValgrindRunner::Private::processStarted);
@@ -295,7 +295,7 @@ void ValgrindRunner::processError(QProcess::ProcessError e)
emit finished(); emit finished();
} }
void ValgrindRunner::processFinished(int ret, QProcess::ExitStatus status) void ValgrindRunner::processFinished()
{ {
emit extraProcessFinished(); emit extraProcessFinished();
@@ -307,7 +307,7 @@ void ValgrindRunner::processFinished(int ret, QProcess::ExitStatus status)
// make sure we don't wait for the connection anymore // make sure we don't wait for the connection anymore
emit finished(); 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()); emit processErrorReceived(errorString(), d->m_valgrindProcess.processError());
} }

View File

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