forked from qt-creator/qt-creator
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
890c1906e6 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>
This commit is contained in:
@@ -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)
|
||||
{
|
||||
ProjectConfiguration::initialize(id);
|
||||
Q_ASSERT(target);
|
||||
m_stepList = new BuildStepList(this, Core::Id(Constants::BUILDSTEPS_DEPLOY));
|
||||
//: Display name of the deploy build step list. Used as part of the labels in the project window.
|
||||
m_stepList->setDefaultDisplayName(tr("Deploy"));
|
||||
//: Default DeployConfiguration display name
|
||||
setDefaultDisplayName(tr("Deploy locally"));
|
||||
ctor();
|
||||
}
|
||||
|
||||
DeployConfiguration::DeployConfiguration(Target *target, DeployConfiguration *source) :
|
||||
ProjectConfiguration(target)
|
||||
{
|
||||
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()
|
||||
DeployConfiguration::DeployConfiguration(Target *target, Core::Id id)
|
||||
: ProjectConfiguration(target, id),
|
||||
m_stepList(this, Constants::BUILDSTEPS_DEPLOY)
|
||||
{
|
||||
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();
|
||||
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"));
|
||||
//: Default DeployConfiguration display name
|
||||
setDefaultDisplayName(tr("Deploy locally"));
|
||||
}
|
||||
|
||||
DeployConfiguration::~DeployConfiguration()
|
||||
void DeployConfiguration::initialize()
|
||||
{
|
||||
delete m_stepList;
|
||||
}
|
||||
|
||||
BuildStepList *DeployConfiguration::stepList() const
|
||||
BuildStepList *DeployConfiguration::stepList()
|
||||
{
|
||||
return m_stepList;
|
||||
return &m_stepList;
|
||||
}
|
||||
|
||||
const BuildStepList *DeployConfiguration::stepList() const
|
||||
{
|
||||
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,37 +137,122 @@ 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
|
||||
///
|
||||
DefaultDeployConfiguration::DefaultDeployConfiguration(Target *target, Core::Id id)
|
||||
: DeployConfiguration(target, id)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
DefaultDeployConfiguration::DefaultDeployConfiguration(Target *target, DeployConfiguration *source)
|
||||
: DeployConfiguration(target, source)
|
||||
{
|
||||
cloneSteps(source);
|
||||
}
|
||||
|
||||
///
|
||||
// DeployConfigurationFactory
|
||||
///
|
||||
|
||||
DeployConfigurationFactory::DeployConfigurationFactory(QObject *parent) :
|
||||
QObject(parent)
|
||||
{ setObjectName(QLatin1String("DeployConfigurationFactory")); }
|
||||
DeployConfigurationFactory::DeployConfigurationFactory()
|
||||
{
|
||||
setObjectName("DeployConfigurationFactory");
|
||||
}
|
||||
|
||||
QList<Core::Id> DeployConfigurationFactory::availableCreationIds(Target *parent) const
|
||||
{
|
||||
if (!canHandle(parent))
|
||||
return {};
|
||||
return Utils::transform(availableBuildTargets(parent), [this](const QString &suffix) {
|
||||
return m_deployConfigBaseId.withSuffix(suffix);
|
||||
});
|
||||
}
|
||||
|
||||
QList<QString> DeployConfigurationFactory::availableBuildTargets(Target *) const
|
||||
{
|
||||
return {QString()};
|
||||
}
|
||||
|
||||
QString DeployConfigurationFactory::displayNameForBuildTarget(const QString &) const
|
||||
{
|
||||
return m_defaultDisplayName;
|
||||
}
|
||||
|
||||
QString DeployConfigurationFactory::displayNameForId(Core::Id id) const
|
||||
{
|
||||
return displayNameForBuildTarget(id.suffixAfter(m_deployConfigBaseId));
|
||||
}
|
||||
|
||||
bool DeployConfigurationFactory::canHandle(Target *target) const
|
||||
{
|
||||
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 DeployConfigurationFactory::canCreate(Target *parent, Core::Id id) const
|
||||
{
|
||||
if (!canHandle(parent))
|
||||
return false;
|
||||
if (!id.name().startsWith(m_deployConfigBaseId.name()))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
DeployConfiguration *DeployConfigurationFactory::create(Target *parent, Core::Id id)
|
||||
{
|
||||
if (!canCreate(parent, id))
|
||||
return nullptr;
|
||||
QTC_ASSERT(m_creator, return nullptr);
|
||||
DeployConfiguration *dc = m_creator(parent);
|
||||
if (!dc)
|
||||
return nullptr;
|
||||
dc->initialize();
|
||||
return dc;
|
||||
}
|
||||
|
||||
bool DeployConfigurationFactory::canClone(Target *parent, DeployConfiguration *product) const
|
||||
{
|
||||
if (!canHandle(parent))
|
||||
return false;
|
||||
const Core::Id id = product->id();
|
||||
if (!id.name().startsWith(m_deployConfigBaseId.name()))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
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;
|
||||
QTC_ASSERT(m_creator, return nullptr);
|
||||
DeployConfiguration *dc = m_creator(parent);
|
||||
QTC_ASSERT(dc, return nullptr);
|
||||
if (!dc->fromMap(map)) {
|
||||
delete dc;
|
||||
dc = nullptr;
|
||||
}
|
||||
return dc;
|
||||
}
|
||||
|
||||
bool DeployConfigurationFactory::canRestore(Target *parent, const QVariantMap &map) const
|
||||
{
|
||||
if (!canHandle(parent))
|
||||
return false;
|
||||
const Core::Id id = idFromMap(map);
|
||||
return id.name().startsWith(m_deployConfigBaseId.name());
|
||||
}
|
||||
|
||||
DeployConfigurationFactory *DeployConfigurationFactory::find(Target *parent, const QVariantMap &map)
|
||||
{
|
||||
@@ -206,76 +275,47 @@ DeployConfigurationFactory *DeployConfigurationFactory::find(Target *parent, Dep
|
||||
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
|
||||
///
|
||||
|
||||
QList<Core::Id> DefaultDeployConfigurationFactory::availableCreationIds(Target *parent) const
|
||||
DefaultDeployConfigurationFactory::DefaultDeployConfigurationFactory()
|
||||
{
|
||||
if (!canHandle(parent))
|
||||
return QList<Core::Id>();
|
||||
return QList<Core::Id>() << Core::Id(DEFAULT_DEPLOYCONFIGURATION_ID);
|
||||
}
|
||||
struct DefaultDeployConfiguration : DeployConfiguration
|
||||
{
|
||||
DefaultDeployConfiguration(Target *t)
|
||||
: DeployConfiguration(t, DEFAULT_DEPLOYCONFIGURATION_ID)
|
||||
{}
|
||||
};
|
||||
|
||||
QString DefaultDeployConfigurationFactory::displayNameForId(Core::Id id) const
|
||||
{
|
||||
if (id == DEFAULT_DEPLOYCONFIGURATION_ID)
|
||||
//: Display name of the default deploy configuration
|
||||
return DeployConfigurationFactory::tr("Deploy Configuration");
|
||||
return QString();
|
||||
}
|
||||
|
||||
bool DefaultDeployConfigurationFactory::canCreate(Target *parent, Core::Id id) const
|
||||
{
|
||||
if (!canHandle(parent))
|
||||
return false;
|
||||
return id == DEFAULT_DEPLOYCONFIGURATION_ID;
|
||||
}
|
||||
|
||||
DeployConfiguration *DefaultDeployConfigurationFactory::create(Target *parent, Core::Id id)
|
||||
{
|
||||
if (!canCreate(parent, id))
|
||||
return nullptr;
|
||||
return new DefaultDeployConfiguration(parent, id);
|
||||
}
|
||||
|
||||
bool DefaultDeployConfigurationFactory::canRestore(Target *parent, const QVariantMap &map) const
|
||||
{
|
||||
return canCreate(parent, idFromMap(map));
|
||||
}
|
||||
|
||||
DeployConfiguration *DefaultDeployConfigurationFactory::restore(Target *parent, const QVariantMap &map)
|
||||
{
|
||||
if (!canRestore(parent, map))
|
||||
return nullptr;
|
||||
auto dc = new DefaultDeployConfiguration(parent, idFromMap(map));
|
||||
if (!dc->fromMap(map)) {
|
||||
delete dc;
|
||||
return nullptr;
|
||||
}
|
||||
return dc;
|
||||
}
|
||||
|
||||
bool DefaultDeployConfigurationFactory::canClone(Target *parent, DeployConfiguration *product) const
|
||||
{
|
||||
return canCreate(parent, product->id());
|
||||
}
|
||||
|
||||
DeployConfiguration *DefaultDeployConfigurationFactory::clone(Target *parent, DeployConfiguration *product)
|
||||
{
|
||||
if (!canClone(parent, product))
|
||||
return nullptr;
|
||||
return new DefaultDeployConfiguration(parent, product);
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user