Coco: Move some build step related code from plugin to cocobuildstep.cpp

Closer to the standard pattern.

Change-Id: Ibbc34b66353e63009651e1593263c58d97ce917c
Reviewed-by: Markus Redeker <markus.redeker@qt.io>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2024-11-20 16:57:57 +01:00
parent 55af0402c8
commit d4eef82528
3 changed files with 67 additions and 57 deletions

View File

@@ -8,33 +8,23 @@
#include "cocotr.h" #include "cocotr.h"
#include <cmakeprojectmanager/cmakeprojectconstants.h> #include <cmakeprojectmanager/cmakeprojectconstants.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <solutions/tasking/tasktree.h> #include <projectexplorer/projectmanager.h>
#include <utils/layoutbuilder.h> #include <projectexplorer/target.h>
#include <qmakeprojectmanager/qmakeprojectmanagerconstants.h> #include <qmakeprojectmanager/qmakeprojectmanagerconstants.h>
#include <solutions/tasking/tasktree.h>
#include <utils/layoutbuilder.h>
#include <QPushButton> #include <QPushButton>
namespace Coco::Internal { namespace Coco::Internal {
using namespace ProjectExplorer; using namespace ProjectExplorer;
QMakeStepFactory::QMakeStepFactory()
{
registerStep<CocoBuildStep>(Utils::Id{Constants::COCO_STEP_ID});
setSupportedProjectType(QmakeProjectManager::Constants::QMAKEPROJECT_ID);
setSupportedStepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
setRepeatable(false);
}
CMakeStepFactory::CMakeStepFactory()
{
registerStep<CocoBuildStep>(Utils::Id{Constants::COCO_STEP_ID});
setSupportedProjectType(CMakeProjectManager::Constants::CMAKE_PROJECT_ID);
setSupportedStepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
setRepeatable(false);
}
CocoBuildStep *CocoBuildStep::create(BuildConfiguration *buildConfig) CocoBuildStep *CocoBuildStep::create(BuildConfiguration *buildConfig)
{ {
// The "new" command creates a small memory leak which we can tolerate. // The "new" command creates a small memory leak which we can tolerate.
@@ -122,4 +112,59 @@ Tasking::GroupItem CocoBuildStep::runRecipe()
return Tasking::GroupItem({}); return Tasking::GroupItem({});
} }
// Factories
class QMakeStepFactory final : public BuildStepFactory
{
public:
QMakeStepFactory()
{
registerStep<CocoBuildStep>(Utils::Id{Constants::COCO_STEP_ID});
setSupportedProjectType(QmakeProjectManager::Constants::QMAKEPROJECT_ID);
setSupportedStepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
setRepeatable(false);
}
};
class CMakeStepFactory final : public BuildStepFactory
{
public:
CMakeStepFactory()
{
registerStep<CocoBuildStep>(Utils::Id{Constants::COCO_STEP_ID});
setSupportedProjectType(CMakeProjectManager::Constants::CMAKE_PROJECT_ID);
setSupportedStepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
setRepeatable(false);
}
};
static void addBuildStep(Target *target)
{
for (BuildConfiguration *config : target->buildConfigurations()) {
if (BuildSettings::supportsBuildConfig(*config)) {
BuildStepList *steps = config->buildSteps();
if (!steps->contains(Constants::COCO_STEP_ID))
steps->insertStep(0, CocoBuildStep::create(config));
steps->firstOfType<CocoBuildStep>()->display(config);
}
}
}
void setupCocoBuildSteps()
{
static QMakeStepFactory theQmakeStepFactory;
static CMakeStepFactory theCmakeStepFactory;
QObject::connect(ProjectManager::instance(), &ProjectManager::projectAdded, [&](Project *project) {
if (Target *target = project->activeTarget())
addBuildStep(target);
QObject::connect(project, &Project::addedTarget, [](Target *target) {
addBuildStep(target);
});
});
}
} // namespace Coco::Internal } // namespace Coco::Internal

View File

@@ -15,18 +15,6 @@ class QPushButton;
namespace Coco::Internal { namespace Coco::Internal {
class QMakeStepFactory: public ProjectExplorer::BuildStepFactory
{
public:
QMakeStepFactory();
};
class CMakeStepFactory: public ProjectExplorer::BuildStepFactory
{
public:
CMakeStepFactory();
};
class CocoBuildStep : public ProjectExplorer::BuildStep class CocoBuildStep : public ProjectExplorer::BuildStep
{ {
Q_OBJECT Q_OBJECT
@@ -56,4 +44,6 @@ private:
QPushButton *m_reconfigureButton; QPushButton *m_reconfigureButton;
}; };
void setupCocoBuildSteps();
} // namespace Coco::Internal } // namespace Coco::Internal

View File

@@ -13,7 +13,6 @@
#include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
#include <projectexplorer/projectmanager.h>
#include <projectexplorer/projectpanelfactory.h> #include <projectexplorer/projectpanelfactory.h>
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
@@ -108,28 +107,13 @@ public:
void addEntryToProjectSettings(); void addEntryToProjectSettings();
private: private:
QMakeStepFactory m_qmakeStepFactory;
CMakeStepFactory m_cmakeStepFactory;
CocoLanguageClient *m_client = nullptr; CocoLanguageClient *m_client = nullptr;
}; };
static void addBuildStep(Target *target)
{
for (BuildConfiguration *config : target->buildConfigurations()) {
if (BuildSettings::supportsBuildConfig(*config)) {
BuildStepList *steps = config->buildSteps();
if (!steps->contains(Constants::COCO_STEP_ID))
steps->insertStep(0, CocoBuildStep::create(config));
steps->firstOfType<CocoBuildStep>()->display(config);
}
}
}
void CocoPlugin::initialize() void CocoPlugin::initialize()
{ {
setupCocoBuildSteps();
IOptionsPage::registerCategory( IOptionsPage::registerCategory(
"I.Coco", "I.Coco",
QCoreApplication::translate("Coco", "Coco"), QCoreApplication::translate("Coco", "Coco"),
@@ -139,15 +123,6 @@ void CocoPlugin::initialize()
GlobalSettingsPage::instance().widget(); GlobalSettingsPage::instance().widget();
addEntryToProjectSettings(); addEntryToProjectSettings();
connect(ProjectManager::instance(), &ProjectManager::projectAdded, this, [&](Project *project) {
if (Target *target = project->activeTarget())
addBuildStep(target);
connect(project, &Project::addedTarget, this, [](Target *target) {
addBuildStep(target);
});
});
initLanguageServer(); initLanguageServer();
} }