summaryrefslogtreecommitdiff
path: root/src/plugins/cmakeprojectmanager
diff options
context:
space:
mode:
authorTobias Hunger <tobias.hunger@digia.com>2013-07-22 15:53:57 +0200
committerTobias Hunger <tobias.hunger@digia.com>2013-09-17 12:00:01 +0200
commitd2adc303353f8b67c476794175f004566e4eedf6 (patch)
tree473f1f2727899dbb0eae43b0f573ad611bd82ab7 /src/plugins/cmakeprojectmanager
parentec436a6d64772c660b38488100f151a0617f0ead (diff)
downloadqt-creator-d2adc303353f8b67c476794175f004566e4eedf6.tar.gz
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>
Diffstat (limited to 'src/plugins/cmakeprojectmanager')
-rw-r--r--src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp93
-rw-r--r--src/plugins/cmakeprojectmanager/cmakebuildconfiguration.h11
-rw-r--r--src/plugins/cmakeprojectmanager/cmakebuildinfo.h65
-rw-r--r--src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.cpp17
-rw-r--r--src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.h24
-rw-r--r--src/plugins/cmakeprojectmanager/cmakeproject.cpp15
-rw-r--r--src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp5
-rw-r--r--src/plugins/cmakeprojectmanager/cmakeprojectmanager.pro3
-rw-r--r--src/plugins/cmakeprojectmanager/cmakeprojectmanager.qbs1
9 files changed, 147 insertions, 87 deletions
diff --git a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp
index 3af1ccf901..825d3e4d20 100644
--- a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp
@@ -29,15 +29,20 @@
#include "cmakebuildconfiguration.h"
+#include "cmakebuildinfo.h"
#include "cmakeopenprojectwizard.h"
#include "cmakeproject.h"
#include "cmakeprojectconstants.h"
+#include <coreplugin/icore.h>
+#include <coreplugin/mimedatabase.h>
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/kit.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/target.h>
+#include <utils/qtcassert.h>
+
#include <QInputDialog>
using namespace CMakeProjectManager;
@@ -117,64 +122,45 @@ CMakeBuildConfigurationFactory::~CMakeBuildConfigurationFactory()
{
}
-QList<Core::Id> CMakeBuildConfigurationFactory::availableCreationIds(const ProjectExplorer::Target *parent) const
+bool CMakeBuildConfigurationFactory::canCreate(const ProjectExplorer::Target *parent) const
{
- if (!canHandle(parent))
- return QList<Core::Id>();
- return QList<Core::Id>() << Core::Id(Constants::CMAKE_BC_ID);
+ return canHandle(parent);
}
-QString CMakeBuildConfigurationFactory::displayNameForId(const Core::Id id) const
+QList<ProjectExplorer::BuildInfo *> CMakeBuildConfigurationFactory::availableBuilds(const ProjectExplorer::Target *parent) const
{
- if (id == Constants::CMAKE_BC_ID)
- return tr("Build");
- return QString();
-}
+ QList<ProjectExplorer::BuildInfo *> result;
+ QTC_ASSERT(canCreate(parent), return result);
-bool CMakeBuildConfigurationFactory::canCreate(const ProjectExplorer::Target *parent, const Core::Id id) const
-{
- if (!canHandle(parent))
- return false;
- if (id == Constants::CMAKE_BC_ID)
- return true;
- return false;
+ CMakeBuildInfo *info = createBuildInfo(parent->kit(), parent->project()->projectDirectory());
+ result << info;
+ return result;
}
-CMakeBuildConfiguration *CMakeBuildConfigurationFactory::create(ProjectExplorer::Target *parent, const Core::Id id, const QString &name)
+ProjectExplorer::BuildConfiguration *CMakeBuildConfigurationFactory::create(ProjectExplorer::Target *parent,
+ const ProjectExplorer::BuildInfo *info) const
{
- if (!canCreate(parent, id))
- 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);
+ CMakeBuildInfo copy(*static_cast<const CMakeBuildInfo *>(info));
CMakeProject *project = static_cast<CMakeProject *>(parent->project());
- 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;
+ if (copy.buildDirectory.isEmpty())
+ copy.buildDirectory
+ = Utils::FileName::fromString(project->shadowBuildDirectory(project->projectFilePath(),
+ parent->kit(),
+ copy.displayName));
- CMakeOpenProjectWizard::BuildInfo info;
- info.sourceDirectory = project->projectDirectory();
- info.environment = Utils::Environment::systemEnvironment();
- parent->kit()->addToEnvironment(info.environment);
- info.buildDirectory = project->shadowBuildDirectory(project->projectFilePath(),
- parent->kit(),
- buildConfigurationName);
- info.kit = parent->kit();
- info.useNinja = false; // This is ignored anyway
-
- CMakeOpenProjectWizard copw(project->projectManager(), CMakeOpenProjectWizard::ChangeDirectory, info);
+ CMakeOpenProjectWizard copw(project->projectManager(), CMakeOpenProjectWizard::ChangeDirectory, &copy);
if (copw.exec() != QDialog::Accepted)
return 0;
CMakeBuildConfiguration *bc = new CMakeBuildConfiguration(parent);
- bc->setDisplayName(buildConfigurationName);
+ bc->setDisplayName(copy.displayName);
+ bc->setDefaultDisplayName(copy.displayName);
ProjectExplorer::BuildStepList *buildSteps = bc->stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
ProjectExplorer::BuildStepList *cleanSteps = bc->stepList(ProjectExplorer::Constants::BUILDSTEPS_CLEAN);
@@ -199,7 +185,9 @@ CMakeBuildConfiguration *CMakeBuildConfigurationFactory::create(ProjectExplorer:
bool CMakeBuildConfigurationFactory::canClone(const ProjectExplorer::Target *parent, ProjectExplorer::BuildConfiguration *source) const
{
- return canCreate(parent, source->id());
+ if (!canHandle(parent))
+ return false;
+ return source->id() == Constants::CMAKE_BC_ID;
}
CMakeBuildConfiguration *CMakeBuildConfigurationFactory::clone(ProjectExplorer::Target *parent, ProjectExplorer::BuildConfiguration *source)
@@ -212,7 +200,9 @@ CMakeBuildConfiguration *CMakeBuildConfigurationFactory::clone(ProjectExplorer::
bool CMakeBuildConfigurationFactory::canRestore(const ProjectExplorer::Target *parent, const QVariantMap &map) const
{
- return canCreate(parent, ProjectExplorer::idFromMap(map));
+ if (!canHandle(parent))
+ return false;
+ return ProjectExplorer::idFromMap(map) == Constants::CMAKE_BC_ID;
}
CMakeBuildConfiguration *CMakeBuildConfigurationFactory::restore(ProjectExplorer::Target *parent, const QVariantMap &map)
@@ -228,11 +218,26 @@ CMakeBuildConfiguration *CMakeBuildConfigurationFactory::restore(ProjectExplorer
bool CMakeBuildConfigurationFactory::canHandle(const ProjectExplorer::Target *t) const
{
+ QTC_ASSERT(t, return false);
if (!t->project()->supportsKit(t->kit()))
return false;
return qobject_cast<CMakeProject *>(t->project());
}
+CMakeBuildInfo *CMakeBuildConfigurationFactory::createBuildInfo(const ProjectExplorer::Kit *k,
+ const QString &sourceDir) const
+{
+ CMakeBuildInfo *info = new CMakeBuildInfo(this);
+ info->typeName = tr("Build");
+ info->kitId = k->id();
+ info->environment = Utils::Environment::systemEnvironment();
+ k->addToEnvironment(info->environment);
+ info->useNinja = false;
+ info->sourceDirectory = sourceDir;
+
+ return info;
+}
+
ProjectExplorer::BuildConfiguration::BuildType CMakeBuildConfiguration::buildType() const
{
QString cmakeBuildType;
diff --git a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.h b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.h
index d4d7286988..2b02f3063e 100644
--- a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.h
+++ b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.h
@@ -38,6 +38,8 @@ class ToolChain;
}
namespace CMakeProjectManager {
+class CMakeBuildInfo;
+
namespace Internal {
class CMakeProject;
@@ -83,11 +85,11 @@ public:
CMakeBuildConfigurationFactory(QObject *parent = 0);
~CMakeBuildConfigurationFactory();
- 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;
- CMakeBuildConfiguration *create(ProjectExplorer::Target *parent, const Core::Id id, const QString &name = QString());
bool canClone(const ProjectExplorer::Target *parent, ProjectExplorer::BuildConfiguration *source) const;
CMakeBuildConfiguration *clone(ProjectExplorer::Target *parent, ProjectExplorer::BuildConfiguration *source);
bool canRestore(const ProjectExplorer::Target *parent, const QVariantMap &map) const;
@@ -95,6 +97,7 @@ public:
private:
bool canHandle(const ProjectExplorer::Target *t) const;
+ CMakeBuildInfo *createBuildInfo(const ProjectExplorer::Kit *k, const QString &sourceDir) const;
};
} // namespace Internal
diff --git a/src/plugins/cmakeprojectmanager/cmakebuildinfo.h b/src/plugins/cmakeprojectmanager/cmakebuildinfo.h
new file mode 100644
index 0000000000..b352f95de9
--- /dev/null
+++ b/src/plugins/cmakeprojectmanager/cmakebuildinfo.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#ifndef CMAKEBUILDINFO_H
+#define CMAKEBUILDINFO_H
+
+#include "cmakebuildconfiguration.h"
+
+#include <projectexplorer/buildinfo.h>
+#include <projectexplorer/kit.h>
+#include <projectexplorer/target.h>
+#include <utils/environment.h>
+
+namespace CMakeProjectManager {
+
+class CMakeBuildInfo : public ProjectExplorer::BuildInfo
+{
+public:
+ CMakeBuildInfo(const ProjectExplorer::IBuildConfigurationFactory *f) :
+ ProjectExplorer::BuildInfo(f) { }
+
+ CMakeBuildInfo(const Internal::CMakeBuildConfiguration *bc) :
+ ProjectExplorer::BuildInfo(ProjectExplorer::IBuildConfigurationFactory::find(bc->target()))
+ {
+ displayName = bc->displayName();
+ buildDirectory = bc->buildDirectory();
+ kitId = bc->target()->kit()->id();
+ environment = bc->environment();
+ useNinja = bc->useNinja();
+ }
+
+ Utils::Environment environment;
+ QString sourceDirectory;
+ bool useNinja;
+};
+
+} // namespace CMakeProjectManager
+
+#endif // CMAKEBUILDINFO_H
diff --git a/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.cpp b/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.cpp
index 790ba14cb4..477a180224 100644
--- a/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.cpp
@@ -30,6 +30,7 @@
#include "cmakeopenprojectwizard.h"
#include "cmakeprojectmanager.h"
#include "cmakebuildconfiguration.h"
+#include "cmakebuildinfo.h"
#include <coreplugin/icore.h>
#include <utils/hostosinfo.h>
@@ -240,13 +241,15 @@ CMakeOpenProjectWizard::CMakeOpenProjectWizard(CMakeManager *cmakeManager, const
}
CMakeOpenProjectWizard::CMakeOpenProjectWizard(CMakeManager *cmakeManager, CMakeOpenProjectWizard::Mode mode,
- const BuildInfo &info)
+ const CMakeBuildInfo *info)
: m_cmakeManager(cmakeManager),
- m_sourceDirectory(info.sourceDirectory),
- m_environment(info.environment),
- m_useNinja(info.useNinja),
- m_kit(info.kit)
+ m_sourceDirectory(info->sourceDirectory),
+ m_environment(info->environment),
+ m_useNinja(info->useNinja),
+ m_kit(0)
{
+ m_kit = ProjectExplorer::KitManager::find(info->kitId);
+
CMakeRunPage::Mode rmode;
if (mode == CMakeOpenProjectWizard::NeedToCreate)
rmode = CMakeRunPage::Recreate;
@@ -258,13 +261,13 @@ CMakeOpenProjectWizard::CMakeOpenProjectWizard(CMakeManager *cmakeManager, CMake
rmode = CMakeRunPage::ChangeDirectory;
if (mode == CMakeOpenProjectWizard::ChangeDirectory) {
- m_buildDirectory = info.buildDirectory;
+ m_buildDirectory = info->buildDirectory.toString();
addPage(new ShadowBuildPage(this, true));
}
if (!m_cmakeManager->isCMakeExecutableValid())
addPage(new ChooseCMakePage(this));
- addPage(new CMakeRunPage(this, rmode, info.buildDirectory));
+ addPage(new CMakeRunPage(this, rmode, info->buildDirectory.toString()));
init();
}
diff --git a/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.h b/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.h
index 5b1a7f6841..793d635ab2 100644
--- a/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.h
+++ b/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.h
@@ -31,6 +31,7 @@
#define CMAKEOPENPROJECTWIZARD_H
#include "cmakebuildconfiguration.h"
+#include "cmakebuildinfo.h"
#include <utils/environment.h>
#include <utils/wizard.h>
@@ -70,34 +71,13 @@ public:
ChangeDirectory
};
- class BuildInfo
- {
- public:
- BuildInfo()
- {}
-
- BuildInfo(CMakeBuildConfiguration *bc)
- : sourceDirectory(bc->target()->project()->projectDirectory())
- , buildDirectory(bc->buildDirectory().toString())
- , environment(bc->environment())
- , useNinja(bc->useNinja())
- , kit(bc->target()->kit())
- {}
-
- QString sourceDirectory;
- QString buildDirectory;
- Utils::Environment environment;
- bool useNinja;
- ProjectExplorer::Kit *kit;
- };
-
/// used at importing a project without a .user file
CMakeOpenProjectWizard(CMakeManager *cmakeManager, const QString &sourceDirectory, Utils::Environment env);
/// used to update if we have already a .user file
/// recreates or updates the cbp file
/// Also used to change the build directory of one buildconfiguration or create a new buildconfiguration
- CMakeOpenProjectWizard(CMakeManager *cmakeManager, Mode mode, const BuildInfo &info);
+ CMakeOpenProjectWizard(CMakeManager *cmakeManager, Mode mode, const CMakeBuildInfo *info);
QString buildDirectory() const;
QString sourceDirectory() const;
diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp
index ea5cf7b9ff..18fd8422e7 100644
--- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp
@@ -141,8 +141,8 @@ void CMakeProject::changeActiveBuildConfiguration(ProjectExplorer::BuildConfigur
}
if (mode != CMakeOpenProjectWizard::Nothing) {
- CMakeOpenProjectWizard copw(m_manager, mode,
- CMakeOpenProjectWizard::BuildInfo(cmakebc));
+ CMakeBuildInfo info(cmakebc);
+ CMakeOpenProjectWizard copw(m_manager, mode, &info);
if (copw.exec() == QDialog::Accepted)
cmakebc->setUseNinja(copw.useNinja()); // NeedToCreate can change the Ninja setting
}
@@ -585,8 +585,8 @@ bool CMakeProject::fromMap(const QVariantMap &map)
mode = CMakeOpenProjectWizard::NeedToUpdate;
if (mode != CMakeOpenProjectWizard::Nothing) {
- CMakeOpenProjectWizard copw(m_manager, mode,
- CMakeOpenProjectWizard::BuildInfo(activeBC));
+ CMakeBuildInfo info(activeBC);
+ CMakeOpenProjectWizard copw(m_manager, mode, &info);
if (copw.exec() != QDialog::Accepted)
return false;
else
@@ -867,8 +867,9 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc)
void CMakeBuildSettingsWidget::openChangeBuildDirectoryDialog()
{
CMakeProject *project = static_cast<CMakeProject *>(m_buildConfiguration->target()->project());
+ CMakeBuildInfo info(m_buildConfiguration);
CMakeOpenProjectWizard copw(project->projectManager(), CMakeOpenProjectWizard::ChangeDirectory,
- CMakeOpenProjectWizard::BuildInfo(m_buildConfiguration));
+ &info);
if (copw.exec() == QDialog::Accepted) {
project->changeBuildDirectory(m_buildConfiguration, copw.buildDirectory());
m_buildConfiguration->setUseNinja(copw.useNinja());
@@ -881,9 +882,9 @@ void CMakeBuildSettingsWidget::runCMake()
if (!ProjectExplorer::ProjectExplorerPlugin::instance()->saveModifiedFiles())
return;
CMakeProject *project = static_cast<CMakeProject *>(m_buildConfiguration->target()->project());
+ CMakeBuildInfo info(m_buildConfiguration);
CMakeOpenProjectWizard copw(project->projectManager(),
- CMakeOpenProjectWizard::WantToUpdate,
- CMakeOpenProjectWizard::BuildInfo(m_buildConfiguration));
+ CMakeOpenProjectWizard::WantToUpdate, &info);
if (copw.exec() == QDialog::Accepted)
project->parseCMakeLists();
}
diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp
index 910d027ab8..b480c9b5db 100644
--- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp
@@ -121,8 +121,9 @@ void CMakeManager::runCMake(ProjectExplorer::Project *project)
CMakeBuildConfiguration *bc
= static_cast<CMakeBuildConfiguration *>(cmakeProject->activeTarget()->activeBuildConfiguration());
- CMakeOpenProjectWizard copw(this, CMakeOpenProjectWizard::WantToUpdate,
- CMakeOpenProjectWizard::BuildInfo(bc));
+ CMakeBuildInfo info(bc);
+
+ CMakeOpenProjectWizard copw(this, CMakeOpenProjectWizard::WantToUpdate, &info);
if (copw.exec() == QDialog::Accepted)
cmakeProject->parseCMakeLists();
}
diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.pro b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.pro
index 49e87adffa..e0e8c8ce97 100644
--- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.pro
+++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.pro
@@ -1,6 +1,7 @@
include(../../qtcreatorplugin.pri)
-HEADERS = cmakeproject.h \
+HEADERS = cmakebuildinfo.h \
+ cmakeproject.h \
cmakeprojectplugin.h \
cmakeprojectmanager.h \
cmakeprojectconstants.h \
diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.qbs b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.qbs
index 335ff10862..1734c6cc94 100644
--- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.qbs
+++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.qbs
@@ -22,6 +22,7 @@ QtcPlugin {
"CMakeProjectManager.mimetypes.xml",
"cmakebuildconfiguration.cpp",
"cmakebuildconfiguration.h",
+ "cmakebuildinfo.h",
"cmakeeditor.cpp",
"cmakeeditor.h",
"cmakeeditorfactory.cpp",