Commit c3192d90 authored by Tobias Hunger's avatar Tobias Hunger

ToolChain: Introduce typeId() and shorten id()

Split up the toolchain id() into a part that is unique per type of
toolchain and call that typeId(). Leave the part that is unique per
toolchain in id().

Add some mapping code for compatibility old settings.

Change-Id: I770881b3274ac5224edc8165b484fec6b0d4d2c6
Reviewed-by: default avatarDaniel Teske <daniel.teske@theqtcompany.com>
parent 26eca3d1
......@@ -47,11 +47,11 @@ namespace ProjectExplorer {
namespace Internal {
AbstractMsvcToolChain::AbstractMsvcToolChain(const QByteArray &id,
AbstractMsvcToolChain::AbstractMsvcToolChain(Core::Id typeId,
Detection d,
const Abi &abi,
const QString& vcvarsBat) :
ToolChain(id, d),
ToolChain(typeId, d),
m_lastEnvironment(Utils::Environment::systemEnvironment()),
m_abi(abi),
m_vcvarsBat(vcvarsBat)
......@@ -62,8 +62,8 @@ AbstractMsvcToolChain::AbstractMsvcToolChain(const QByteArray &id,
Q_ASSERT(!m_vcvarsBat.isEmpty());
}
AbstractMsvcToolChain::AbstractMsvcToolChain(const QByteArray &id, Detection d) :
ToolChain(id, d),
AbstractMsvcToolChain::AbstractMsvcToolChain(Core::Id typeId, Detection d) :
ToolChain(typeId, d),
m_lastEnvironment(Utils::Environment::systemEnvironment())
{ }
......
......@@ -44,8 +44,8 @@ namespace Internal {
class PROJECTEXPLORER_EXPORT AbstractMsvcToolChain : public ToolChain
{
public:
explicit AbstractMsvcToolChain(const QByteArray &id, Detection d, const Abi &abi, const QString& vcvarsBat);
explicit AbstractMsvcToolChain(const QByteArray &id, Detection d);
explicit AbstractMsvcToolChain(Core::Id typeId, Detection d, const Abi &abi, const QString& vcvarsBat);
explicit AbstractMsvcToolChain(Core::Id typeId, Detection d);
Abi targetAbi() const override;
......
......@@ -248,8 +248,8 @@ GccToolChain::GccToolChain(Detection d) :
ToolChain(Constants::GCC_TOOLCHAIN_ID, d)
{ }
GccToolChain::GccToolChain(const QByteArray &id, Detection d) :
ToolChain(id, d)
GccToolChain::GccToolChain(Core::Id typeId, Detection d) :
ToolChain(typeId, d)
{ }
void GccToolChain::setCompilerCommand(const FileName &path)
......
......@@ -57,7 +57,7 @@ class LinuxIccToolChainFactory;
class PROJECTEXPLORER_EXPORT GccToolChain : public ToolChain
{
public:
GccToolChain(const QByteArray &id, Detection d);
GccToolChain(Core::Id typeId, Detection d);
QString type() const override;
QString typeDisplayName() const override;
Abi targetAbi() const override;
......
......@@ -36,6 +36,7 @@
#include "task.h"
#include <utils/fileutils.h>
#include <utils/qtcassert.h>
#include <QCoreApplication>
#include <QUuid>
......@@ -56,20 +57,14 @@ class ToolChainPrivate
public:
typedef ToolChain::Detection Detection;
explicit ToolChainPrivate(const QByteArray &id, Detection d) :
explicit ToolChainPrivate(Core::Id typeId, Detection d) :
m_id(QUuid::createUuid().toByteArray()),
m_typeId(typeId),
m_detection(d)
{
m_id = createId(id);
}
static QByteArray createId(const QByteArray &id)
{
QByteArray newId = id.left(id.indexOf(':'));
newId.append(':' + QUuid::createUuid().toByteArray());
return newId;
}
{ }
QByteArray m_id;
Core::Id m_typeId;
Detection m_detection;
mutable QString m_displayName;
};
......@@ -84,12 +79,12 @@ public:
// --------------------------------------------------------------------------
ToolChain::ToolChain(const QByteArray &id, Detection d) :
d(new Internal::ToolChainPrivate(id, d))
ToolChain::ToolChain(Core::Id typeId, Detection d) :
d(new Internal::ToolChainPrivate(typeId, d))
{ }
ToolChain::ToolChain(const ToolChain &other) :
d(new Internal::ToolChainPrivate(other.d->m_id, ManualDetection))
d(new Internal::ToolChainPrivate(other.d->m_typeId, ManualDetection))
{
// leave the autodetection bit at false.
d->m_displayName = QCoreApplication::translate("ProjectExplorer::ToolChain", "Clone of %1")
......@@ -137,6 +132,11 @@ Utils::FileName ToolChain::suggestedDebugger() const
return ToolChainManager::defaultDebugger(targetAbi());
}
Core::Id ToolChain::typeId() const
{
return d->m_typeId;
}
bool ToolChain::canClone() const
{
return true;
......@@ -147,11 +147,8 @@ bool ToolChain::operator == (const ToolChain &tc) const
if (this == &tc)
return true;
const QByteArray thisId = id().left(id().indexOf(':'));
const QByteArray tcId = tc.id().left(tc.id().indexOf(':'));
// We ignore displayname
return thisId == tcId && isAutoDetected() == tc.isAutoDetected();
return typeId() == tc.typeId() && isAutoDetected() == tc.isAutoDetected();
}
/*!
......@@ -163,7 +160,8 @@ bool ToolChain::operator == (const ToolChain &tc) const
QVariantMap ToolChain::toMap() const
{
QVariantMap result;
result.insert(QLatin1String(ID_KEY), QString::fromUtf8(id()));
QString idToSave = d->m_typeId.toString() + QLatin1Char(':') + QString::fromUtf8(id());
result.insert(QLatin1String(ID_KEY), idToSave);
result.insert(QLatin1String(DISPLAY_NAME_KEY), displayName());
result.insert(QLatin1String(AUTODETECT_KEY), isAutoDetected());
......@@ -192,8 +190,14 @@ void ToolChain::setDetection(ToolChain::Detection de)
bool ToolChain::fromMap(const QVariantMap &data)
{
d->m_displayName = data.value(QLatin1String(DISPLAY_NAME_KEY)).toString();
// make sure we have new style ids:
d->m_id = data.value(QLatin1String(ID_KEY)).toByteArray();
const QString id = data.value(QLatin1String(ID_KEY)).toString();
int pos = id.indexOf(QLatin1Char(':'));
QTC_ASSERT(pos > 0, return false);
d->m_typeId = Core::Id::fromString(id.left(pos));
d->m_id = id.mid(pos).toUtf8();
const bool autoDetect = data.value(QLatin1String(AUTODETECT_KEY), false).toBool();
d->m_detection = autoDetect ? AutoDetectionFromSettings : ManualDetection;
......@@ -262,11 +266,6 @@ QByteArray ToolChainFactory::idFromMap(const QVariantMap &data)
return data.value(QLatin1String(ID_KEY)).toByteArray();
}
void ToolChainFactory::idToMap(QVariantMap &data, const QString id)
{
data.insert(QLatin1String(ID_KEY), id);
}
void ToolChainFactory::autoDetectionToMap(QVariantMap &data, bool detected)
{
data.insert(QLatin1String(AUTODETECT_KEY), detected);
......
......@@ -83,6 +83,7 @@ public:
virtual Utils::FileName suggestedDebugger() const;
virtual QString type() const = 0;
Core::Id typeId() const;
virtual QString typeDisplayName() const = 0;
virtual Abi targetAbi() const = 0;
......@@ -157,7 +158,7 @@ public:
virtual QVariantMap toMap() const;
virtual QList<Task> validateKit(const Kit *k) const;
protected:
explicit ToolChain(const QByteArray &id, Detection d);
explicit ToolChain(Core::Id typeId, Detection d);
explicit ToolChain(const ToolChain &);
void toolChainUpdated();
......@@ -191,7 +192,6 @@ public:
virtual ToolChain *restore(const QVariantMap &data);
static QByteArray idFromMap(const QVariantMap &data);
static void idToMap(QVariantMap &data, const QString id);
static void autoDetectionToMap(QVariantMap &data, bool detected);
protected:
......
......@@ -299,7 +299,19 @@ ToolChain *ToolChainManager::findToolChain(const QByteArray &id)
if (id.isEmpty())
return 0;
return Utils::findOrDefault(d->m_toolChains, Utils::equal(&ToolChain::id, id));
ToolChain *tc = Utils::findOrDefault(d->m_toolChains, Utils::equal(&ToolChain::id, id));
// Compatibility with versions 3.5 and earlier:
if (!tc) {
const int pos = id.indexOf(':');
if (pos < 0)
return tc;
const QByteArray shortId = id.mid(pos + 1);
tc = Utils::findOrDefault(d->m_toolChains, Utils::equal(&ToolChain::id, shortId));
}
return tc;
}
FileName ToolChainManager::defaultDebugger(const Abi &abi)
......
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