Commit 17266884 authored by Tobias Hunger's avatar Tobias Hunger

Make use of ProjectConfiguration class in BuildSteps

 * Use new BuildSteps interface (as seen in ProjectConfiguration).
 * Use new factory to construct/clone/restore them.

Reviewed-by: dt
parent c410d268
......@@ -26,7 +26,9 @@
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "makestep.h"
#include "cmakeprojectconstants.h"
#include "cmakeproject.h"
#include "cmakebuildconfiguration.h"
......@@ -44,25 +46,48 @@ using namespace CMakeProjectManager;
using namespace CMakeProjectManager::Internal;
using namespace ProjectExplorer;
namespace {
const char * const MS_ID("CMakeProjectManager.MakeStep");
const char * const CLEAN_KEY("CMakeProjectManager.MakeStep.Clean");
const char * const BUILD_TARGETS_KEY("CMakeProjectManager.MakeStep.BuildTargets");
const char * const ADDITIONAL_ARGUMENTS_KEY("CMakeProjectManager.MakeStep.AdditionalArguments");
}
// TODO: Move progress information into an IOutputParser!
MakeStep::MakeStep(BuildConfiguration *bc) :
AbstractProcessStep(bc), m_clean(false), m_futureInterface(0)
AbstractProcessStep(bc, QLatin1String(MS_ID)), m_clean(false),
m_futureInterface(0)
{
m_percentProgress = QRegExp("^\\[\\s*(\\d*)%\\]");
ctor();
}
MakeStep::MakeStep(BuildConfiguration *bc, const QString &id) :
AbstractProcessStep(bc, id), m_clean(false),
m_futureInterface(0)
{
ctor();
}
MakeStep::MakeStep(MakeStep *bs, BuildConfiguration *bc) :
AbstractProcessStep(bs, bc),
MakeStep::MakeStep(BuildConfiguration *bc, MakeStep *bs) :
AbstractProcessStep(bc, bs),
m_clean(bs->m_clean),
m_futureInterface(0),
m_buildTargets(bs->m_buildTargets),
m_additionalArguments(bs->m_buildTargets)
{
ctor();
}
void MakeStep::ctor()
{
m_percentProgress = QRegExp("^\\[\\s*(\\d*)%\\]");
setDisplayName(tr("Make", "CMakeProjectManager::MakeStep display name."));
}
MakeStep::~MakeStep()
{
}
CMakeBuildConfiguration *MakeStep::cmakeBuildConfiguration() const
......@@ -75,31 +100,25 @@ void MakeStep::setClean(bool clean)
m_clean = clean;
}
void MakeStep::restoreFromGlobalMap(const QMap<QString, QVariant> &map)
QVariantMap MakeStep::toMap() const
{
if (map.value("clean").isValid() && map.value("clean").toBool())
m_clean = true;
AbstractProcessStep::restoreFromGlobalMap(map);
QVariantMap map(AbstractProcessStep::toMap());
map.insert(QLatin1String(CLEAN_KEY), m_clean);
map.insert(QLatin1String(BUILD_TARGETS_KEY), m_buildTargets);
map.insert(QLatin1String(ADDITIONAL_ARGUMENTS_KEY), m_additionalArguments);
return map;
}
void MakeStep::restoreFromLocalMap(const QMap<QString, QVariant> &map)
bool MakeStep::fromMap(const QVariantMap &map)
{
m_buildTargets = map["buildTargets"].toStringList();
m_additionalArguments = map["additionalArguments"].toStringList();
if (map.value("clean").isValid() && map.value("clean").toBool())
m_clean = true;
AbstractProcessStep::restoreFromLocalMap(map);
}
m_clean = map.value(QLatin1String(CLEAN_KEY)).toBool();
m_buildTargets = map.value(QLatin1String(BUILD_TARGETS_KEY)).toStringList();
m_additionalArguments = map.value(QLatin1String(ADDITIONAL_ARGUMENTS_KEY)).toStringList();
void MakeStep::storeIntoLocalMap(QMap<QString, QVariant> &map)
{
map["buildTargets"] = m_buildTargets;
map["additionalArguments"] = m_additionalArguments;
if (m_clean)
map["clean"] = true;
AbstractProcessStep::storeIntoLocalMap(map);
return BuildStep::fromMap(map);
}
bool MakeStep::init()
{
CMakeBuildConfiguration *bc = cmakeBuildConfiguration();
......@@ -132,16 +151,6 @@ void MakeStep::run(QFutureInterface<bool> &fi)
m_futureInterface = 0;
}
QString MakeStep::id()
{
return Constants::MAKESTEP;
}
QString MakeStep::displayName()
{
return QLatin1String("Make");
}
BuildStepConfigWidget *MakeStep::createConfigWidget()
{
return new MakeStepConfigWidget(this);
......@@ -238,7 +247,7 @@ void MakeStepConfigWidget::itemChanged(QListWidgetItem *item)
QString MakeStepConfigWidget::displayName() const
{
return "Make";
return tr("Make", "CMakeProjectManager::MakeStepConfigWidget display name.");
}
void MakeStepConfigWidget::init()
......@@ -298,31 +307,68 @@ QString MakeStepConfigWidget::summaryText() const
// MakeStepFactory
//
bool MakeStepFactory::canCreate(const QString &id) const
MakeStepFactory::MakeStepFactory(QObject *parent) :
ProjectExplorer::IBuildStepFactory(parent)
{
return (Constants::MAKESTEP == id);
}
BuildStep *MakeStepFactory::create(BuildConfiguration *bc, const QString &id) const
MakeStepFactory::~MakeStepFactory()
{
Q_ASSERT(id == Constants::MAKESTEP);
return new MakeStep(bc);
}
BuildStep *MakeStepFactory::clone(BuildStep *bs, BuildConfiguration *bc) const
bool MakeStepFactory::canCreate(BuildConfiguration *parent, const QString &id) const
{
return new MakeStep(static_cast<MakeStep *>(bs), bc);
if (!qobject_cast<CMakeBuildConfiguration *>(parent))
return false;
return QLatin1String(MS_ID) == id;
}
QStringList MakeStepFactory::canCreateForBuildConfiguration(BuildConfiguration *bc) const
BuildStep *MakeStepFactory::create(BuildConfiguration *parent, const QString &id)
{
Q_UNUSED(bc);
return QStringList();
if (!canCreate(parent, id))
return 0;
return new MakeStep(parent);
}
QString MakeStepFactory::displayNameForId(const QString &id) const
bool MakeStepFactory::canClone(BuildConfiguration *parent, BuildStep *source) const
{
return canCreate(parent, source->id());
}
BuildStep *MakeStepFactory::clone(BuildConfiguration *parent, BuildStep *source)
{
if (!canClone(parent, source))
return 0;
return new MakeStep(parent, static_cast<MakeStep *>(source));
}
bool MakeStepFactory::canRestore(BuildConfiguration *parent, const QVariantMap &map) const
{
Q_UNUSED(id);
return "Make";
QString id(ProjectExplorer::idFromMap(map));
return canCreate(parent, id);
}
BuildStep *MakeStepFactory::restore(BuildConfiguration *parent, const QVariantMap &map)
{
if (!canRestore(parent, map))
return 0;
MakeStep *bs(new MakeStep(parent));
if (bs->fromMap(map))
return bs;
delete bs;
return 0;
}
QStringList MakeStepFactory::availableCreationIds(ProjectExplorer::BuildConfiguration *parent) const
{
if (!qobject_cast<CMakeBuildConfiguration *>(parent))
return QStringList();
return QStringList() << QLatin1String(MS_ID);
}
QString MakeStepFactory::displayNameForId(const QString &id) const
{
if (id == QLatin1String(MS_ID))
return tr("Make", "Display name for CMakeProjectManager::MakeStep id.");
return QString();
}
......@@ -42,16 +42,18 @@ namespace CMakeProjectManager {
namespace Internal {
class CMakeBuildConfiguration;
class MakeStepFactory;
class MakeStep : public ProjectExplorer::AbstractProcessStep
{
Q_OBJECT
friend class MakeStepFactory;
friend class MakeStepConfigWidget; // TODO remove
// This is for modifying internal data
public:
MakeStep(ProjectExplorer::BuildConfiguration *bc);
MakeStep(MakeStep *bs, ProjectExplorer::BuildConfiguration *bc);
~MakeStep();
virtual ~MakeStep();
CMakeBuildConfiguration *cmakeBuildConfiguration() const;
......@@ -59,8 +61,6 @@ public:
virtual void run(QFutureInterface<bool> &fi);
virtual QString id();
virtual QString displayName();
virtual ProjectExplorer::BuildStepConfigWidget *createConfigWidget();
virtual bool immutable() const;
bool buildsTarget(const QString &target) const;
......@@ -68,17 +68,22 @@ public:
QStringList additionalArguments() const;
void setAdditionalArguments(const QStringList &list);
virtual void restoreFromGlobalMap(const QMap<QString, QVariant> &map);
virtual void restoreFromLocalMap(const QMap<QString, QVariant> &map);
virtual void storeIntoLocalMap(QMap<QString, QVariant> &map);
void setClean(bool clean);
QVariantMap toMap() const;
protected:
MakeStep(ProjectExplorer::BuildConfiguration *bc, MakeStep *bs);
MakeStep(ProjectExplorer::BuildConfiguration *bc, const QString &id);
bool fromMap(const QVariantMap &map);
// For parsing [ 76%]
virtual void stdOut(const QString &line);
private:
void ctor();
bool m_clean;
QRegExp m_percentProgress;
QFutureInterface<bool> *m_futureInterface;
......@@ -108,10 +113,20 @@ private:
class MakeStepFactory : public ProjectExplorer::IBuildStepFactory
{
virtual bool canCreate(const QString &id) const;
virtual ProjectExplorer::BuildStep *create(ProjectExplorer::BuildConfiguration *bc, const QString &id) const;
virtual ProjectExplorer::BuildStep *clone(ProjectExplorer::BuildStep *bs, ProjectExplorer::BuildConfiguration *bc) const;
virtual QStringList canCreateForBuildConfiguration(ProjectExplorer::BuildConfiguration *bc) const;
Q_OBJECT
public:
explicit MakeStepFactory(QObject *parent = 0);
virtual ~MakeStepFactory();
virtual bool canCreate(ProjectExplorer::BuildConfiguration *parent, const QString &id) const;
virtual ProjectExplorer::BuildStep *create(ProjectExplorer::BuildConfiguration *parent, const QString &id);
virtual bool canClone(ProjectExplorer::BuildConfiguration *parent, ProjectExplorer::BuildStep *source) const;
virtual ProjectExplorer::BuildStep *clone(ProjectExplorer::BuildConfiguration *parent, ProjectExplorer::BuildStep *source);
virtual bool canRestore(ProjectExplorer::BuildConfiguration *parent, const QVariantMap &map) const;
virtual ProjectExplorer::BuildStep *restore(ProjectExplorer::BuildConfiguration *parent, const QVariantMap &map);
virtual QStringList availableCreationIds(ProjectExplorer::BuildConfiguration *bc) const;
virtual QString displayNameForId(const QString &id) const;
};
......
......@@ -49,17 +49,41 @@
using namespace GenericProjectManager;
using namespace GenericProjectManager::Internal;
namespace {
const char * const GENERIC_MS_ID("GenericProjectManager.GenericMakeStep");
const char * const GENERIC_MS_DISPLAY_NAME(QT_TRANSLATE_NOOP("GenericProjectManager::Internal::GenericMakeStep",
"Make"));
const char * const BUILD_TARGETS_KEY("GenericProjectManager.GenericMakeStep.BuildTargets");
const char * const MAKE_ARGUMENTS_KEY("GenericProjectManager.GenericMakeStep.MakeArguments");
const char * const MAKE_COMMAND_KEY("GenericProjectManager.GenericMakeStep.MakeCommand");
}
GenericMakeStep::GenericMakeStep(ProjectExplorer::BuildConfiguration *bc) :
AbstractProcessStep(bc)
AbstractProcessStep(bc, QLatin1String(GENERIC_MS_ID))
{
ctor();
}
GenericMakeStep::GenericMakeStep(ProjectExplorer::BuildConfiguration *bc, const QString &id) :
AbstractProcessStep(bc, id)
{
ctor();
}
GenericMakeStep::GenericMakeStep(ProjectExplorer::BuildConfiguration *bc, GenericMakeStep *bs) :
AbstractProcessStep(bc, bs),
m_buildTargets(bs->m_buildTargets),
m_makeArguments(bs->m_makeArguments),
m_makeCommand(bs->m_makeCommand)
{
ctor();
}
GenericMakeStep::GenericMakeStep(GenericMakeStep *bs, ProjectExplorer::BuildConfiguration *bc) :
AbstractProcessStep(bs, bc)
void GenericMakeStep::ctor()
{
m_buildTargets = bs->m_buildTargets;
m_makeArguments = bs->m_makeArguments;
m_makeCommand = bs->m_makeCommand;
setDisplayName(QCoreApplication::translate("GenericProjectManager::Internal::GenericMakeStep",
GENERIC_MS_DISPLAY_NAME));
}
GenericMakeStep::~GenericMakeStep()
......@@ -93,20 +117,23 @@ bool GenericMakeStep::init()
return AbstractProcessStep::init();
}
void GenericMakeStep::restoreFromLocalMap(const QMap<QString, QVariant> &map)
QVariantMap GenericMakeStep::toMap() const
{
m_buildTargets = map.value("buildTargets").toStringList();
m_makeArguments = map.value("makeArguments").toStringList();
m_makeCommand = map.value("makeCommand").toString();
ProjectExplorer::AbstractProcessStep::restoreFromLocalMap(map);
QVariantMap map(AbstractProcessStep::toMap());
map.insert(QLatin1String(BUILD_TARGETS_KEY), m_buildTargets);
map.insert(QLatin1String(MAKE_ARGUMENTS_KEY), m_makeArguments);
map.insert(QLatin1String(MAKE_COMMAND_KEY), m_makeCommand);
return map;
}
void GenericMakeStep::storeIntoLocalMap(QMap<QString, QVariant> &map)
bool GenericMakeStep::fromMap(const QVariantMap &map)
{
map["buildTargets"] = m_buildTargets;
map["makeArguments"] = m_makeArguments;
map["makeCommand"] = m_makeCommand;
ProjectExplorer::AbstractProcessStep::storeIntoLocalMap(map);
m_buildTargets = map.value(QLatin1String(BUILD_TARGETS_KEY)).toStringList();
m_makeArguments = map.value(QLatin1String(MAKE_ARGUMENTS_KEY)).toStringList();
m_makeCommand = map.value(QLatin1String(MAKE_COMMAND_KEY)).toString();
return BuildStep::fromMap(map);
}
QStringList GenericMakeStep::replacedArguments() const
......@@ -142,16 +169,6 @@ void GenericMakeStep::run(QFutureInterface<bool> &fi)
AbstractProcessStep::run(fi);
}
QString GenericMakeStep::id()
{
return Constants::MAKESTEP;
}
QString GenericMakeStep::displayName()
{
return "Make";
}
ProjectExplorer::BuildStepConfigWidget *GenericMakeStep::createConfigWidget()
{
return new GenericMakeStepConfigWidget(this);
......@@ -211,7 +228,7 @@ GenericMakeStepConfigWidget::GenericMakeStepConfigWidget(GenericMakeStep *makeSt
QString GenericMakeStepConfigWidget::displayName() const
{
return "Make";
return tr("Make", "GenericMakestep display name.");
}
// TODO: Label should update when tool chain is changed
......@@ -280,32 +297,77 @@ void GenericMakeStepConfigWidget::makeArgumentsLineEditTextEdited()
// GenericMakeStepFactory
//
bool GenericMakeStepFactory::canCreate(const QString &id) const
GenericMakeStepFactory::GenericMakeStepFactory(QObject *parent) :
ProjectExplorer::IBuildStepFactory(parent)
{
}
GenericMakeStepFactory::~GenericMakeStepFactory()
{
}
bool GenericMakeStepFactory::canCreate(ProjectExplorer::BuildConfiguration *parent, const QString &id) const
{
if (!qobject_cast<GenericBuildConfiguration *>(parent))
return false;
return id == QLatin1String(GENERIC_MS_ID);
}
ProjectExplorer::BuildStep *GenericMakeStepFactory::create(ProjectExplorer::BuildConfiguration *parent,
const QString &id)
{
if (!canCreate(parent, id))
return 0;
return new GenericMakeStep(parent);
}
bool GenericMakeStepFactory::canClone(ProjectExplorer::BuildConfiguration *parent,
ProjectExplorer::BuildStep *source) const
{
const QString id(source->id());
return canCreate(parent, id);
}
ProjectExplorer::BuildStep *GenericMakeStepFactory::clone(ProjectExplorer::BuildConfiguration *parent,
ProjectExplorer::BuildStep *source)
{
return (Constants::MAKESTEP == id);
if (!canClone(parent, source))
return 0;
GenericMakeStep *old(qobject_cast<GenericMakeStep *>(source));
Q_ASSERT(old);
return new GenericMakeStep(parent, old);
}
ProjectExplorer::BuildStep *GenericMakeStepFactory::create(ProjectExplorer::BuildConfiguration *bc,
const QString &id) const
bool GenericMakeStepFactory::canRestore(ProjectExplorer::BuildConfiguration *parent,
const QVariantMap &map) const
{
Q_ASSERT(id == Constants::MAKESTEP);
return new GenericMakeStep(bc);
QString id(ProjectExplorer::idFromMap(map));
return canCreate(parent, id);
}
ProjectExplorer::BuildStep *GenericMakeStepFactory::clone(ProjectExplorer::BuildStep *bs,
ProjectExplorer::BuildConfiguration *bc) const
ProjectExplorer::BuildStep *GenericMakeStepFactory::restore(ProjectExplorer::BuildConfiguration *parent,
const QVariantMap &map)
{
return new GenericMakeStep(static_cast<GenericMakeStep*>(bs), bc);
if (!canRestore(parent, map))
return 0;
GenericMakeStep *bs(new GenericMakeStep(parent));
if (bs->fromMap(map))
return bs;
delete bs;
return 0;
}
QStringList GenericMakeStepFactory::canCreateForBuildConfiguration(ProjectExplorer::BuildConfiguration *bc) const
QStringList GenericMakeStepFactory::availableCreationIds(ProjectExplorer::BuildConfiguration *parent) const
{
Q_UNUSED(bc);
return QStringList();
if (!qobject_cast<GenericBuildConfiguration *>(parent))
return QStringList();
return QStringList() << QLatin1String(GENERIC_MS_ID);
}
QString GenericMakeStepFactory::displayNameForId(const QString &id) const
{
QTC_ASSERT(id == Constants::MAKESTEP, return QString());
return "Make";
if (id == QLatin1String(GENERIC_MS_ID))
return QCoreApplication::translate("GenericProjectManager::Internal::GenericMakeStep",
GENERIC_MS_DISPLAY_NAME);
return QString();
}
......@@ -45,28 +45,24 @@ namespace Internal {
class GenericBuildConfiguration;
class GenericMakeStepConfigWidget;
struct GenericMakeStepSettings
{
};
class GenericMakeStepFactory;
class GenericMakeStep : public ProjectExplorer::AbstractProcessStep
{
Q_OBJECT
friend class GenericMakeStepConfigWidget; // TODO remove again?
friend class GenericMakeStepFactory;
public:
GenericMakeStep(ProjectExplorer::BuildConfiguration *bc);
GenericMakeStep(GenericMakeStep *bs, ProjectExplorer::BuildConfiguration *bc);
~GenericMakeStep();
virtual ~GenericMakeStep();
GenericBuildConfiguration *genericBuildConfiguration() const;
virtual bool init();
virtual void run(QFutureInterface<bool> &fi);
virtual QString id();
virtual QString displayName();
virtual ProjectExplorer::BuildStepConfigWidget *createConfigWidget();
virtual bool immutable() const;
bool buildsTarget(const QString &target) const;
......@@ -74,9 +70,16 @@ public:
QStringList replacedArguments() const;
QString makeCommand() const;
virtual void restoreFromLocalMap(const QMap<QString, QVariant> &map);
virtual void storeIntoLocalMap(QMap<QString, QVariant> &map);
QVariantMap toMap() const;
protected:
GenericMakeStep(ProjectExplorer::BuildConfiguration *bc, GenericMakeStep *bs);
GenericMakeStep(ProjectExplorer::BuildConfiguration *bc, const QString &id);
virtual bool fromMap(const QVariantMap &map);
private:
void ctor();
QStringList m_buildTargets;
QStringList m_makeArguments;
QString m_makeCommand;
......@@ -104,12 +107,25 @@ private:
class GenericMakeStepFactory : public ProjectExplorer::IBuildStepFactory
{
virtual bool canCreate(const QString &id) const;
virtual ProjectExplorer::BuildStep *create(ProjectExplorer::BuildConfiguration *bc,
const QString &id) const;
virtual ProjectExplorer::BuildStep *clone(ProjectExplorer::BuildStep *bs,
ProjectExplorer::BuildConfiguration *bc) const;
virtual QStringList canCreateForBuildConfiguration(ProjectExplorer::BuildConfiguration *bc) const;
Q_OBJECT
public:
explicit GenericMakeStepFactory(QObject *parent = 0);
virtual ~GenericMakeStepFactory();
virtual bool canCreate(ProjectExplorer::BuildConfiguration *parent, const QString &id) const;
virtual ProjectExplorer::BuildStep *create(ProjectExplorer::BuildConfiguration *parent,
const QString &id);
virtual bool canClone(ProjectExplorer::BuildConfiguration *parent,
ProjectExplorer::BuildStep *source) const;
virtual ProjectExplorer::BuildStep *clone(ProjectExplorer::BuildConfiguration *parent,
ProjectExplorer::BuildStep *source);
virtual bool canRestore(ProjectExplorer::BuildConfiguration *parent,
const QVariantMap &map) const;
virtual ProjectExplorer::BuildStep *restore(ProjectExplorer::BuildConfiguration *parent,
const QVariantMap &map);
virtual QStringList availableCreationIds(ProjectExplorer::BuildConfiguration *bc) const;
virtual QString displayNameForId(const QString &id) const;
};
......
......@@ -42,21 +42,19 @@
using namespace ProjectExplorer;
AbstractProcessStep::AbstractProcessStep(BuildConfiguration *bc) :
BuildStep(bc), m_timer(0), m_futureInterface(0),
AbstractProcessStep::AbstractProcessStep(BuildConfiguration *bc, const QString &id) :
BuildStep(bc, id), m_timer(0), m_futureInterface(0),
m_enabled(true), m_ignoreReturnValue(false),
m_process(0), m_eventLoop(0), m_outputParserChain(0)
{
}
AbstractProcessStep::AbstractProcessStep(AbstractProcessStep *bs,
BuildConfiguration *bc) :
BuildStep(bs, bc), m_timer(0), m_futureInterface(0),
AbstractProcessStep::AbstractProcessStep(BuildConfiguration *bc,
AbstractProcessStep *bs) :
BuildStep(bc, bs), m_timer(0), m_futureInterface(0),
m_enabled(bs->m_enabled), m_ignoreReturnValue(bs->m_ignoreReturnValue),
m_process(0), m_eventLoop(0), m_outputParserChain(0)
{
}
AbstractProcessStep::~AbstractProcessStep()
......
......@@ -67,9 +67,8 @@ class IOutputParser;
class PROJECTEXPLORER_EXPORT AbstractProcessStep : public BuildStep