From 6734de4b453ad62f6b4411dd040f831c14789379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Thu, 13 Oct 2022 15:16:18 +0200 Subject: [PATCH] Allow to override default paths using new env variable and rename additional paths to *EXTRA_PATH --- doc/test-plugin.qdoc | 4 +-- .../experiences/experiencemanager.cpp | 28 ++++++++++----- .../integrations/apikeysprovidersloader.cpp | 27 ++++++++++----- .../thingmanagerimplementation.cpp | 33 ++++++++++++------ libnymea-core/platform/platform.cpp | 34 +++++++++++++------ 5 files changed, 86 insertions(+), 40 deletions(-) diff --git a/doc/test-plugin.qdoc b/doc/test-plugin.qdoc index f9a18e9a..49a9b312 100644 --- a/doc/test-plugin.qdoc +++ b/doc/test-plugin.qdoc @@ -12,11 +12,11 @@ To make nymead load the plugin from the plugins build directory, run nymead with an environment variable exported \code - $ NYMEA_PLUGINS_PATH=/path/to/plugin/ nymead -n + $ NYMEA_PLUGINS_EXTRA_PATH=/path/to/plugin/ nymead -n \endcode In order to easier debug things, it is advised to enable debug output for the device manager and your plugin. E.g. \code - $ NYMEA_PLUGINS_PATH=/path/to/plugin nymead -n -d DeviceManager -d YourPlugin + $ NYMEA_PLUGINS_EXTRA_PATH=/path/to/plugin nymead -n -d DeviceManager -d YourPlugin \endcode */ diff --git a/libnymea-core/experiences/experiencemanager.cpp b/libnymea-core/experiences/experiencemanager.cpp index 5b48a090..a2e0e2eb 100644 --- a/libnymea-core/experiences/experiencemanager.cpp +++ b/libnymea-core/experiences/experiencemanager.cpp @@ -75,18 +75,30 @@ void ExperienceManager::loadPlugins() QStringList ExperienceManager::pluginSearchDirs() const { + const char *envDefaultPath = "NYMEA_EXPERIENCE_PLUGINS_PATH"; + const char *envExtraPath = "NYMEA_EXPERIENCE_PLUGINS_EXTRA_PATH"; + QStringList searchDirs; - QByteArray envPath = qgetenv("NYMEA_EXPERIENCE_PLUGINS_PATH"); - if (!envPath.isEmpty()) { - searchDirs << QString(envPath).split(':'); + QByteArray envExtraPathData = qgetenv(envExtraPath); + if (!envExtraPathData.isEmpty()) { + searchDirs << QString::fromUtf8(envExtraPathData).split(':'); } - foreach (QString libraryPath, QCoreApplication::libraryPaths()) { - searchDirs << libraryPath.replace("qt5", "nymea").replace("plugins", "experiences"); + if (qEnvironmentVariableIsSet(envDefaultPath)) { + QByteArray envDefaultPathData = qgetenv(envDefaultPath); + if (!envDefaultPathData.isEmpty()) { + searchDirs << QString::fromUtf8(envDefaultPathData).split(':'); + } + } else { + foreach (QString libraryPath, QCoreApplication::libraryPaths()) { + searchDirs << libraryPath.replace("qt5", "nymea").replace("plugins", "experiences"); + } + searchDirs << QDir(QCoreApplication::applicationDirPath() + "/../lib/nymea/experiences").absolutePath(); + searchDirs << QDir(QCoreApplication::applicationDirPath() + "/../experiences/").absolutePath(); + searchDirs << QDir(QCoreApplication::applicationDirPath() + "/../../../experiences/").absolutePath(); } - searchDirs << QCoreApplication::applicationDirPath() + "/../lib/nymea/experiences"; - searchDirs << QCoreApplication::applicationDirPath() + "/../experiences/"; - searchDirs << QCoreApplication::applicationDirPath() + "/../../../experiences/"; + + searchDirs.removeDuplicates(); return searchDirs; } diff --git a/libnymea-core/integrations/apikeysprovidersloader.cpp b/libnymea-core/integrations/apikeysprovidersloader.cpp index 6d9e9fb3..aa5a529a 100644 --- a/libnymea-core/integrations/apikeysprovidersloader.cpp +++ b/libnymea-core/integrations/apikeysprovidersloader.cpp @@ -39,18 +39,29 @@ QHash ApiKeysProvidersLoader::allApiKeys() const QStringList ApiKeysProvidersLoader::pluginSearchDirs() const { + const char *envDefaultPath = "NYMEA_APIKEYS_PLUGINS_PATH"; + const char *envExtraPath = "NYMEA_APIKEYS_PLUGINS_EXTRA_PATH"; + QStringList searchDirs; - QByteArray envPath = qgetenv("NYMEA_APIKEYS_PLUGINS_PATH"); - if (!envPath.isEmpty()) { - searchDirs << QString(envPath).split(':'); + QByteArray envExtraPathData = qgetenv(envExtraPath); + if (!envExtraPathData.isEmpty()) { + searchDirs << QString::fromUtf8(envExtraPathData).split(':'); } - foreach (QString libraryPath, QCoreApplication::libraryPaths()) { - searchDirs << libraryPath.replace("qt5", "nymea").replace("plugins", "apikeysproviders"); + if (qEnvironmentVariableIsSet(envDefaultPath)) { + QByteArray envDefaultPathData = qgetenv(envDefaultPath); + if (!envDefaultPathData.isEmpty()) { + searchDirs << QString::fromUtf8(envDefaultPathData).split(':'); + } + } else { + foreach (QString libraryPath, QCoreApplication::libraryPaths()) { + searchDirs << libraryPath.replace("qt5", "nymea").replace("plugins", "apikeysproviders"); + } + searchDirs << QDir(QCoreApplication::applicationDirPath() + "/../lib/nymea/apikeysproviders").absolutePath(); + searchDirs << QDir(QCoreApplication::applicationDirPath() + "/../apikeysproviders/").absolutePath(); + searchDirs << QDir(QCoreApplication::applicationDirPath() + "/../../../apikeysproviders/").absolutePath(); } - searchDirs << QDir(QCoreApplication::applicationDirPath() + "/../lib/nymea/apikeysproviders/").absolutePath(); - searchDirs << QDir(QCoreApplication::applicationDirPath() + "/../apikeysproviders/").absolutePath(); - searchDirs << QDir(QCoreApplication::applicationDirPath() + "/../../../apikeysproviders/").absolutePath(); + searchDirs.removeDuplicates(); return searchDirs; } diff --git a/libnymea-core/integrations/thingmanagerimplementation.cpp b/libnymea-core/integrations/thingmanagerimplementation.cpp index 537c1703..b06fd739 100644 --- a/libnymea-core/integrations/thingmanagerimplementation.cpp +++ b/libnymea-core/integrations/thingmanagerimplementation.cpp @@ -131,21 +131,32 @@ ThingManagerImplementation::~ThingManagerImplementation() QStringList ThingManagerImplementation::pluginSearchDirs() { + const char *envDefaultPath = "NYMEA_PLUGINS_PATH"; + const char *envExtraPath = "NYMEA_PLUGINS_EXTRA_PATH"; + QStringList searchDirs; - QByteArray envPath = qgetenv("NYMEA_PLUGINS_PATH"); - if (!envPath.isEmpty()) { - searchDirs << QString(envPath).split(':'); + QByteArray envExtraPathData = qgetenv(envExtraPath); + if (!envExtraPathData.isEmpty()) { + searchDirs << QString::fromUtf8(envExtraPathData).split(':'); } - foreach (QString libraryPath, QCoreApplication::libraryPaths()) { - searchDirs << libraryPath.replace("qt5", "nymea"); + if (qEnvironmentVariableIsSet(envDefaultPath)) { + QByteArray envDefaultPathData = qgetenv(envDefaultPath); + if (!envDefaultPathData.isEmpty()) { + searchDirs << QString::fromUtf8(envDefaultPathData).split(':'); + } + } else { + foreach (QString libraryPath, QCoreApplication::libraryPaths()) { + searchDirs << libraryPath.replace("qt5", "nymea"); + } + foreach (QString libraryPath, QCoreApplication::libraryPaths()) { + searchDirs << libraryPath.replace("plugins", "nymea/plugins"); + } + searchDirs << QDir(QCoreApplication::applicationDirPath() + "/../lib/nymea/plugins/").absolutePath(); + searchDirs << QDir(QCoreApplication::applicationDirPath() + "/../plugins/").absolutePath(); + searchDirs << QDir(QCoreApplication::applicationDirPath() + "/../../../plugins/").absolutePath(); } - foreach (QString libraryPath, QCoreApplication::libraryPaths()) { - searchDirs << libraryPath.replace("plugins", "nymea/plugins"); - } - searchDirs << QDir(QCoreApplication::applicationDirPath() + "/../lib/nymea/plugins/").absolutePath(); - searchDirs << QDir(QCoreApplication::applicationDirPath() + "/../plugins/").absolutePath(); - searchDirs << QDir(QCoreApplication::applicationDirPath() + "/../../../plugins/").absolutePath(); + searchDirs.removeDuplicates(); return searchDirs; } diff --git a/libnymea-core/platform/platform.cpp b/libnymea-core/platform/platform.cpp index 98692357..fd46d48e 100644 --- a/libnymea-core/platform/platform.cpp +++ b/libnymea-core/platform/platform.cpp @@ -101,21 +101,33 @@ PlatformZeroConfController *Platform::zeroConfController() const QStringList Platform::pluginSearchDirs() const { + const char *envDefaultPath = "NYMEA_PLATFORM_PLUGINS_PATH"; + const char *envExtraPath = "NYMEA_PLATFORM_PLUGINS_EXTRA_PATH"; + QStringList searchDirs; - QByteArray envPath = qgetenv("NYMEA_PLATFORM_PLUGINS_PATH"); - if (!envPath.isEmpty()) { - searchDirs << QString(envPath).split(':'); + QByteArray envExtraPathData = qgetenv(envExtraPath); + if (!envExtraPathData.isEmpty()) { + searchDirs << QString::fromUtf8(envExtraPathData).split(':'); } - foreach (QString libraryPath, QCoreApplication::libraryPaths()) { - searchDirs << libraryPath.replace("qt5", "nymea").replace("plugins", "platform"); + if (qEnvironmentVariableIsSet(envDefaultPath)) { + QByteArray envDefaultPathData = qgetenv(envDefaultPath); + if (!envDefaultPathData.isEmpty()) { + searchDirs << QString::fromUtf8(envDefaultPathData).split(':'); + } + } else { + foreach (QString libraryPath, QCoreApplication::libraryPaths()) { + searchDirs << libraryPath.replace("qt5", "nymea").replace("plugins", "platform"); + } + foreach (QString libraryPath, QCoreApplication::libraryPaths()) { + searchDirs << libraryPath.replace("plugins", "nymea/platform"); + } + searchDirs << QDir(QCoreApplication::applicationDirPath() + "/../lib/nymea/platform/").absolutePath(); + searchDirs << QDir(QCoreApplication::applicationDirPath() + "/../platform/").absolutePath(); + searchDirs << QDir(QCoreApplication::applicationDirPath() + "/../../../platform/").absolutePath(); } - foreach (QString libraryPath, QCoreApplication::libraryPaths()) { - searchDirs << libraryPath.replace("plugins", "nymea/platform"); - } - searchDirs << QCoreApplication::applicationDirPath() + "/../lib/nymea/platform/"; - searchDirs << QCoreApplication::applicationDirPath() + "/../platform/"; - searchDirs << QCoreApplication::applicationDirPath() + "/../../../platform/"; + + searchDirs.removeDuplicates(); return searchDirs; }