From bf8392637215b4eb7d34a3c0c84008c43faf81ae Mon Sep 17 00:00:00 2001 From: hjk Date: Fri, 14 Jun 2019 12:06:26 +0200 Subject: [PATCH] ProjectExplorer: Add a central ToolChainFactory::createToolChain(type) This is meant to be the only function directly creating tool chain objects in the long run (and also the only one setting ids, removing the need to spell them out in the individual constructors). Change-Id: Idef242612a5a3f7012628b4080a03d6ee70e5ba0 Reviewed-by: Christian Kandeler --- src/plugins/ios/iosconfigurations.cpp | 4 ++-- src/plugins/projectexplorer/toolchain.cpp | 13 +++++++++++++ src/plugins/projectexplorer/toolchain.h | 2 ++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/plugins/ios/iosconfigurations.cpp b/src/plugins/ios/iosconfigurations.cpp index 6f9e134cc98..928a6ec8c25 100644 --- a/src/plugins/ios/iosconfigurations.cpp +++ b/src/plugins/ios/iosconfigurations.cpp @@ -575,7 +575,7 @@ ProvisioningProfilePtr IosConfigurations::provisioningProfile(const QString &pro Utils::equal(&ProvisioningProfile::identifier, profileID)); } -static ClangToolChain *createToolChain(const XcodePlatform &platform, +static ClangToolChain *createIosToolChain(const XcodePlatform &platform, const XcodePlatform::ToolchainTarget &target, Core::Id l) { @@ -616,7 +616,7 @@ QList IosToolChainFactory::autoDetect(const QList &exi existingClangToolChains); auto createOrAdd = [&](ClangToolChain* toolChain, Core::Id l) { if (!toolChain) { - toolChain = createToolChain(platform, target, l); + toolChain = createIosToolChain(platform, target, l); existingClangToolChains.append(toolChain); } toolChains.append(toolChain); diff --git a/src/plugins/projectexplorer/toolchain.cpp b/src/plugins/projectexplorer/toolchain.cpp index ccc47381d84..76041a38d8e 100644 --- a/src/plugins/projectexplorer/toolchain.cpp +++ b/src/plugins/projectexplorer/toolchain.cpp @@ -486,6 +486,19 @@ void ToolChainFactory::autoDetectionToMap(QVariantMap &data, bool detected) data.insert(QLatin1String(AUTODETECT_KEY), detected); } +ToolChain *ToolChainFactory::createToolChain(Core::Id toolChainType) +{ + for (ToolChainFactory *factory : qAsConst(Internal::g_toolChainFactories)) { + if (factory->m_supportedToolChainType == toolChainType) { + if (ToolChain *tc = factory->create()) { + tc->d->m_typeId = toolChainType; + return tc; + } + } + } + return nullptr; +} + QSet ToolChainFactory::supportedLanguages() const { return m_supportsAllLanguages ? ToolChainManager::allLanguages() : m_supportedLanguages; diff --git a/src/plugins/projectexplorer/toolchain.h b/src/plugins/projectexplorer/toolchain.h index a6399a310e0..cbac188278e 100644 --- a/src/plugins/projectexplorer/toolchain.h +++ b/src/plugins/projectexplorer/toolchain.h @@ -206,6 +206,8 @@ public: static Core::Id typeIdFromMap(const QVariantMap &data); static void autoDetectionToMap(QVariantMap &data, bool detected); + static ToolChain *createToolChain(Core::Id toolChainType); + QSet supportedLanguages() const; void setUserCreatable(bool userCreatable);