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:
hjk
2023-08-30 17:09:09 +02:00
parent 4132ffd662
commit 95a3087a7b
7 changed files with 43 additions and 95 deletions

View File

@@ -161,47 +161,12 @@
namespace ExtensionSystem { namespace ExtensionSystem {
namespace Internal { namespace Internal {
class ObjectInitializer
{
public:
ObjectCreator creator;
ObjectDestructor destructor;
ObjectCreationPolicy policy;
};
class IPluginPrivate class IPluginPrivate
{ {
public: public:
void tryCreateObjects();
QList<TestCreator> testCreators; 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 } // Internal
/*! /*!
@@ -217,20 +182,10 @@ IPlugin::IPlugin()
*/ */
IPlugin::~IPlugin() IPlugin::~IPlugin()
{ {
for (const std::function<void()> &dtor : std::as_const(d->objectDestructors))
dtor();
delete d; delete d;
d = nullptr; 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) bool IPlugin::initialize(const QStringList &arguments, QString *errorString)
{ {
Q_UNUSED(arguments) Q_UNUSED(arguments)
@@ -239,14 +194,6 @@ bool IPlugin::initialize(const QStringList &arguments, QString *errorString)
return true; return true;
} }
/*!
\internal
*/
void IPlugin::tryCreateObjects()
{
d->tryCreateObjects();
}
/*! /*!
Registers a function object that creates a test object with the owner Registers a function object that creates a test object with the owner
\a creator. \a creator.

View File

@@ -5,8 +5,6 @@
#include "extensionsystem_global.h" #include "extensionsystem_global.h"
#include <utils/id.h>
#include <QObject> #include <QObject>
#include <functional> #include <functional>
@@ -17,17 +15,6 @@ namespace Internal { class IPluginPrivate; }
using TestCreator = std::function<QObject *()>; 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 class EXTENSIONSYSTEM_EXPORT IPlugin : public QObject
{ {
Q_OBJECT Q_OBJECT
@@ -52,7 +39,6 @@ public:
// Deprecated in 10.0, use addTest() // Deprecated in 10.0, use addTest()
virtual QVector<QObject *> createTestObjects() const; virtual QVector<QObject *> createTestObjects() const;
virtual void tryCreateObjects();
protected: protected:
virtual void initialize() {} virtual void initialize() {}
@@ -61,17 +47,6 @@ protected:
void addTest(Args && ...args) { addTestCreator([args...] { return new Test(args...); }); } void addTest(Args && ...args) { addTestCreator([args...] { return new Test(args...); }); }
void addTestCreator(const TestCreator &creator); 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: signals:
void asynchronousShutdownFinished(); void asynchronousShutdownFinished();

View File

@@ -1124,7 +1124,6 @@ bool PluginSpecPrivate::initializePlugin()
hasError = true; hasError = true;
return false; return false;
} }
plugin->tryCreateObjects();
state = PluginSpec::Initialized; state = PluginSpec::Initialized;
return true; return true;
} }
@@ -1151,7 +1150,6 @@ bool PluginSpecPrivate::initializeExtensions()
return false; return false;
} }
plugin->extensionsInitialized(); plugin->extensionsInitialized();
plugin->tryCreateObjects();
state = PluginSpec::Running; state = PluginSpec::Running;
return true; return true;
} }
@@ -1172,7 +1170,6 @@ bool PluginSpecPrivate::delayedInitialize()
return false; return false;
} }
const bool res = plugin->delayedInitialize(); const bool res = plugin->delayedInitialize();
plugin->tryCreateObjects();
return res; return res;
} }

View File

@@ -74,6 +74,16 @@ public:
* be executed in the build process) * 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 class AutotoolsProjectPlugin final : public ExtensionSystem::IPlugin
{ {
Q_OBJECT Q_OBJECT
@@ -81,14 +91,10 @@ class AutotoolsProjectPlugin final : public ExtensionSystem::IPlugin
void initialize() final void initialize() final
{ {
ProjectManager::registerProjectType<AutotoolsProject>(Constants::MAKEFILE_MIMETYPE); d = std::make_unique<AutotoolsProjectPluginPrivate>();
addManaged<AutotoolsBuildConfigurationFactory>();
addManaged<MakeStepFactory>();
addManaged<AutogenStepFactory>();
addManaged<ConfigureStepFactory>();
addManaged<AutoreconfStepFactory>();
} }
std::unique_ptr<AutotoolsProjectPluginPrivate> d;
}; };
} // AutotoolsProjectManager::Internal } // AutotoolsProjectManager::Internal

View File

@@ -7,16 +7,23 @@
namespace Conan::Internal { namespace Conan::Internal {
class ConanPluginPrivate
{
public:
ConanInstallStepFactory conanInstallStepFactory;
};
class ConanPlugin final : public ExtensionSystem::IPlugin class ConanPlugin final : public ExtensionSystem::IPlugin
{ {
Q_OBJECT Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Conan.json") Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Conan.json")
public: void initialize()
ConanPlugin()
{ {
addManaged<ConanInstallStepFactory>(); d = std::make_unique<ConanPluginPrivate>();
} }
std::unique_ptr<ConanPluginPrivate> d;
}; };
} // Conan::Internal } // Conan::Internal

View File

@@ -8,17 +8,25 @@
namespace IncrediBuild::Internal { namespace IncrediBuild::Internal {
class IncrediBuildPluginPrivate
{
public:
BuildConsoleStepFactory buildConsoleStepFactory;
IBConsoleStepFactory ibConsolStepFactory;
};
class IncrediBuildPlugin final : public ExtensionSystem::IPlugin class IncrediBuildPlugin final : public ExtensionSystem::IPlugin
{ {
Q_OBJECT Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "IncrediBuild.json") Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "IncrediBuild.json")
public: public:
IncrediBuildPlugin() void initialize()
{ {
addManaged<BuildConsoleStepFactory>(); d = std::make_unique<IncrediBuildPluginPrivate>();
addManaged<IBConsoleStepFactory>();
} }
std::unique_ptr<IncrediBuildPluginPrivate> d;
}; };
} // IncrediBuild::Internal } // IncrediBuild::Internal

View File

@@ -12,6 +12,12 @@
namespace Vcpkg::Internal { namespace Vcpkg::Internal {
class VcpkgPluginPrivate
{
public:
VcpkgManifestEditorFactory vcpkgManifestEditorFactory;
};
class VcpkgPlugin final : public ExtensionSystem::IPlugin class VcpkgPlugin final : public ExtensionSystem::IPlugin
{ {
Q_OBJECT Q_OBJECT
@@ -22,12 +28,14 @@ public:
{ {
ProjectExplorer::JsonWizardFactory::addWizardPath(":/vcpkg/wizards/"); ProjectExplorer::JsonWizardFactory::addWizardPath(":/vcpkg/wizards/");
addManaged<VcpkgManifestEditorFactory>(); d = std::make_unique<VcpkgPluginPrivate>();
#ifdef WITH_TESTS #ifdef WITH_TESTS
addTest<VcpkgSearchTest>(); addTest<VcpkgSearchTest>();
#endif #endif
} }
std::unique_ptr<VcpkgPluginPrivate> d;
}; };
} // namespace Vcpkg::Internal } // namespace Vcpkg::Internal