forked from qt-creator/qt-creator
ProjectExplorer: React to QtcProcess::done in ApplicationLauncher
The 'modern' way. Change-Id: I80c0bb0b9c7c08e6aef724d430a8dbbd4b0c2777 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -72,7 +72,7 @@ public:
|
|||||||
|
|
||||||
~ApplicationLauncherPrivate() override {
|
~ApplicationLauncherPrivate() override {
|
||||||
if (m_state == Run)
|
if (m_state == Run)
|
||||||
emit q->finished();
|
emit q->done();
|
||||||
}
|
}
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
@@ -178,7 +178,7 @@ void ApplicationLauncherPrivate::stop()
|
|||||||
if (!isRunning())
|
if (!isRunning())
|
||||||
return;
|
return;
|
||||||
m_process.stopProcess();
|
m_process.stopProcess();
|
||||||
QTimer::singleShot(100, this, [this] { emit q->finished(); });
|
QTimer::singleShot(100, this, [this] { emit q->done(); });
|
||||||
} else {
|
} else {
|
||||||
if (m_stopRequested)
|
if (m_stopRequested)
|
||||||
return;
|
return;
|
||||||
@@ -224,7 +224,7 @@ void ApplicationLauncherPrivate::handleDone()
|
|||||||
|
|
||||||
if (m_isLocal) {
|
if (m_isLocal) {
|
||||||
if (m_resultData.m_error == QProcess::UnknownError) {
|
if (m_resultData.m_error == QProcess::UnknownError) {
|
||||||
emit q->finished();
|
emit q->done();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// TODO: why below handlings are different?
|
// TODO: why below handlings are different?
|
||||||
@@ -233,7 +233,6 @@ void ApplicationLauncherPrivate::handleDone()
|
|||||||
if (m_processRunning && m_process.processId() == 0) {
|
if (m_processRunning && m_process.processId() == 0) {
|
||||||
m_processRunning = false;
|
m_processRunning = false;
|
||||||
m_resultData.m_exitCode = -1; // FIXME: Why?
|
m_resultData.m_exitCode = -1; // FIXME: Why?
|
||||||
emit q->finished();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
QString errorString;
|
QString errorString;
|
||||||
@@ -252,23 +251,19 @@ void ApplicationLauncherPrivate::handleDone()
|
|||||||
if (m_processRunning && !isRunning()) {
|
if (m_processRunning && !isRunning()) {
|
||||||
m_processRunning = false;
|
m_processRunning = false;
|
||||||
m_resultData.m_exitCode = -1;
|
m_resultData.m_exitCode = -1;
|
||||||
emit q->finished();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
emit q->errorOccurred(m_resultData.m_error);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
QTC_ASSERT(m_state == Run, return);
|
QTC_ASSERT(m_state == Run, emit q->done(); return);
|
||||||
if (m_resultData.m_error == QProcess::FailedToStart) {
|
if (m_resultData.m_error == QProcess::FailedToStart) {
|
||||||
m_resultData.m_exitStatus = QProcess::CrashExit;
|
m_resultData.m_exitStatus = QProcess::CrashExit;
|
||||||
emit q->errorOccurred(m_resultData.m_error);
|
|
||||||
} else if (m_resultData.m_exitStatus == QProcess::CrashExit) {
|
} else if (m_resultData.m_exitStatus == QProcess::CrashExit) {
|
||||||
m_resultData.m_error = QProcess::Crashed;
|
m_resultData.m_error = QProcess::Crashed;
|
||||||
emit q->errorOccurred(m_resultData.m_error);
|
|
||||||
}
|
}
|
||||||
m_state = Inactive;
|
m_state = Inactive;
|
||||||
emit q->finished();
|
|
||||||
}
|
}
|
||||||
|
emit q->done();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplicationLauncherPrivate::handleStandardOutput()
|
void ApplicationLauncherPrivate::handleStandardOutput()
|
||||||
@@ -312,6 +307,11 @@ QProcess::ExitStatus ApplicationLauncher::exitStatus() const
|
|||||||
return d->m_resultData.m_exitStatus;
|
return d->m_resultData.m_exitStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QProcess::ProcessError ApplicationLauncher::error() const
|
||||||
|
{
|
||||||
|
return d->m_resultData.m_error;
|
||||||
|
}
|
||||||
|
|
||||||
void ApplicationLauncher::start()
|
void ApplicationLauncher::start()
|
||||||
{
|
{
|
||||||
d->start();
|
d->start();
|
||||||
@@ -357,8 +357,7 @@ void ApplicationLauncherPrivate::start()
|
|||||||
m_resultData.m_errorString = ApplicationLauncher::tr("Cannot run: No device.");
|
m_resultData.m_errorString = ApplicationLauncher::tr("Cannot run: No device.");
|
||||||
m_resultData.m_error = QProcess::FailedToStart;
|
m_resultData.m_error = QProcess::FailedToStart;
|
||||||
m_resultData.m_exitStatus = QProcess::CrashExit;
|
m_resultData.m_exitStatus = QProcess::CrashExit;
|
||||||
emit q->errorOccurred(QProcess::FailedToStart);
|
emit q->done();
|
||||||
emit q->finished();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,8 +365,7 @@ void ApplicationLauncherPrivate::start()
|
|||||||
m_resultData.m_errorString = ApplicationLauncher::tr("Cannot run: No command given.");
|
m_resultData.m_errorString = ApplicationLauncher::tr("Cannot run: No command given.");
|
||||||
m_resultData.m_error = QProcess::FailedToStart;
|
m_resultData.m_error = QProcess::FailedToStart;
|
||||||
m_resultData.m_exitStatus = QProcess::CrashExit;
|
m_resultData.m_exitStatus = QProcess::CrashExit;
|
||||||
emit q->errorOccurred(QProcess::FailedToStart);
|
emit q->done();
|
||||||
emit q->finished();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -63,12 +63,12 @@ public:
|
|||||||
|
|
||||||
int exitCode() const;
|
int exitCode() const;
|
||||||
QProcess::ExitStatus exitStatus() const;
|
QProcess::ExitStatus exitStatus() const;
|
||||||
|
QProcess::ProcessError error() 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 started();
|
void started();
|
||||||
void finished();
|
void done();
|
||||||
void errorOccurred(QProcess::ProcessError error);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<Internal::ApplicationLauncherPrivate> d;
|
std::unique_ptr<Internal::ApplicationLauncherPrivate> d;
|
||||||
|
@@ -1220,30 +1220,22 @@ void SimpleTargetRunner::doStart(const Runnable &runnable)
|
|||||||
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::finished, this, [this, runnable]() {
|
connect(&m_launcher, &ApplicationLauncher::done, this, [this, runnable] {
|
||||||
if (m_stopReported)
|
if (m_stopReported)
|
||||||
return;
|
return;
|
||||||
const QString msg = (m_launcher.exitStatus() == QProcess::CrashExit)
|
QString msg = tr("%2 exited with code %1").arg(m_launcher.exitCode());
|
||||||
? tr("%1 crashed.") : tr("%2 exited with code %1").arg(m_launcher.exitCode());
|
if (m_launcher.exitStatus() == QProcess::CrashExit)
|
||||||
|
msg = tr("%1 crashed.");
|
||||||
|
else if (m_stopForced)
|
||||||
|
msg = tr("The process was ended forcefully.");
|
||||||
|
else if (m_launcher.error() != QProcess::UnknownError)
|
||||||
|
msg = userMessageForProcessError(m_launcher.error(), runnable.command.executable());
|
||||||
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;
|
||||||
reportStopped();
|
reportStopped();
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(&m_launcher, &ApplicationLauncher::errorOccurred,
|
|
||||||
this, [this, runnable](QProcess::ProcessError error) {
|
|
||||||
if (m_stopReported)
|
|
||||||
return;
|
|
||||||
if (error == QProcess::Timedout)
|
|
||||||
return; // No actual change on the process side.
|
|
||||||
const QString msg = m_stopForced ? tr("The process was ended forcefully.")
|
|
||||||
: userMessageForProcessError(error, runnable.command.executable());
|
|
||||||
appendMessage(msg, Utils::NormalMessageFormat);
|
|
||||||
m_stopReported = true;
|
|
||||||
reportStopped();
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(&m_launcher, &ApplicationLauncher::appendMessage, this, &RunWorker::appendMessage);
|
connect(&m_launcher, &ApplicationLauncher::appendMessage, this, &RunWorker::appendMessage);
|
||||||
|
|
||||||
const bool isDesktop = runnable.device.isNull()
|
const bool isDesktop = runnable.device.isNull()
|
||||||
|
Reference in New Issue
Block a user