forked from qt-creator/qt-creator
BuildConfigurationFactory: Refactor code
Refactor the code of the build configuration factories. The idea is to generalize the code so much that we can allow plugins to install custom build configuration factories for the platforms they support. To support this use case the following changes where done here: * BuildInfo class was introduced to describe one build configuration that can be created by a factory. * Factories report a list of BuildInfo to describe what they can produce. This fixes the need for factories to implicitly create one buildconfiguration and then create another one 'officially' to support debug and release build configurations to be set up for projects. * Do no longer work around factories to create build configurations. Change-Id: Ic372e4a9b5c582633b467d130538948472b89d91 Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
@@ -31,7 +31,11 @@
|
||||
|
||||
#include "genericmakestep.h"
|
||||
#include "genericproject.h"
|
||||
#include "genericprojectconstants.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/mimedatabase.h>
|
||||
#include <projectexplorer/buildinfo.h>
|
||||
#include <projectexplorer/buildsteplist.h>
|
||||
#include <projectexplorer/kitinformation.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
@@ -83,53 +87,35 @@ GenericBuildConfigurationFactory::~GenericBuildConfigurationFactory()
|
||||
{
|
||||
}
|
||||
|
||||
QList<Core::Id> GenericBuildConfigurationFactory::availableCreationIds(const Target *parent) const
|
||||
bool GenericBuildConfigurationFactory::canCreate(const Target *parent) const
|
||||
{
|
||||
if (!canHandle(parent))
|
||||
return QList<Core::Id>();
|
||||
return QList<Core::Id>() << Core::Id(GENERIC_BC_ID);
|
||||
return canHandle(parent);
|
||||
}
|
||||
|
||||
QString GenericBuildConfigurationFactory::displayNameForId(const Core::Id id) const
|
||||
QList<BuildInfo *> GenericBuildConfigurationFactory::availableBuilds(const Target *parent) const
|
||||
{
|
||||
if (id == GENERIC_BC_ID)
|
||||
return tr("Build");
|
||||
return QString();
|
||||
QList<ProjectExplorer::BuildInfo *> result;
|
||||
QTC_ASSERT(canCreate(parent), return result);
|
||||
|
||||
BuildInfo *info = createBuildInfo(parent->kit(), Utils::FileName::fromString(parent->project()->projectDirectory()));
|
||||
result << info;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool GenericBuildConfigurationFactory::canCreate(const Target *parent, const Core::Id id) const
|
||||
BuildConfiguration *GenericBuildConfigurationFactory::create(Target *parent, const BuildInfo *info) const
|
||||
{
|
||||
if (!canHandle(parent))
|
||||
return false;
|
||||
if (id == GENERIC_BC_ID)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
BuildConfiguration *GenericBuildConfigurationFactory::create(Target *parent, const Core::Id id, const QString &name)
|
||||
{
|
||||
if (!canCreate(parent, id))
|
||||
return 0;
|
||||
|
||||
//TODO asking for name is duplicated everywhere, but maybe more
|
||||
// wizards will show up, that incorporate choosing the nam
|
||||
bool ok = true;
|
||||
QString buildConfigurationName = name;
|
||||
if (buildConfigurationName.isNull())
|
||||
buildConfigurationName = QInputDialog::getText(0,
|
||||
tr("New Configuration"),
|
||||
tr("New configuration name:"),
|
||||
QLineEdit::Normal,
|
||||
QString(), &ok);
|
||||
buildConfigurationName = buildConfigurationName.trimmed();
|
||||
if (!ok || buildConfigurationName.isEmpty())
|
||||
return 0;
|
||||
QTC_ASSERT(canCreate(parent), return 0);
|
||||
QTC_ASSERT(info->factory() == this, return 0);
|
||||
QTC_ASSERT(info->kitId == parent->kit()->id(), return 0);
|
||||
QTC_ASSERT(!info->displayName.isEmpty(), return 0);
|
||||
|
||||
GenericBuildConfiguration *bc = new GenericBuildConfiguration(parent);
|
||||
bc->setDisplayName(buildConfigurationName);
|
||||
bc->setDisplayName(info->displayName);
|
||||
bc->setDefaultDisplayName(info->displayName);
|
||||
bc->setBuildDirectory(info->buildDirectory);
|
||||
|
||||
BuildStepList *buildSteps = bc->stepList(Constants::BUILDSTEPS_BUILD);
|
||||
BuildStepList *cleanSteps = bc->stepList(Constants::BUILDSTEPS_CLEAN);
|
||||
BuildStepList *buildSteps = bc->stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
|
||||
BuildStepList *cleanSteps = bc->stepList(ProjectExplorer::Constants::BUILDSTEPS_CLEAN);
|
||||
|
||||
Q_ASSERT(buildSteps);
|
||||
GenericMakeStep *makeStep = new GenericMakeStep(buildSteps);
|
||||
@@ -147,7 +133,9 @@ BuildConfiguration *GenericBuildConfigurationFactory::create(Target *parent, con
|
||||
|
||||
bool GenericBuildConfigurationFactory::canClone(const Target *parent, BuildConfiguration *source) const
|
||||
{
|
||||
return canCreate(parent, source->id());
|
||||
if (!canHandle(parent))
|
||||
return false;
|
||||
return source->id() == GENERIC_BC_ID;
|
||||
}
|
||||
|
||||
BuildConfiguration *GenericBuildConfigurationFactory::clone(Target *parent, BuildConfiguration *source)
|
||||
@@ -159,7 +147,9 @@ BuildConfiguration *GenericBuildConfigurationFactory::clone(Target *parent, Buil
|
||||
|
||||
bool GenericBuildConfigurationFactory::canRestore(const Target *parent, const QVariantMap &map) const
|
||||
{
|
||||
return canCreate(parent, ProjectExplorer::idFromMap(map));
|
||||
if (!canHandle(parent))
|
||||
return false;
|
||||
return ProjectExplorer::idFromMap(map) == GENERIC_BC_ID;
|
||||
}
|
||||
|
||||
BuildConfiguration *GenericBuildConfigurationFactory::restore(Target *parent, const QVariantMap &map)
|
||||
@@ -180,6 +170,16 @@ bool GenericBuildConfigurationFactory::canHandle(const Target *t) const
|
||||
return qobject_cast<GenericProject *>(t->project());
|
||||
}
|
||||
|
||||
BuildInfo *GenericBuildConfigurationFactory::createBuildInfo(const ProjectExplorer::Kit *k,
|
||||
const Utils::FileName &buildDir) const
|
||||
{
|
||||
BuildInfo *info = new BuildInfo(this);
|
||||
info->typeName = tr("Build");
|
||||
info->buildDirectory = buildDir;
|
||||
info->kitId = k->id();
|
||||
return info;
|
||||
}
|
||||
|
||||
BuildConfiguration::BuildType GenericBuildConfiguration::buildType() const
|
||||
{
|
||||
return Unknown;
|
||||
|
||||
@@ -33,7 +33,10 @@
|
||||
#include <projectexplorer/buildconfiguration.h>
|
||||
#include <projectexplorer/namedwidget.h>
|
||||
|
||||
namespace Utils { class PathChooser; }
|
||||
namespace Utils {
|
||||
class FileName;
|
||||
class PathChooser;
|
||||
} // namespace Utils
|
||||
|
||||
namespace GenericProjectManager {
|
||||
namespace Internal {
|
||||
@@ -69,11 +72,11 @@ public:
|
||||
explicit GenericBuildConfigurationFactory(QObject *parent = 0);
|
||||
~GenericBuildConfigurationFactory();
|
||||
|
||||
QList<Core::Id> availableCreationIds(const ProjectExplorer::Target *parent) const;
|
||||
QString displayNameForId(const Core::Id id) const;
|
||||
bool canCreate(const ProjectExplorer::Target *parent) const;
|
||||
QList<ProjectExplorer::BuildInfo *> availableBuilds(const ProjectExplorer::Target *parent) const;
|
||||
ProjectExplorer::BuildConfiguration *create(ProjectExplorer::Target *parent,
|
||||
const ProjectExplorer::BuildInfo *info) const;
|
||||
|
||||
bool canCreate(const ProjectExplorer::Target *parent, const Core::Id id) const;
|
||||
ProjectExplorer::BuildConfiguration *create(ProjectExplorer::Target *parent, const Core::Id id, const QString &name = QString());
|
||||
bool canClone(const ProjectExplorer::Target *parent, ProjectExplorer::BuildConfiguration *source) const;
|
||||
ProjectExplorer::BuildConfiguration *clone(ProjectExplorer::Target *parent, ProjectExplorer::BuildConfiguration *source);
|
||||
bool canRestore(const ProjectExplorer::Target *parent, const QVariantMap &map) const;
|
||||
@@ -81,6 +84,7 @@ public:
|
||||
|
||||
private:
|
||||
bool canHandle(const ProjectExplorer::Target *t) const;
|
||||
ProjectExplorer::BuildInfo *createBuildInfo(const ProjectExplorer::Kit *k, const Utils::FileName &buildDir) const;
|
||||
};
|
||||
|
||||
class GenericBuildSettingsWidget : public ProjectExplorer::NamedWidget
|
||||
|
||||
Reference in New Issue
Block a user