forked from qt-creator/qt-creator
ProjectExplorer: Code cosmetics in toolchain.cpp
Mostly namespaces, but also centralize access to the factory list for better debugging. Change-Id: Ic8b19b8c110dc925e0f7ae27af1da2b9e1ec6086 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -14,7 +14,6 @@
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QUuid>
|
||||
|
||||
@@ -22,18 +21,22 @@
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
static const char ID_KEY[] = "ProjectExplorer.ToolChain.Id";
|
||||
static const char DISPLAY_NAME_KEY[] = "ProjectExplorer.ToolChain.DisplayName";
|
||||
static const char AUTODETECT_KEY[] = "ProjectExplorer.ToolChain.Autodetect";
|
||||
static const char DETECTION_SOURCE_KEY[] = "ProjectExplorer.ToolChain.DetectionSource";
|
||||
static const char LANGUAGE_KEY_V1[] = "ProjectExplorer.ToolChain.Language"; // For QtCreator <= 4.2
|
||||
static const char LANGUAGE_KEY_V2[] = "ProjectExplorer.ToolChain.LanguageV2"; // For QtCreator > 4.2
|
||||
const char CODE_MODEL_TRIPLE_KEY[] = "ExplicitCodeModelTargetTriple";
|
||||
|
||||
namespace ProjectExplorer {
|
||||
namespace Internal {
|
||||
|
||||
static QList<ToolChainFactory *> g_toolChainFactories;
|
||||
const char ID_KEY[] = "ProjectExplorer.ToolChain.Id";
|
||||
const char DISPLAY_NAME_KEY[] = "ProjectExplorer.ToolChain.DisplayName";
|
||||
const char AUTODETECT_KEY[] = "ProjectExplorer.ToolChain.Autodetect";
|
||||
const char DETECTION_SOURCE_KEY[] = "ProjectExplorer.ToolChain.DetectionSource";
|
||||
const char LANGUAGE_KEY_V1[] = "ProjectExplorer.ToolChain.Language"; // For QtCreator <= 4.2
|
||||
const char LANGUAGE_KEY_V2[] = "ProjectExplorer.ToolChain.LanguageV2"; // For QtCreator > 4.2
|
||||
const char CODE_MODEL_TRIPLE_KEY[] = "ExplicitCodeModelTargetTriple";
|
||||
|
||||
QList<ToolChainFactory *> &toolChainFactories()
|
||||
{
|
||||
static QList<ToolChainFactory *> theToolChainFactories;
|
||||
return theToolChainFactories;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// ToolChainPrivate
|
||||
@@ -44,7 +47,7 @@ class ToolChainPrivate
|
||||
public:
|
||||
using Detection = ToolChain::Detection;
|
||||
|
||||
explicit ToolChainPrivate(Utils::Id typeId) :
|
||||
explicit ToolChainPrivate(Id typeId) :
|
||||
m_id(QUuid::createUuid().toByteArray()),
|
||||
m_typeId(typeId),
|
||||
m_predefinedMacrosCache(new ToolChain::MacrosCache::element_type()),
|
||||
@@ -59,11 +62,11 @@ public:
|
||||
QString m_compilerCommandKey;
|
||||
Abi m_targetAbi;
|
||||
QString m_targetAbiKey;
|
||||
QSet<Utils::Id> m_supportedLanguages;
|
||||
QSet<Id> m_supportedLanguages;
|
||||
mutable QString m_displayName;
|
||||
QString m_typeDisplayName;
|
||||
Utils::Id m_typeId;
|
||||
Utils::Id m_language;
|
||||
Id m_typeId;
|
||||
Id m_language;
|
||||
Detection m_detection = ToolChain::UninitializedDetection;
|
||||
QString m_detectionSource;
|
||||
QString m_explicitCodeModelTargetTriple;
|
||||
@@ -76,24 +79,24 @@ public:
|
||||
|
||||
// Deprecated used from QtCreator <= 4.2
|
||||
|
||||
Utils::Id fromLanguageV1(int language)
|
||||
Id fromLanguageV1(int language)
|
||||
{
|
||||
switch (language)
|
||||
{
|
||||
case Deprecated::Toolchain::C :
|
||||
return Utils::Id(Constants::C_LANGUAGE_ID);
|
||||
return Id(Constants::C_LANGUAGE_ID);
|
||||
case Deprecated::Toolchain::Cxx:
|
||||
return Utils::Id(Constants::CXX_LANGUAGE_ID);
|
||||
return Id(Constants::CXX_LANGUAGE_ID);
|
||||
case Deprecated::Toolchain::None:
|
||||
default:
|
||||
return Utils::Id();
|
||||
return Id();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
namespace Deprecated {
|
||||
namespace Toolchain {
|
||||
namespace Deprecated::Toolchain {
|
||||
|
||||
QString languageId(Language l)
|
||||
{
|
||||
switch (l) {
|
||||
@@ -106,8 +109,10 @@ QString languageId(Language l)
|
||||
};
|
||||
return QString();
|
||||
}
|
||||
} // namespace Toolchain
|
||||
} // namespace Deprecated
|
||||
|
||||
} // namespace Deprecated::ToolChain
|
||||
|
||||
using namespace Internal;
|
||||
|
||||
/*!
|
||||
\class ProjectExplorer::ToolChain
|
||||
@@ -117,12 +122,12 @@ QString languageId(Language l)
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
ToolChain::ToolChain(Utils::Id typeId) :
|
||||
d(std::make_unique<Internal::ToolChainPrivate>(typeId))
|
||||
ToolChain::ToolChain(Id typeId) :
|
||||
d(std::make_unique<ToolChainPrivate>(typeId))
|
||||
{
|
||||
}
|
||||
|
||||
void ToolChain::setLanguage(Utils::Id language)
|
||||
void ToolChain::setLanguage(Id language)
|
||||
{
|
||||
QTC_ASSERT(!d->m_language.isValid() || isAutoDetected(), return);
|
||||
QTC_ASSERT(language.isValid(), return);
|
||||
@@ -174,7 +179,7 @@ QStringList ToolChain::suggestedMkspecList() const
|
||||
return {};
|
||||
}
|
||||
|
||||
Utils::Id ToolChain::typeId() const
|
||||
Id ToolChain::typeId() const
|
||||
{
|
||||
return d->m_typeId;
|
||||
}
|
||||
@@ -199,7 +204,7 @@ FilePaths ToolChain::includedFiles(const QStringList &flags, const FilePath &dir
|
||||
return {};
|
||||
}
|
||||
|
||||
Utils::Id ToolChain::language() const
|
||||
Id ToolChain::language() const
|
||||
{
|
||||
return d->m_language;
|
||||
}
|
||||
@@ -217,7 +222,7 @@ bool ToolChain::operator == (const ToolChain &tc) const
|
||||
|
||||
ToolChain *ToolChain::clone() const
|
||||
{
|
||||
for (ToolChainFactory *f : std::as_const(Internal::g_toolChainFactories)) {
|
||||
for (ToolChainFactory *f : std::as_const(toolChainFactories())) {
|
||||
if (f->supportedToolChainType() == d->m_typeId) {
|
||||
ToolChain *tc = f->create();
|
||||
QTC_ASSERT(tc, return nullptr);
|
||||
@@ -354,7 +359,7 @@ bool ToolChain::fromMap(const QVariantMap &data)
|
||||
const QString id = data.value(QLatin1String(ID_KEY)).toString();
|
||||
int pos = id.indexOf(QLatin1Char(':'));
|
||||
QTC_ASSERT(pos > 0, return false);
|
||||
d->m_typeId = Utils::Id::fromString(id.left(pos));
|
||||
d->m_typeId = Id::fromString(id.left(pos));
|
||||
d->m_id = id.mid(pos + 1).toUtf8();
|
||||
|
||||
const bool autoDetect = data.value(QLatin1String(AUTODETECT_KEY), false).toBool();
|
||||
@@ -369,15 +374,15 @@ bool ToolChain::fromMap(const QVariantMap &data)
|
||||
const QString langId = data.value(QLatin1String(LANGUAGE_KEY_V2)).toString();
|
||||
const int pos = langId.lastIndexOf('.');
|
||||
if (pos >= 0)
|
||||
d->m_language = Utils::Id::fromString(langId.mid(pos + 1));
|
||||
d->m_language = Id::fromString(langId.mid(pos + 1));
|
||||
else
|
||||
d->m_language = Utils::Id::fromString(langId);
|
||||
d->m_language = Id::fromString(langId);
|
||||
} else if (data.contains(LANGUAGE_KEY_V1)) { // Import from old settings
|
||||
d->m_language = Internal::fromLanguageV1(data.value(QLatin1String(LANGUAGE_KEY_V1)).toInt());
|
||||
}
|
||||
|
||||
if (!d->m_language.isValid())
|
||||
d->m_language = Utils::Id(Constants::CXX_LANGUAGE_ID);
|
||||
d->m_language = Id(Constants::CXX_LANGUAGE_ID);
|
||||
|
||||
if (!d->m_targetAbiKey.isEmpty())
|
||||
d->m_targetAbi = Abi::fromString(data.value(d->m_targetAbiKey).toString());
|
||||
@@ -410,9 +415,8 @@ static long toLanguageVersionAsLong(QByteArray dateAsByteArray)
|
||||
return result;
|
||||
}
|
||||
|
||||
Utils::LanguageVersion ToolChain::cxxLanguageVersion(const QByteArray &cplusplusMacroValue)
|
||||
LanguageVersion ToolChain::cxxLanguageVersion(const QByteArray &cplusplusMacroValue)
|
||||
{
|
||||
using Utils::LanguageVersion;
|
||||
const long version = toLanguageVersionAsLong(cplusplusMacroValue);
|
||||
|
||||
if (version > 201703L)
|
||||
@@ -427,10 +431,8 @@ Utils::LanguageVersion ToolChain::cxxLanguageVersion(const QByteArray &cplusplus
|
||||
return LanguageVersion::CXX03;
|
||||
}
|
||||
|
||||
Utils::LanguageVersion ToolChain::languageVersion(const Utils::Id &language, const Macros ¯os)
|
||||
LanguageVersion ToolChain::languageVersion(const Id &language, const Macros ¯os)
|
||||
{
|
||||
using Utils::LanguageVersion;
|
||||
|
||||
if (language == Constants::CXX_LANGUAGE_ID) {
|
||||
for (const ProjectExplorer::Macro ¯o : macros) {
|
||||
if (macro.key == "__cplusplus") // Check for the C++ identifying macro
|
||||
@@ -548,17 +550,17 @@ void ToolChain::setExplicitCodeModelTargetTriple(const QString &triple)
|
||||
|
||||
ToolChainFactory::ToolChainFactory()
|
||||
{
|
||||
Internal::g_toolChainFactories.append(this);
|
||||
toolChainFactories().append(this);
|
||||
}
|
||||
|
||||
ToolChainFactory::~ToolChainFactory()
|
||||
{
|
||||
Internal::g_toolChainFactories.removeOne(this);
|
||||
toolChainFactories().removeOne(this);
|
||||
}
|
||||
|
||||
const QList<ToolChainFactory *> ToolChainFactory::allToolChainFactories()
|
||||
{
|
||||
return Internal::g_toolChainFactories;
|
||||
return toolChainFactories();
|
||||
}
|
||||
|
||||
Toolchains ToolChainFactory::autoDetect(const ToolchainDetector &detector) const
|
||||
@@ -611,9 +613,9 @@ QByteArray ToolChainFactory::idFromMap(const QVariantMap &data)
|
||||
return rawIdData(data).second.toUtf8();
|
||||
}
|
||||
|
||||
Utils::Id ToolChainFactory::typeIdFromMap(const QVariantMap &data)
|
||||
Id ToolChainFactory::typeIdFromMap(const QVariantMap &data)
|
||||
{
|
||||
return Utils::Id::fromString(rawIdData(data).first);
|
||||
return Id::fromString(rawIdData(data).first);
|
||||
}
|
||||
|
||||
void ToolChainFactory::autoDetectionToMap(QVariantMap &data, bool detected)
|
||||
@@ -621,9 +623,9 @@ void ToolChainFactory::autoDetectionToMap(QVariantMap &data, bool detected)
|
||||
data.insert(QLatin1String(AUTODETECT_KEY), detected);
|
||||
}
|
||||
|
||||
ToolChain *ToolChainFactory::createToolChain(Utils::Id toolChainType)
|
||||
ToolChain *ToolChainFactory::createToolChain(Id toolChainType)
|
||||
{
|
||||
for (ToolChainFactory *factory : std::as_const(Internal::g_toolChainFactories)) {
|
||||
for (ToolChainFactory *factory : std::as_const(toolChainFactories())) {
|
||||
if (factory->m_supportedToolChainType == toolChainType) {
|
||||
if (ToolChain *tc = factory->create()) {
|
||||
tc->d->m_typeId = toolChainType;
|
||||
@@ -634,22 +636,22 @@ ToolChain *ToolChainFactory::createToolChain(Utils::Id toolChainType)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QList<Utils::Id> ToolChainFactory::supportedLanguages() const
|
||||
QList<Id> ToolChainFactory::supportedLanguages() const
|
||||
{
|
||||
return m_supportsAllLanguages ? ToolChainManager::allLanguages() : m_supportedLanguages;
|
||||
}
|
||||
|
||||
Utils::Id ToolChainFactory::supportedToolChainType() const
|
||||
Id ToolChainFactory::supportedToolChainType() const
|
||||
{
|
||||
return m_supportedToolChainType;
|
||||
}
|
||||
|
||||
void ToolChainFactory::setSupportedToolChainType(const Utils::Id &supportedToolChain)
|
||||
void ToolChainFactory::setSupportedToolChainType(const Id &supportedToolChain)
|
||||
{
|
||||
m_supportedToolChainType = supportedToolChain;
|
||||
}
|
||||
|
||||
void ToolChainFactory::setSupportedLanguages(const QList<Utils::Id> &supportedLanguages)
|
||||
void ToolChainFactory::setSupportedLanguages(const QList<Id> &supportedLanguages)
|
||||
{
|
||||
m_supportedLanguages = supportedLanguages;
|
||||
}
|
||||
@@ -678,11 +680,11 @@ ToolchainDetector::ToolchainDetector(const Toolchains &alreadyKnown,
|
||||
QTC_CHECK(device);
|
||||
}
|
||||
|
||||
BadToolchain::BadToolchain(const Utils::FilePath &filePath)
|
||||
BadToolchain::BadToolchain(const FilePath &filePath)
|
||||
: BadToolchain(filePath, filePath.symLinkTarget(), filePath.lastModified())
|
||||
{}
|
||||
|
||||
BadToolchain::BadToolchain(const Utils::FilePath &filePath, const Utils::FilePath &symlinkTarget,
|
||||
BadToolchain::BadToolchain(const FilePath &filePath, const FilePath &symlinkTarget,
|
||||
const QDateTime ×tamp)
|
||||
: filePath(filePath), symlinkTarget(symlinkTarget), timestamp(timestamp)
|
||||
{}
|
||||
|
||||
Reference in New Issue
Block a user