ProjectExplorer: Add function for retrieving toolchain factory by type

Change-Id: I0968738c50e7fce56a016c4801054131a1ea33c9
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Kandeler
2024-07-11 13:03:12 +02:00
parent a67d95d138
commit ec5e055a90
4 changed files with 26 additions and 32 deletions

View File

@@ -447,13 +447,8 @@ static Toolchain *armGccToolchain(const FilePath &path, Id language)
return t->compilerCommand() == path && t->language() == language;
});
if (!toolChain) {
ToolchainFactory *gccFactory
= Utils::findOrDefault(ToolchainFactory::allToolchainFactories(),
[](ToolchainFactory *f) {
return f->supportedToolchainType()
== ProjectExplorer::Constants::GCC_TOOLCHAIN_TYPEID;
});
if (gccFactory) {
if (ToolchainFactory * const gccFactory = ToolchainFactory::factoryForType(
ProjectExplorer::Constants::GCC_TOOLCHAIN_TYPEID)) {
const QList<Toolchain *> detected = gccFactory->detectForImport({path, language});
if (!detected.isEmpty()) {
toolChain = detected.first();
@@ -474,13 +469,8 @@ static Toolchain *iarToolchain(const FilePath &path, Id language)
&& t->language() == language;
});
if (!toolChain) {
ToolchainFactory *iarFactory
= Utils::findOrDefault(ToolchainFactory::allToolchainFactories(),
[](ToolchainFactory *f) {
return f->supportedToolchainType()
== BareMetal::Constants::IAREW_TOOLCHAIN_TYPEID;
});
if (iarFactory) {
if (ToolchainFactory * const iarFactory = ToolchainFactory::factoryForType(
BareMetal::Constants::IAREW_TOOLCHAIN_TYPEID)) {
Toolchains detected = iarFactory->autoDetect(
{{}, DeviceManager::defaultDesktopDevice(), {}});
if (detected.isEmpty())

View File

@@ -220,17 +220,15 @@ bool Toolchain::operator == (const Toolchain &tc) const
Toolchain *Toolchain::clone() const
{
for (ToolchainFactory *f : std::as_const(toolchainFactories())) {
if (f->supportedToolchainType() == d->m_typeId) {
Toolchain *tc = f->create();
QTC_ASSERT(tc, return nullptr);
Store data;
toMap(data);
tc->fromMap(data);
// New ID for the clone. It's different.
tc->d->m_id = QUuid::createUuid().toByteArray();
return tc;
}
if (ToolchainFactory *const f = ToolchainFactory::factoryForType(d->m_typeId)) {
Toolchain *tc = f->create();
QTC_ASSERT(tc, return nullptr);
Store data;
toMap(data);
tc->fromMap(data);
// New ID for the clone. It's different.
tc->d->m_id = QUuid::createUuid().toByteArray();
return tc;
}
QTC_CHECK(false);
return nullptr;
@@ -573,6 +571,13 @@ const QList<ToolchainFactory *> ToolchainFactory::allToolchainFactories()
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
{
Q_UNUSED(detector)

View File

@@ -265,6 +265,7 @@ public:
virtual ~ToolchainFactory();
static const QList<ToolchainFactory *> allToolchainFactories();
static ToolchainFactory *factoryForType(Utils::Id typeId);
QString displayName() const { return m_displayName; }
Utils::Id supportedToolchainType() const;

View File

@@ -267,13 +267,11 @@ Toolchains ToolchainSettingsAccessor::toolChains(const Store &data) const
bool restored = false;
const Utils::Id tcType = ToolchainFactory::typeIdFromMap(tcMap);
if (tcType.isValid()) {
for (ToolchainFactory *f : factories) {
if (f->supportedToolchainType() == tcType) {
if (Toolchain *tc = f->restore(tcMap)) {
result.append(tc);
restored = true;
break;
}
if (ToolchainFactory * const f = ToolchainFactory::factoryForType(tcType)) {
if (Toolchain *tc = f->restore(tcMap)) {
result.append(tc);
restored = true;
break;
}
}
}