forked from qt-creator/qt-creator
ExtensionSystem: Stop reworking initialization order system
This reverts b91f234c7d
and some changes on top.
With the static-in-function approach the dependency seem to be
more easier to solve than with the the central mechanism here.
Change-Id: I65be3ced847b31c25637280376f2fe30003f0527
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -161,47 +161,12 @@
|
||||
namespace ExtensionSystem {
|
||||
namespace Internal {
|
||||
|
||||
class ObjectInitializer
|
||||
{
|
||||
public:
|
||||
ObjectCreator creator;
|
||||
ObjectDestructor destructor;
|
||||
ObjectCreationPolicy policy;
|
||||
};
|
||||
|
||||
class IPluginPrivate
|
||||
{
|
||||
public:
|
||||
void tryCreateObjects();
|
||||
|
||||
QList<TestCreator> testCreators;
|
||||
|
||||
QList<ObjectInitializer> objectInitializers;
|
||||
QList<std::function<void()>> objectDestructors;
|
||||
|
||||
// For debugging purposes:
|
||||
QList<void *> createdObjects; // Not owned.
|
||||
};
|
||||
|
||||
void IPluginPrivate::tryCreateObjects()
|
||||
{
|
||||
QList<ObjectInitializer> unhandledObjectInitializers;
|
||||
|
||||
for (const ObjectInitializer &initializer : std::as_const(objectInitializers)) {
|
||||
if (!initializer.policy.dependsOn.isEmpty()) {
|
||||
qWarning("Initialization dependencies are not supported yet");
|
||||
unhandledObjectInitializers.append(initializer);
|
||||
continue;
|
||||
}
|
||||
|
||||
void *object = initializer.creator();
|
||||
createdObjects.append(object);
|
||||
objectDestructors.append([initializer, object] { initializer.destructor(object); });
|
||||
}
|
||||
|
||||
objectInitializers = unhandledObjectInitializers;
|
||||
}
|
||||
|
||||
} // Internal
|
||||
|
||||
/*!
|
||||
@@ -217,20 +182,10 @@ IPlugin::IPlugin()
|
||||
*/
|
||||
IPlugin::~IPlugin()
|
||||
{
|
||||
for (const std::function<void()> &dtor : std::as_const(d->objectDestructors))
|
||||
dtor();
|
||||
|
||||
delete d;
|
||||
d = nullptr;
|
||||
}
|
||||
|
||||
void IPlugin::addManagedHelper(const ObjectCreator &creator,
|
||||
const ObjectDestructor &destructor,
|
||||
const ObjectCreationPolicy &policy)
|
||||
{
|
||||
d->objectInitializers.append({creator, destructor, policy});
|
||||
}
|
||||
|
||||
bool IPlugin::initialize(const QStringList &arguments, QString *errorString)
|
||||
{
|
||||
Q_UNUSED(arguments)
|
||||
@@ -239,14 +194,6 @@ bool IPlugin::initialize(const QStringList &arguments, QString *errorString)
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
*/
|
||||
void IPlugin::tryCreateObjects()
|
||||
{
|
||||
d->tryCreateObjects();
|
||||
}
|
||||
|
||||
/*!
|
||||
Registers a function object that creates a test object with the owner
|
||||
\a creator.
|
||||
|
@@ -5,8 +5,6 @@
|
||||
|
||||
#include "extensionsystem_global.h"
|
||||
|
||||
#include <utils/id.h>
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <functional>
|
||||
@@ -17,17 +15,6 @@ namespace Internal { class IPluginPrivate; }
|
||||
|
||||
using TestCreator = std::function<QObject *()>;
|
||||
|
||||
using ObjectCreator = std::function<void *()>;
|
||||
using ObjectDestructor = std::function<void(void *)>;
|
||||
|
||||
struct EXTENSIONSYSTEM_EXPORT ObjectCreationPolicy
|
||||
{
|
||||
// Can be empty if nothing depends on it.
|
||||
Utils::Id id;
|
||||
// Objects with empty dependencies are created as soon as possible.
|
||||
QList<Utils::Id> dependsOn;
|
||||
};
|
||||
|
||||
class EXTENSIONSYSTEM_EXPORT IPlugin : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -52,7 +39,6 @@ public:
|
||||
|
||||
// Deprecated in 10.0, use addTest()
|
||||
virtual QVector<QObject *> createTestObjects() const;
|
||||
virtual void tryCreateObjects();
|
||||
|
||||
protected:
|
||||
virtual void initialize() {}
|
||||
@@ -61,17 +47,6 @@ protected:
|
||||
void addTest(Args && ...args) { addTestCreator([args...] { return new Test(args...); }); }
|
||||
void addTestCreator(const TestCreator &creator);
|
||||
|
||||
template <typename Type>
|
||||
void addManaged(const ObjectCreationPolicy &policy = {}) {
|
||||
addManagedHelper([]() -> void * { return new Type(); },
|
||||
[](void *p) { delete static_cast<Type *>(p); },
|
||||
policy);
|
||||
}
|
||||
|
||||
void addManagedHelper(const ObjectCreator &creator,
|
||||
const ObjectDestructor &destructor,
|
||||
const ObjectCreationPolicy &policy);
|
||||
|
||||
signals:
|
||||
void asynchronousShutdownFinished();
|
||||
|
||||
|
@@ -1124,7 +1124,6 @@ bool PluginSpecPrivate::initializePlugin()
|
||||
hasError = true;
|
||||
return false;
|
||||
}
|
||||
plugin->tryCreateObjects();
|
||||
state = PluginSpec::Initialized;
|
||||
return true;
|
||||
}
|
||||
@@ -1151,7 +1150,6 @@ bool PluginSpecPrivate::initializeExtensions()
|
||||
return false;
|
||||
}
|
||||
plugin->extensionsInitialized();
|
||||
plugin->tryCreateObjects();
|
||||
state = PluginSpec::Running;
|
||||
return true;
|
||||
}
|
||||
@@ -1172,7 +1170,6 @@ bool PluginSpecPrivate::delayedInitialize()
|
||||
return false;
|
||||
}
|
||||
const bool res = plugin->delayedInitialize();
|
||||
plugin->tryCreateObjects();
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@@ -74,6 +74,16 @@ public:
|
||||
* be executed in the build process)
|
||||
*/
|
||||
|
||||
class AutotoolsProjectPluginPrivate
|
||||
{
|
||||
public:
|
||||
AutotoolsBuildConfigurationFactory buildConfigFactory;
|
||||
MakeStepFactory makeStepFactory;
|
||||
AutogenStepFactory autogenStepFactory;
|
||||
ConfigureStepFactory configureStepFactory;
|
||||
AutoreconfStepFactory autoreconfStepFactory;
|
||||
};
|
||||
|
||||
class AutotoolsProjectPlugin final : public ExtensionSystem::IPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -81,14 +91,10 @@ class AutotoolsProjectPlugin final : public ExtensionSystem::IPlugin
|
||||
|
||||
void initialize() final
|
||||
{
|
||||
ProjectManager::registerProjectType<AutotoolsProject>(Constants::MAKEFILE_MIMETYPE);
|
||||
|
||||
addManaged<AutotoolsBuildConfigurationFactory>();
|
||||
addManaged<MakeStepFactory>();
|
||||
addManaged<AutogenStepFactory>();
|
||||
addManaged<ConfigureStepFactory>();
|
||||
addManaged<AutoreconfStepFactory>();
|
||||
d = std::make_unique<AutotoolsProjectPluginPrivate>();
|
||||
}
|
||||
|
||||
std::unique_ptr<AutotoolsProjectPluginPrivate> d;
|
||||
};
|
||||
|
||||
} // AutotoolsProjectManager::Internal
|
||||
|
@@ -7,16 +7,23 @@
|
||||
|
||||
namespace Conan::Internal {
|
||||
|
||||
class ConanPluginPrivate
|
||||
{
|
||||
public:
|
||||
ConanInstallStepFactory conanInstallStepFactory;
|
||||
};
|
||||
|
||||
class ConanPlugin final : public ExtensionSystem::IPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Conan.json")
|
||||
|
||||
public:
|
||||
ConanPlugin()
|
||||
void initialize()
|
||||
{
|
||||
addManaged<ConanInstallStepFactory>();
|
||||
d = std::make_unique<ConanPluginPrivate>();
|
||||
}
|
||||
|
||||
std::unique_ptr<ConanPluginPrivate> d;
|
||||
};
|
||||
|
||||
} // Conan::Internal
|
||||
|
@@ -8,17 +8,25 @@
|
||||
|
||||
namespace IncrediBuild::Internal {
|
||||
|
||||
class IncrediBuildPluginPrivate
|
||||
{
|
||||
public:
|
||||
BuildConsoleStepFactory buildConsoleStepFactory;
|
||||
IBConsoleStepFactory ibConsolStepFactory;
|
||||
};
|
||||
|
||||
class IncrediBuildPlugin final : public ExtensionSystem::IPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "IncrediBuild.json")
|
||||
|
||||
public:
|
||||
IncrediBuildPlugin()
|
||||
void initialize()
|
||||
{
|
||||
addManaged<BuildConsoleStepFactory>();
|
||||
addManaged<IBConsoleStepFactory>();
|
||||
d = std::make_unique<IncrediBuildPluginPrivate>();
|
||||
}
|
||||
|
||||
std::unique_ptr<IncrediBuildPluginPrivate> d;
|
||||
};
|
||||
|
||||
} // IncrediBuild::Internal
|
||||
|
@@ -12,6 +12,12 @@
|
||||
|
||||
namespace Vcpkg::Internal {
|
||||
|
||||
class VcpkgPluginPrivate
|
||||
{
|
||||
public:
|
||||
VcpkgManifestEditorFactory vcpkgManifestEditorFactory;
|
||||
};
|
||||
|
||||
class VcpkgPlugin final : public ExtensionSystem::IPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -22,12 +28,14 @@ public:
|
||||
{
|
||||
ProjectExplorer::JsonWizardFactory::addWizardPath(":/vcpkg/wizards/");
|
||||
|
||||
addManaged<VcpkgManifestEditorFactory>();
|
||||
d = std::make_unique<VcpkgPluginPrivate>();
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
addTest<VcpkgSearchTest>();
|
||||
#endif
|
||||
}
|
||||
|
||||
std::unique_ptr<VcpkgPluginPrivate> d;
|
||||
};
|
||||
|
||||
} // namespace Vcpkg::Internal
|
||||
|
Reference in New Issue
Block a user