Process: Refactor timeout handling

Rename ProcessResult::Hang into Canceled.

Change the behavior of the Process:
Whenever the terminate() or kill() is called, including
indirect calls through stop() or runBlocking()'s timeout,
mark the process result as Canceled.
In this way the Process running by a call to start()
may also finish with Canceled state. Before it was only
happening for processes started via runBlocking().

Adapt the runBlockingStdOut_data() test accordingly.

Get rid of ProcessInterface::m_canceledByUser field.
Use ProcessResult::Canceled state instead.

Fix existing 3 usages of m_canceledByUser field.
Use standarized exitMessage() method for them.

Add automatic measurement of process execution.
Introduce processDuration() getter.
Use it for reporting exitMessage() instead of timeoutS().

Change-Id: I1a68559ce844caef863a97a6b0577b0238011f70
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Jarek Kobus
2024-01-22 12:49:58 +01:00
parent 886ac041e5
commit f6be85b1d2
9 changed files with 51 additions and 70 deletions

View File

@@ -131,7 +131,16 @@ void CMakeProcess::run(const BuildDirParameters &parameters, const QStringList &
});
connect(m_process.get(), &Process::done, this, [this] {
handleProcessDone(m_process->resultData());
if (m_process->result() != ProcessResult::FinishedWithSuccess) {
const QString message = m_process->exitMessage();
BuildSystem::appendBuildSystemOutput(addCMakePrefix({{}, message}).join('\n'));
TaskHub::addTask(BuildSystemTask(Task::Error, message));
}
emit finished(m_process->exitCode());
const QString elapsedTime = Utils::formatElapsedTime(m_elapsed.elapsed());
BuildSystem::appendBuildSystemOutput(addCMakePrefix({{}, elapsedTime}).join('\n'));
});
CommandLine commandLine(cmakeExecutable);
@@ -158,32 +167,6 @@ void CMakeProcess::stop()
m_process->stop();
}
void CMakeProcess::handleProcessDone(const Utils::ProcessResultData &resultData)
{
const int code = resultData.m_exitCode;
QString msg;
if (resultData.m_error == QProcess::FailedToStart) {
msg = ::CMakeProjectManager::Tr::tr("CMake process failed to start.");
} else if (resultData.m_exitStatus != QProcess::NormalExit) {
if (resultData.m_canceledByUser)
msg = ::CMakeProjectManager::Tr::tr("CMake process was canceled by the user.");
else
msg = ::CMakeProjectManager::Tr::tr("CMake process crashed.");
} else if (code != 0) {
msg = ::CMakeProjectManager::Tr::tr("CMake process exited with exit code %1.").arg(code);
}
if (!msg.isEmpty()) {
BuildSystem::appendBuildSystemOutput(addCMakePrefix({QString(), msg}).join('\n'));
TaskHub::addTask(BuildSystemTask(Task::Error, msg));
}
emit finished(code);
const QString elapsedTime = Utils::formatElapsedTime(m_elapsed.elapsed());
BuildSystem::appendBuildSystemOutput(addCMakePrefix({QString(), elapsedTime}).join('\n'));
}
QString addCMakePrefix(const QString &str)
{
auto qColorToAnsiCode = [] (const QColor &color) {

View File

@@ -36,8 +36,6 @@ signals:
void stdOutReady(const QString &s);
private:
void handleProcessDone(const Utils::ProcessResultData &resultData);
std::unique_ptr<Utils::Process> m_process;
Utils::OutputFormatter m_parser;
QElapsedTimer m_elapsed;