diff options
author | hjk <hjk@qt.io> | 2017-11-29 12:28:40 +0100 |
---|---|---|
committer | hjk <hjk@qt.io> | 2017-12-08 11:17:55 +0000 |
commit | 53a151074ad37d12e730fbd85ec0e0675d00f6d0 (patch) | |
tree | 041526d48608270cad2db171696fa6cf7099a852 /src/plugins/projectexplorer/deployconfiguration.cpp | |
parent | 9d3c5c6ff5ba059f036efae5fd9572fe454b5d84 (diff) |
ProjectExplorer/all: Re-organize BuildSteps/{Deploy,Build}Config setup
This follow the rough pattern of recent *RunConfigurationFactory changes
for build and deploy configurations.
- Collapse the two lines of constructors similar to what
890c1906e6fb2ec did for RunConfigurations
* Deploy* was purely mechanical
* Build* ctors are split in connects() in the ctor body
to create "empty shell for clone" etc
and build step additions in initialize() functions which
are only used in the create() case.
-- Allows to collapse the shared 'ctor()' functions, too.
- Move FooBuildConfigurationFactory::create() implementations
to FooBuildConfiguration() constructor. That was a strange
and unneeded ping-pong between factories and objects, and
furthermore allows one level less of indirection (and for a
later, left out here, some reduction of the
FooBuildConfiguration interfaces that were only used to
accommodate the *Factory::create() functions.
- Most {Build,Deploy}Configuration{,Factory} classes had a canHandle(),
but there wasn't one in the base classses. Have one there.
- Most canHandle() functions were checking simple restrictions on
e.g. project or target types, specify those by setters in the
constructors instead and check them in the base canHandle()
- clone() is generally replaced by a creation of a "shell object"
and a fromMap(source->toMap()), implemented in the base, there
are two cases left for Android and Qbs that needed(?) some extra
polish
- generally use canHandle() in base implementation, instead
of doing that in all Derived::canFoo()
- as a result, canCreate/create/canClone/clone reimplementations
are not needed anymore, keep the base implementation for
now (could be inlined into their only users later), but
de-virtualize them.
- Combine Ios{Preset,DSym}BuildStepFactory. There was only one
'dsym' build step they could create.
- Split the 'mangled' id into the ProjectConfiguration subtype
specific constant identifier, and a QString extraId() bit.
Only maintain the mangled id in saved settings.
- Make ProjectConfiguration::m_id a constant member, adapt
all constructors of derived classe.
Not done in this patch:
- Finish possible cosmetic changes on top
- Add a way to specify restrictions to supported Qt versions
(used in Android/Ios), as the base implementation does not
depend on the qtsupport plugin
- Combine the QList<X> availableFoo() + createFoo(X) function
pairs to somthing like a direct
QList<struct { X; std::function<X()>; }> fooCreators()
to avoid e.g. the baseId.withSuffix() <-> id.suffixAfter(base)
pingpong
- Remove the *Factories from the global object pool
- Do something about priority(). Falling back to plain
qmake in android+qmake setup is not helpful.
Change-Id: I2be7d88d554c5aa8b7db8edf5b93278e1ae0112a
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
Diffstat (limited to 'src/plugins/projectexplorer/deployconfiguration.cpp')
-rw-r--r-- | src/plugins/projectexplorer/deployconfiguration.cpp | 262 |
1 files changed, 151 insertions, 111 deletions
diff --git a/src/plugins/projectexplorer/deployconfiguration.cpp b/src/plugins/projectexplorer/deployconfiguration.cpp index 6f44d135b1..1c3967442d 100644 --- a/src/plugins/projectexplorer/deployconfiguration.cpp +++ b/src/plugins/projectexplorer/deployconfiguration.cpp @@ -34,62 +34,51 @@ #include <extensionsystem/pluginmanager.h> +#include <utils/algorithm.h> + namespace ProjectExplorer { const char BUILD_STEP_LIST_COUNT[] = "ProjectExplorer.BuildConfiguration.BuildStepListCount"; const char BUILD_STEP_LIST_PREFIX[] = "ProjectExplorer.BuildConfiguration.BuildStepList."; const char DEFAULT_DEPLOYCONFIGURATION_ID[] = "ProjectExplorer.DefaultDeployConfiguration"; -DeployConfiguration::DeployConfiguration(Target *target, Core::Id id) : - ProjectConfiguration(target) +DeployConfiguration::DeployConfiguration(Target *target, Core::Id id) + : ProjectConfiguration(target, id), + m_stepList(this, Constants::BUILDSTEPS_DEPLOY) { - ProjectConfiguration::initialize(id); - Q_ASSERT(target); - m_stepList = new BuildStepList(this, Core::Id(Constants::BUILDSTEPS_DEPLOY)); + Utils::MacroExpander *expander = macroExpander(); + expander->setDisplayName(tr("Deploy Settings")); + expander->setAccumulating(true); + expander->registerSubProvider([target] { + BuildConfiguration *bc = target->activeBuildConfiguration(); + return bc ? bc->macroExpander() : target->macroExpander(); + }); + //: Display name of the deploy build step list. Used as part of the labels in the project window. - m_stepList->setDefaultDisplayName(tr("Deploy")); + m_stepList.setDefaultDisplayName(tr("Deploy")); //: Default DeployConfiguration display name setDefaultDisplayName(tr("Deploy locally")); - ctor(); } -DeployConfiguration::DeployConfiguration(Target *target, DeployConfiguration *source) : - ProjectConfiguration(target) +void DeployConfiguration::initialize() { - ProjectConfiguration::copyFrom(source); - Q_ASSERT(target); - // Do not clone stepLists here, do that in the derived constructor instead - // otherwise BuildStepFactories might reject to set up a BuildStep for us - // since we are not yet the derived class! - ctor(); } -void DeployConfiguration::ctor() +BuildStepList *DeployConfiguration::stepList() { - Utils::MacroExpander *expander = macroExpander(); - expander->setDisplayName(tr("Deploy Settings")); - expander->setAccumulating(true); - expander->registerSubProvider([this]() -> Utils::MacroExpander * { - BuildConfiguration *bc = target()->activeBuildConfiguration(); - return bc ? bc->macroExpander() : target()->macroExpander(); - }); + return &m_stepList; } -DeployConfiguration::~DeployConfiguration() +const BuildStepList *DeployConfiguration::stepList() const { - delete m_stepList; -} - -BuildStepList *DeployConfiguration::stepList() const -{ - return m_stepList; + return &m_stepList; } QVariantMap DeployConfiguration::toMap() const { QVariantMap map(ProjectConfiguration::toMap()); map.insert(QLatin1String(BUILD_STEP_LIST_COUNT), 1); - map.insert(QLatin1String(BUILD_STEP_LIST_PREFIX) + QLatin1Char('0'), m_stepList->toMap()); + map.insert(QLatin1String(BUILD_STEP_LIST_PREFIX) + QLatin1Char('0'), m_stepList.toMap()); return map; } @@ -118,23 +107,18 @@ bool DeployConfiguration::fromMap(const QVariantMap &map) return false; QVariantMap data = map.value(QLatin1String(BUILD_STEP_LIST_PREFIX) + QLatin1Char('0')).toMap(); if (!data.isEmpty()) { - delete m_stepList; - m_stepList = new BuildStepList(this, Core::Id()); - if (!m_stepList->fromMap(data)) { + m_stepList.clear(); + if (!m_stepList.fromMap(data)) { qWarning() << "Failed to restore deploy step list"; - delete m_stepList; - m_stepList = 0; + m_stepList.clear(); return false; } - m_stepList->setDefaultDisplayName(tr("Deploy")); + m_stepList.setDefaultDisplayName(tr("Deploy")); } else { qWarning() << "No data for deploy step list found!"; return false; } - // We assume that we hold the deploy list - Q_ASSERT(m_stepList && m_stepList->id() == Constants::BUILDSTEPS_DEPLOY); - return true; } @@ -153,129 +137,185 @@ bool DeployConfiguration::isActive() const return target()->isActive() && target()->activeDeployConfiguration() == this; } -void DeployConfiguration::cloneSteps(DeployConfiguration *source) -{ - if (source == this) - return; - delete m_stepList; - m_stepList = new BuildStepList(this, source->stepList()); - m_stepList->cloneSteps(source->stepList()); -} /// -// DefaultDeployConfiguration +// DeployConfigurationFactory /// -DefaultDeployConfiguration::DefaultDeployConfiguration(Target *target, Core::Id id) - : DeployConfiguration(target, id) -{ -} - -DefaultDeployConfiguration::DefaultDeployConfiguration(Target *target, DeployConfiguration *source) - : DeployConfiguration(target, source) +DeployConfigurationFactory::DeployConfigurationFactory() { - cloneSteps(source); + setObjectName("DeployConfigurationFactory"); } -/// -// DeployConfigurationFactory -/// - -DeployConfigurationFactory::DeployConfigurationFactory(QObject *parent) : - QObject(parent) -{ setObjectName(QLatin1String("DeployConfigurationFactory")); } - -DeployConfigurationFactory *DeployConfigurationFactory::find(Target *parent, const QVariantMap &map) +QList<Core::Id> DeployConfigurationFactory::availableCreationIds(Target *parent) const { - return ExtensionSystem::PluginManager::getObject<DeployConfigurationFactory>( - [&parent, &map](DeployConfigurationFactory *factory) { - return factory->canRestore(parent, map); - }); + if (!canHandle(parent)) + return {}; + return Utils::transform(availableBuildTargets(parent), [this](const QString &suffix) { + return m_deployConfigBaseId.withSuffix(suffix); + }); } -QList<DeployConfigurationFactory *> DeployConfigurationFactory::find(Target *parent) +QList<QString> DeployConfigurationFactory::availableBuildTargets(Target *) const { - return ExtensionSystem::PluginManager::getObjects<DeployConfigurationFactory>( - [&parent](DeployConfigurationFactory *factory) { - return !factory->availableCreationIds(parent).isEmpty(); - }); + return {QString()}; } -DeployConfigurationFactory *DeployConfigurationFactory::find(Target *parent, DeployConfiguration *dc) +QString DeployConfigurationFactory::displayNameForBuildTarget(const QString &) const { - return ExtensionSystem::PluginManager::getObject<DeployConfigurationFactory>( - [&parent, &dc](DeployConfigurationFactory *factory) { - return factory->canClone(parent, dc); - }); + return m_defaultDisplayName; } -/// -// DefaultDeployConfigurationFactory -/// - -QList<Core::Id> DefaultDeployConfigurationFactory::availableCreationIds(Target *parent) const +QString DeployConfigurationFactory::displayNameForId(Core::Id id) const { - if (!canHandle(parent)) - return QList<Core::Id>(); - return QList<Core::Id>() << Core::Id(DEFAULT_DEPLOYCONFIGURATION_ID); + return displayNameForBuildTarget(id.suffixAfter(m_deployConfigBaseId)); } -QString DefaultDeployConfigurationFactory::displayNameForId(Core::Id id) const +bool DeployConfigurationFactory::canHandle(Target *target) const { - if (id == DEFAULT_DEPLOYCONFIGURATION_ID) - //: Display name of the default deploy configuration - return DeployConfigurationFactory::tr("Deploy Configuration"); - return QString(); + if (m_supportedProjectType.isValid()) { + if (target->project()->id() != m_supportedProjectType) + return false; + } + + if (!target->project()->supportsKit(target->kit())) + return false; + + if (!m_supportedTargetDeviceTypes.isEmpty()) { + if (!m_supportedTargetDeviceTypes.contains( + DeviceTypeKitInformation::deviceTypeId(target->kit()))) + return false; + } + + return true; } -bool DefaultDeployConfigurationFactory::canCreate(Target *parent, Core::Id id) const +bool DeployConfigurationFactory::canCreate(Target *parent, Core::Id id) const { if (!canHandle(parent)) return false; - return id == DEFAULT_DEPLOYCONFIGURATION_ID; + if (!id.name().startsWith(m_deployConfigBaseId.name())) + return false; + return true; } -DeployConfiguration *DefaultDeployConfigurationFactory::create(Target *parent, Core::Id id) +DeployConfiguration *DeployConfigurationFactory::create(Target *parent, Core::Id id) { if (!canCreate(parent, id)) return nullptr; - return new DefaultDeployConfiguration(parent, id); + QTC_ASSERT(m_creator, return nullptr); + DeployConfiguration *dc = m_creator(parent); + if (!dc) + return nullptr; + dc->initialize(); + return dc; } -bool DefaultDeployConfigurationFactory::canRestore(Target *parent, const QVariantMap &map) const +bool DeployConfigurationFactory::canClone(Target *parent, DeployConfiguration *product) const { - return canCreate(parent, idFromMap(map)); + if (!canHandle(parent)) + return false; + const Core::Id id = product->id(); + if (!id.name().startsWith(m_deployConfigBaseId.name())) + return false; + return true; } -DeployConfiguration *DefaultDeployConfigurationFactory::restore(Target *parent, const QVariantMap &map) +DeployConfiguration *DeployConfigurationFactory::clone(Target *parent, DeployConfiguration *product) +{ + QTC_ASSERT(m_creator, return nullptr); + if (!canClone(parent, product)) + return nullptr; + DeployConfiguration *dc = m_creator(parent); + QVariantMap data = product->toMap(); + dc->fromMap(data); + return dc; +} + +DeployConfiguration *DeployConfigurationFactory::restore(Target *parent, const QVariantMap &map) { if (!canRestore(parent, map)) return nullptr; - auto dc = new DefaultDeployConfiguration(parent, idFromMap(map)); + QTC_ASSERT(m_creator, return nullptr); + DeployConfiguration *dc = m_creator(parent); + QTC_ASSERT(dc, return nullptr); if (!dc->fromMap(map)) { delete dc; - return nullptr; + dc = nullptr; } return dc; } -bool DefaultDeployConfigurationFactory::canClone(Target *parent, DeployConfiguration *product) const +bool DeployConfigurationFactory::canRestore(Target *parent, const QVariantMap &map) const { - return canCreate(parent, product->id()); + if (!canHandle(parent)) + return false; + const Core::Id id = idFromMap(map); + return id.name().startsWith(m_deployConfigBaseId.name()); } -DeployConfiguration *DefaultDeployConfigurationFactory::clone(Target *parent, DeployConfiguration *product) +DeployConfigurationFactory *DeployConfigurationFactory::find(Target *parent, const QVariantMap &map) { - if (!canClone(parent, product)) - return nullptr; - return new DefaultDeployConfiguration(parent, product); + return ExtensionSystem::PluginManager::getObject<DeployConfigurationFactory>( + [&parent, &map](DeployConfigurationFactory *factory) { + return factory->canRestore(parent, map); + }); +} + +QList<DeployConfigurationFactory *> DeployConfigurationFactory::find(Target *parent) +{ + return ExtensionSystem::PluginManager::getObjects<DeployConfigurationFactory>( + [&parent](DeployConfigurationFactory *factory) { + return !factory->availableCreationIds(parent).isEmpty(); + }); +} + +DeployConfigurationFactory *DeployConfigurationFactory::find(Target *parent, DeployConfiguration *dc) +{ + return ExtensionSystem::PluginManager::getObject<DeployConfigurationFactory>( + [&parent, &dc](DeployConfigurationFactory *factory) { + return factory->canClone(parent, dc); + }); +} + +void DeployConfigurationFactory::setSupportedTargetDeviceTypes(const QList<Core::Id> &ids) +{ + m_supportedTargetDeviceTypes = ids; +} + +void DeployConfigurationFactory::setDefaultDisplayName(const QString &defaultDisplayName) +{ + m_defaultDisplayName = defaultDisplayName; +} + +void DeployConfigurationFactory::setSupportedProjectType(Core::Id id) +{ + m_supportedProjectType = id; +} + +/// +// DefaultDeployConfigurationFactory +/// + +DefaultDeployConfigurationFactory::DefaultDeployConfigurationFactory() +{ + struct DefaultDeployConfiguration : DeployConfiguration + { + DefaultDeployConfiguration(Target *t) + : DeployConfiguration(t, DEFAULT_DEPLOYCONFIGURATION_ID) + {} + }; + + registerDeployConfiguration<DefaultDeployConfiguration>(DEFAULT_DEPLOYCONFIGURATION_ID); + setSupportedTargetDeviceTypes({Constants::DESKTOP_DEVICE_TYPE}); + //: Display name of the default deploy configuration + setDefaultDisplayName(DeployConfigurationFactory::tr("Deploy Configuration")); } bool DefaultDeployConfigurationFactory::canHandle(Target *parent) const { - if (!parent->project()->supportsKit(parent->kit()) || parent->project()->needsSpecialDeployment()) - return false; - return DeviceTypeKitInformation::deviceTypeId(parent->kit()) == Constants::DESKTOP_DEVICE_TYPE; + return DeployConfigurationFactory::canHandle(parent) + && !parent->project()->needsSpecialDeployment(); } } // namespace ProjectExplorer |