Commit 16a7d5da authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Make use of ProjectConfiguration in the BuildConfigurations

 * Make use of the ProjectConfiguration base class in the
   BuildConfigurations and update the factories accordingly.

Reviewed-by: dt
parent 17266884
......@@ -40,47 +40,56 @@
using namespace CMakeProjectManager;
using namespace Internal;
CMakeBuildConfiguration::CMakeBuildConfiguration(CMakeProject *pro)
: BuildConfiguration(pro),
namespace {
const char * const CMAKE_BC_ID("CMakeProjectManager.CMakeBuildConfiguration");
const char * const USER_ENVIRONMENT_CHANGES_KEY("CMakeProjectManager.CMakeBuildConfiguration.UserEnvironmentChanges");
const char * const MSVC_VERSION_KEY("CMakeProjectManager.CMakeBuildConfiguration.MsvcVersion");
const char * const BUILD_DIRECTORY_KEY("CMakeProjectManager.CMakeBuildConfiguration.BuildDirectory");
}
CMakeBuildConfiguration::CMakeBuildConfiguration(CMakeProject *project) :
BuildConfiguration(project, QLatin1String(CMAKE_BC_ID)),
m_toolChain(0),
m_clearSystemEnvironment(false)
{
}
CMakeBuildConfiguration::CMakeBuildConfiguration(CMakeProject *pro, const QMap<QString, QVariant> &map)
: BuildConfiguration(pro, map),
m_toolChain(0)
CMakeBuildConfiguration::CMakeBuildConfiguration(CMakeProject *project, const QString &id) :
BuildConfiguration(project, id),
m_toolChain(0),
m_clearSystemEnvironment(false)
{
QMap<QString, QVariant>::const_iterator it = map.constFind("clearSystemEnvironment");
m_clearSystemEnvironment = (it != map.constEnd() && it.value().toBool());
m_userEnvironmentChanges =
ProjectExplorer::EnvironmentItem::fromStringList(
map.value("userEnvironmentChanges").toStringList());
m_msvcVersion = map.value("msvcVersion").toString();
m_buildDirectory = map.value("buildDirectory").toString();
}
CMakeBuildConfiguration::CMakeBuildConfiguration(CMakeBuildConfiguration *source)
: BuildConfiguration(source),
CMakeBuildConfiguration::CMakeBuildConfiguration(CMakeProject *pro, CMakeBuildConfiguration *source) :
BuildConfiguration(pro, source),
m_toolChain(0),
m_clearSystemEnvironment(source->m_clearSystemEnvironment),
m_userEnvironmentChanges(source->m_userEnvironmentChanges),
m_buildDirectory(source->m_buildDirectory),
m_msvcVersion(source->m_msvcVersion)
{
}
void CMakeBuildConfiguration::toMap(QMap<QString, QVariant> &map) const
QVariantMap CMakeBuildConfiguration::toMap() const
{
map.insert("userEnvironmentChanges",
QVariantMap map(ProjectExplorer::BuildConfiguration::toMap());
map.insert(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY),
ProjectExplorer::EnvironmentItem::toStringList(m_userEnvironmentChanges));
map.insert("msvcVersion", m_msvcVersion);
map.insert("buildDirectory", m_buildDirectory);
BuildConfiguration::toMap(map);
map.insert(QLatin1String(MSVC_VERSION_KEY), m_msvcVersion);
map.insert(QLatin1String(BUILD_DIRECTORY_KEY), m_buildDirectory);
return map;
}
bool CMakeBuildConfiguration::fromMap(const QVariantMap &map)
{
m_userEnvironmentChanges = ProjectExplorer::EnvironmentItem::fromStringList(map.value(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY)).toStringList());
m_msvcVersion = map.value(QLatin1String(MSVC_VERSION_KEY)).toString();
m_buildDirectory = map.value(QLatin1String(BUILD_DIRECTORY_KEY)).toString();
return BuildConfiguration::fromMap(map);
}
CMakeBuildConfiguration::~CMakeBuildConfiguration()
......@@ -212,9 +221,8 @@ void CMakeBuildConfiguration::setMsvcVersion(const QString &msvcVersion)
\class CMakeBuildConfigurationFactory
*/
CMakeBuildConfigurationFactory::CMakeBuildConfigurationFactory(CMakeProject *project)
: IBuildConfigurationFactory(project),
m_project(project)
CMakeBuildConfigurationFactory::CMakeBuildConfigurationFactory(QObject *parent) :
ProjectExplorer::IBuildConfigurationFactory(parent)
{
}
......@@ -222,20 +230,36 @@ CMakeBuildConfigurationFactory::~CMakeBuildConfigurationFactory()
{
}
QStringList CMakeBuildConfigurationFactory::availableCreationIds() const
QStringList CMakeBuildConfigurationFactory::availableCreationIds(ProjectExplorer::Project *parent) const
{
return QStringList() << "Create";
if (!qobject_cast<CMakeProject *>(parent))
return QStringList();
return QStringList() << QLatin1String(CMAKE_BC_ID);
}
QString CMakeBuildConfigurationFactory::displayNameForId(const QString &id) const
{
QTC_ASSERT(id == "Create", return QString());
return tr("Create");
if (id == QLatin1String(CMAKE_BC_ID))
return tr("Build");
return QString();
}
ProjectExplorer::BuildConfiguration *CMakeBuildConfigurationFactory::create(const QString &id) const
bool CMakeBuildConfigurationFactory::canCreate(ProjectExplorer::Project *parent, const QString &id) const
{
QTC_ASSERT(id == "Create", return 0);
if (!qobject_cast<CMakeProject *>(parent))
return false;
if (id == QLatin1String(CMAKE_BC_ID))
return true;
return false;
}
ProjectExplorer::BuildConfiguration *CMakeBuildConfigurationFactory::create(ProjectExplorer::Project *parent, const QString &id)
{
if (!canCreate(parent, id))
return 0;
CMakeProject *cmProject = static_cast<CMakeProject *>(parent);
Q_ASSERT(cmProject);
//TODO configuration name should be part of the cmakeopenprojectwizard
bool ok;
......@@ -247,7 +271,7 @@ ProjectExplorer::BuildConfiguration *CMakeBuildConfigurationFactory::create(cons
&ok);
if (!ok || buildConfigurationName.isEmpty())
return false;
CMakeBuildConfiguration *bc = new CMakeBuildConfiguration(m_project);
CMakeBuildConfiguration *bc = new CMakeBuildConfiguration(cmProject);
bc->setDisplayName(buildConfigurationName);
MakeStep *makeStep = new MakeStep(bc);
......@@ -258,35 +282,55 @@ ProjectExplorer::BuildConfiguration *CMakeBuildConfigurationFactory::create(cons
cleanMakeStep->setAdditionalArguments(QStringList() << "clean");
cleanMakeStep->setClean(true);
CMakeOpenProjectWizard copw(m_project->projectManager(),
m_project->sourceDirectory(),
CMakeOpenProjectWizard copw(cmProject->projectManager(),
cmProject->sourceDirectory(),
bc->buildDirectory(),
bc->environment());
if (copw.exec() != QDialog::Accepted) {
delete bc;
return false;
}
m_project->addBuildConfiguration(bc); // this also makes the name unique
cmProject->addBuildConfiguration(bc); // this also makes the name unique
bc->setBuildDirectory(copw.buildDirectory());
bc->setMsvcVersion(copw.msvcVersion());
m_project->parseCMakeLists();
cmProject->parseCMakeLists();
// Default to all
if (m_project->hasTarget("all"))
if (cmProject->hasTarget("all"))
makeStep->setBuildTarget("all", true);
return bc;
}
ProjectExplorer::BuildConfiguration *CMakeBuildConfigurationFactory::clone(ProjectExplorer::BuildConfiguration *source) const
bool CMakeBuildConfigurationFactory::canClone(ProjectExplorer::Project *parent, ProjectExplorer::BuildConfiguration *source) const
{
return canCreate(parent, source->id());
}
ProjectExplorer::BuildConfiguration *CMakeBuildConfigurationFactory::clone(ProjectExplorer::Project *parent, ProjectExplorer::BuildConfiguration *source)
{
if (!canClone(parent, source))
return 0;
CMakeBuildConfiguration *old = static_cast<CMakeBuildConfiguration *>(source);
CMakeBuildConfiguration *bc = new CMakeBuildConfiguration(old);
return bc;
CMakeProject *cmProject(static_cast<CMakeProject *>(parent));
return new CMakeBuildConfiguration(cmProject, old);
}
ProjectExplorer::BuildConfiguration *CMakeBuildConfigurationFactory::restore(const QVariantMap &map) const
bool CMakeBuildConfigurationFactory::canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const
{
CMakeBuildConfiguration *bc = new CMakeBuildConfiguration(m_project, map);
return bc;
QString id(ProjectExplorer::idFromMap(map));
return canCreate(parent, id);
}
ProjectExplorer::BuildConfiguration *CMakeBuildConfigurationFactory::restore(ProjectExplorer::Project *parent, const QVariantMap &map)
{
if (!canRestore(parent, map))
return 0;
CMakeProject *cmProject(static_cast<CMakeProject *>(parent));
CMakeBuildConfiguration *bc = new CMakeBuildConfiguration(cmProject);
if (bc->fromMap(map))
return bc;
delete bc;
return 0;
}
......@@ -37,14 +37,15 @@ namespace CMakeProjectManager {
namespace Internal {
class CMakeProject;
class CMakeBuildConfigurationFactory;
class CMakeBuildConfiguration : public ProjectExplorer::BuildConfiguration
{
Q_OBJECT
friend class CMakeBuildConfigurationFactory;
public:
CMakeBuildConfiguration(CMakeProject *pro);
CMakeBuildConfiguration(CMakeProject *pro, const QMap<QString, QVariant> &map);
CMakeBuildConfiguration(CMakeBuildConfiguration *source);
~CMakeBuildConfiguration();
CMakeProject *cmakeProject() const;
......@@ -62,17 +63,21 @@ public:
ProjectExplorer::ToolChain::ToolChainType toolChainType() const;
ProjectExplorer::ToolChain *toolChain() const;
void setBuildDirectory(const QString &buildDirectory);
QString msvcVersion() const;
void setMsvcVersion(const QString &msvcVersion);
void toMap(QMap<QString, QVariant> &map) const;
QVariantMap toMap() const;
signals:
void msvcVersionChanged();
protected:
CMakeBuildConfiguration(CMakeProject *pro, const QString &id);
CMakeBuildConfiguration(CMakeProject *pro, CMakeBuildConfiguration *source);
virtual bool fromMap(const QVariantMap &map);
private:
void updateToolChain() const;
mutable ProjectExplorer::ToolChain *m_toolChain;
......@@ -87,18 +92,18 @@ class CMakeBuildConfigurationFactory : public ProjectExplorer::IBuildConfigurati
Q_OBJECT
public:
CMakeBuildConfigurationFactory(CMakeProject *project);
CMakeBuildConfigurationFactory(QObject *parent = 0);
~CMakeBuildConfigurationFactory();
QStringList availableCreationIds() const;
QStringList availableCreationIds(ProjectExplorer::Project *project) const;
QString displayNameForId(const QString &id) const;
ProjectExplorer::BuildConfiguration *create(const QString &id) const;
ProjectExplorer::BuildConfiguration *clone(ProjectExplorer::BuildConfiguration *source) const;
ProjectExplorer::BuildConfiguration *restore(const QVariantMap &map) const;
private:
CMakeProject *m_project;
bool canCreate(ProjectExplorer::Project *parent, const QString &id) const;
ProjectExplorer::BuildConfiguration *create(ProjectExplorer::Project *parent, const QString &id);
bool canClone(ProjectExplorer::Project *parent, ProjectExplorer::BuildConfiguration *source) const;
ProjectExplorer::BuildConfiguration *clone(ProjectExplorer::Project *parent, ProjectExplorer::BuildConfiguration *source);
bool canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const;
ProjectExplorer::BuildConfiguration *restore(ProjectExplorer::Project *parent, const QVariantMap &map);
};
} // namespace Internal
......
......@@ -35,7 +35,6 @@ namespace Constants {
const char * const PROJECTCONTEXT = "CMakeProject.ProjectContext";
const char * const CMAKEMIMETYPE = "text/x-cmake"; // TOOD check that this is correct
const char * const MAKESTEP = "CMakeProjectManager.MakeStep";
const char * const CMAKERUNCONFIGURATION = "CMakeProjectManager.CMakeRunConfiguration";
......
......@@ -40,28 +40,44 @@ using namespace GenericProjectManager;
using namespace GenericProjectManager::Internal;
using ProjectExplorer::BuildConfiguration;
namespace {
const char * const GENERIC_BC_ID("GenericProjectManager.GenericBuildConfiguration");
const char * const BUILD_DIRECTORY_KEY("GenericProjectManager.GenericBuildConfiguration.BuildDirectory");
}
GenericBuildConfiguration::GenericBuildConfiguration(GenericProject *pro)
: BuildConfiguration(pro)
: BuildConfiguration(pro, QLatin1String(GENERIC_BC_ID))
{
}
GenericBuildConfiguration::GenericBuildConfiguration(GenericProject *pro, const QVariantMap &map)
: BuildConfiguration(pro, map)
GenericBuildConfiguration::GenericBuildConfiguration(GenericProject *pro, const QString &id)
: BuildConfiguration(pro, id)
{
m_buildDirectory = map.value("buildDirectory").toString();
}
GenericBuildConfiguration::GenericBuildConfiguration(GenericBuildConfiguration *source)
: BuildConfiguration(source),
GenericBuildConfiguration::GenericBuildConfiguration(GenericProject *pro, GenericBuildConfiguration *source) :
BuildConfiguration(pro, source),
m_buildDirectory(source->m_buildDirectory)
{
}
GenericBuildConfiguration::~GenericBuildConfiguration()
{
}
QVariantMap GenericBuildConfiguration::toMap() const
{
QVariantMap map(BuildConfiguration::toMap());
map.insert(QLatin1String(BUILD_DIRECTORY_KEY), m_buildDirectory);
return map;
}
void GenericBuildConfiguration::toMap(QVariantMap &map) const
bool GenericBuildConfiguration::fromMap(const QVariantMap &map)
{
map.insert("buildDirectory", m_buildDirectory);
m_buildDirectory = map.value(QLatin1String(BUILD_DIRECTORY_KEY)).toString();
return BuildConfiguration::fromMap(map);
}
ProjectExplorer::Environment GenericBuildConfiguration::environment() const
......@@ -98,9 +114,8 @@ GenericProject *GenericBuildConfiguration::genericProject() const
\class GenericBuildConfigurationFactory
*/
GenericBuildConfigurationFactory::GenericBuildConfigurationFactory(GenericProject *project)
: IBuildConfigurationFactory(project),
m_project(project)
GenericBuildConfigurationFactory::GenericBuildConfigurationFactory(QObject *parent) :
ProjectExplorer::IBuildConfigurationFactory(parent)
{
}
......@@ -108,20 +123,34 @@ GenericBuildConfigurationFactory::~GenericBuildConfigurationFactory()
{
}
QStringList GenericBuildConfigurationFactory::availableCreationIds() const
QStringList GenericBuildConfigurationFactory::availableCreationIds(ProjectExplorer::Project *parent) const
{
return QStringList() << "Create";
Q_UNUSED(parent);
return QStringList() << QLatin1String(GENERIC_BC_ID);
}
QString GenericBuildConfigurationFactory::displayNameForId(const QString &id) const
{
QTC_ASSERT(id == "Create", return QString());
return tr("Create");
if (id == QLatin1String(GENERIC_BC_ID))
return tr("Build");
return QString();
}
BuildConfiguration *GenericBuildConfigurationFactory::create(const QString &id) const
bool GenericBuildConfigurationFactory::canCreate(ProjectExplorer::Project *parent, const QString &id) const
{
QTC_ASSERT(id == "Create", return false);
if (!qobject_cast<GenericProject *>(parent))
return false;
if (id == QLatin1String(GENERIC_BC_ID))
return true;
return false;
}
BuildConfiguration *GenericBuildConfigurationFactory::create(ProjectExplorer::Project *parent, const QString &id)
{
if (!canCreate(parent, id))
return 0;
GenericProject *project(static_cast<GenericProject *>(parent));
//TODO asking for name is duplicated everywhere, but maybe more
// wizards will show up, that incorporate choosing the name
bool ok;
......@@ -133,9 +162,9 @@ BuildConfiguration *GenericBuildConfigurationFactory::create(const QString &id)
&ok);
if (!ok || buildConfigurationName.isEmpty())
return false;
GenericBuildConfiguration *bc = new GenericBuildConfiguration(m_project);
GenericBuildConfiguration *bc = new GenericBuildConfiguration(project);
bc->setDisplayName(buildConfigurationName);
m_project->addBuildConfiguration(bc); // also makes the name unique...
project->addBuildConfiguration(bc); // also makes the name unique...
GenericMakeStep *makeStep = new GenericMakeStep(bc);
bc->insertBuildStep(0, makeStep);
......@@ -143,14 +172,33 @@ BuildConfiguration *GenericBuildConfigurationFactory::create(const QString &id)
return bc;
}
BuildConfiguration *GenericBuildConfigurationFactory::clone(BuildConfiguration *source) const
bool GenericBuildConfigurationFactory::canClone(ProjectExplorer::Project *parent, ProjectExplorer::BuildConfiguration *source) const
{
GenericBuildConfiguration *bc = new GenericBuildConfiguration(static_cast<GenericBuildConfiguration *>(source));
return bc;
return canCreate(parent, source->id());
}
BuildConfiguration *GenericBuildConfigurationFactory::restore(const QVariantMap &map) const
BuildConfiguration *GenericBuildConfigurationFactory::clone(ProjectExplorer::Project *parent, BuildConfiguration *source)
{
GenericBuildConfiguration *bc = new GenericBuildConfiguration(m_project, map);
return bc;
if (!canClone(parent, source))
return 0;
GenericProject *project(static_cast<GenericProject *>(parent));
return new GenericBuildConfiguration(project, qobject_cast<GenericBuildConfiguration *>(source));
}
bool GenericBuildConfigurationFactory::canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const
{
QString id(ProjectExplorer::idFromMap(map));
return canCreate(parent, id);
}
BuildConfiguration *GenericBuildConfigurationFactory::restore(ProjectExplorer::Project *parent, const QVariantMap &map)
{
if (!canRestore(parent, map))
return 0;
GenericProject *project(static_cast<GenericProject *>(parent));
GenericBuildConfiguration *bc(new GenericBuildConfiguration(project));
if (bc->fromMap(map))
return bc;
delete bc;
return 0;
}
......@@ -36,22 +36,29 @@ namespace GenericProjectManager {
namespace Internal {
class GenericProject;
class GenericBuildConfigurationFactory;
class GenericBuildConfiguration : public ProjectExplorer::BuildConfiguration
{
Q_OBJECT
friend class GenericBuildConfigurationFactory;
public:
GenericBuildConfiguration(GenericProject *pro);
GenericBuildConfiguration(GenericProject *pro, const QVariantMap &map);
GenericBuildConfiguration(GenericBuildConfiguration *source);
explicit GenericBuildConfiguration(GenericProject *pro);
virtual ~GenericBuildConfiguration();
GenericProject *genericProject() const;
virtual ProjectExplorer::Environment environment() const;
virtual QString buildDirectory() const;
void setBuildDirectory(const QString &buildDirectory);
void toMap(QVariantMap &map) const;
QVariantMap toMap() const;
protected:
GenericBuildConfiguration(GenericProject *pro, GenericBuildConfiguration *source);
GenericBuildConfiguration(GenericProject *pro, const QString &id);
virtual bool fromMap(const QVariantMap &map);
private:
QString m_buildDirectory;
};
......@@ -61,18 +68,18 @@ class GenericBuildConfigurationFactory : public ProjectExplorer::IBuildConfigura
Q_OBJECT
public:
GenericBuildConfigurationFactory(GenericProject *project);
~GenericBuildConfigurationFactory();
explicit GenericBuildConfigurationFactory(QObject *parent = 0);
virtual ~GenericBuildConfigurationFactory();
QStringList availableCreationIds() const;
QStringList availableCreationIds(ProjectExplorer::Project *project) const;
QString displayNameForId(const QString &id) const;
ProjectExplorer::BuildConfiguration *create(const QString &id) const;
ProjectExplorer::BuildConfiguration *clone(ProjectExplorer::BuildConfiguration *source) const;
ProjectExplorer::BuildConfiguration *restore(const QVariantMap &map) const;
private:
GenericProject *m_project;
bool canCreate(ProjectExplorer::Project *parent, const QString &id) const;
ProjectExplorer::BuildConfiguration *create(ProjectExplorer::Project *parent, const QString &id);
bool canClone(ProjectExplorer::Project *parent, ProjectExplorer::BuildConfiguration *source) const;
ProjectExplorer::BuildConfiguration *clone(ProjectExplorer::Project *parent, ProjectExplorer::BuildConfiguration *source);
bool canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const;
ProjectExplorer::BuildConfiguration *restore(ProjectExplorer::Project *parent, const QVariantMap &map);
};
} // namespace GenericProjectManager
......
......@@ -36,6 +36,7 @@
using namespace ProjectExplorer;
namespace {
IBuildStepFactory *findCloneFactory(BuildConfiguration *parent, BuildStep *source)
{
QList<IBuildStepFactory *> factories = ExtensionSystem::PluginManager::instance()->getObjects<IBuildStepFactory>();
......@@ -44,24 +45,35 @@ IBuildStepFactory *findCloneFactory(BuildConfiguration *parent, BuildStep *sourc
return factory;
return 0;
}
} // namespace
BuildConfiguration::BuildConfiguration(Project *pro)
: m_project(pro)
IBuildStepFactory *findRestoreFactory(BuildConfiguration *parent, const QVariantMap &map)
{
QList<IBuildStepFactory *> factories = ExtensionSystem::PluginManager::instance()->getObjects<IBuildStepFactory>();
foreach(IBuildStepFactory *factory, factories)
if (factory->canRestore(parent, map))
return factory;
return 0;
}
BuildConfiguration::BuildConfiguration(Project *pro, const QVariantMap &map)
: m_project(pro)
const char * const BUILD_STEPS_COUNT_KEY("ProjectExplorer.BuildConfiguration.BuildStepsCount");
const char * const BUILD_STEPS_PREFIX("ProjectExplorer.BuildConfiguration.BuildSteps.");
const char * const CLEAN_STEPS_COUNT_KEY("ProjectExplorer.BuildConfiguration.CleanStepsCount");
const char * const CLEAN_STEPS_PREFIX("ProjectExplorer.BuildConfiguration.CleanSteps.");
} // namespace
BuildConfiguration::BuildConfiguration(Project *project, const QString &id) :
ProjectConfiguration(id),
m_project(project)
{
m_displayName = map.value("ProjectExplorer.BuildConfiguration.DisplayName").toString();
Q_ASSERT(m_project);
}
BuildConfiguration::BuildConfiguration(BuildConfiguration *source)
: m_displayName(source->m_displayName),
m_project(source->m_project)
BuildConfiguration::BuildConfiguration(Project *project, BuildConfiguration *source) :
ProjectConfiguration(source),
m_project(project)
{
Q_ASSERT(m_project);
foreach(BuildStep *originalbs, source->buildSteps()) {
IBuildStepFactory *factory = findCloneFactory(this, originalbs);
BuildStep *clonebs = factory->clone(this, originalbs);
......@@ -82,22 +94,55 @@ BuildConfiguration::~BuildConfiguration()
qDeleteAll(m_cleanSteps);
}
QString BuildConfiguration::displayName() const
QVariantMap BuildConfiguration::toMap() const
{
return m_displayName;
}
QVariantMap map(ProjectConfiguration::toMap());
map.insert(QLatin1String(BUILD_STEPS_COUNT_KEY), m_buildSteps.count());
for (int i = 0; i < m_buildSteps.count(); ++i)