forked from qt-creator/qt-creator
CMakeProcess: Simplify implementation by using ProcessProgress
Change-Id: I9e9665f7e57ebb7d3028396e792161aa2c3a648e Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
#include "cmakeparser.h"
|
||||
#include "cmakeprojectmanagertr.h"
|
||||
|
||||
#include <coreplugin/progressmanager/progressmanager.h>
|
||||
#include <coreplugin/progressmanager/processprogress.h>
|
||||
#include <projectexplorer/buildsystem.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/taskhub.h>
|
||||
@@ -16,15 +16,12 @@
|
||||
#include <utils/qtcprocess.h>
|
||||
#include <utils/stringutils.h>
|
||||
|
||||
#include <QFutureWatcher>
|
||||
|
||||
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<void>();
|
||||
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<void>);
|
||||
connect(m_futureWatcher.get(), &QFutureWatcher<void>::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());
|
||||
|
||||
@@ -6,17 +6,11 @@
|
||||
#include <utils/outputformatter.h>
|
||||
|
||||
#include <QElapsedTimer>
|
||||
#include <QFutureInterface>
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
|
||||
#include <memory>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
template<class T>
|
||||
class QFutureWatcher;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Utils {
|
||||
class ProcessResultData;
|
||||
class QtcProcess;
|
||||
@@ -48,8 +42,6 @@ private:
|
||||
|
||||
std::unique_ptr<Utils::QtcProcess> m_process;
|
||||
Utils::OutputFormatter m_parser;
|
||||
QFutureInterface<void> m_futureInterface;
|
||||
std::unique_ptr<QFutureWatcher<void>> m_futureWatcher;
|
||||
QElapsedTimer m_elapsed;
|
||||
int m_lastExitCode = 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user