Commit 0d162be2 authored by dt's avatar dt

Make BuildSteps one instance per BuildConfiguration

Enables users to change which buildsteps get run per buildconfiguration.
Some further tweaks are probably necessary. This is a rather big
change, though it should work. :)
parent ab038986
......@@ -105,6 +105,13 @@ bool CMakeBuildConfigurationFactory::create(const QString &type) const
return false;
BuildConfiguration *bc = new BuildConfiguration(buildConfigurationName);
MakeStep *makeStep = new MakeStep(m_project, bc);
bc->insertBuildStep(0, makeStep);
MakeStep *cleanMakeStep = new MakeStep(m_project, bc);
bc->insertCleanStep(0, cleanMakeStep);
cleanMakeStep->setClean(true);
CMakeOpenProjectWizard copw(m_project->projectManager(),
m_project->sourceDirectory(),
m_project->buildDirectory(bc),
......@@ -114,12 +121,14 @@ bool CMakeBuildConfigurationFactory::create(const QString &type) const
return false;
}
m_project->addBuildConfiguration(bc); // this also makes the name unique
// Default to all
if (m_project->targets().contains("all"))
m_project->makeStep()->setBuildTarget(buildConfigurationName, "all", true);
bc->setValue("buildDirectory", copw.buildDirectory());
bc->setValue("msvcVersion", copw.msvcVersion());
m_project->parseCMakeLists();
// Default to all
if (m_project->targets().contains("all"))
makeStep->setBuildTarget("all", true);
return true;
}
......@@ -627,17 +636,6 @@ void CMakeProject::saveSettingsImpl(ProjectExplorer::PersistentSettingsWriter &w
Project::saveSettingsImpl(writer);
}
MakeStep *CMakeProject::makeStep() const
{
foreach (ProjectExplorer::BuildStep *bs, buildSteps()) {
MakeStep *ms = qobject_cast<MakeStep *>(bs);
if (ms)
return ms;
}
return 0;
}
bool CMakeProject::restoreSettingsImpl(ProjectExplorer::PersistentSettingsReader &reader)
{
Project::restoreSettingsImpl(reader);
......@@ -651,22 +649,19 @@ bool CMakeProject::restoreSettingsImpl(ProjectExplorer::PersistentSettingsReader
if (copw.exec() != QDialog::Accepted)
return false;
qDebug()<<"ccd.buildDirectory()"<<copw.buildDirectory();
// Now create a standard build configuration
makeStep = new MakeStep(this);
insertBuildStep(0, makeStep);
ProjectExplorer::BuildConfiguration *bc = new ProjectExplorer::BuildConfiguration("all");
addBuildConfiguration(bc);
bc->setValue("msvcVersion", copw.msvcVersion());
if (!copw.buildDirectory().isEmpty())
bc->setValue("buildDirectory", copw.buildDirectory());
//TODO save arguments somewhere copw.arguments()
MakeStep *cleanMakeStep = new MakeStep(this);
insertCleanStep(0, cleanMakeStep);
// Now create a standard build configuration
makeStep = new MakeStep(this, bc);
bc->insertBuildStep(0, makeStep);
//TODO save arguments somewhere copw.arguments()
MakeStep *cleanMakeStep = new MakeStep(this, bc);
bc->insertCleanStep(0, cleanMakeStep);
cleanMakeStep->setClean(true);
setActiveBuildConfiguration(bc);
} else {
......@@ -697,15 +692,15 @@ bool CMakeProject::restoreSettingsImpl(ProjectExplorer::PersistentSettingsReader
}
}
if (!hasUserFile && targets().contains("all"))
makeStep->setBuildTarget("all", "all", true);
m_watcher = new ProjectExplorer::FileWatcher(this);
connect(m_watcher, SIGNAL(fileChanged(QString)), this, SLOT(fileChanged(QString)));
bool result = parseCMakeLists(); // Gets the directory from the active buildconfiguration
if (!result)
return false;
if (!hasUserFile && targets().contains("all"))
makeStep->setBuildTarget("all", true);
connect(this, SIGNAL(activeBuildConfigurationChanged()),
this, SLOT(slotActiveBuildConfiguration()));
return true;
......
......@@ -113,7 +113,6 @@ public:
virtual ProjectExplorer::ProjectNode *rootProjectNode() const;
virtual QStringList files(FilesMode fileMode) const;
MakeStep *makeStep() const;
QStringList targets() const;
QString buildParser(ProjectExplorer::BuildConfiguration *configuration) const;
CMakeTarget targetForTitle(const QString &title);
......
......@@ -40,13 +40,25 @@
using namespace CMakeProjectManager;
using namespace CMakeProjectManager::Internal;
using namespace ProjectExplorer;
MakeStep::MakeStep(CMakeProject *pro)
: AbstractMakeStep(pro), m_pro(pro), m_clean(false)
MakeStep::MakeStep(CMakeProject *pro, BuildConfiguration *bc)
: AbstractMakeStep(pro, bc), m_pro(pro), m_clean(false), m_futureInterface(0)
{
m_percentProgress = QRegExp("^\\[\\s*(\\d*)%\\]");
}
MakeStep::MakeStep(MakeStep *bs, BuildConfiguration *bc)
: AbstractMakeStep(bs, bc),
m_pro(bs->m_pro),
m_clean(bs->m_clean),
m_futureInterface(0),
m_buildTargets(bs->m_buildTargets),
m_additionalArguments(bs->m_buildTargets)
{
}
MakeStep::~MakeStep()
{
......@@ -57,53 +69,34 @@ void MakeStep::setClean(bool clean)
m_clean = clean;
}
void MakeStep::restoreFromMap(const QMap<QString, QVariant> &map)
void MakeStep::restoreFromGlobalMap(const QMap<QString, QVariant> &map)
{
if (map.value("clean").isValid() && map.value("clean").toBool())
m_clean = true;
ProjectExplorer::AbstractMakeStep::restoreFromMap(map);
}
void MakeStep::storeIntoMap(QMap<QString, QVariant> &map)
{
if (m_clean)
map["clean"] = true;
ProjectExplorer::AbstractMakeStep::storeIntoMap(map);
}
void MakeStep::restoreFromMap(const QString &buildConfiguration, const QMap<QString, QVariant> &map)
{
m_values[buildConfiguration].buildTargets = map["buildTargets"].toStringList();
m_values[buildConfiguration].additionalArguments = map["additionalArguments"].toStringList();
ProjectExplorer::AbstractMakeStep::restoreFromMap(buildConfiguration, map);
}
void MakeStep::storeIntoMap(const QString &buildConfiguration, QMap<QString, QVariant> &map)
{
map["buildTargets"] = m_values.value(buildConfiguration).buildTargets;
map["additionalArguments"] = m_values.value(buildConfiguration).additionalArguments;
ProjectExplorer::AbstractMakeStep::storeIntoMap(buildConfiguration, map);
AbstractMakeStep::restoreFromGlobalMap(map);
}
void MakeStep::addBuildConfiguration(const QString & name)
void MakeStep::restoreFromLocalMap(const QMap<QString, QVariant> &map)
{
m_values.insert(name, MakeStepSettings());
}
void MakeStep::removeBuildConfiguration(const QString & name)
{
m_values.remove(name);
m_buildTargets = map["buildTargets"].toStringList();
m_additionalArguments = map["additionalArguments"].toStringList();
if (map.value("clean").isValid() && map.value("clean").toBool())
m_clean = true;
AbstractMakeStep::restoreFromLocalMap(map);
}
void MakeStep::copyBuildConfiguration(const QString &source, const QString &dest)
void MakeStep::storeIntoLocalMap(QMap<QString, QVariant> &map)
{
m_values.insert(dest, m_values.value(source));
map["buildTargets"] = m_buildTargets;
map["additionalArguments"] = m_additionalArguments;
if (m_clean)
map["clean"] = true;
AbstractMakeStep::storeIntoLocalMap(map);
}
bool MakeStep::init(const QString &buildConfiguration)
bool MakeStep::init()
{
ProjectExplorer::BuildConfiguration *bc = m_pro->buildConfiguration(buildConfiguration);
BuildConfiguration *bc = buildConfiguration();
setBuildParser(m_pro->buildParser(bc));
setEnabled(true);
......@@ -111,13 +104,13 @@ bool MakeStep::init(const QString &buildConfiguration)
setCommand(m_pro->toolChain(bc)->makeCommand());
QStringList arguments = m_values.value(buildConfiguration).buildTargets;
arguments << additionalArguments(buildConfiguration);
setArguments(arguments); // TODO
QStringList arguments = m_buildTargets;
arguments << additionalArguments();
setArguments(arguments);
setEnvironment(m_pro->environment(bc));
setIgnoreReturnValue(m_clean);
return AbstractMakeStep::init(buildConfiguration);
return AbstractMakeStep::init();
}
void MakeStep::run(QFutureInterface<bool> &fi)
......@@ -140,7 +133,7 @@ QString MakeStep::displayName()
return "Make";
}
ProjectExplorer::BuildStepConfigWidget *MakeStep::createConfigWidget()
BuildStepConfigWidget *MakeStep::createConfigWidget()
{
return new MakeStepConfigWidget(this);
}
......@@ -166,29 +159,29 @@ CMakeProject *MakeStep::project() const
return m_pro;
}
bool MakeStep::buildsTarget(const QString &buildConfiguration, const QString &target) const
bool MakeStep::buildsTarget(const QString &target) const
{
return m_values.value(buildConfiguration).buildTargets.contains(target);
return m_buildTargets.contains(target);
}
void MakeStep::setBuildTarget(const QString &buildConfiguration, const QString &target, bool on)
void MakeStep::setBuildTarget(const QString &target, bool on)
{
QStringList old = m_values.value(buildConfiguration).buildTargets;
QStringList old = m_buildTargets;
if (on && !old.contains(target))
old << target;
else if(!on && old.contains(target))
old.removeOne(target);
m_values[buildConfiguration].buildTargets = old;
m_buildTargets = old;
}
QStringList MakeStep::additionalArguments(const QString &buildConfiguration) const
QStringList MakeStep::additionalArguments() const
{
return m_values.value(buildConfiguration).additionalArguments;
return m_additionalArguments;
}
void MakeStep::setAdditionalArguments(const QString &buildConfiguration, const QStringList &list)
void MakeStep::setAdditionalArguments(const QStringList &list)
{
m_values[buildConfiguration].additionalArguments = list;
m_additionalArguments = list;
}
//
......@@ -227,13 +220,13 @@ MakeStepConfigWidget::MakeStepConfigWidget(MakeStep *makeStep)
void MakeStepConfigWidget::additionalArgumentsEdited()
{
m_makeStep->setAdditionalArguments(m_buildConfiguration, ProjectExplorer::Environment::parseCombinedArgString(m_additionalArguments->text()));
m_makeStep->setAdditionalArguments(Environment::parseCombinedArgString(m_additionalArguments->text()));
updateDetails();
}
void MakeStepConfigWidget::itemChanged(QListWidgetItem *item)
{
m_makeStep->setBuildTarget(m_buildConfiguration, item->text(), item->checkState() & Qt::Checked);
m_makeStep->setBuildTarget(item->text(), item->checkState() & Qt::Checked);
updateDetails();
}
......@@ -242,30 +235,29 @@ QString MakeStepConfigWidget::displayName() const
return "Make";
}
void MakeStepConfigWidget::init(const QString &buildConfiguration)
void MakeStepConfigWidget::init()
{
// disconnect to make the changes to the items
disconnect(m_targetsList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*)));
m_buildConfiguration = buildConfiguration;
int count = m_targetsList->count();
for(int i = 0; i < count; ++i) {
QListWidgetItem *item = m_targetsList->item(i);
item->setCheckState(m_makeStep->buildsTarget(buildConfiguration, item->text()) ? Qt::Checked : Qt::Unchecked);
item->setCheckState(m_makeStep->buildsTarget(item->text()) ? Qt::Checked : Qt::Unchecked);
}
// and connect again
connect(m_targetsList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*)));
m_additionalArguments->setText(ProjectExplorer::Environment::joinArgumentList(m_makeStep->additionalArguments(m_buildConfiguration)));
m_additionalArguments->setText(Environment::joinArgumentList(m_makeStep->additionalArguments()));
updateDetails();
}
void MakeStepConfigWidget::updateDetails()
{
QStringList arguments = m_makeStep->m_values.value(m_buildConfiguration).buildTargets;
arguments << m_makeStep->additionalArguments(m_buildConfiguration);
QStringList arguments = m_makeStep->m_buildTargets;
arguments << m_makeStep->additionalArguments();
m_summaryText = tr("<b>Make:</b> %1 %2")
.arg(m_makeStep->project()->toolChain(
m_makeStep->project()->buildConfiguration(m_buildConfiguration))
m_makeStep->buildConfiguration())
->makeCommand(),
arguments.join(" "));
emit updateSummary();
......@@ -285,15 +277,20 @@ bool MakeStepFactory::canCreate(const QString &name) const
return (Constants::MAKESTEP == name);
}
ProjectExplorer::BuildStep *MakeStepFactory::create(ProjectExplorer::Project *project, const QString &name) const
BuildStep *MakeStepFactory::create(Project *project, BuildConfiguration *bc, const QString &name) const
{
Q_ASSERT(name == Constants::MAKESTEP);
CMakeProject *pro = qobject_cast<CMakeProject *>(project);
Q_ASSERT(pro);
return new MakeStep(pro);
return new MakeStep(pro, bc);
}
BuildStep *MakeStepFactory::clone(BuildStep *bs, BuildConfiguration *bc) const
{
return new MakeStep(static_cast<MakeStep *>(bs), bc);
}
QStringList MakeStepFactory::canCreateForProject(ProjectExplorer::Project * /* pro */) const
QStringList MakeStepFactory::canCreateForProject(Project * /* pro */) const
{
return QStringList();
}
......
......@@ -43,21 +43,16 @@ namespace Internal {
class CMakeProject;
struct MakeStepSettings
{
QStringList buildTargets;
QStringList additionalArguments;
};
class MakeStep : public ProjectExplorer::AbstractMakeStep
{
Q_OBJECT
friend class MakeStepConfigWidget; // TODO remove
// This is for modifying m_values
// This is for modifying internal data
public:
MakeStep(CMakeProject *pro);
MakeStep(CMakeProject *pro, ProjectExplorer::BuildConfiguration *bc);
MakeStep(MakeStep *bs, ProjectExplorer::BuildConfiguration *bc);
~MakeStep();
virtual bool init(const QString &buildConfiguration);
virtual bool init();
virtual void run(QFutureInterface<bool> &fi);
......@@ -66,22 +61,18 @@ public:
virtual ProjectExplorer::BuildStepConfigWidget *createConfigWidget();
virtual bool immutable() const;
CMakeProject *project() const;
bool buildsTarget(const QString &buildConfiguration, const QString &target) const;
void setBuildTarget(const QString &buildConfiguration, const QString &target, bool on);
QStringList additionalArguments(const QString &buildConfiguration) const;
void setAdditionalArguments(const QString &buildConfiguration, const QStringList &list);
bool buildsTarget(const QString &target) const;
void setBuildTarget(const QString &target, bool on);
QStringList additionalArguments() const;
void setAdditionalArguments(const QStringList &list);
virtual void restoreFromMap(const QMap<QString, QVariant> &map);
virtual void storeIntoMap(QMap<QString, QVariant> &map);
virtual void restoreFromGlobalMap(const QMap<QString, QVariant> &map);
void setClean(bool clean);
virtual void restoreFromLocalMap(const QMap<QString, QVariant> &map);
virtual void storeIntoLocalMap(QMap<QString, QVariant> &map);
virtual void restoreFromMap(const QString &buildConfiguration, const QMap<QString, QVariant> &map);
virtual void storeIntoMap(const QString &buildConfiguration, QMap<QString, QVariant> &map);
void setClean(bool clean);
virtual void addBuildConfiguration(const QString & name);
virtual void removeBuildConfiguration(const QString & name);
virtual void copyBuildConfiguration(const QString &source, const QString &dest);
protected:
// For parsing [ 76%]
virtual void stdOut(const QString &line);
......@@ -90,7 +81,8 @@ private:
bool m_clean;
QRegExp m_percentProgress;
QFutureInterface<bool> *m_futureInterface;
QMap<QString, MakeStepSettings> m_values;
QStringList m_buildTargets;
QStringList m_additionalArguments;
};
class MakeStepConfigWidget :public ProjectExplorer::BuildStepConfigWidget
......@@ -99,14 +91,13 @@ class MakeStepConfigWidget :public ProjectExplorer::BuildStepConfigWidget
public:
MakeStepConfigWidget(MakeStep *makeStep);
virtual QString displayName() const;
virtual void init(const QString &buildConfiguration);
virtual void init();
virtual QString summaryText() const;
private slots:
void itemChanged(QListWidgetItem*);
void additionalArgumentsEdited();
void updateDetails();
private:
QString m_buildConfiguration;
MakeStep *m_makeStep;
QListWidget *m_targetsList;
QLineEdit *m_additionalArguments;
......@@ -116,7 +107,8 @@ private:
class MakeStepFactory : public ProjectExplorer::IBuildStepFactory
{
virtual bool canCreate(const QString &name) const;
virtual ProjectExplorer::BuildStep *create(ProjectExplorer::Project *pro, const QString &name) const;
virtual ProjectExplorer::BuildStep *create(ProjectExplorer::Project *pro, ProjectExplorer::BuildConfiguration *bc, const QString &name) const;
virtual ProjectExplorer::BuildStep *clone(ProjectExplorer::BuildStep *bs, ProjectExplorer::BuildConfiguration *bc) const;
virtual QStringList canCreateForProject(ProjectExplorer::Project *pro) const;
virtual QString displayNameForName(const QString &name) const;
};
......
......@@ -47,8 +47,8 @@
using namespace GenericProjectManager;
using namespace GenericProjectManager::Internal;
GenericMakeStep::GenericMakeStep(GenericProject *pro)
: AbstractMakeStep(pro), m_pro(pro)
GenericMakeStep::GenericMakeStep(GenericProject *pro, ProjectExplorer::BuildConfiguration *bc)
: AbstractMakeStep(pro, bc), m_pro(pro)
{
}
......@@ -56,9 +56,9 @@ GenericMakeStep::~GenericMakeStep()
{
}
bool GenericMakeStep::init(const QString &buildConfigurationName)
bool GenericMakeStep::init()
{
ProjectExplorer::BuildConfiguration *bc = m_pro->buildConfiguration(buildConfigurationName);
ProjectExplorer::BuildConfiguration *bc = buildConfiguration();
const QString buildParser = m_pro->buildParser(bc);
setBuildParser(buildParser);
qDebug() << "*** build parser:" << buildParser;
......@@ -69,50 +69,34 @@ bool GenericMakeStep::init(const QString &buildConfigurationName)
const QString buildDir = vm->resolve(rawBuildDir);
setWorkingDirectory(buildDir);
setCommand(makeCommand(buildConfigurationName));
setArguments(replacedArguments(buildConfigurationName));
setCommand(makeCommand());
setArguments(replacedArguments());
setEnvironment(m_pro->environment(bc));
return AbstractMakeStep::init(buildConfigurationName);
return AbstractMakeStep::init();
}
void GenericMakeStep::restoreFromMap(const QString &buildConfiguration, const QMap<QString, QVariant> &map)
void GenericMakeStep::restoreFromLocalMap(const QMap<QString, QVariant> &map)
{
m_values[buildConfiguration].buildTargets = map.value("buildTargets").toStringList();
m_values[buildConfiguration].makeArguments = map.value("makeArguments").toStringList();
m_values[buildConfiguration].makeCommand = map.value("makeCommand").toString();
ProjectExplorer::AbstractMakeStep::restoreFromMap(buildConfiguration, map);
m_buildTargets = map.value("buildTargets").toStringList();
m_makeArguments = map.value("makeArguments").toStringList();
m_makeCommand = map.value("makeCommand").toString();
ProjectExplorer::AbstractMakeStep::restoreFromLocalMap(map);
}
void GenericMakeStep::storeIntoMap(const QString &buildConfiguration, QMap<QString, QVariant> &map)
void GenericMakeStep::storeIntoLocalMap(QMap<QString, QVariant> &map)
{
map["buildTargets"] = m_values.value(buildConfiguration).buildTargets;
map["makeArguments"] = m_values.value(buildConfiguration).makeArguments;
map["makeCommand"] = m_values.value(buildConfiguration).makeCommand;
ProjectExplorer::AbstractMakeStep::storeIntoMap(buildConfiguration, map);
map["buildTargets"] = m_buildTargets;
map["makeArguments"] = m_makeArguments;
map["makeCommand"] = m_makeCommand;
ProjectExplorer::AbstractMakeStep::storeIntoLocalMap(map);
}
void GenericMakeStep::addBuildConfiguration(const QString & name)
{
m_values.insert(name, GenericMakeStepSettings());
}
void GenericMakeStep::removeBuildConfiguration(const QString & name)
{
m_values.remove(name);
}
void GenericMakeStep::copyBuildConfiguration(const QString &source, const QString &dest)
{
m_values.insert(dest, m_values.value(source));
}
QStringList GenericMakeStep::replacedArguments(const QString &buildConfiguration) const
QStringList GenericMakeStep::replacedArguments() const
{
Core::VariableManager *vm = Core::VariableManager::instance();
const QStringList targets = m_values.value(buildConfiguration).buildTargets;
QStringList arguments = m_values.value(buildConfiguration).makeArguments;
const QStringList targets = m_buildTargets;
QStringList arguments = m_makeArguments;
QStringList replacedArguments;
foreach (const QString &arg, arguments) {
replacedArguments.append(vm->resolve(arg));
......@@ -123,9 +107,9 @@ QStringList GenericMakeStep::replacedArguments(const QString &buildConfiguration
return replacedArguments;
}
QString GenericMakeStep::makeCommand(const QString &buildConfiguration) const
QString GenericMakeStep::makeCommand() const
{
QString command = m_values.value(buildConfiguration).makeCommand;
QString command = m_makeCommand;
if (command.isEmpty()) {
if (ProjectExplorer::ToolChain *toolChain = m_pro->toolChain())
command = toolChain->makeCommand();
......@@ -165,20 +149,20 @@ GenericProject *GenericMakeStep::project() const
return m_pro;
}
bool GenericMakeStep::buildsTarget(const QString &buildConfiguration, const QString &target) const
bool GenericMakeStep::buildsTarget(const QString &target) const
{
return m_values.value(buildConfiguration).buildTargets.contains(target);
return m_buildTargets.contains(target);
}
void GenericMakeStep::setBuildTarget(const QString &buildConfiguration, const QString &target, bool on)
void GenericMakeStep::setBuildTarget(const QString &target, bool on)
{
QStringList old = m_values.value(buildConfiguration).buildTargets;
QStringList old = m_buildTargets;
if (on && !old.contains(target))
old << target;
else if(!on && old.contains(target))
old.removeOne(target);
m_values[buildConfiguration].buildTargets = old;
m_buildTargets = old;
}
//
......@@ -220,19 +204,17 @@ QString GenericMakeStepConfigWidget::displayName() const
// TODO: Label should update when tool chain is changed
void GenericMakeStepConfigWidget::updateMakeOverrrideLabel()
{
m_ui->makeLabel->setText(tr("Override %1:").arg(m_makeStep->makeCommand(m_buildConfiguration)));
m_ui->makeLabel->setText(tr("Override %1:").arg(m_makeStep->makeCommand()));
}
void GenericMakeStepConfigWidget::init(const QString &buildConfiguration)
void GenericMakeStepConfigWidget::init()
{
m_buildConfiguration = buildConfiguration;
updateMakeOverrrideLabel();
QString makeCommand = m_makeStep->m_values.value(buildConfiguration).makeCommand;
QString makeCommand = m_makeStep->m_makeCommand;
m_ui->makeLineEdit->setText(makeCommand);
const QStringList &makeArguments = m_makeStep->m_values.value(buildConfiguration).makeArguments;
const QStringList &makeArguments = m_makeStep->m_makeArguments;
m_ui->makeArgumentsLineEdit->setText(ProjectExplorer::Environment::joinArgumentList(makeArguments));
// Disconnect to make the changes to the items
......@@ -241,7 +223,7 @@ void GenericMakeStepConfigWidget::init(const QString &buildConfiguration)
int count = m_ui->targetsList->count();
for (int i = 0; i < count; ++i) {
QListWidgetItem *item = m_ui->targetsList->item(i);
item->setCheckState(m_makeStep->buildsTarget(buildConfiguration, item->text()) ? Qt::Checked : Qt::Unchecked);
item->setCheckState(m_makeStep->buildsTarget(item->text()) ? Qt::Checked : Qt::Unchecked);
}