From 165d364a6d7a6c7fa352f529b782eb357d76eb67 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Mon, 10 Oct 2022 12:28:29 +0200 Subject: [PATCH] CMakeProcess: Simplify implementation by using ProcessProgress Change-Id: I9e9665f7e57ebb7d3028396e792161aa2c3a648e Reviewed-by: hjk --- .../cmakeprojectmanager/cmakeprocess.cpp | 46 ++++--------------- .../cmakeprojectmanager/cmakeprocess.h | 8 ---- 2 files changed, 9 insertions(+), 45 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakeprocess.cpp b/src/plugins/cmakeprojectmanager/cmakeprocess.cpp index 4960b2e5c09..cc62b8402ff 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprocess.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeprocess.cpp @@ -7,7 +7,7 @@ #include "cmakeparser.h" #include "cmakeprojectmanagertr.h" -#include +#include #include #include #include @@ -16,15 +16,12 @@ #include #include -#include - +using namespace Core; using namespace ProjectExplorer; using namespace Utils; namespace CMakeProjectManager::Internal { -const int USER_STOP_EXIT_CODE = 15; - static QString stripTrailingNewline(QString str) { if (str.endsWith('\n')) @@ -37,13 +34,6 @@ CMakeProcess::CMakeProcess() = default; CMakeProcess::~CMakeProcess() { m_parser.flush(); - - if (m_futureWatcher) { - m_futureWatcher.reset(); - // None of the progress related functions will work after this! - m_futureInterface.reportCanceled(); - m_futureInterface.reportFinished(); - } } void CMakeProcess::run(const BuildDirParameters ¶meters, const QStringList &arguments) @@ -130,17 +120,10 @@ void CMakeProcess::run(const BuildDirParameters ¶meters, const QStringList & BuildSystem::startNewBuildSystemOutput(::CMakeProjectManager::Tr::tr("Running %1 in %2.") .arg(commandLine.toUserOutput(), buildDirectory.toUserOutput())); - m_futureInterface = QFutureInterface(); - m_futureInterface.setProgressRange(0, 1); - Core::ProgressManager::addTimedTask(m_futureInterface, - ::CMakeProjectManager::Tr::tr("Configuring \"%1\"") - .arg(parameters.projectName), - "CMake.Configure", - 10); - m_futureWatcher.reset(new QFutureWatcher); - connect(m_futureWatcher.get(), &QFutureWatcher::canceled, this, &CMakeProcess::stop); - m_futureWatcher->setFuture(m_futureInterface.future()); - + ProcessProgress *progress = new ProcessProgress(m_process.get()); + progress->setDisplayName(::CMakeProjectManager::Tr::tr("Configuring \"%1\"") + .arg(parameters.projectName)); + m_process->setTimeoutS(10); // for process progress timeout estimation m_process->setCommand(commandLine); emit started(); m_elapsed.start(); @@ -149,25 +132,19 @@ void CMakeProcess::run(const BuildDirParameters ¶meters, const QStringList & void CMakeProcess::stop() { - if (!m_process) - return; - m_process->close(); - handleProcessDone({USER_STOP_EXIT_CODE, QProcess::CrashExit, QProcess::Crashed, {}}); + if (m_process) + m_process->stop(); } void CMakeProcess::handleProcessDone(const Utils::ProcessResultData &resultData) { - if (m_futureWatcher) { - m_futureWatcher->disconnect(); - m_futureWatcher.release()->deleteLater(); - } 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 (m_futureInterface.isCanceled() || code == USER_STOP_EXIT_CODE) + if (resultData.m_canceledByUser) msg = ::CMakeProjectManager::Tr::tr("CMake process was canceled by the user."); else msg = ::CMakeProjectManager::Tr::tr("CMake process crashed."); @@ -179,13 +156,8 @@ void CMakeProcess::handleProcessDone(const Utils::ProcessResultData &resultData) if (!msg.isEmpty()) { BuildSystem::appendBuildSystemOutput(msg + '\n'); TaskHub::addTask(BuildSystemTask(Task::Error, msg)); - m_futureInterface.reportCanceled(); - } else { - m_futureInterface.setProgressValue(1); } - m_futureInterface.reportFinished(); - emit finished(); const QString elapsedTime = Utils::formatElapsedTime(m_elapsed.elapsed()); diff --git a/src/plugins/cmakeprojectmanager/cmakeprocess.h b/src/plugins/cmakeprojectmanager/cmakeprocess.h index 31ff1d37c5d..c242ff38b1e 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprocess.h +++ b/src/plugins/cmakeprojectmanager/cmakeprocess.h @@ -6,17 +6,11 @@ #include #include -#include #include #include #include -QT_BEGIN_NAMESPACE -template -class QFutureWatcher; -QT_END_NAMESPACE - namespace Utils { class ProcessResultData; class QtcProcess; @@ -48,8 +42,6 @@ private: std::unique_ptr m_process; Utils::OutputFormatter m_parser; - QFutureInterface m_futureInterface; - std::unique_ptr> m_futureWatcher; QElapsedTimer m_elapsed; int m_lastExitCode = 0; };