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:
@@ -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);
|
||||
|
||||
CMakeBuildInfo *info = createBuildInfo(parent->kit(), parent->project()->projectDirectory());
|
||||
result << info;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool CMakeBuildConfigurationFactory::canCreate(const ProjectExplorer::Target *parent, const Core::Id id) const
|
||||
ProjectExplorer::BuildConfiguration *CMakeBuildConfigurationFactory::create(ProjectExplorer::Target *parent,
|
||||
const ProjectExplorer::BuildInfo *info) const
|
||||
{
|
||||
if (!canHandle(parent))
|
||||
return false;
|
||||
if (id == Constants::CMAKE_BC_ID)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
CMakeBuildConfiguration *CMakeBuildConfigurationFactory::create(ProjectExplorer::Target *parent, const Core::Id id, const QString &name)
|
||||
{
|
||||
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, ©);
|
||||
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;
|
||||
|
||||
@@ -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
|
||||
|
||||
65
src/plugins/cmakeprojectmanager/cmakebuildinfo.h
Normal file
65
src/plugins/cmakeprojectmanager/cmakebuildinfo.h
Normal file
@@ -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
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
include(../../qtcreatorplugin.pri)
|
||||
|
||||
HEADERS = cmakeproject.h \
|
||||
HEADERS = cmakebuildinfo.h \
|
||||
cmakeproject.h \
|
||||
cmakeprojectplugin.h \
|
||||
cmakeprojectmanager.h \
|
||||
cmakeprojectconstants.h \
|
||||
|
||||
@@ -22,6 +22,7 @@ QtcPlugin {
|
||||
"CMakeProjectManager.mimetypes.xml",
|
||||
"cmakebuildconfiguration.cpp",
|
||||
"cmakebuildconfiguration.h",
|
||||
"cmakebuildinfo.h",
|
||||
"cmakeeditor.cpp",
|
||||
"cmakeeditor.h",
|
||||
"cmakeeditorfactory.cpp",
|
||||
|
||||
Reference in New Issue
Block a user