From 7c40e9303976fc326c6fd7884239fa9947f2ea0d 2017-08-27 16:25:14 From: Alexis Jeandet Date: 2017-08-27 16:25:14 Subject: [PATCH] Some minor improvements on plugin loading: SciQLOP now looks recursively into a list of path and only tries to load dynamic library files. Signed-off-by: Alexis Jeandet --- diff --git a/app/src/Main.cpp b/app/src/Main.cpp index 9cde88d..30db0fe 100644 --- a/app/src/Main.cpp +++ b/app/src/Main.cpp @@ -34,11 +34,8 @@ Q_LOGGING_CATEGORY(LOG_Main, "Main") namespace { -/// Name of the directory containing the plugins - -#if _WIN32 || _WIN64 const auto PLUGIN_DIRECTORY_NAME = QStringLiteral("plugins"); -#endif + } // namespace @@ -52,28 +49,32 @@ int main(int argc, char *argv[]) w.show(); // Loads plugins - auto pluginDir = QDir{sqpApp->applicationDirPath()}; + auto pluginDir = QDir{a.applicationDirPath()}; + auto pluginLookupPath = { + a.applicationDirPath(), + a.applicationDirPath() + "/" + PLUGIN_DIRECTORY_NAME, + a.applicationDirPath() + "/../lib64/SciQlop", + a.applicationDirPath() + "/../lib64/sciqlop", + a.applicationDirPath() + "/../lib/SciQlop", + a.applicationDirPath() + "/../lib/sciqlop", + a.applicationDirPath() + "/../plugins", + }; + #if _WIN32 || _WIN64 pluginDir.mkdir(PLUGIN_DIRECTORY_NAME); pluginDir.cd(PLUGIN_DIRECTORY_NAME); #endif + PluginManager pluginManager{}; -#if __unix || __APPLE -#if __x86_64__ || __ppc64__ - if (!pluginDir.cd("../lib64/SciQlop")) { - pluginDir.cd("../lib64/sciqlop"); + for (auto &&path : pluginLookupPath) { + QDir directory{path}; + if (directory.exists()) { + qCDebug(LOG_Main()) + << QObject::tr("Plugin directory: %1").arg(directory.absolutePath()); + pluginManager.loadPlugins(directory); + } } -#else - if (!pluginDir.cd("../lib/SciQlop")) { - pluginDir.cd("../lib/sciqlop"); - } -#endif -#endif - qCDebug(LOG_Main()) << QObject::tr("Plugin directory: %1").arg(pluginDir.absolutePath()); - - PluginManager pluginManager{}; - pluginManager.loadPlugins(pluginDir); return a.exec(); } diff --git a/core/src/Plugin/PluginManager.cpp b/core/src/Plugin/PluginManager.cpp index 5609cfe..c27f53f 100644 --- a/core/src/Plugin/PluginManager.cpp +++ b/core/src/Plugin/PluginManager.cpp @@ -106,9 +106,15 @@ PluginManager::PluginManager() : impl{spimpl::make_unique_implloadPlugin(pluginInfo.absoluteFilePath()); + auto pluginInfoList + = pluginDir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name); + for (auto entryInfo : qAsConst(pluginInfoList)) { + if (entryInfo.isDir()) + this->loadPlugins(QDir{entryInfo.absoluteFilePath()}); + else { + if (QLibrary::isLibrary(entryInfo.absoluteFilePath())) + impl->loadPlugin(entryInfo.absoluteFilePath()); + } } } diff --git a/plugins/amda/meson.build b/plugins/amda/meson.build index 51b18fd..6f836de 100644 --- a/plugins/amda/meson.build +++ b/plugins/amda/meson.build @@ -37,6 +37,9 @@ amdaplugin_moc_plugin_files = moc_gen.process(amdaplugin_moc_headers) amdaplugin_rcc_plugin_files = rcc_gen.process(amdaplugin_resources_files) +#amdaplugin_rcc_plugin_files = qt5.preprocess( +# qresources : amdaplugin_resources_files) + amdaplugin_moc_files = qt5.preprocess( ui_files : amdaplugin_ui_files) @@ -45,7 +48,7 @@ sciqlop_amdaplugin = library('amdaplugin', amdaplugin_moc_files, amdaplugin_rcc_plugin_files, amdaplugin_moc_plugin_files, - cpp_args : '-DAMDA_LIB', + cpp_args : ['-DAMDA_LIB','-DQT_PLUGIN'], link_with : [sciqlop_core, sciqlop_gui], include_directories : [amdaplugin_inc, core_inc, gui_inc], dependencies : [qt5core, qt5gui, qt5widgets, qt5network],