forked from qt-creator/qt-creator
QbsProjectManager: Introduce QbsRequest
It's going to be used in task tree for QbsBuildStep, QbsCleanStep and QbsInstallStep. Change-Id: I347562b72a628b66d648f943c2fbf67df69c0bc5 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -25,6 +25,7 @@ add_qtc_plugin(QbsProjectManager
|
|||||||
qbsprojectmanagerconstants.h
|
qbsprojectmanagerconstants.h
|
||||||
qbsprojectmanagerplugin.cpp qbsprojectmanagerplugin.h
|
qbsprojectmanagerplugin.cpp qbsprojectmanagerplugin.h
|
||||||
qbsprojectparser.cpp qbsprojectparser.h
|
qbsprojectparser.cpp qbsprojectparser.h
|
||||||
|
qbsrequest.cpp qbsrequest.h
|
||||||
qbssession.cpp qbssession.h
|
qbssession.cpp qbssession.h
|
||||||
qbssettings.cpp qbssettings.h
|
qbssettings.cpp qbssettings.h
|
||||||
)
|
)
|
||||||
|
@@ -54,6 +54,8 @@ QtcPlugin {
|
|||||||
"qbsprojectmanagerplugin.h",
|
"qbsprojectmanagerplugin.h",
|
||||||
"qbsprojectparser.cpp",
|
"qbsprojectparser.cpp",
|
||||||
"qbsprojectparser.h",
|
"qbsprojectparser.h",
|
||||||
|
"qbsrequest.cpp",
|
||||||
|
"qbsrequest.h",
|
||||||
"qbssession.cpp",
|
"qbssession.cpp",
|
||||||
"qbssession.h",
|
"qbssession.h",
|
||||||
"qbssettings.cpp",
|
"qbssettings.cpp",
|
||||||
|
88
src/plugins/qbsprojectmanager/qbsrequest.cpp
Normal file
88
src/plugins/qbsprojectmanager/qbsrequest.cpp
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
// Copyright (C) 2023 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
|
#include "qbsrequest.h"
|
||||||
|
|
||||||
|
#include "qbsprojectmanagertr.h"
|
||||||
|
#include "qbssession.h"
|
||||||
|
|
||||||
|
#include <projectexplorer/task.h>
|
||||||
|
|
||||||
|
#include <utils/commandline.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
|
using namespace ProjectExplorer;
|
||||||
|
using namespace Tasking;
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
|
namespace QbsProjectManager::Internal {
|
||||||
|
|
||||||
|
QbsRequest::~QbsRequest()
|
||||||
|
{
|
||||||
|
if (m_isRunning)
|
||||||
|
m_session->cancelCurrentJob();
|
||||||
|
}
|
||||||
|
|
||||||
|
void QbsRequest::setSession(QbsSession *session)
|
||||||
|
{
|
||||||
|
QTC_ASSERT(!m_isRunning, return);
|
||||||
|
m_session = session;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QbsRequest::start()
|
||||||
|
{
|
||||||
|
QTC_ASSERT(!m_isRunning, return);
|
||||||
|
QTC_ASSERT(m_session, emit done(false); return);
|
||||||
|
QTC_ASSERT(m_requestData, emit done(false); return);
|
||||||
|
|
||||||
|
const auto handleDone = [this](const ErrorInfo &error) {
|
||||||
|
m_isRunning = false;
|
||||||
|
m_session->disconnect(this);
|
||||||
|
for (const ErrorInfoItem &item : error.items) {
|
||||||
|
emit outputAdded(item.description, BuildStep::OutputFormat::Stdout);
|
||||||
|
emit taskAdded(CompileTask(Task::Error, item.description, item.filePath, item.line));
|
||||||
|
}
|
||||||
|
emit done(error.items.isEmpty());
|
||||||
|
};
|
||||||
|
connect(m_session, &QbsSession::projectBuilt, this, handleDone);
|
||||||
|
connect(m_session, &QbsSession::projectCleaned, this, handleDone);
|
||||||
|
connect(m_session, &QbsSession::projectInstalled, this, handleDone);
|
||||||
|
connect(m_session, &QbsSession::errorOccurred, this, [handleDone](QbsSession::Error error) {
|
||||||
|
handleDone(ErrorInfo(QbsSession::errorString(error)));
|
||||||
|
});
|
||||||
|
connect(m_session, &QbsSession::taskStarted, this, [this](const QString &desciption, int max) {
|
||||||
|
m_description = desciption;
|
||||||
|
m_maxProgress = max;
|
||||||
|
});
|
||||||
|
connect(m_session, &QbsSession::maxProgressChanged, this, [this](int max) {
|
||||||
|
m_maxProgress = max;
|
||||||
|
});
|
||||||
|
connect(m_session, &QbsSession::taskProgress, this, [this](int progress) {
|
||||||
|
if (m_maxProgress > 0)
|
||||||
|
emit progressChanged(progress * 100 / m_maxProgress, m_description);
|
||||||
|
});
|
||||||
|
connect(m_session, &QbsSession::commandDescription, this, [this](const QString &message) {
|
||||||
|
emit outputAdded(message, BuildStep::OutputFormat::Stdout);
|
||||||
|
});
|
||||||
|
connect(m_session, &QbsSession::processResult, this, [this](const FilePath &executable,
|
||||||
|
const QStringList &arguments,
|
||||||
|
const FilePath &workingDir,
|
||||||
|
const QStringList &stdOut,
|
||||||
|
const QStringList &stdErr,
|
||||||
|
bool success) {
|
||||||
|
Q_UNUSED(workingDir);
|
||||||
|
const bool hasOutput = !stdOut.isEmpty() || !stdErr.isEmpty();
|
||||||
|
if (success && !hasOutput)
|
||||||
|
return;
|
||||||
|
emit outputAdded(executable.toUserOutput() + ' ' + ProcessArgs::joinArgs(arguments),
|
||||||
|
BuildStep::OutputFormat::Stdout);
|
||||||
|
for (const QString &line : stdErr)
|
||||||
|
emit outputAdded(line, BuildStep::OutputFormat::Stderr);
|
||||||
|
for (const QString &line : stdOut)
|
||||||
|
emit outputAdded(line, BuildStep::OutputFormat::Stdout);
|
||||||
|
});
|
||||||
|
m_isRunning = true;
|
||||||
|
m_session->sendRequest(*m_requestData);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace QbsProjectManager::Internal
|
52
src/plugins/qbsprojectmanager/qbsrequest.h
Normal file
52
src/plugins/qbsprojectmanager/qbsrequest.h
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
// Copyright (C) 2023 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <projectexplorer/buildstep.h>
|
||||||
|
|
||||||
|
#include <solutions/tasking/tasktree.h>
|
||||||
|
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
namespace QbsProjectManager::Internal {
|
||||||
|
|
||||||
|
class QbsSession;
|
||||||
|
|
||||||
|
class QbsRequest final : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
~QbsRequest() override;
|
||||||
|
|
||||||
|
void setSession(QbsSession *session);
|
||||||
|
void setRequestData(const QJsonObject &requestData) { m_requestData = requestData; }
|
||||||
|
void start();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void done(bool success);
|
||||||
|
void progressChanged(int progress, const QString &info); // progress in %
|
||||||
|
void outputAdded(const QString &output, ProjectExplorer::BuildStep::OutputFormat format);
|
||||||
|
void taskAdded(const ProjectExplorer::Task &task);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QbsSession *m_session = nullptr;
|
||||||
|
std::optional<QJsonObject> m_requestData;
|
||||||
|
bool m_isRunning = false;
|
||||||
|
QString m_description;
|
||||||
|
int m_maxProgress = 100;
|
||||||
|
};
|
||||||
|
|
||||||
|
class QbsRequestTaskAdapter : public Tasking::TaskAdapter<QbsRequest>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QbsRequestTaskAdapter() { connect(task(), &QbsRequest::done, this, &TaskInterface::done); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void start() final { task()->start(); }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace QbsProjectManager::Internal
|
||||||
|
|
||||||
|
TASKING_DECLARE_TASK(QbsRequestTask, QbsProjectManager::Internal::QbsRequestTaskAdapter);
|
Reference in New Issue
Block a user