forked from qt-creator/qt-creator
QbsCleanStep: Employ task tree for running
Task-number: QTCREATORBUG-29168 Change-Id: I68e097747f8383d319d5c14eeb5bb9f1a94353a5 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -4,8 +4,6 @@
|
||||
#include "qbsbuildconfiguration.h"
|
||||
|
||||
#include "qbsbuildstep.h"
|
||||
#include "qbscleanstep.h"
|
||||
#include "qbsinstallstep.h"
|
||||
#include "qbsproject.h"
|
||||
#include "qbsprojectmanagerconstants.h"
|
||||
#include "qbsprojectmanagertr.h"
|
||||
@@ -144,10 +142,6 @@ QbsBuildConfiguration::~QbsBuildConfiguration()
|
||||
if (const auto qbs = qobject_cast<QbsBuildStep *>(bs))
|
||||
qbs->dropSession();
|
||||
}
|
||||
for (BuildStep * const cs : cleanSteps()->steps()) {
|
||||
if (const auto qcs = qobject_cast<QbsCleanStep *>(cs))
|
||||
qcs->dropSession();
|
||||
}
|
||||
delete m_buildSystem;
|
||||
}
|
||||
|
||||
|
@@ -4,32 +4,27 @@
|
||||
#include "qbscleanstep.h"
|
||||
|
||||
#include "qbsbuildconfiguration.h"
|
||||
#include "qbsproject.h"
|
||||
#include "qbsprojectmanagerconstants.h"
|
||||
#include "qbsprojectmanagertr.h"
|
||||
#include "qbsrequest.h"
|
||||
#include "qbssession.h"
|
||||
|
||||
#include <projectexplorer/buildsteplist.h>
|
||||
#include <projectexplorer/kit.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/buildmanager.h>
|
||||
#include <projectexplorer/target.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Tasking;
|
||||
using namespace Utils;
|
||||
|
||||
namespace QbsProjectManager {
|
||||
namespace Internal {
|
||||
namespace QbsProjectManager::Internal {
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// QbsCleanStep:
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
QbsCleanStep::QbsCleanStep(BuildStepList *bsl, Utils::Id id)
|
||||
QbsCleanStep::QbsCleanStep(BuildStepList *bsl, Id id)
|
||||
: BuildStep(bsl, id)
|
||||
{
|
||||
setDisplayName(Tr::tr("Qbs Clean"));
|
||||
@@ -55,25 +50,11 @@ QbsCleanStep::QbsCleanStep(BuildStepList *bsl, Utils::Id id)
|
||||
});
|
||||
}
|
||||
|
||||
QbsCleanStep::~QbsCleanStep()
|
||||
{
|
||||
doCancel();
|
||||
if (m_session)
|
||||
m_session->disconnect(this);
|
||||
}
|
||||
|
||||
void QbsCleanStep::dropSession()
|
||||
{
|
||||
if (m_session) {
|
||||
doCancel();
|
||||
m_session->disconnect(this);
|
||||
m_session = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool QbsCleanStep::init()
|
||||
{
|
||||
if (buildSystem()->isParsing() || m_session)
|
||||
if (!BuildStep::init())
|
||||
return false;
|
||||
if (buildSystem()->isParsing())
|
||||
return false;
|
||||
const auto bc = static_cast<QbsBuildConfiguration *>(buildConfiguration());
|
||||
if (!bc)
|
||||
@@ -82,64 +63,36 @@ bool QbsCleanStep::init()
|
||||
return true;
|
||||
}
|
||||
|
||||
void QbsCleanStep::doRun()
|
||||
GroupItem QbsCleanStep::runRecipe()
|
||||
{
|
||||
m_session = static_cast<QbsBuildSystem*>(buildSystem())->session();
|
||||
if (!m_session) {
|
||||
emit addOutput(Tr::tr("No qbs session exists for this target."), OutputFormat::ErrorMessage);
|
||||
emit finished(false);
|
||||
return;
|
||||
const auto onSetup = [this](QbsRequest &request) {
|
||||
QbsSession *session = static_cast<QbsBuildSystem*>(buildSystem())->session();
|
||||
if (!session) {
|
||||
emit addOutput(Tr::tr("No qbs session exists for this target."),
|
||||
OutputFormat::ErrorMessage);
|
||||
return SetupResult::StopWithError;
|
||||
}
|
||||
|
||||
QJsonObject request;
|
||||
request.insert("type", "clean-project");
|
||||
QJsonObject requestData;
|
||||
requestData.insert("type", "clean-project");
|
||||
if (!m_products.isEmpty())
|
||||
request.insert("products", QJsonArray::fromStringList(m_products));
|
||||
request.insert("dry-run", dryRun());
|
||||
request.insert("keep-going", keepGoing());
|
||||
m_session->sendRequest(request);
|
||||
m_maxProgress = 0;
|
||||
connect(m_session, &QbsSession::projectCleaned, this, &QbsCleanStep::cleaningDone);
|
||||
connect(m_session, &QbsSession::taskStarted, this, &QbsCleanStep::handleTaskStarted);
|
||||
connect(m_session, &QbsSession::taskProgress, this, &QbsCleanStep::handleProgress);
|
||||
connect(m_session, &QbsSession::errorOccurred, this, [this] {
|
||||
cleaningDone(ErrorInfo(Tr::tr("Cleaning canceled: Qbs session failed.")));
|
||||
requestData.insert("products", QJsonArray::fromStringList(m_products));
|
||||
requestData.insert("dry-run", dryRun());
|
||||
requestData.insert("keep-going", keepGoing());
|
||||
|
||||
request.setSession(session);
|
||||
request.setRequestData(requestData);
|
||||
connect(&request, &QbsRequest::progressChanged, this, &BuildStep::progress);
|
||||
connect(&request, &QbsRequest::outputAdded, this,
|
||||
[this](const QString &output, OutputFormat format) {
|
||||
emit addOutput(output, format);
|
||||
});
|
||||
}
|
||||
connect(&request, &QbsRequest::taskAdded, this, [this](const Task &task) {
|
||||
emit addTask(task, 1);
|
||||
});
|
||||
return SetupResult::Continue;
|
||||
};
|
||||
|
||||
void QbsCleanStep::doCancel()
|
||||
{
|
||||
if (m_session)
|
||||
m_session->cancelCurrentJob();
|
||||
}
|
||||
|
||||
void QbsCleanStep::cleaningDone(const ErrorInfo &error)
|
||||
{
|
||||
m_session->disconnect(this);
|
||||
m_session = nullptr;
|
||||
|
||||
for (const ErrorInfoItem &item : error.items)
|
||||
createTaskAndOutput(Task::Error, item.description, item.filePath, item.line);
|
||||
emit finished(!error.hasError());
|
||||
}
|
||||
|
||||
void QbsCleanStep::handleTaskStarted(const QString &desciption, int max)
|
||||
{
|
||||
Q_UNUSED(desciption)
|
||||
m_maxProgress = max;
|
||||
}
|
||||
|
||||
void QbsCleanStep::handleProgress(int value)
|
||||
{
|
||||
if (m_maxProgress > 0)
|
||||
emit progress(value * 100 / m_maxProgress, m_description);
|
||||
}
|
||||
|
||||
void QbsCleanStep::createTaskAndOutput(Task::TaskType type, const QString &message,
|
||||
const FilePath &file, int line)
|
||||
{
|
||||
emit addOutput(message, OutputFormat::Stdout);
|
||||
emit addTask(CompileTask(type, message, file, line), 1);
|
||||
return QbsRequestTask(onSetup);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
@@ -154,5 +107,4 @@ QbsCleanStepFactory::QbsCleanStepFactory()
|
||||
setDisplayName(Tr::tr("Qbs Clean"));
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QbsProjectManager
|
||||
} // namespace QbsProjectManager::Internal
|
||||
|
@@ -3,18 +3,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "qbsbuildconfiguration.h"
|
||||
|
||||
#include <projectexplorer/buildstep.h>
|
||||
#include <projectexplorer/task.h>
|
||||
|
||||
#include <utils/aspects.h>
|
||||
|
||||
namespace QbsProjectManager {
|
||||
namespace Internal {
|
||||
|
||||
class ErrorInfo;
|
||||
class QbsSession;
|
||||
namespace QbsProjectManager::Internal {
|
||||
|
||||
class QbsCleanStep final : public ProjectExplorer::BuildStep
|
||||
{
|
||||
@@ -22,33 +13,16 @@ class QbsCleanStep final : public ProjectExplorer::BuildStep
|
||||
|
||||
public:
|
||||
QbsCleanStep(ProjectExplorer::BuildStepList *bsl, Utils::Id id);
|
||||
~QbsCleanStep() override;
|
||||
|
||||
QbsBuildStepData stepData() const;
|
||||
|
||||
void dropSession();
|
||||
|
||||
private:
|
||||
bool init() override;
|
||||
void doRun() override;
|
||||
void doCancel() override;
|
||||
|
||||
void cleaningDone(const ErrorInfo &error);
|
||||
void handleTaskStarted(const QString &desciption, int max);
|
||||
void handleProgress(int value);
|
||||
|
||||
void createTaskAndOutput(ProjectExplorer::Task::TaskType type,
|
||||
const QString &message, const Utils::FilePath &file, int line);
|
||||
Tasking::GroupItem runRecipe() final;
|
||||
|
||||
Utils::BoolAspect dryRun{this};
|
||||
Utils::BoolAspect keepGoing{this};
|
||||
Utils::StringAspect effectiveCommand{this};
|
||||
|
||||
QStringList m_products;
|
||||
QbsSession *m_session = nullptr;
|
||||
QString m_description;
|
||||
int m_maxProgress;
|
||||
bool m_showCompilerOutput = true;
|
||||
};
|
||||
|
||||
class QbsCleanStepFactory : public ProjectExplorer::BuildStepFactory
|
||||
@@ -57,5 +31,4 @@ public:
|
||||
QbsCleanStepFactory();
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QbsProjectManager
|
||||
} // namespace QbsProjectManager::Internal
|
||||
|
Reference in New Issue
Block a user