KPluginLoader
Open, Needs TriagePublic

Description

KPluginLoader is not much more than a wrapper around QPluginLoader. The code itself suggests removing it eventually: https://invent.kde.org/frameworks/kcoreaddons/-/blob/master/src/lib/plugin/kpluginloader.cpp#L24

The main feature it provides is the pluginVersion method that extracts a version number that has been put into the binary via the K_EXPORT_PLUGIN_VERSION macro. Very few projects actually make proper use of the information though:

For most use cases using QPluginLoader would therefore be sufficient. Removing the version handling as it is now would allow to get rid of the KPluginLoader class. What would stay around in some form are the various static methods for finding plugins.

For the cases where we still want to do version checking I see a few alternatives:

  • Add the version information to the JSON metadata instead. This would allow to do the filtering earlier in the loading process and not require to load the plugin before discarding it again.
  • Keep the version information in the binary and load it from a static function, something like
quint32 readVersion(const QString &fileName) {
    QLibrary lib(fileName);
    quint32 *version = reinterpret_cast<quint32 *>(lib.resolve("kde_plugin_version"));
    return *version;
}

This requires the plugin to be loaded before calling it though.

ervin moved this task from Needs Input to In Discussion on the KF6 board.Mar 28 2021, 8:14 AM
ervin moved this task from In Discussion to Needs Input on the KF6 board.
ervin moved this task from Needs Input to In Discussion on the KF6 board.

Notes from the sprint:

Create a convenience function for loading plugins, something like:

static Either<T *, QString> instantiatePlugin(const QString &fileName, QObject *parent = nullptr, const QVariantList &args = {})

Error handling: KExpected or custom struct? Kind of part of a larger discussion about error handling

Read plugin version from JSON instead of a magic symbol: T14302

Get rid of KPluginLoader in favor of QPluginLoader directly

Move plugin finding methods from KPluginLoader namespace to KPluginMetaData namespace

Investigate unused methods in KPluginLoader namespace

Add application plugin path to default search path