Commit 2a93b540 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer
Browse files

Move build environment customization down to BuildConfiguration

The functionality was duplicated between the Qt4 and CMake build
configurations and their configuration widgets. This change moves it
down to BuildConfiguration, in addition also making it available for the
Generic Project.

Also provides an upgrade path for the configuration.

Task-number: QTCREATOR-24
Reviewed-by: dt
Reviewed-by: Tobias Hunger
parent 434e51c6
......@@ -44,23 +44,19 @@ using namespace Internal;
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");
} // namespace
CMakeBuildConfiguration::CMakeBuildConfiguration(CMakeTarget *parent) :
BuildConfiguration(parent, QLatin1String(CMAKE_BC_ID)),
m_toolChain(0),
m_clearSystemEnvironment(false)
m_toolChain(0)
{
}
CMakeBuildConfiguration::CMakeBuildConfiguration(CMakeTarget *parent, CMakeBuildConfiguration *source) :
BuildConfiguration(parent, source),
m_toolChain(0),
m_clearSystemEnvironment(source->m_clearSystemEnvironment),
m_userEnvironmentChanges(source->m_userEnvironmentChanges),
m_buildDirectory(source->m_buildDirectory),
m_msvcVersion(source->m_msvcVersion)
{
......@@ -70,8 +66,6 @@ CMakeBuildConfiguration::CMakeBuildConfiguration(CMakeTarget *parent, CMakeBuild
QVariantMap CMakeBuildConfiguration::toMap() const
{
QVariantMap map(ProjectExplorer::BuildConfiguration::toMap());
map.insert(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY),
ProjectExplorer::EnvironmentItem::toStringList(m_userEnvironmentChanges));
map.insert(QLatin1String(MSVC_VERSION_KEY), m_msvcVersion);
map.insert(QLatin1String(BUILD_DIRECTORY_KEY), m_buildDirectory);
return map;
......@@ -79,7 +73,6 @@ QVariantMap CMakeBuildConfiguration::toMap() const
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();
......@@ -96,55 +89,6 @@ CMakeTarget *CMakeBuildConfiguration::cmakeTarget() const
return static_cast<CMakeTarget *>(target());
}
ProjectExplorer::Environment CMakeBuildConfiguration::baseEnvironment() const
{
ProjectExplorer::Environment env = useSystemEnvironment() ?
ProjectExplorer::Environment(QProcess::systemEnvironment()) :
ProjectExplorer::Environment();
return env;
}
QString CMakeBuildConfiguration::baseEnvironmentText() const
{
if (useSystemEnvironment())
return tr("System Environment");
else
return tr("Clear Environment");
}
ProjectExplorer::Environment CMakeBuildConfiguration::environment() const
{
ProjectExplorer::Environment env = baseEnvironment();
env.modify(userEnvironmentChanges());
return env;
}
void CMakeBuildConfiguration::setUseSystemEnvironment(bool b)
{
if (b == m_clearSystemEnvironment)
return;
m_clearSystemEnvironment = !b;
emit environmentChanged();
}
bool CMakeBuildConfiguration::useSystemEnvironment() const
{
return !m_clearSystemEnvironment;
}
QList<ProjectExplorer::EnvironmentItem> CMakeBuildConfiguration::userEnvironmentChanges() const
{
return m_userEnvironmentChanges;
}
void CMakeBuildConfiguration::setUserEnvironmentChanges(const QList<ProjectExplorer::EnvironmentItem> &diff)
{
if (m_userEnvironmentChanges == diff)
return;
m_userEnvironmentChanges = diff;
emit environmentChanged();
}
QString CMakeBuildConfiguration::buildDirectory() const
{
QString buildDirectory = m_buildDirectory;
......
......@@ -50,14 +50,6 @@ public:
CMakeTarget *cmakeTarget() const;
ProjectExplorer::Environment environment() const;
ProjectExplorer::Environment baseEnvironment() const;
QString baseEnvironmentText() const;
void setUserEnvironmentChanges(const QList<ProjectExplorer::EnvironmentItem> &diff);
QList<ProjectExplorer::EnvironmentItem> userEnvironmentChanges() const;
bool useSystemEnvironment() const;
void setUseSystemEnvironment(bool b);
virtual QString buildDirectory() const;
ProjectExplorer::ToolChain::ToolChainType toolChainType() const;
......@@ -80,8 +72,6 @@ protected:
private:
void updateToolChain() const;
mutable ProjectExplorer::ToolChain *m_toolChain;
bool m_clearSystemEnvironment;
QList<ProjectExplorer::EnvironmentItem> m_userEnvironmentChanges;
QString m_buildDirectory;
QString m_msvcVersion;
};
......
......@@ -34,10 +34,10 @@
#include "cmaketarget.h"
#include "makestep.h"
#include "cmakeopenprojectwizard.h"
#include "cmakebuildenvironmentwidget.h"
#include "cmakebuildconfiguration.h"
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/buildenvironmentwidget.h>
#include <cpptools/cppmodelmanagerinterface.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/qtcassert.h>
......@@ -449,7 +449,7 @@ ProjectExplorer::BuildConfigWidget *CMakeProject::createConfigWidget()
QList<ProjectExplorer::BuildConfigWidget*> CMakeProject::subConfigWidgets()
{
QList<ProjectExplorer::BuildConfigWidget*> list;
list << new CMakeBuildEnvironmentWidget(this);
list << new BuildEnvironmentWidget;
return list;
}
......
......@@ -11,7 +11,6 @@ HEADERS = cmakeproject.h \
makestep.h \
cmakerunconfiguration.h \
cmakeopenprojectwizard.h \
cmakebuildenvironmentwidget.h \
cmakebuildconfiguration.h
SOURCES = cmakeproject.cpp \
cmakeprojectplugin.cpp \
......@@ -21,7 +20,6 @@ SOURCES = cmakeproject.cpp \
makestep.cpp \
cmakerunconfiguration.cpp \
cmakeopenprojectwizard.cpp \
cmakebuildenvironmentwidget.cpp \
cmakebuildconfiguration.cpp
RESOURCES += cmakeproject.qrc
FORMS +=
......
......@@ -33,6 +33,7 @@
#include "genericprojectconstants.h"
#include "generictarget.h"
#include <projectexplorer/buildenvironmentwidget.h>
#include <projectexplorer/toolchain.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <cpptools/cppmodelmanagerinterface.h>
......@@ -399,7 +400,9 @@ ProjectExplorer::BuildConfigWidget *GenericProject::createConfigWidget()
QList<ProjectExplorer::BuildConfigWidget*> GenericProject::subConfigWidgets()
{
return QList<ProjectExplorer::BuildConfigWidget*>();
QList<ProjectExplorer::BuildConfigWidget*> list;
list << new BuildEnvironmentWidget;
return list;
}
GenericProjectNode *GenericProject::rootProjectNode() const
......
......@@ -33,6 +33,8 @@
#include <coreplugin/icore.h>
#include <extensionsystem/pluginmanager.h>
#include <QtCore/QProcess>
using namespace ProjectExplorer;
namespace {
......@@ -59,19 +61,24 @@ const char * const BUILD_STEPS_COUNT_KEY("ProjectExplorer.BuildConfiguration.Bui
const char * const BUILD_STEPS_PREFIX("ProjectExplorer.BuildConfiguration.BuildStep.");
const char * const CLEAN_STEPS_COUNT_KEY("ProjectExplorer.BuildConfiguration.CleanStepsCount");
const char * const CLEAN_STEPS_PREFIX("ProjectExplorer.BuildConfiguration.CleanStep.");
const char * const CLEAR_SYSTEM_ENVIRONMENT_KEY("ProjectExplorer.BuildConfiguration.ClearSystemEnvironment");
const char * const USER_ENVIRONMENT_CHANGES_KEY("ProjectExplorer.BuildConfiguration.UserEnvironmentChanges");
} // namespace
BuildConfiguration::BuildConfiguration(Target *target, const QString &id) :
ProjectConfiguration(id),
m_target(target)
m_target(target),
m_clearSystemEnvironment(false)
{
Q_ASSERT(m_target);
}
BuildConfiguration::BuildConfiguration(Target *target, BuildConfiguration *source) :
ProjectConfiguration(source),
m_target(target)
m_target(target),
m_clearSystemEnvironment(source->m_clearSystemEnvironment),
m_userEnvironmentChanges(source->m_userEnvironmentChanges)
{
Q_ASSERT(m_target);
}
......@@ -91,6 +98,8 @@ QVariantMap BuildConfiguration::toMap() const
map.insert(QLatin1String(CLEAN_STEPS_COUNT_KEY), m_cleanSteps.count());
for (int i = 0; i < m_cleanSteps.count(); ++i)
map.insert(QString::fromLatin1(CLEAN_STEPS_PREFIX) + QString::number(i), m_cleanSteps.at(i)->toMap());
map.insert(QLatin1String(CLEAR_SYSTEM_ENVIRONMENT_KEY), m_clearSystemEnvironment);
map.insert(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY), EnvironmentItem::toStringList(m_userEnvironmentChanges));
return map;
}
......@@ -165,6 +174,9 @@ bool BuildConfiguration::fromMap(const QVariantMap &map)
insertCleanStep(m_cleanSteps.count(), bs);
}
m_clearSystemEnvironment = map.value(QLatin1String(CLEAR_SYSTEM_ENVIRONMENT_KEY)).toBool();
m_userEnvironmentChanges = EnvironmentItem::fromStringList(map.value(QLatin1String(USER_ENVIRONMENT_CHANGES_KEY)).toStringList());
return true;
}
......@@ -220,6 +232,54 @@ Target *BuildConfiguration::target() const
return m_target;
}
Environment BuildConfiguration::baseEnvironment() const
{
if (useSystemEnvironment())
return Environment(QProcess::systemEnvironment());
return Environment();
}
QString BuildConfiguration::baseEnvironmentText() const
{
if (useSystemEnvironment())
return tr("System Environment");
else
return tr("Clean Environment");
}
Environment BuildConfiguration::environment() const
{
Environment env = baseEnvironment();
env.modify(userEnvironmentChanges());
return env;
}
void BuildConfiguration::setUseSystemEnvironment(bool b)
{
if (useSystemEnvironment() == b)
return;
m_clearSystemEnvironment = !b;
emit environmentChanged();
}
bool BuildConfiguration::useSystemEnvironment() const
{
return !m_clearSystemEnvironment;
}
QList<EnvironmentItem> BuildConfiguration::userEnvironmentChanges() const
{
return m_userEnvironmentChanges;
}
void BuildConfiguration::setUserEnvironmentChanges(const QList<ProjectExplorer::EnvironmentItem> &diff)
{
if (m_userEnvironmentChanges == diff)
return;
m_userEnvironmentChanges = diff;
emit environmentChanged();
}
///
// IBuildConfigurationFactory
///
......
......@@ -63,11 +63,19 @@ public:
void removeCleanStep(int position);
void moveCleanStepUp(int position);
virtual Environment environment() const = 0;
virtual QString buildDirectory() const = 0;
Target *target() const;
// TODO: Maybe the BuildConfiguration is not the best place for the environment
virtual Environment baseEnvironment() const;
QString baseEnvironmentText() const;
Environment environment() const;
void setUserEnvironmentChanges(const QList<EnvironmentItem> &diff);
QList<EnvironmentItem> userEnvironmentChanges() const;
bool useSystemEnvironment() const;
void setUseSystemEnvironment(bool b);
virtual QVariantMap toMap() const;
signals:
......@@ -85,6 +93,9 @@ private:
QList<BuildStep *> m_buildSteps;
QList<BuildStep *> m_cleanSteps;
Target *m_target;
bool m_clearSystemEnvironment;
QList<EnvironmentItem> m_userEnvironmentChanges;
};
class PROJECTEXPLORER_EXPORT IBuildConfigurationFactory :
......
......@@ -27,29 +27,27 @@
**
**************************************************************************/
#include "cmakebuildenvironmentwidget.h"
#include "cmakeproject.h"
#include "cmakebuildconfiguration.h"
#include <projectexplorer/environmenteditmodel.h>
#include "buildenvironmentwidget.h"
#include "buildconfiguration.h"
#include "environmenteditmodel.h"
#include <utils/qtcassert.h>
#include <QtGui/QVBoxLayout>
#include <QtGui/QCheckBox>
namespace {
bool debug = false;
}
using namespace CMakeProjectManager;
using namespace CMakeProjectManager::Internal;
using namespace ProjectExplorer;
CMakeBuildEnvironmentWidget::CMakeBuildEnvironmentWidget(CMakeProject *project)
: BuildConfigWidget(), m_pro(project), m_buildConfiguration(0)
BuildEnvironmentWidget::BuildEnvironmentWidget()
: m_buildConfiguration(0)
{
QVBoxLayout *vbox = new QVBoxLayout(this);
vbox->setMargin(0);
m_clearSystemEnvironmentCheckBox = new QCheckBox(this);
m_clearSystemEnvironmentCheckBox->setText(tr("Clear system environment"));
m_buildEnvironmentWidget = new ProjectExplorer::EnvironmentWidget(this, m_clearSystemEnvironmentCheckBox);
m_buildEnvironmentWidget = new EnvironmentWidget(this, m_clearSystemEnvironmentCheckBox);
vbox->addWidget(m_buildEnvironmentWidget);
connect(m_buildEnvironmentWidget, SIGNAL(userChangesChanged()),
......@@ -58,26 +56,31 @@ CMakeBuildEnvironmentWidget::CMakeBuildEnvironmentWidget(CMakeProject *project)
this, SLOT(clearSystemEnvironmentCheckBoxClicked(bool)));
}
QString CMakeBuildEnvironmentWidget::displayName() const
QString BuildEnvironmentWidget::displayName() const
{
return tr("Build Environment");
}
void CMakeBuildEnvironmentWidget::init(ProjectExplorer::BuildConfiguration *bc)
void BuildEnvironmentWidget::init(BuildConfiguration *bc)
{
if (debug)
qDebug() << "Qt4BuildConfigWidget::init()";
QTC_ASSERT(bc, return);
if (m_buildConfiguration) {
disconnect(m_buildConfiguration, SIGNAL(environmentChanged()),
this, SLOT(environmentChanged()));
}
m_buildConfiguration = static_cast<CMakeBuildConfiguration *>(bc);
m_buildConfiguration = static_cast<BuildConfiguration *>(bc);
if (!m_buildConfiguration) {
setEnabled(false);
return;
}
setEnabled(true);
connect(m_buildConfiguration, SIGNAL(environmentChanged()),
this, SLOT(environmentChanged()));
m_clearSystemEnvironmentCheckBox->setChecked(!m_buildConfiguration->useSystemEnvironment());
m_buildEnvironmentWidget->setBaseEnvironment(m_buildConfiguration->baseEnvironment());
m_buildEnvironmentWidget->setBaseEnvironmentText(m_buildConfiguration->baseEnvironmentText());
......@@ -85,19 +88,19 @@ void CMakeBuildEnvironmentWidget::init(ProjectExplorer::BuildConfiguration *bc)
m_buildEnvironmentWidget->updateButtons();
}
void CMakeBuildEnvironmentWidget::environmentModelUserChangesChanged()
void BuildEnvironmentWidget::environmentModelUserChangesChanged()
{
m_buildConfiguration->setUserEnvironmentChanges(m_buildEnvironmentWidget->userChanges());
}
void CMakeBuildEnvironmentWidget::clearSystemEnvironmentCheckBoxClicked(bool checked)
void BuildEnvironmentWidget::clearSystemEnvironmentCheckBoxClicked(bool checked)
{
m_buildConfiguration->setUseSystemEnvironment(!checked);
m_buildEnvironmentWidget->setBaseEnvironment(m_buildConfiguration->baseEnvironment());
m_buildEnvironmentWidget->setBaseEnvironmentText(m_buildConfiguration->baseEnvironmentText());
}
void CMakeBuildEnvironmentWidget::environmentChanged()
void BuildEnvironmentWidget::environmentChanged()
{
m_buildEnvironmentWidget->setBaseEnvironment(m_buildConfiguration->baseEnvironment());
m_buildEnvironmentWidget->setBaseEnvironmentText(m_buildConfiguration->baseEnvironmentText());
......
......@@ -27,32 +27,29 @@
**
**************************************************************************/
#ifndef QT4BUILDENVIRONMENTWIDGET_H
#define QT4BUILDENVIRONMENTWIDGET_H
#ifndef BUILDENVIRONMENTWIDGET_H
#define BUILDENVIRONMENTWIDGET_H
#include <projectexplorer/buildstep.h>
QT_BEGIN_NAMESPACE
class QCheckBox;
QT_END_NAMESPACE
namespace ProjectExplorer {
class EnvironmentWidget;
}
namespace CMakeProjectManager {
namespace Internal {
class CMakeProject;
class CMakeBuildConfiguration;
class EnvironmentWidget;
class BuildConfiguration;
class CMakeBuildEnvironmentWidget : public ProjectExplorer::BuildConfigWidget
class PROJECTEXPLORER_EXPORT BuildEnvironmentWidget : public BuildConfigWidget
{
Q_OBJECT
public:
CMakeBuildEnvironmentWidget(CMakeProject *project);
BuildEnvironmentWidget();
QString displayName() const;
void init(ProjectExplorer::BuildConfiguration *bc);
void init(BuildConfiguration *bc);
private slots:
void environmentModelUserChangesChanged();
......@@ -60,13 +57,11 @@ private slots:
void environmentChanged();
private:
ProjectExplorer::EnvironmentWidget *m_buildEnvironmentWidget;
EnvironmentWidget *m_buildEnvironmentWidget;
QCheckBox *m_clearSystemEnvironmentCheckBox;
CMakeProject *m_pro;
CMakeBuildConfiguration *m_buildConfiguration;
BuildConfiguration *m_buildConfiguration;
};
} // namespace Internal
} // namespace Qt4ProjectManager
#endif // QT4BUILDENVIRONMENTWIDGET_H
#endif // BUILDENVIRONMENTWIDGET_H
......@@ -75,7 +75,8 @@ HEADERS += projectexplorer.h \
targetselector.h \
targetsettingswidget.h \
doubletabwidget.h \
addtargetdialog.h
addtargetdialog.h \
buildenvironmentwidget.h
SOURCES += projectexplorer.cpp \
projectwindow.cpp \
buildmanager.cpp \
......@@ -137,7 +138,8 @@ SOURCES += projectexplorer.cpp \
targetselector.cpp \
targetsettingswidget.cpp \
doubletabwidget.cpp \
addtargetdialog.cpp
addtargetdialog.cpp \
buildenvironmentwidget.cpp
FORMS += processstep.ui \
editorsettingspropertiespage.ui \
runsettingspropertiespage.ui \
......
......@@ -49,13 +49,10 @@ const char * const WAS_UPDATED("ProjectExplorer.Project.Updater.DidUpdate");
const char * const PROJECT_FILE_POSTFIX(".user");
// Version 0 is used in Qt Creator 1.3.x and
// (in a slighly differnt flavour) post 1.3 master.
// (in a slighly different flavour) post 1.3 master.
class Version0Handler : public UserFileVersionHandler
{
public:
Version0Handler();
~Version0Handler();
int userFileVersion() const
{
return 0;
......@@ -80,9 +77,6 @@ private:
class Version1Handler : public UserFileVersionHandler
{
public:
Version1Handler();
~Version1Handler();
int userFileVersion() const
{
return 1;
......@@ -115,11 +109,29 @@ private:
};
};
// Version 2 is used in master post Qt Creator 2.0 alpha.
class Version2Handler : public UserFileVersionHandler
{
public:
int userFileVersion() const
{
return 2;
}
QString displayUserFileVersion() const
{
return QLatin1String("2.0-alpha+git");
}
QVariantMap update(Project *project, const QVariantMap &map);
};
//
// Helper functions:
//
QString fileNameFor(const QString &name) {
static QString fileNameFor(const QString &name)
{
QString baseName(name);
QString environmentExtension(QString::fromLocal8Bit(qgetenv("QTC_EXTENSION")));
if (!environmentExtension.isEmpty()) {
......@@ -147,6 +159,31 @@ UserFileVersionHandler::~UserFileVersionHandler()
{
}
/**
* Performs a simple renaming of the listed keys in \a changes recursively on \a map.
*/
QVariantMap UserFileVersionHandler::renameKeys(const QList<Change> &changes, QVariantMap map)
{
foreach (const Change &change, changes) {
QVariantMap::iterator oldSetting = map.find(change.first);
if (oldSetting != map.end()) {
map.insert(change.second, oldSetting.value());
map.erase(oldSetting);
}
}
QVariantMap::iterator i = map.begin();
while (i != map.end()) {
QVariant v = i.value();
if (v.type() == QVariant::Map)
i.value() = renameKeys(changes, v.toMap());
++i;
}
return map;
}
// -------------------------------------------------------------------------
// UserFileAccessor
// -------------------------------------------------------------------------
......@@ -157,6 +194,7 @@ UserFileAccessor::UserFileAccessor() :
{
addVersionHandler(new Version0Handler);
addVersionHandler(new Version1Handler);
addVersionHandler(new Version2Handler);
}
UserFileAccessor::~UserFileAccessor()
......@@ -250,14 +288,6 @@ void UserFileAccessor::addVersionHandler(UserFileVersionHandler *handler)
// Version0Handler
// -------------------------------------------------------------------------
Version0Handler::Version0Handler()
{
}
Version0Handler::~Version0Handler()