forked from qt-creator/qt-creator
ProjectExplorer: Add function for retrieving toolchain factory by type
Change-Id: I0968738c50e7fce56a016c4801054131a1ea33c9 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -447,13 +447,8 @@ static Toolchain *armGccToolchain(const FilePath &path, Id language)
|
|||||||
return t->compilerCommand() == path && t->language() == language;
|
return t->compilerCommand() == path && t->language() == language;
|
||||||
});
|
});
|
||||||
if (!toolChain) {
|
if (!toolChain) {
|
||||||
ToolchainFactory *gccFactory
|
if (ToolchainFactory * const gccFactory = ToolchainFactory::factoryForType(
|
||||||
= Utils::findOrDefault(ToolchainFactory::allToolchainFactories(),
|
ProjectExplorer::Constants::GCC_TOOLCHAIN_TYPEID)) {
|
||||||
[](ToolchainFactory *f) {
|
|
||||||
return f->supportedToolchainType()
|
|
||||||
== ProjectExplorer::Constants::GCC_TOOLCHAIN_TYPEID;
|
|
||||||
});
|
|
||||||
if (gccFactory) {
|
|
||||||
const QList<Toolchain *> detected = gccFactory->detectForImport({path, language});
|
const QList<Toolchain *> detected = gccFactory->detectForImport({path, language});
|
||||||
if (!detected.isEmpty()) {
|
if (!detected.isEmpty()) {
|
||||||
toolChain = detected.first();
|
toolChain = detected.first();
|
||||||
@@ -474,13 +469,8 @@ static Toolchain *iarToolchain(const FilePath &path, Id language)
|
|||||||
&& t->language() == language;
|
&& t->language() == language;
|
||||||
});
|
});
|
||||||
if (!toolChain) {
|
if (!toolChain) {
|
||||||
ToolchainFactory *iarFactory
|
if (ToolchainFactory * const iarFactory = ToolchainFactory::factoryForType(
|
||||||
= Utils::findOrDefault(ToolchainFactory::allToolchainFactories(),
|
BareMetal::Constants::IAREW_TOOLCHAIN_TYPEID)) {
|
||||||
[](ToolchainFactory *f) {
|
|
||||||
return f->supportedToolchainType()
|
|
||||||
== BareMetal::Constants::IAREW_TOOLCHAIN_TYPEID;
|
|
||||||
});
|
|
||||||
if (iarFactory) {
|
|
||||||
Toolchains detected = iarFactory->autoDetect(
|
Toolchains detected = iarFactory->autoDetect(
|
||||||
{{}, DeviceManager::defaultDesktopDevice(), {}});
|
{{}, DeviceManager::defaultDesktopDevice(), {}});
|
||||||
if (detected.isEmpty())
|
if (detected.isEmpty())
|
||||||
|
|||||||
@@ -220,8 +220,7 @@ bool Toolchain::operator == (const Toolchain &tc) const
|
|||||||
|
|
||||||
Toolchain *Toolchain::clone() const
|
Toolchain *Toolchain::clone() const
|
||||||
{
|
{
|
||||||
for (ToolchainFactory *f : std::as_const(toolchainFactories())) {
|
if (ToolchainFactory *const f = ToolchainFactory::factoryForType(d->m_typeId)) {
|
||||||
if (f->supportedToolchainType() == d->m_typeId) {
|
|
||||||
Toolchain *tc = f->create();
|
Toolchain *tc = f->create();
|
||||||
QTC_ASSERT(tc, return nullptr);
|
QTC_ASSERT(tc, return nullptr);
|
||||||
Store data;
|
Store data;
|
||||||
@@ -231,7 +230,6 @@ Toolchain *Toolchain::clone() const
|
|||||||
tc->d->m_id = QUuid::createUuid().toByteArray();
|
tc->d->m_id = QUuid::createUuid().toByteArray();
|
||||||
return tc;
|
return tc;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
QTC_CHECK(false);
|
QTC_CHECK(false);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@@ -573,6 +571,13 @@ const QList<ToolchainFactory *> ToolchainFactory::allToolchainFactories()
|
|||||||
return toolchainFactories();
|
return toolchainFactories();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ToolchainFactory *ToolchainFactory::factoryForType(Id typeId)
|
||||||
|
{
|
||||||
|
return Utils::findOrDefault(allToolchainFactories(), [typeId](ToolchainFactory *factory) {
|
||||||
|
return factory->supportedToolchainType() == typeId;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Toolchains ToolchainFactory::autoDetect(const ToolchainDetector &detector) const
|
Toolchains ToolchainFactory::autoDetect(const ToolchainDetector &detector) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(detector)
|
Q_UNUSED(detector)
|
||||||
|
|||||||
@@ -265,6 +265,7 @@ public:
|
|||||||
virtual ~ToolchainFactory();
|
virtual ~ToolchainFactory();
|
||||||
|
|
||||||
static const QList<ToolchainFactory *> allToolchainFactories();
|
static const QList<ToolchainFactory *> allToolchainFactories();
|
||||||
|
static ToolchainFactory *factoryForType(Utils::Id typeId);
|
||||||
|
|
||||||
QString displayName() const { return m_displayName; }
|
QString displayName() const { return m_displayName; }
|
||||||
Utils::Id supportedToolchainType() const;
|
Utils::Id supportedToolchainType() const;
|
||||||
|
|||||||
@@ -267,8 +267,7 @@ Toolchains ToolchainSettingsAccessor::toolChains(const Store &data) const
|
|||||||
bool restored = false;
|
bool restored = false;
|
||||||
const Utils::Id tcType = ToolchainFactory::typeIdFromMap(tcMap);
|
const Utils::Id tcType = ToolchainFactory::typeIdFromMap(tcMap);
|
||||||
if (tcType.isValid()) {
|
if (tcType.isValid()) {
|
||||||
for (ToolchainFactory *f : factories) {
|
if (ToolchainFactory * const f = ToolchainFactory::factoryForType(tcType)) {
|
||||||
if (f->supportedToolchainType() == tcType) {
|
|
||||||
if (Toolchain *tc = f->restore(tcMap)) {
|
if (Toolchain *tc = f->restore(tcMap)) {
|
||||||
result.append(tc);
|
result.append(tc);
|
||||||
restored = true;
|
restored = true;
|
||||||
@@ -276,7 +275,6 @@ Toolchains ToolchainSettingsAccessor::toolChains(const Store &data) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (!restored)
|
if (!restored)
|
||||||
qWarning("Warning: Unable to restore compiler type '%s' for tool chain %s.",
|
qWarning("Warning: Unable to restore compiler type '%s' for tool chain %s.",
|
||||||
qPrintable(tcType.toString()),
|
qPrintable(tcType.toString()),
|
||||||
|
|||||||
Reference in New Issue
Block a user