WebAssembly: Convert to new plugin setup scheme

Change-Id: I7d5def6084a0cc2cf164a4d72b693b44f8be7005
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
hjk
2023-11-24 15:33:31 +01:00
parent 0afd50aa33
commit e729c37d95
10 changed files with 163 additions and 191 deletions

View File

@@ -5,39 +5,53 @@
#include "webassemblydevice.h" #include "webassemblydevice.h"
#include "webassemblytr.h" #include "webassemblytr.h"
#include <projectexplorer/devicesupport/desktopdevice.h>
#include <projectexplorer/devicesupport/idevicefactory.h>
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Utils; using namespace Utils;
namespace WebAssembly { namespace WebAssembly::Internal {
namespace Internal {
WebAssemblyDevice::WebAssemblyDevice() class WebAssemblyDevice final : public DesktopDevice
{ {
setupId(IDevice::AutoDetected, Constants::WEBASSEMBLY_DEVICE_DEVICE_ID); public:
setType(Constants::WEBASSEMBLY_DEVICE_TYPE); WebAssemblyDevice()
const QString displayNameAndType = Tr::tr("Web Browser"); {
settings()->displayName.setDefaultValue(displayNameAndType); setupId(IDevice::AutoDetected, Constants::WEBASSEMBLY_DEVICE_DEVICE_ID);
setDisplayType(displayNameAndType); setType(Constants::WEBASSEMBLY_DEVICE_TYPE);
setDeviceState(IDevice::DeviceStateUnknown); const QString displayNameAndType = Tr::tr("Web Browser");
setMachineType(IDevice::Hardware); settings()->displayName.setDefaultValue(displayNameAndType);
setOsType(OsTypeOther); setDisplayType(displayNameAndType);
setFileAccess(nullptr); setDeviceState(IDevice::DeviceStateUnknown);
} setMachineType(IDevice::Hardware);
setOsType(OsTypeOther);
setFileAccess(nullptr);
}
};
IDevice::Ptr WebAssemblyDevice::create() IDevicePtr createWebAssemblyDevice()
{ {
return IDevicePtr(new WebAssemblyDevice); return IDevicePtr(new WebAssemblyDevice);
} }
WebAssemblyDeviceFactory::WebAssemblyDeviceFactory() class WebAssemblyDeviceFactory final : public IDeviceFactory
: ProjectExplorer::IDeviceFactory(Constants::WEBASSEMBLY_DEVICE_TYPE)
{ {
setDisplayName(Tr::tr("WebAssembly Runtime")); public:
setCombinedIcon(":/webassembly/images/webassemblydevicesmall.png", WebAssemblyDeviceFactory()
":/webassembly/images/webassemblydevice.png"); : IDeviceFactory(Constants::WEBASSEMBLY_DEVICE_TYPE)
setConstructionFunction(&WebAssemblyDevice::create); {
setCreator(&WebAssemblyDevice::create); setDisplayName(Tr::tr("WebAssembly Runtime"));
setCombinedIcon(":/webassembly/images/webassemblydevicesmall.png",
":/webassembly/images/webassemblydevice.png");
setConstructionFunction(&createWebAssemblyDevice);
setCreator(&createWebAssemblyDevice);
}
};
void setupWebAssemblyDevice()
{
static WebAssemblyDeviceFactory theWebAssemblyDeviceFactory;
} }
} // namespace Internal } // WebAssembly::Internal
} // namespace WebAssembly

View File

@@ -3,26 +3,12 @@
#pragma once #pragma once
#include <projectexplorer/devicesupport/desktopdevice.h> #include <projectexplorer/devicesupport/idevicefwd.h>
#include <projectexplorer/devicesupport/idevicefactory.h>
namespace WebAssembly { namespace WebAssembly::Internal {
namespace Internal {
class WebAssemblyDevice final : public ProjectExplorer::DesktopDevice ProjectExplorer::IDevicePtr createWebAssemblyDevice();
{
public:
static ProjectExplorer::IDevice::Ptr create();
private: void setupWebAssemblyDevice();
WebAssemblyDevice();
};
class WebAssemblyDeviceFactory final : public ProjectExplorer::IDeviceFactory } // WebAssembly::Interenal
{
public:
WebAssemblyDeviceFactory();
};
} // namespace Internal
} // namespace WebAssembly

View File

@@ -10,7 +10,6 @@
#include "webassemblydevice.h" #include "webassemblydevice.h"
#include "webassemblyqtversion.h" #include "webassemblyqtversion.h"
#include "webassemblyrunconfiguration.h" #include "webassemblyrunconfiguration.h"
#include "webassemblysettings.h"
#include "webassemblytoolchain.h" #include "webassemblytoolchain.h"
#include "webassemblytr.h" #include "webassemblytr.h"
@@ -18,6 +17,8 @@
#include <coreplugin/icontext.h> #include <coreplugin/icontext.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <extensionsystem/iplugin.h>
#include <projectexplorer/devicesupport/devicemanager.h> #include <projectexplorer/devicesupport/devicemanager.h>
#include <projectexplorer/kitmanager.h> #include <projectexplorer/kitmanager.h>
@@ -31,47 +32,7 @@ using namespace Utils;
namespace WebAssembly::Internal { namespace WebAssembly::Internal {
class WebAssemblyPluginPrivate static void askUserAboutEmSdkSetup()
{
public:
WebAssemblyToolchainFactory toolChainFactory;
WebAssemblyDeviceFactory deviceFactory;
WebAssemblyQtVersionFactory qtVersionFactory;
EmrunRunConfigurationFactory emrunRunConfigurationFactory;
EmrunRunWorkerFactory emrunRunWorkerFactory;
};
static WebAssemblyPluginPrivate *dd = nullptr;
WebAssemblyPlugin::WebAssemblyPlugin()
{
setObjectName("WebAssemblyPlugin");
}
WebAssemblyPlugin::~WebAssemblyPlugin()
{
delete dd;
dd = nullptr;
}
void WebAssemblyPlugin::initialize()
{
dd = new WebAssemblyPluginPrivate;
#ifdef WITH_TESTS
addTest<WebAssemblyTest>();
#endif // WITH_TESTS
}
void WebAssemblyPlugin::extensionsInitialized()
{
connect(KitManager::instance(), &KitManager::kitsLoaded, this, [] {
DeviceManager::instance()->addDevice(WebAssemblyDevice::create());
askUserAboutEmSdkSetup();
});
}
void WebAssemblyPlugin::askUserAboutEmSdkSetup()
{ {
const char setupWebAssemblyEmSdk[] = "SetupWebAssemblyEmSdk"; const char setupWebAssemblyEmSdk[] = "SetupWebAssemblyEmSdk";
@@ -91,4 +52,32 @@ void WebAssemblyPlugin::askUserAboutEmSdkSetup()
ICore::infoBar()->addInfo(info); ICore::infoBar()->addInfo(info);
} }
class WebAssemblyPlugin final : public ExtensionSystem::IPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "WebAssembly.json")
public:
void initialize() final
{
setupWebAssemblyToolchain();
setupWebAssemblyDevice();
setupWebAssemblyQtVersion();
setupEmrunRunSupport();
#ifdef WITH_TESTS
addTest<WebAssemblyTest>();
#endif // WITH_TESTS
}
void extensionsInitialized() final
{
connect(KitManager::instance(), &KitManager::kitsLoaded, this, [] {
DeviceManager::instance()->addDevice(createWebAssemblyDevice());
askUserAboutEmSdkSetup();
});
}
};
} // WebAssembly::Internal } // WebAssembly::Internal
#include "webassemblyplugin.moc"

View File

@@ -1,24 +0,0 @@
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include <extensionsystem/iplugin.h>
namespace WebAssembly::Internal {
class WebAssemblyPlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "WebAssembly.json")
public:
WebAssemblyPlugin();
~WebAssemblyPlugin() override;
void initialize() override;
void extensionsInitialized() override;
static void askUserAboutEmSdkSetup();
};
} // WebAssembly::Internal

View File

@@ -1,17 +1,22 @@
// Copyright (C) 2020 The Qt Company Ltd. // Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "webassemblyconstants.h"
#include "webassemblyqtversion.h" #include "webassemblyqtversion.h"
#include "webassemblyconstants.h"
#include "webassemblytr.h" #include "webassemblytr.h"
#include <coreplugin/featureprovider.h>
#include <coreplugin/icore.h>
#include <projectexplorer/abi.h> #include <projectexplorer/abi.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <remotelinux/remotelinux_constants.h>
#include <coreplugin/featureprovider.h> #include <qtsupport/qtversionfactory.h>
#include <coreplugin/icore.h>
#include <qtsupport/qtversionmanager.h> #include <qtsupport/qtversionmanager.h>
#include <remotelinux/remotelinux_constants.h>
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/hostosinfo.h> #include <utils/hostosinfo.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
@@ -22,8 +27,7 @@
using namespace QtSupport; using namespace QtSupport;
using namespace Utils; using namespace Utils;
namespace WebAssembly { namespace WebAssembly::Internal {
namespace Internal {
WebAssemblyQtVersion::WebAssemblyQtVersion() = default; WebAssemblyQtVersion::WebAssemblyQtVersion() = default;
@@ -37,16 +41,6 @@ QSet<Id> WebAssemblyQtVersion::targetDeviceTypes() const
return {Constants::WEBASSEMBLY_DEVICE_TYPE}; return {Constants::WEBASSEMBLY_DEVICE_TYPE};
} }
WebAssemblyQtVersionFactory::WebAssemblyQtVersionFactory()
{
setQtVersionCreator([] { return new WebAssemblyQtVersion; });
setSupportedType(Constants::WEBASSEMBLY_QT_VERSION);
setPriority(1);
setRestrictionChecker([](const SetupData &setup) {
return setup.platforms.contains("wasm");
});
}
bool WebAssemblyQtVersion::isValid() const bool WebAssemblyQtVersion::isValid() const
{ {
return QtVersion::isValid() && qtVersion() >= minimumSupportedQtVersion(); return QtVersion::isValid() && qtVersion() >= minimumSupportedQtVersion();
@@ -84,5 +78,23 @@ bool WebAssemblyQtVersion::isUnsupportedQtVersionInstalled()
}); });
} }
} // namespace Internal class WebAssemblyQtVersionFactory final : public QtVersionFactory
} // namespace WebAssembly {
public:
WebAssemblyQtVersionFactory()
{
setQtVersionCreator([] { return new WebAssemblyQtVersion; });
setSupportedType(Constants::WEBASSEMBLY_QT_VERSION);
setPriority(1);
setRestrictionChecker([](const SetupData &setup) {
return setup.platforms.contains("wasm");
});
}
};
void setupWebAssemblyQtVersion()
{
static WebAssemblyQtVersionFactory theWebAssemblyQtVersionFactory;
}
} // WebAssembly::Internal

View File

@@ -3,34 +3,27 @@
#pragma once #pragma once
#include <qtsupport/qtversionfactory.h>
#include <qtsupport/baseqtversion.h> #include <qtsupport/baseqtversion.h>
namespace WebAssembly { namespace WebAssembly::Internal {
namespace Internal {
class WebAssemblyQtVersion : public QtSupport::QtVersion class WebAssemblyQtVersion final : public QtSupport::QtVersion
{ {
public: public:
WebAssemblyQtVersion(); WebAssemblyQtVersion();
QString description() const override; QString description() const final;
QSet<Utils::Id> targetDeviceTypes() const override; QSet<Utils::Id> targetDeviceTypes() const final;
bool isValid() const override; bool isValid() const final;
QString invalidReason() const override; QString invalidReason() const final;
static const QVersionNumber &minimumSupportedQtVersion(); static const QVersionNumber &minimumSupportedQtVersion();
static bool isQtVersionInstalled(); static bool isQtVersionInstalled();
static bool isUnsupportedQtVersionInstalled(); static bool isUnsupportedQtVersionInstalled();
}; };
class WebAssemblyQtVersionFactory : public QtSupport::QtVersionFactory void setupWebAssemblyQtVersion();
{
public:
WebAssemblyQtVersionFactory();
};
} // namespace Internal } // WebAssembly::Internal
} // namespace WebAssembly

View File

@@ -13,6 +13,7 @@
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/runconfigurationaspects.h> #include <projectexplorer/runconfigurationaspects.h>
#include <projectexplorer/runconfiguration.h>
#include <projectexplorer/runcontrol.h> #include <projectexplorer/runcontrol.h>
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
@@ -221,17 +222,31 @@ public:
// Factories // Factories
EmrunRunConfigurationFactory::EmrunRunConfigurationFactory() class EmrunRunConfigurationFactory final : public ProjectExplorer::RunConfigurationFactory
{ {
registerRunConfiguration<EmrunRunConfiguration>(Constants::WEBASSEMBLY_RUNCONFIGURATION_EMRUN); public:
addSupportedTargetDeviceType(Constants::WEBASSEMBLY_DEVICE_TYPE); EmrunRunConfigurationFactory()
} {
registerRunConfiguration<EmrunRunConfiguration>(Constants::WEBASSEMBLY_RUNCONFIGURATION_EMRUN);
addSupportedTargetDeviceType(Constants::WEBASSEMBLY_DEVICE_TYPE);
}
};
EmrunRunWorkerFactory::EmrunRunWorkerFactory() class EmrunRunWorkerFactory final : public ProjectExplorer::RunWorkerFactory
{ {
setProduct<EmrunRunWorker>(); public:
addSupportedRunMode(ProjectExplorer::Constants::NORMAL_RUN_MODE); EmrunRunWorkerFactory()
addSupportedRunConfig(Constants::WEBASSEMBLY_RUNCONFIGURATION_EMRUN); {
setProduct<EmrunRunWorker>();
addSupportedRunMode(ProjectExplorer::Constants::NORMAL_RUN_MODE);
addSupportedRunConfig(Constants::WEBASSEMBLY_RUNCONFIGURATION_EMRUN);
}
};
void setupEmrunRunSupport()
{
static EmrunRunConfigurationFactory theEmrunRunConfigurationFactory;
static EmrunRunWorkerFactory theEmrunRunWorkerFactory;
} }
} // Webassembly::Internal } // Webassembly::Internal

View File

@@ -3,8 +3,8 @@
#pragma once #pragma once
#include <projectexplorer/runconfiguration.h> #include <QList>
#include <projectexplorer/runcontrol.h> #include <QString>
namespace WebAssembly::Internal { namespace WebAssembly::Internal {
@@ -13,17 +13,6 @@ using WebBrowserEntries = QList<WebBrowserEntry>;
WebBrowserEntries parseEmrunOutput(const QByteArray &output); WebBrowserEntries parseEmrunOutput(const QByteArray &output);
void setupEmrunRunSupport();
class EmrunRunConfigurationFactory final : public ProjectExplorer::RunConfigurationFactory
{
public:
EmrunRunConfigurationFactory();
};
class EmrunRunWorkerFactory final : public ProjectExplorer::RunWorkerFactory
{
public:
EmrunRunWorkerFactory();
};
} // Webassembly::Internal } // Webassembly::Internal

View File

@@ -26,8 +26,7 @@ using namespace ProjectExplorer;
using namespace QtSupport; using namespace QtSupport;
using namespace Utils; using namespace Utils;
namespace WebAssembly { namespace WebAssembly::Internal {
namespace Internal {
static const Abi &toolChainAbi() static const Abi &toolChainAbi()
{ {
@@ -168,20 +167,28 @@ bool WebAssemblyToolChain::areToolChainsRegistered()
return !ToolchainManager::findToolchains(toolChainAbi()).isEmpty(); return !ToolchainManager::findToolchains(toolChainAbi()).isEmpty();
} }
WebAssemblyToolchainFactory::WebAssemblyToolchainFactory() class WebAssemblyToolchainFactory final : public ToolchainFactory
{ {
setDisplayName(Tr::tr("Emscripten")); public:
setSupportedToolChainType(Constants::WEBASSEMBLY_TOOLCHAIN_TYPEID); WebAssemblyToolchainFactory()
setSupportedLanguages({ProjectExplorer::Constants::C_LANGUAGE_ID, {
ProjectExplorer::Constants::CXX_LANGUAGE_ID}); setDisplayName(Tr::tr("Emscripten"));
setToolchainConstructor([] { return new WebAssemblyToolChain; }); setSupportedToolChainType(Constants::WEBASSEMBLY_TOOLCHAIN_TYPEID);
setUserCreatable(true); setSupportedLanguages({ProjectExplorer::Constants::C_LANGUAGE_ID,
ProjectExplorer::Constants::CXX_LANGUAGE_ID});
setToolchainConstructor([] { return new WebAssemblyToolChain; });
setUserCreatable(true);
}
Toolchains autoDetect(const ToolchainDetector &detector) const
{
return doAutoDetect(detector);
}
};
void setupWebAssemblyToolchain()
{
static WebAssemblyToolchainFactory theWebAssemblyToolchainFactory;
} }
Toolchains WebAssemblyToolchainFactory::autoDetect(const ToolchainDetector &detector) const } // WebAssembly::Internal
{
return doAutoDetect(detector);
}
} // namespace Internal
} // namespace WebAssembly

View File

@@ -7,8 +7,7 @@
#include <QVersionNumber> #include <QVersionNumber>
namespace WebAssembly { namespace WebAssembly::Internal {
namespace Internal {
class WebAssemblyToolChain final : public ProjectExplorer::GccToolChain class WebAssemblyToolChain final : public ProjectExplorer::GccToolChain
{ {
@@ -25,14 +24,6 @@ public:
static bool areToolChainsRegistered(); static bool areToolChainsRegistered();
}; };
class WebAssemblyToolchainFactory : public ProjectExplorer::ToolchainFactory void setupWebAssemblyToolchain();
{
public:
WebAssemblyToolchainFactory();
ProjectExplorer::Toolchains autoDetect( } // WebAssembly::Internal
const ProjectExplorer::ToolchainDetector &detector) const final;
};
} // namespace Internal
} // namespace WebAssembly