diff --git a/src/plugins/qbsprojectmanager/qbsbuildconfiguration.cpp b/src/plugins/qbsprojectmanager/qbsbuildconfiguration.cpp index 243ac8cbf23..476bd5b071f 100644 --- a/src/plugins/qbsprojectmanager/qbsbuildconfiguration.cpp +++ b/src/plugins/qbsprojectmanager/qbsbuildconfiguration.cpp @@ -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(bs)) qbs->dropSession(); } - for (BuildStep * const cs : cleanSteps()->steps()) { - if (const auto qcs = qobject_cast(cs)) - qcs->dropSession(); - } delete m_buildSystem; } diff --git a/src/plugins/qbsprojectmanager/qbscleanstep.cpp b/src/plugins/qbsprojectmanager/qbscleanstep.cpp index 9d6799a5fb1..475d38e9478 100644 --- a/src/plugins/qbsprojectmanager/qbscleanstep.cpp +++ b/src/plugins/qbsprojectmanager/qbscleanstep.cpp @@ -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 -#include #include -#include -#include -#include #include #include 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(buildConfiguration()); if (!bc) @@ -82,64 +63,36 @@ bool QbsCleanStep::init() return true; } -void QbsCleanStep::doRun() +GroupItem QbsCleanStep::runRecipe() { - m_session = static_cast(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(buildSystem())->session(); + if (!session) { + emit addOutput(Tr::tr("No qbs session exists for this target."), + OutputFormat::ErrorMessage); + return SetupResult::StopWithError; + } + QJsonObject requestData; + requestData.insert("type", "clean-project"); + if (!m_products.isEmpty()) + requestData.insert("products", QJsonArray::fromStringList(m_products)); + requestData.insert("dry-run", dryRun()); + requestData.insert("keep-going", keepGoing()); - QJsonObject request; - request.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."))); - }); -} + 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 diff --git a/src/plugins/qbsprojectmanager/qbscleanstep.h b/src/plugins/qbsprojectmanager/qbscleanstep.h index b3552993366..132287afd7c 100644 --- a/src/plugins/qbsprojectmanager/qbscleanstep.h +++ b/src/plugins/qbsprojectmanager/qbscleanstep.h @@ -3,18 +3,9 @@ #pragma once -#include "qbsbuildconfiguration.h" - #include -#include -#include - -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