WebAssembly: Move auto-detection into stand-alone function

Change-Id: I641946e62998371e6e45b6c6d75e069b8729eaa6
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
hjk
2022-01-24 15:14:09 +01:00
parent bd095d1ebe
commit 9b7f580a14
2 changed files with 43 additions and 44 deletions

View File

@@ -111,51 +111,7 @@ const QVersionNumber &WebAssemblyToolChain::minimumSupportedEmSdkVersion()
return number; return number;
} }
void WebAssemblyToolChain::registerToolChains() static Toolchains doAutoDetect(const ToolchainDetector &detector)
{
// Remove old toolchains
for (ToolChain *tc : ToolChainManager::findToolChains(toolChainAbi())) {
if (tc->detection() != ToolChain::AutoDetection)
continue;
ToolChainManager::deregisterToolChain(tc);
};
// Create new toolchains and register them
ToolChainFactory *factory =
findOrDefault(ToolChainFactory::allToolChainFactories(), [](ToolChainFactory *f){
return f->supportedToolChainType() == Constants::WEBASSEMBLY_TOOLCHAIN_TYPEID;
});
QTC_ASSERT(factory, return);
for (auto toolChain : factory->autoDetect(ToolchainDetector({}, {})))
ToolChainManager::registerToolChain(toolChain);
// Let kits pick up the new toolchains
for (Kit *kit : KitManager::kits()) {
if (!kit->isAutoDetected())
continue;
const QtVersion *qtVersion = QtKitAspect::qtVersion(kit);
if (!qtVersion || qtVersion->type() != Constants::WEBASSEMBLY_QT_VERSION)
continue;
kit->fix();
}
}
bool WebAssemblyToolChain::areToolChainsRegistered()
{
return !ToolChainManager::findToolChains(toolChainAbi()).isEmpty();
}
WebAssemblyToolChainFactory::WebAssemblyToolChainFactory()
{
setDisplayName(WebAssemblyToolChain::tr("Emscripten"));
setSupportedToolChainType(Constants::WEBASSEMBLY_TOOLCHAIN_TYPEID);
setSupportedLanguages({ProjectExplorer::Constants::C_LANGUAGE_ID,
ProjectExplorer::Constants::CXX_LANGUAGE_ID});
setToolchainConstructor([] { return new WebAssemblyToolChain; });
setUserCreatable(true);
}
Toolchains WebAssemblyToolChainFactory::autoDetect(const ToolchainDetector &detector) const
{ {
const FilePath sdk = WebAssemblyEmSdk::registeredEmSdk(); const FilePath sdk = WebAssemblyEmSdk::registeredEmSdk();
if (!WebAssemblyEmSdk::isValid(sdk)) if (!WebAssemblyEmSdk::isValid(sdk))
@@ -192,5 +148,51 @@ Toolchains WebAssemblyToolChainFactory::autoDetect(const ToolchainDetector &dete
return result; return result;
} }
void WebAssemblyToolChain::registerToolChains()
{
// Remove old toolchains
for (ToolChain *tc : ToolChainManager::findToolChains(toolChainAbi())) {
if (tc->detection() != ToolChain::AutoDetection)
continue;
ToolChainManager::deregisterToolChain(tc);
};
// Create new toolchains and register them
ToolchainDetector detector({}, {});
const Toolchains toolchains = doAutoDetect(detector);
for (auto toolChain : toolchains)
ToolChainManager::registerToolChain(toolChain);
// Let kits pick up the new toolchains
for (Kit *kit : KitManager::kits()) {
if (!kit->isAutoDetected())
continue;
const QtVersion *qtVersion = QtKitAspect::qtVersion(kit);
if (!qtVersion || qtVersion->type() != Constants::WEBASSEMBLY_QT_VERSION)
continue;
kit->fix();
}
}
bool WebAssemblyToolChain::areToolChainsRegistered()
{
return !ToolChainManager::findToolChains(toolChainAbi()).isEmpty();
}
WebAssemblyToolChainFactory::WebAssemblyToolChainFactory()
{
setDisplayName(WebAssemblyToolChain::tr("Emscripten"));
setSupportedToolChainType(Constants::WEBASSEMBLY_TOOLCHAIN_TYPEID);
setSupportedLanguages({ProjectExplorer::Constants::C_LANGUAGE_ID,
ProjectExplorer::Constants::CXX_LANGUAGE_ID});
setToolchainConstructor([] { return new WebAssemblyToolChain; });
setUserCreatable(true);
}
Toolchains WebAssemblyToolChainFactory::autoDetect(const ToolchainDetector &detector) const
{
return doAutoDetect(detector);
}
} // namespace Internal } // namespace Internal
} // namespace WebAssembly } // namespace WebAssembly

View File

@@ -37,6 +37,8 @@ class WebAssemblyToolChain final : public ProjectExplorer::GccToolChain
Q_DECLARE_TR_FUNCTIONS(WebAssembly::Internal::WebAssemblyToolChain) Q_DECLARE_TR_FUNCTIONS(WebAssembly::Internal::WebAssemblyToolChain)
public: public:
WebAssemblyToolChain();
void addToEnvironment(Utils::Environment &env) const override; void addToEnvironment(Utils::Environment &env) const override;
Utils::FilePath makeCommand(const Utils::Environment &environment) const override; Utils::FilePath makeCommand(const Utils::Environment &environment) const override;
@@ -45,11 +47,6 @@ public:
static const QVersionNumber &minimumSupportedEmSdkVersion(); static const QVersionNumber &minimumSupportedEmSdkVersion();
static void registerToolChains(); static void registerToolChains();
static bool areToolChainsRegistered(); static bool areToolChainsRegistered();
private:
WebAssemblyToolChain();
friend class WebAssemblyToolChainFactory;
}; };
class WebAssemblyToolChainFactory : public ProjectExplorer::ToolChainFactory class WebAssemblyToolChainFactory : public ProjectExplorer::ToolChainFactory