Utils: Drop QProcess specific parameters from QtcProcess::finished()

Mid-term plan is to concentrate on use of QtcProcess::result()
instead which is a bit more system-agnostic.

There's quite a bit of potential for downstream cleanup by
re-using QtcProcess::exitMessage() now.

Change-Id: I3806b3f5933d96e64b7cfb18cc6c52823fddcbcd
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-05-28 14:48:25 +02:00
parent 9426ce99a1
commit fe7d6f0def
31 changed files with 72 additions and 62 deletions

View File

@@ -224,7 +224,7 @@ Archive *Archive::unarchive(const FilePath &src, const FilePath &dest)
archive->m_process, archive->m_process,
&QtcProcess::finished, &QtcProcess::finished,
archive, archive,
[archive](int, QProcess::ExitStatus) { [archive] {
if (!archive->m_process) if (!archive->m_process)
return; return;
archive->finished(archive->m_process->result() == QtcProcess::FinishedWithSuccess); archive->finished(archive->m_process->result() == QtcProcess::FinishedWithSuccess);

View File

@@ -192,6 +192,7 @@ public:
QTimer m_timer; QTimer m_timer;
QEventLoop m_eventLoop; QEventLoop m_eventLoop;
QtcProcess::Result m_result = QtcProcess::StartFailed; QtcProcess::Result m_result = QtcProcess::StartFailed;
QProcess::ExitStatus m_exitStatus = QProcess::NormalExit;
int m_exitCode = -1; int m_exitCode = -1;
FilePath m_binary; FilePath m_binary;
ChannelBuffer m_stdOut; ChannelBuffer m_stdOut;
@@ -1079,13 +1080,14 @@ void QtcProcessPrivate::slotTimeout()
} }
} }
void QtcProcessPrivate::slotFinished(int exitCode, QProcess::ExitStatus e) void QtcProcessPrivate::slotFinished(int exitCode, QProcess::ExitStatus status)
{ {
if (debug) if (debug)
qDebug() << Q_FUNC_INFO << exitCode << e; qDebug() << Q_FUNC_INFO << exitCode << status;
m_hangTimerCount = 0; m_hangTimerCount = 0;
m_exitStatus = status;
switch (e) { switch (status) {
case QProcess::NormalExit: case QProcess::NormalExit:
m_result = interpretExitCode(exitCode); m_result = interpretExitCode(exitCode);
m_exitCode = exitCode; m_exitCode = exitCode;
@@ -1098,7 +1100,7 @@ void QtcProcessPrivate::slotFinished(int exitCode, QProcess::ExitStatus e)
break; break;
} }
m_eventLoop.quit(); m_eventLoop.quit();
emit q->finished(m_exitCode, e); emit q->finished();
} }
void QtcProcessPrivate::slotError(QProcess::ProcessError e) void QtcProcessPrivate::slotError(QProcess::ProcessError e)

View File

@@ -173,7 +173,7 @@ public:
signals: signals:
void started(); void started();
void finished(int exitCode, QProcess::ExitStatus exitStatus); void finished();
void errorOccurred(QProcess::ProcessError error); void errorOccurred(QProcess::ProcessError error);
void stateChanged(QProcess::ProcessState state); void stateChanged(QProcess::ProcessState state);

View File

@@ -730,15 +730,13 @@ void AndroidSettingsWidget::downloadOpenSslRepo(const bool silent)
openButton->deleteLater(); openButton->deleteLater();
}; };
connect(gitCloner, &QtcProcess::finished, connect(gitCloner, &QtcProcess::finished, [=] {
m_ui.openSslPathChooser,
[=](int exitCode, QProcess::ExitStatus exitStatus) {
openSslProgressDialog->close(); openSslProgressDialog->close();
validateOpenSsl(); validateOpenSsl();
m_ui.openSslPathChooser->triggerChanged(); // After cloning, the path exists m_ui.openSslPathChooser->triggerChanged(); // After cloning, the path exists
if (!openSslProgressDialog->wasCanceled() if (!openSslProgressDialog->wasCanceled()
|| (exitStatus == QProcess::NormalExit && exitCode != 0)) { || gitCloner->result() == QtcProcess::FinishedWithError) {
failDialog(); failDialog();
} }
}); });

View File

@@ -183,7 +183,7 @@ void CMakeProcess::processStandardError()
}); });
} }
void CMakeProcess::handleProcessFinished(int code, QProcess::ExitStatus status) void CMakeProcess::handleProcessFinished()
{ {
QTC_ASSERT(m_process && m_future, return); QTC_ASSERT(m_process && m_future, return);
@@ -192,8 +192,9 @@ void CMakeProcess::handleProcessFinished(int code, QProcess::ExitStatus status)
processStandardOutput(); processStandardOutput();
processStandardError(); processStandardError();
const int code = m_process->exitCode();
QString msg; QString msg;
if (status != QProcess::NormalExit) { if (m_process->exitStatus() != QProcess::NormalExit) {
if (m_processWasCanceled) { if (m_processWasCanceled) {
msg = tr("CMake process was canceled by the user."); msg = tr("CMake process was canceled by the user.");
} else { } else {

View File

@@ -64,12 +64,13 @@ public:
void processStandardError(); void processStandardError();
int lastExitCode() const { return m_lastExitCode; } int lastExitCode() const { return m_lastExitCode; }
signals: signals:
void started(); void started();
void finished(); void finished();
private: private:
void handleProcessFinished(int code, QProcess::ExitStatus status); void handleProcessFinished();
void checkForCancelled(); void checkForCancelled();
std::unique_ptr<Utils::QtcProcess> m_process; std::unique_ptr<Utils::QtcProcess> m_process;

View File

@@ -679,9 +679,9 @@ void ExternalToolRunner::started()
m_process->closeWriteChannel(); m_process->closeWriteChannel();
} }
void ExternalToolRunner::finished(int exitCode, QProcess::ExitStatus status) void ExternalToolRunner::finished()
{ {
if (status == QProcess::NormalExit && exitCode == 0 if (m_process->result() == QtcProcess::FinishedWithSuccess
&& (m_tool->outputHandling() == ExternalTool::ReplaceSelection && (m_tool->outputHandling() == ExternalTool::ReplaceSelection
|| m_tool->errorHandling() == ExternalTool::ReplaceSelection)) { || m_tool->errorHandling() == ExternalTool::ReplaceSelection)) {
ExternalToolManager::emitReplaceSelectionRequested(m_processOutput); ExternalToolManager::emitReplaceSelectionRequested(m_processOutput);

View File

@@ -135,7 +135,7 @@ public:
private: private:
void started(); void started();
void finished(int exitCode, QProcess::ExitStatus status); void finished();
void error(QProcess::ProcessError error); void error(QProcess::ProcessError error);
void readStandardOutput(); void readStandardOutput();
void readStandardError(); void readStandardError();

View File

@@ -130,11 +130,11 @@ void ExecuteFilter::accept(LocatorFilterEntry selection,
p->runHeadCommand(); p->runHeadCommand();
} }
void ExecuteFilter::finished(int exitCode, QProcess::ExitStatus status) void ExecuteFilter::finished()
{ {
const QString commandName = headCommand(); const QString commandName = headCommand();
QString message; QString message;
if (status == QProcess::NormalExit && exitCode == 0) if (m_process->result() == QtcProcess::FinishedWithSuccess)
message = tr("Command \"%1\" finished.").arg(commandName); message = tr("Command \"%1\" finished.").arg(commandName);
else else
message = tr("Command \"%1\" failed.").arg(commandName); message = tr("Command \"%1\" failed.").arg(commandName);

View File

@@ -55,7 +55,7 @@ public:
QString *newText, int *selectionStart, int *selectionLength) const override; QString *newText, int *selectionStart, int *selectionLength) const override;
private: private:
void finished(int exitCode, QProcess::ExitStatus status); void finished();
void readStandardOutput(); void readStandardOutput();
void readStandardError(); void readStandardError();
void runHeadCommand(); void runHeadCommand();

View File

@@ -170,7 +170,7 @@ void CppcheckRunner::handleStarted()
m_tool.startParsing(); m_tool.startParsing();
} }
void CppcheckRunner::handleFinished(int) void CppcheckRunner::handleFinished()
{ {
if (m_process->error() != QProcess::FailedToStart) { if (m_process->error() != QProcess::FailedToStart) {
m_tool.finishParsing(); m_tool.finishParsing();

View File

@@ -61,7 +61,7 @@ private:
void readOutput(); void readOutput();
void readError(); void readError();
void handleStarted(); void handleStarted();
void handleFinished(int); void handleFinished();
CppcheckTool &m_tool; CppcheckTool &m_tool;
Utils::QtcProcess *m_process = nullptr; Utils::QtcProcess *m_process = nullptr;

View File

@@ -4085,12 +4085,12 @@ void GdbEngine::handleGdbError(QProcess::ProcessError error)
} }
} }
void GdbEngine::handleGdbFinished(int exitCode, QProcess::ExitStatus exitStatus) void GdbEngine::handleGdbFinished()
{ {
if (m_commandTimer.isActive()) if (m_commandTimer.isActive())
m_commandTimer.stop(); m_commandTimer.stop();
notifyDebuggerProcessFinished(exitCode, exitStatus, "GDB"); notifyDebuggerProcessFinished(m_gdbProc.exitCode(), m_gdbProc.exitStatus(), "GDB");
} }
void GdbEngine::abortDebuggerProcess() void GdbEngine::abortDebuggerProcess()

View File

@@ -111,7 +111,7 @@ private: ////////// General Interface //////////
// The engine is still running just fine, but it failed to acquire a debuggee. // The engine is still running just fine, but it failed to acquire a debuggee.
void notifyInferiorSetupFailedHelper(const QString &msg); void notifyInferiorSetupFailedHelper(const QString &msg);
void handleGdbFinished(int exitCode, QProcess::ExitStatus exitStatus); void handleGdbFinished();
void handleGdbError(QProcess::ProcessError error); void handleGdbError(QProcess::ProcessError error);
void readGdbStandardOutput(); void readGdbStandardOutput();
void readGdbStandardError(); void readGdbStandardError();

View File

@@ -820,9 +820,9 @@ QString LldbEngine::errorMessage(QProcess::ProcessError error) const
} }
} }
void LldbEngine::handleLldbFinished(int exitCode, QProcess::ExitStatus exitStatus) void LldbEngine::handleLldbFinished()
{ {
notifyDebuggerProcessFinished(exitCode, exitStatus, "LLDB"); notifyDebuggerProcessFinished(m_lldbProc.exitCode(), m_lldbProc.exitStatus(), "LLDB");
} }
void LldbEngine::readLldbStandardError() void LldbEngine::readLldbStandardError()

View File

@@ -112,7 +112,7 @@ private:
QString errorMessage(QProcess::ProcessError error) const; QString errorMessage(QProcess::ProcessError error) const;
bool hasCapability(unsigned cap) const override; bool hasCapability(unsigned cap) const override;
void handleLldbFinished(int exitCode, QProcess::ExitStatus exitStatus); void handleLldbFinished();
void handleLldbError(QProcess::ProcessError error); void handleLldbError(QProcess::ProcessError error);
void readLldbStandardOutput(); void readLldbStandardOutput();
void readLldbStandardError(); void readLldbStandardError();

View File

@@ -246,7 +246,7 @@ signals:
private: private:
void processError(QProcess::ProcessError); void processError(QProcess::ProcessError);
void processFinished(int exitCode, QProcess::ExitStatus); void processFinished();
void timeout(); void timeout();
void errorTermination(const QString &msg); void errorTermination(const QString &msg);
@@ -351,16 +351,16 @@ void QueryContext::processError(QProcess::ProcessError e)
VcsOutputWindow::appendError(msg); VcsOutputWindow::appendError(msg);
} }
void QueryContext::processFinished(int exitCode, QProcess::ExitStatus es) void QueryContext::processFinished()
{ {
if (m_timer.isActive()) if (m_timer.isActive())
m_timer.stop(); m_timer.stop();
emit errorText(m_error); emit errorText(m_error);
if (es != QProcess::NormalExit) { if (m_process.exitStatus() != QProcess::NormalExit) {
errorTermination(tr("%1 crashed.").arg(m_binary)); errorTermination(tr("%1 crashed.").arg(m_binary));
return; return;
} else if (exitCode) { } else if (m_process.exitCode()) {
errorTermination(tr("%1 returned %2.").arg(m_binary).arg(exitCode)); errorTermination(tr("%1 returned %2.").arg(m_binary).arg(m_process.exitCode()));
return; return;
} }
emit resultRetrieved(m_output); emit resultRetrieved(m_output);

View File

@@ -107,7 +107,7 @@ private:
}; };
void processError(QProcess::ProcessError); void processError(QProcess::ProcessError);
void processFinished(int exitCode, QProcess::ExitStatus); void processFinished();
void processReadyReadStandardError(); void processReadyReadStandardError();
void processReadyReadStandardOutput(); void processReadyReadStandardOutput();
@@ -176,14 +176,14 @@ void FetchContext::start()
m_process.closeWriteChannel(); m_process.closeWriteChannel();
} }
void FetchContext::processFinished(int exitCode, QProcess::ExitStatus es) void FetchContext::processFinished()
{ {
if (es != QProcess::NormalExit) { if (m_process.exitStatus() != QProcess::NormalExit) {
handleError(tr("%1 crashed.").arg(m_git.toUserOutput())); handleError(tr("%1 crashed.").arg(m_git.toUserOutput()));
return; return;
} }
if (exitCode) { if (m_process.exitCode()) {
handleError(tr("%1 returned %2.").arg(m_git.toUserOutput()).arg(exitCode)); handleError(tr("%1 returned %2.").arg(m_git.toUserOutput()).arg(m_process.exitCode()));
return; return;
} }
if (m_state == FetchState) { if (m_state == FetchState) {

View File

@@ -134,10 +134,11 @@ void StdIOClientInterface::sendData(const QByteArray &data)
m_process.write(data); m_process.write(data);
} }
void StdIOClientInterface::onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus) void StdIOClientInterface::onProcessFinished()
{ {
if (exitStatus == QProcess::CrashExit) if (m_process.exitStatus() == QProcess::CrashExit)
emit error(tr("Crashed with exit code %1: %2").arg(exitCode).arg(m_process.errorString())); emit error(tr("Crashed with exit code %1: %2")
.arg(m_process.exitCode()).arg(m_process.errorString()));
emit finished(); emit finished();
} }

View File

@@ -89,7 +89,7 @@ protected:
private: private:
void readError(); void readError();
void readOutput(); void readOutput();
void onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus); void onProcessFinished();
}; };
} // namespace LanguageClient } // namespace LanguageClient

View File

@@ -166,7 +166,9 @@ void MesonProcess::setupProcess(const Command &command,
if (m_process) if (m_process)
disconnect(m_process.get()); disconnect(m_process.get());
m_process = std::make_unique<Utils::QtcProcess>(); m_process = std::make_unique<Utils::QtcProcess>();
connect(m_process.get(), &QtcProcess::finished, this, &MesonProcess::handleProcessFinished); connect(m_process.get(), &QtcProcess::finished, this, [this] {
handleProcessFinished(m_process->exitCode(), m_process->exitStatus());
});
connect(m_process.get(), &QtcProcess::errorOccurred, this, &MesonProcess::handleProcessError); connect(m_process.get(), &QtcProcess::errorOccurred, this, &MesonProcess::handleProcessError);
if (!captureStdo) { if (!captureStdo) {
connect(m_process.get(), connect(m_process.get(),

View File

@@ -133,19 +133,19 @@ void PerforceChecker::slotError(QProcess::ProcessError error)
} }
} }
void PerforceChecker::slotFinished(int exitCode, QProcess::ExitStatus exitStatus) void PerforceChecker::slotFinished()
{ {
if (m_timedOut) if (m_timedOut)
return; return;
switch (exitStatus) { switch (m_process.exitStatus()) {
case QProcess::CrashExit: case QProcess::CrashExit:
emitFailed(tr("\"%1\" crashed.").arg(QDir::toNativeSeparators(m_binary))); emitFailed(tr("\"%1\" crashed.").arg(QDir::toNativeSeparators(m_binary)));
break; break;
case QProcess::NormalExit: case QProcess::NormalExit:
if (exitCode) { if (m_process.exitCode()) {
const QString stdErr = QString::fromLocal8Bit(m_process.readAllStandardError()); const QString stdErr = QString::fromLocal8Bit(m_process.readAllStandardError());
emitFailed(tr("\"%1\" terminated with exit code %2: %3"). emitFailed(tr("\"%1\" terminated with exit code %2: %3").
arg(QDir::toNativeSeparators(m_binary)).arg(exitCode).arg(stdErr)); arg(QDir::toNativeSeparators(m_binary)).arg(m_process.exitCode()).arg(stdErr));
} else { } else {
parseOutput(QString::fromLocal8Bit(m_process.readAllStandardOutput())); parseOutput(QString::fromLocal8Bit(m_process.readAllStandardOutput()));
} }

View File

@@ -59,7 +59,7 @@ signals:
private: private:
void slotError(QProcess::ProcessError error); void slotError(QProcess::ProcessError error);
void slotFinished(int exitCode, QProcess::ExitStatus exitStatus); void slotFinished();
void slotTimeOut(); void slotTimeOut();
void emitFailed(const QString &); void emitFailed(const QString &);

View File

@@ -401,7 +401,7 @@ void AbstractProcessStep::finish(bool success)
emit finished(success); emit finished(success);
} }
void AbstractProcessStep::slotProcessFinished(int, QProcess::ExitStatus) void AbstractProcessStep::slotProcessFinished()
{ {
QtcProcess *process = d->m_process.get(); QtcProcess *process = d->m_process.get();
if (!process) // Happens when the process was canceled and handed over to the Reaper. if (!process) // Happens when the process was canceled and handed over to the Reaper.

View File

@@ -76,7 +76,7 @@ protected:
private: private:
void processReadyReadStdOutput(); void processReadyReadStdOutput();
void processReadyReadStdError(); void processReadyReadStdError();
void slotProcessFinished(int, QProcess::ExitStatus); void slotProcessFinished();
class Private; class Private;
Private *d; Private *d;

View File

@@ -138,8 +138,9 @@ ApplicationLauncherPrivate::ApplicationLauncherPrivate(ApplicationLauncher *pare
this, &ApplicationLauncherPrivate::readLocalStandardOutput); this, &ApplicationLauncherPrivate::readLocalStandardOutput);
connect(&m_guiProcess, &QtcProcess::errorOccurred, connect(&m_guiProcess, &QtcProcess::errorOccurred,
this, &ApplicationLauncherPrivate::localGuiProcessError); this, &ApplicationLauncherPrivate::localGuiProcessError);
connect(&m_guiProcess, &QtcProcess::finished, connect(&m_guiProcess, &QtcProcess::finished, this, [this] {
this, &ApplicationLauncherPrivate::localProcessDone); localProcessDone(m_guiProcess.exitCode(), m_guiProcess.exitStatus());
});
connect(&m_guiProcess, &QtcProcess::started, connect(&m_guiProcess, &QtcProcess::started,
this, &ApplicationLauncherPrivate::handleProcessStarted); this, &ApplicationLauncherPrivate::handleProcessStarted);
connect(&m_guiProcess, &QtcProcess::errorOccurred, connect(&m_guiProcess, &QtcProcess::errorOccurred,
@@ -151,8 +152,9 @@ ApplicationLauncherPrivate::ApplicationLauncherPrivate(ApplicationLauncher *pare
this, &ApplicationLauncherPrivate::handleProcessStarted); this, &ApplicationLauncherPrivate::handleProcessStarted);
connect(&m_consoleProcess, &ConsoleProcess::processError, connect(&m_consoleProcess, &ConsoleProcess::processError,
this, &ApplicationLauncherPrivate::localConsoleProcessError); this, &ApplicationLauncherPrivate::localConsoleProcessError);
connect(&m_consoleProcess, &ConsoleProcess::processStopped, connect(&m_consoleProcess, &ConsoleProcess::processStopped, this, [this] {
this, &ApplicationLauncherPrivate::localProcessDone); localProcessDone(m_consoleProcess.exitCode(), m_consoleProcess.exitStatus());
});
connect(&m_consoleProcess, &ConsoleProcess::errorOccurred, connect(&m_consoleProcess, &ConsoleProcess::errorOccurred,
q, &ApplicationLauncher::error); q, &ApplicationLauncher::error);

View File

@@ -292,15 +292,16 @@ private:
.arg(m_killTimer.isActive() ? tr("user") : tr("time out"))); .arg(m_killTimer.isActive() ? tr("user") : tr("time out")));
} }
void installFinished(int exitCode, QProcess::ExitStatus exitStatus) void installFinished()
{ {
m_future.reportFinished(); m_future.reportFinished();
if (exitStatus == QProcess::NormalExit && exitCode == 0) { if (m_process.result() == QtcProcess::FinishedWithSuccess) {
if (Client *client = registerLanguageServer(m_python)) if (Client *client = registerLanguageServer(m_python))
LanguageClientManager::openDocumentWithClient(m_document, client); LanguageClientManager::openDocumentWithClient(m_document, client);
} else { } else {
Core::MessageManager::writeFlashing( Core::MessageManager::writeFlashing(
tr("Installing the Python language server failed with exit code %1").arg(exitCode)); tr("Installing the Python language server failed with exit code %1")
.arg(m_process.exitCode()));
} }
deleteLater(); deleteLater();
} }

View File

@@ -179,8 +179,10 @@ void WinRtDeviceFactory::onProcessError()
tr("Error while executing winrtrunner: %1").arg(m_process->errorString())); tr("Error while executing winrtrunner: %1").arg(m_process->errorString()));
} }
void WinRtDeviceFactory::onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus) void WinRtDeviceFactory::onProcessFinished()
{ {
int exitCode = m_process->exitCode();
QProcess::ExitStatus exitStatus = m_process->exitStatus();
qCDebug(winrtDeviceLog) << __FUNCTION__ << "Exit code:" << exitCode <<"\tExit status:" qCDebug(winrtDeviceLog) << __FUNCTION__ << "Exit code:" << exitCode <<"\tExit status:"
<< exitStatus; << exitStatus;
if (exitStatus == QProcess::CrashExit) { if (exitStatus == QProcess::CrashExit) {

View File

@@ -67,7 +67,7 @@ public:
private: private:
void onProcessError(); void onProcessError();
void onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus); void onProcessFinished();
static bool allPrerequisitesLoaded(); static bool allPrerequisitesLoaded();
QString findRunnerFilePath() const; QString findRunnerFilePath() const;

View File

@@ -144,13 +144,13 @@ void WinRtRunnerHelper::onProcessReadyReadStdErr()
appendMessage(QString::fromLocal8Bit(m_process->readAllStandardError()), Utils::StdErrFormat); appendMessage(QString::fromLocal8Bit(m_process->readAllStandardError()), Utils::StdErrFormat);
} }
void WinRtRunnerHelper::onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus) void WinRtRunnerHelper::onProcessFinished()
{ {
QTC_ASSERT(m_process, return); QTC_ASSERT(m_process, return);
m_process->disconnect(); m_process->disconnect();
m_process->deleteLater(); m_process->deleteLater();
m_process = nullptr; m_process = nullptr;
emit finished(exitCode, exitStatus); emit finished();
} }
void WinRtRunnerHelper::onProcessError(QProcess::ProcessError processError) void WinRtRunnerHelper::onProcessError(QProcess::ProcessError processError)

View File

@@ -55,7 +55,7 @@ public:
signals: signals:
void started(); void started();
void finished(int exitCode, QProcess::ExitStatus exitStatus); void finished();
void error(QProcess::ProcessError error); void error(QProcess::ProcessError error);
private: private:
@@ -63,7 +63,7 @@ private:
void onProcessReadyReadStdOut(); void onProcessReadyReadStdOut();
void onProcessReadyReadStdErr(); void onProcessReadyReadStdErr();
void onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus); void onProcessFinished();
void onProcessError(QProcess::ProcessError processError); void onProcessError(QProcess::ProcessError processError);
void startWinRtRunner(const RunConf &conf); void startWinRtRunner(const RunConf &conf);