Commit c78258cd authored by Daniel Teske's avatar Daniel Teske

Allow the user to restrict rc creation to certain .pro

Task-number: QTCREATORBUG-10953
Change-Id: Iff1a31c007ac777bfa390d48237480ef56ffc0e4
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent d15e0aa9
......@@ -37,6 +37,25 @@
namespace Utils
{
template<typename T, typename F>
bool anyOf(const T &container, F predicate)
{
return std::any_of(container.begin(), container.end(), predicate);
}
template<typename T, typename F>
bool allOf(const T &container, F predicate)
{
return std::all_of(container.begin(), container.end(), predicate);
}
template<typename T, typename F>
void erase(QList<T> &container, F predicate)
{
container.erase(std::remove_if(container.begin(), container.end(), predicate),
container.end());
}
// Note: add overloads for other container types as needed
template<typename T, typename F>
Q_REQUIRED_RESULT
......
......@@ -85,17 +85,20 @@ bool AndroidRunConfigurationFactory::canClone(Target *parent, RunConfiguration *
return canCreate(parent, source->id());
}
QList<Core::Id> AndroidRunConfigurationFactory::availableCreationIds(Target *parent) const
QList<Core::Id> AndroidRunConfigurationFactory::availableCreationIds(Target *parent, CreationMode mode) const
{
QList<Core::Id> ids;
if (!AndroidManager::supportsAndroid(parent))
return ids;
return QList<Core::Id>();
QmakeProject *project = static_cast<QmakeProject *>(parent->project());
QList<QmakeProFileNode *> nodes = project->allProFiles(QList<QmakeProjectType>()
<< ApplicationTemplate
<< LibraryTemplate);
if (mode == AutoCreate)
nodes = QmakeProject::nodesWithQtcRunnable(nodes);
const Core::Id base = Core::Id(ANDROID_RC_ID_PREFIX);
return QmakeProject::idsForNodes(base, nodes);
}
......
......@@ -51,7 +51,7 @@ public:
explicit AndroidRunConfigurationFactory(QObject *parent = 0);
QString displayNameForId(const Core::Id id) const;
QList<Core::Id> availableCreationIds(ProjectExplorer::Target *parent) const;
QList<Core::Id> availableCreationIds(ProjectExplorer::Target *parent, CreationMode mode = UserCreate) const;
bool canCreate(ProjectExplorer::Target *parent, const Core::Id id) const;
......
......@@ -84,8 +84,9 @@ bool BareMetalRunConfigurationFactory::canClone(Target *parent, RunConfiguration
return bmrc && canCreate(parent, source->id());
}
QList<Core::Id> BareMetalRunConfigurationFactory::availableCreationIds(Target *parent) const
QList<Core::Id> BareMetalRunConfigurationFactory::availableCreationIds(Target *parent, CreationMode mode) const
{
Q_UNUSED(mode)
QList<Core::Id> result;
if (!canHandle(parent))
return result;
......
......@@ -42,7 +42,7 @@ public:
~BareMetalRunConfigurationFactory();
QString displayNameForId(const Core::Id id) const;
QList<Core::Id> availableCreationIds(ProjectExplorer::Target *parent) const;
QList<Core::Id> availableCreationIds(ProjectExplorer::Target *parent, CreationMode mode) const;
bool canCreate(ProjectExplorer::Target *parent, const Core::Id id) const;
......
......@@ -352,8 +352,9 @@ CMakeRunConfigurationFactory::~CMakeRunConfigurationFactory()
}
// used to show the list of possible additons to a project, returns a list of ids
QList<Core::Id> CMakeRunConfigurationFactory::availableCreationIds(Target *parent) const
QList<Core::Id> CMakeRunConfigurationFactory::availableCreationIds(Target *parent, CreationMode mode) const
{
Q_UNUSED(mode)
if (!canHandle(parent))
return QList<Core::Id>();
CMakeProject *project = static_cast<CMakeProject *>(parent->project());
......
......@@ -138,7 +138,7 @@ public:
bool canClone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *product) const;
ProjectExplorer::RunConfiguration *clone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *product);
QList<Core::Id> availableCreationIds(ProjectExplorer::Target *parent) const;
QList<Core::Id> availableCreationIds(ProjectExplorer::Target *parent, CreationMode mode) const;
QString displayNameForId(const Core::Id id) const;
static Core::Id idFromBuildTarget(const QString &target);
......
......@@ -59,7 +59,11 @@ namespace Internal {
static QString pathFromId(const Core::Id id)
{
return id.suffixAfter(IOS_RC_ID_PREFIX);
QString pathStr = id.toString();
const QString prefix = QLatin1String(IOS_RC_ID_PREFIX);
if (!pathStr.startsWith(prefix))
return QString();
return pathStr.mid(prefix.size());
}
IosRunConfigurationFactory::IosRunConfigurationFactory(QObject *parent)
......@@ -88,19 +92,19 @@ bool IosRunConfigurationFactory::canClone(Target *parent, RunConfiguration *sour
return canCreate(parent, source->id());
}
QList<Core::Id> IosRunConfigurationFactory::availableCreationIds(Target *parent) const
QList<Core::Id> IosRunConfigurationFactory::availableCreationIds(Target *parent, CreationMode mode) const
{
QList<Core::Id> ids;
if (!IosManager::supportsIos(parent))
return ids;
Core::Id baseId(IOS_RC_ID_PREFIX);
return QList<Core::Id>();
QmakeProject *project = static_cast<QmakeProject *>(parent->project());
QList<QmakeProFileNode *> nodes = project->allProFiles(QList<QmakeProjectType>()
<< ApplicationTemplate
<< LibraryTemplate
<< AuxTemplate);
if (mode == AutoCreate)
nodes = QmakeProject::nodesWithQtcRunnable(nodes);
Core::Id baseId(IOS_RC_ID_PREFIX);
return QmakeProject::idsForNodes(baseId, nodes);
}
......
......@@ -51,7 +51,7 @@ public:
explicit IosRunConfigurationFactory(QObject *parent = 0);
QString displayNameForId(const Core::Id id) const QTC_OVERRIDE;
QList<Core::Id> availableCreationIds(ProjectExplorer::Target *parent) const QTC_OVERRIDE;
QList<Core::Id> availableCreationIds(ProjectExplorer::Target *parent, CreationMode mode = UserCreate) const QTC_OVERRIDE;
bool canCreate(ProjectExplorer::Target *parent, const Core::Id id) const QTC_OVERRIDE;
......
......@@ -217,7 +217,8 @@ public:
explicit IRunConfigurationFactory(QObject *parent = 0);
virtual ~IRunConfigurationFactory();
virtual QList<Core::Id> availableCreationIds(Target *parent) const = 0;
enum CreationMode {UserCreate, AutoCreate};
virtual QList<Core::Id> availableCreationIds(Target *parent, CreationMode mode = UserCreate) const = 0;
virtual QString displayNameForId(const Core::Id id) const = 0;
virtual bool canCreate(Target *parent, const Core::Id id) const = 0;
......
......@@ -599,26 +599,31 @@ void Target::updateDefaultRunConfigurations()
int configuredCount = existingConfigured.count();
// find all RC ids that can get created:
QList<Core::Id> factoryIds;
QList<Core::Id> availableFactoryIds;
foreach (IRunConfigurationFactory *rcFactory, rcFactories)
factoryIds.append(rcFactory->availableCreationIds(this));
availableFactoryIds.append(rcFactory->availableCreationIds(this));
QList<Core::Id> autoCreateFactoryIds;
foreach (IRunConfigurationFactory *rcFactory, rcFactories)
autoCreateFactoryIds.append(rcFactory->availableCreationIds(this,
IRunConfigurationFactory::AutoCreate));
// Put outdated RCs into toRemove, do not bother with factories
// that produce already existing RCs
QList<RunConfiguration *> toRemove;
QList<Core::Id> toIgnore;
foreach (RunConfiguration *rc, existingConfigured) {
if (factoryIds.contains(rc->id()))
if (availableFactoryIds.contains(rc->id()))
toIgnore.append(rc->id()); // Already there
else
toRemove << rc;
}
foreach (Core::Id i, toIgnore)
factoryIds.removeAll(i);
autoCreateFactoryIds.removeAll(i);
configuredCount -= toRemove.count();
// Create new RCs and put them into newConfigured/newUnconfigured
foreach (Core::Id id, factoryIds) {
foreach (Core::Id id, autoCreateFactoryIds) {
IRunConfigurationFactory *factory = 0;
foreach (IRunConfigurationFactory *i, rcFactories) {
if (i->canCreate(this, id)) {
......
......@@ -550,8 +550,9 @@ RunConfiguration *QbsRunConfigurationFactory::clone(Target *parent, RunConfigura
return new QbsRunConfiguration(parent, old);
}
QList<Core::Id> QbsRunConfigurationFactory::availableCreationIds(Target *parent) const
QList<Core::Id> QbsRunConfigurationFactory::availableCreationIds(Target *parent, CreationMode mode) const
{
Q_UNUSED(mode)
QList<Core::Id> result;
if (!canHandle(parent))
return result;
......
......@@ -181,7 +181,7 @@ public:
bool canClone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *source) const;
ProjectExplorer::RunConfiguration *clone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *source);
QList<Core::Id> availableCreationIds(ProjectExplorer::Target *parent) const;
QList<Core::Id> availableCreationIds(ProjectExplorer::Target *parent, CreationMode mode) const;
QString displayNameForId(const Core::Id id) const;
private:
......
......@@ -667,14 +667,15 @@ RunConfiguration *DesktopQmakeRunConfigurationFactory::clone(Target *parent, Run
return new DesktopQmakeRunConfiguration(parent, old);
}
QList<Core::Id> DesktopQmakeRunConfigurationFactory::availableCreationIds(Target *parent) const
QList<Core::Id> DesktopQmakeRunConfigurationFactory::availableCreationIds(Target *parent, CreationMode mode) const
{
QList<Core::Id> result;
if (!canHandle(parent))
return result;
return QList<Core::Id>();
QmakeProject *project = static_cast<QmakeProject *>(parent->project());
QList<QmakeProFileNode *> nodes = project->applicationProFiles();
if (mode == AutoCreate)
nodes = QmakeProject::nodesWithQtcRunnable(nodes);
return QmakeProject::idsForNodes(Core::Id(QMAKE_RC_PREFIX), nodes);
}
......
......@@ -193,7 +193,7 @@ public:
bool canClone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *source) const;
ProjectExplorer::RunConfiguration *clone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *source);
QList<Core::Id> availableCreationIds(ProjectExplorer::Target *parent) const;
QList<Core::Id> availableCreationIds(ProjectExplorer::Target *parent, CreationMode mode) const;
QString displayNameForId(const Core::Id id) const;
QList<ProjectExplorer::RunConfiguration *> runConfigurationsForNode(ProjectExplorer::Target *t,
......
......@@ -1591,6 +1591,12 @@ bool QmakeProFileNode::isDebugAndRelease() const
return configValues.contains(QLatin1String("debug_and_release"));
}
bool QmakeProFileNode::isQtcRunnable() const
{
const QStringList configValues = m_varValues.value(ConfigVar);
return configValues.contains(QLatin1String("qtc_runnable"));
}
QmakeProjectType QmakeProFileNode::projectType() const
{
return m_projectType;
......
......@@ -410,6 +410,7 @@ public:
bool showInSimpleTree(QmakeProjectType projectType) const;
bool isDebugAndRelease() const;
bool isQtcRunnable() const;
void setParseInProgress(bool b);
void setParseInProgressRecursive(bool b);
......
......@@ -1103,6 +1103,17 @@ bool QmakeProject::hasApplicationProFile(const QString &path) const
return false;
}
QList<QmakeProFileNode *> QmakeProject::nodesWithQtcRunnable(QList<QmakeProFileNode *> nodes)
{
std::function<bool (QmakeProFileNode *)> hasQtcRunnable = [](QmakeProFileNode *node) {
return node->isQtcRunnable();
};
if (anyOf(nodes, hasQtcRunnable))
erase(nodes, std::not1(hasQtcRunnable));
return nodes;
}
QList<Core::Id> QmakeProject::idsForNodes(const Core::Id base, const QList<QmakeProFileNode *> &nodes)
{
return Utils::transform(nodes, [&base](QmakeProFileNode *node) {
......
......@@ -92,6 +92,7 @@ public:
QList<QmakeProFileNode *> applicationProFiles(Parsing parse = ExactParse) const;
bool hasApplicationProFile(const QString &path) const;
static QList<QmakeProFileNode *> nodesWithQtcRunnable(QList<QmakeProFileNode *> nodes);
static QList<Core::Id> idsForNodes(const Core::Id base, const QList<QmakeProFileNode *> &nodes);
void notifyChanged(const QString &name);
......
......@@ -50,8 +50,9 @@ QmlProjectRunConfigurationFactory::~QmlProjectRunConfigurationFactory()
{
}
QList<Core::Id> QmlProjectRunConfigurationFactory::availableCreationIds(ProjectExplorer::Target *parent) const
QList<Core::Id> QmlProjectRunConfigurationFactory::availableCreationIds(ProjectExplorer::Target *parent, CreationMode mode) const
{
Q_UNUSED(mode)
if (!canHandle(parent))
return QList<Core::Id>();
......
......@@ -43,7 +43,7 @@ public:
explicit QmlProjectRunConfigurationFactory(QObject *parent = 0);
~QmlProjectRunConfigurationFactory();
QList<Core::Id> availableCreationIds(ProjectExplorer::Target *parent) const;
QList<Core::Id> availableCreationIds(ProjectExplorer::Target *parent, CreationMode mode) const;
QString displayNameForId(const Core::Id id) const;
bool canCreate(ProjectExplorer::Target *parent, const Core::Id id) const;
......
......@@ -37,6 +37,7 @@
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/target.h>
#include <qmakeprojectmanager/qmakeproject.h>
#include <qmakeprojectmanager/qmakenodes.h>
using namespace Qnx;
using namespace Qnx::Internal;
......@@ -51,19 +52,21 @@ BlackBerryRunConfigurationFactory::BlackBerryRunConfigurationFactory(QObject *pa
{
}
QList<Core::Id> BlackBerryRunConfigurationFactory::availableCreationIds(ProjectExplorer::Target *parent) const
QList<Core::Id> BlackBerryRunConfigurationFactory::availableCreationIds(ProjectExplorer::Target *parent, CreationMode mode) const
{
QList<Core::Id> ids;
using QmakeProjectManager::QmakeProject;
if (!canHandle(parent))
return ids;
return QList<Core::Id>();
QmakeProjectManager::QmakeProject *qt4Project = qobject_cast<QmakeProjectManager::QmakeProject *>(parent->project());
QmakeProject *qt4Project = qobject_cast<QmakeProject *>(parent->project());
if (!qt4Project)
return ids;
return QList<Core::Id>();
QList<QmakeProjectManager::QmakeProFileNode *> nodes = qt4Project->applicationProFiles();
return QmakeProjectManager::QmakeProject::idsForNodes(Core::Id(Constants::QNX_BB_RUNCONFIGURATION_PREFIX),
nodes);
QList<QmakeProjectManager::QmakeProFileNode *> nodes = qt4Project->applicationProFiles();
if (mode == AutoCreate)
nodes = QmakeProject::nodesWithQtcRunnable(nodes);
return QmakeProject::idsForNodes(Core::Id(Constants::QNX_QNX_RUNCONFIGURATION_PREFIX),
nodes);
}
QString BlackBerryRunConfigurationFactory::displayNameForId(const Core::Id id) const
......
......@@ -34,6 +34,8 @@
#include <projectexplorer/runconfiguration.h>
namespace QmakeProjectManager { class QmakeProFileNode; }
namespace Qnx {
namespace Internal {
......@@ -43,7 +45,7 @@ class BlackBerryRunConfigurationFactory : public ProjectExplorer::IRunConfigurat
public:
explicit BlackBerryRunConfigurationFactory(QObject *parent = 0);
QList<Core::Id> availableCreationIds(ProjectExplorer::Target *parent) const;
QList<Core::Id> availableCreationIds(ProjectExplorer::Target *parent, CreationMode mode) const;
QString displayNameForId(const Core::Id id) const;
bool canCreate(ProjectExplorer::Target *parent, const Core::Id id) const;
......
......@@ -38,6 +38,7 @@
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/target.h>
#include <qmakeprojectmanager/qmakeproject.h>
#include <qmakeprojectmanager/qmakenodes.h>
using namespace Qnx;
using namespace Qnx::Internal;
......@@ -52,18 +53,22 @@ QnxRunConfigurationFactory::QnxRunConfigurationFactory(QObject *parent) :
{
}
QList<Core::Id> QnxRunConfigurationFactory::availableCreationIds(ProjectExplorer::Target *parent) const
QList<Core::Id> QnxRunConfigurationFactory::availableCreationIds(ProjectExplorer::Target *parent, CreationMode mode) const
{
QList<Core::Id> ids;
using QmakeProjectManager::QmakeProject;
if (!canHandle(parent))
return ids;
return QList<Core::Id>();
QmakeProjectManager::QmakeProject *qt4Project = qobject_cast<QmakeProjectManager::QmakeProject *>(parent->project());
QmakeProject *qt4Project = qobject_cast<QmakeProject *>(parent->project());
if (!qt4Project)
return ids;
return QList<Core::Id>();
QList<QmakeProjectManager::QmakeProFileNode *> nodes = qt4Project->applicationProFiles();
return QmakeProjectManager::QmakeProject::idsForNodes(Core::Id(Constants::QNX_QNX_RUNCONFIGURATION_PREFIX),
nodes);
if (mode == AutoCreate)
nodes = QmakeProject::nodesWithQtcRunnable(nodes);
return QmakeProject::idsForNodes(Core::Id(Constants::QNX_QNX_RUNCONFIGURATION_PREFIX),
nodes);
}
QString QnxRunConfigurationFactory::displayNameForId(const Core::Id id) const
......
......@@ -34,6 +34,8 @@
#include <projectexplorer/runconfiguration.h>
namespace QmakeProjectManager { class QmakeProFileNode; }
namespace Qnx {
namespace Internal {
......@@ -43,7 +45,7 @@ class QnxRunConfigurationFactory : public ProjectExplorer::IRunConfigurationFact
public:
explicit QnxRunConfigurationFactory(QObject *parent = 0);
QList<Core::Id> availableCreationIds(ProjectExplorer::Target *parent) const;
QList<Core::Id> availableCreationIds(ProjectExplorer::Target *parent, CreationMode mode) const;
QString displayNameForId(const Core::Id id) const;
bool canCreate(ProjectExplorer::Target *parent, const Core::Id id) const;
......
......@@ -367,8 +367,9 @@ bool CustomExecutableRunConfigurationFactory::canHandle(Target *parent) const
return parent->project()->supportsKit(parent->kit());
}
QList<Core::Id> CustomExecutableRunConfigurationFactory::availableCreationIds(Target *parent) const
QList<Core::Id> CustomExecutableRunConfigurationFactory::availableCreationIds(Target *parent, CreationMode mode) const
{
Q_UNUSED(mode)
if (!canHandle(parent))
return QList<Core::Id>();
return QList<Core::Id>() << Core::Id(CUSTOM_EXECUTABLE_ID);
......
......@@ -112,7 +112,7 @@ public:
explicit CustomExecutableRunConfigurationFactory(QObject *parent = 0);
~CustomExecutableRunConfigurationFactory();
QList<Core::Id> availableCreationIds(ProjectExplorer::Target *parent) const;
QList<Core::Id> availableCreationIds(ProjectExplorer::Target *parent, CreationMode mode) const;
QString displayNameForId(const Core::Id id) const;
bool canCreate(ProjectExplorer::Target *parent, const Core::Id id) const;
......
......@@ -49,7 +49,10 @@ namespace Internal {
namespace {
QString pathFromId(Core::Id id)
{
return id.suffixAfter(RemoteLinuxRunConfiguration::IdPrefix);
QByteArray idStr = id.name();
if (!idStr.startsWith(RemoteLinuxRunConfiguration::IdPrefix))
return QString();
return QString::fromUtf8(idStr.mid(strlen(RemoteLinuxRunConfiguration::IdPrefix)));
}
} // namespace
......@@ -88,8 +91,9 @@ bool RemoteLinuxRunConfigurationFactory::canClone(Target *parent, RunConfigurati
return rlrc && canCreate(parent, source->id());
}
QList<Core::Id> RemoteLinuxRunConfigurationFactory::availableCreationIds(Target *parent) const
QList<Core::Id> RemoteLinuxRunConfigurationFactory::availableCreationIds(Target *parent, CreationMode mode) const
{
Q_UNUSED(mode)
QList<Core::Id> result;
if (!canHandle(parent))
return result;
......
......@@ -43,7 +43,7 @@ public:
~RemoteLinuxRunConfigurationFactory();
QString displayNameForId(const Core::Id id) const;
QList<Core::Id> availableCreationIds(ProjectExplorer::Target *parent) const;
QList<Core::Id> availableCreationIds(ProjectExplorer::Target *parent, CreationMode mode) const;
bool canCreate(ProjectExplorer::Target *parent, const Core::Id id) const;
......
......@@ -72,8 +72,9 @@ WinRtRunConfigurationFactory::WinRtRunConfigurationFactory()
{
}
QList<Core::Id> WinRtRunConfigurationFactory::availableCreationIds(Target *parent) const
QList<Core::Id> WinRtRunConfigurationFactory::availableCreationIds(Target *parent, CreationMode mode) const
{
Q_UNUSED(mode)
QList<Core::Id> result;
if (isKitCompatible(parent->kit()))
result.append(Core::Id(winrtConfigurationIdC));
......
......@@ -43,7 +43,7 @@ class WinRtRunConfigurationFactory : public ProjectExplorer::IRunConfigurationF
public:
WinRtRunConfigurationFactory();
QList<Core::Id> availableCreationIds(ProjectExplorer::Target *parent) const;
QList<Core::Id> availableCreationIds(ProjectExplorer::Target *parent, CreationMode mode) const;
QString displayNameForId(const Core::Id id) const;
bool canCreate(ProjectExplorer::Target *parent, const Core::Id id) const;
bool canRestore(ProjectExplorer::Target *parent, const QVariantMap &map) const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment