forked from qt-creator/qt-creator
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:
@@ -111,6 +111,43 @@ const QVersionNumber &WebAssemblyToolChain::minimumSupportedEmSdkVersion()
|
|||||||
return number;
|
return number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Toolchains doAutoDetect(const ToolchainDetector &detector)
|
||||||
|
{
|
||||||
|
const FilePath sdk = WebAssemblyEmSdk::registeredEmSdk();
|
||||||
|
if (!WebAssemblyEmSdk::isValid(sdk))
|
||||||
|
return {};
|
||||||
|
|
||||||
|
if (detector.device) {
|
||||||
|
// Only detect toolchains from the emsdk installation device
|
||||||
|
const FilePath deviceRoot = detector.device->mapToGlobalPath({});
|
||||||
|
if (deviceRoot.host() != sdk.host())
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
Environment env = sdk.deviceEnvironment();
|
||||||
|
WebAssemblyEmSdk::addToEnvironment(sdk, env);
|
||||||
|
|
||||||
|
Toolchains result;
|
||||||
|
for (auto languageId : {ProjectExplorer::Constants::C_LANGUAGE_ID,
|
||||||
|
ProjectExplorer::Constants::CXX_LANGUAGE_ID}) {
|
||||||
|
auto toolChain = new WebAssemblyToolChain;
|
||||||
|
toolChain->setLanguage(languageId);
|
||||||
|
toolChain->setDetection(ToolChain::AutoDetection);
|
||||||
|
const bool cLanguage = languageId == ProjectExplorer::Constants::C_LANGUAGE_ID;
|
||||||
|
const QString script = QLatin1String(cLanguage ? "emcc" : "em++")
|
||||||
|
+ QLatin1String(sdk.osType() == OsTypeWindows ? ".bat" : "");
|
||||||
|
const FilePath scriptFile = sdk.withNewPath(script).searchInDirectories(env.path());
|
||||||
|
toolChain->setCompilerCommand(scriptFile);
|
||||||
|
|
||||||
|
const QString displayName = WebAssemblyToolChain::tr("Emscripten Compiler %1 for %2")
|
||||||
|
.arg(toolChain->version(), QLatin1String(cLanguage ? "C" : "C++"));
|
||||||
|
toolChain->setDisplayName(displayName);
|
||||||
|
result.append(toolChain);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void WebAssemblyToolChain::registerToolChains()
|
void WebAssemblyToolChain::registerToolChains()
|
||||||
{
|
{
|
||||||
// Remove old toolchains
|
// Remove old toolchains
|
||||||
@@ -121,12 +158,9 @@ void WebAssemblyToolChain::registerToolChains()
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Create new toolchains and register them
|
// Create new toolchains and register them
|
||||||
ToolChainFactory *factory =
|
ToolchainDetector detector({}, {});
|
||||||
findOrDefault(ToolChainFactory::allToolChainFactories(), [](ToolChainFactory *f){
|
const Toolchains toolchains = doAutoDetect(detector);
|
||||||
return f->supportedToolChainType() == Constants::WEBASSEMBLY_TOOLCHAIN_TYPEID;
|
for (auto toolChain : toolchains)
|
||||||
});
|
|
||||||
QTC_ASSERT(factory, return);
|
|
||||||
for (auto toolChain : factory->autoDetect(ToolchainDetector({}, {})))
|
|
||||||
ToolChainManager::registerToolChain(toolChain);
|
ToolChainManager::registerToolChain(toolChain);
|
||||||
|
|
||||||
// Let kits pick up the new toolchains
|
// Let kits pick up the new toolchains
|
||||||
@@ -157,39 +191,7 @@ WebAssemblyToolChainFactory::WebAssemblyToolChainFactory()
|
|||||||
|
|
||||||
Toolchains WebAssemblyToolChainFactory::autoDetect(const ToolchainDetector &detector) const
|
Toolchains WebAssemblyToolChainFactory::autoDetect(const ToolchainDetector &detector) const
|
||||||
{
|
{
|
||||||
const FilePath sdk = WebAssemblyEmSdk::registeredEmSdk();
|
return doAutoDetect(detector);
|
||||||
if (!WebAssemblyEmSdk::isValid(sdk))
|
|
||||||
return {};
|
|
||||||
|
|
||||||
if (detector.device) {
|
|
||||||
// Only detect toolchains from the emsdk installation device
|
|
||||||
const FilePath deviceRoot = detector.device->mapToGlobalPath({});
|
|
||||||
if (deviceRoot.host() != sdk.host())
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
Environment env = sdk.deviceEnvironment();
|
|
||||||
WebAssemblyEmSdk::addToEnvironment(sdk, env);
|
|
||||||
|
|
||||||
Toolchains result;
|
|
||||||
for (auto languageId : {ProjectExplorer::Constants::C_LANGUAGE_ID,
|
|
||||||
ProjectExplorer::Constants::CXX_LANGUAGE_ID}) {
|
|
||||||
auto toolChain = new WebAssemblyToolChain;
|
|
||||||
toolChain->setLanguage(languageId);
|
|
||||||
toolChain->setDetection(ToolChain::AutoDetection);
|
|
||||||
const bool cLanguage = languageId == ProjectExplorer::Constants::C_LANGUAGE_ID;
|
|
||||||
const QString script = QLatin1String(cLanguage ? "emcc" : "em++")
|
|
||||||
+ QLatin1String(sdk.osType() == OsTypeWindows ? ".bat" : "");
|
|
||||||
const FilePath scriptFile = sdk.withNewPath(script).searchInDirectories(env.path());
|
|
||||||
toolChain->setCompilerCommand(scriptFile);
|
|
||||||
|
|
||||||
const QString displayName = WebAssemblyToolChain::tr("Emscripten Compiler %1 for %2")
|
|
||||||
.arg(toolChain->version(), QLatin1String(cLanguage ? "C" : "C++"));
|
|
||||||
toolChain->setDisplayName(displayName);
|
|
||||||
result.append(toolChain);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user