Merge PR #584: Allow to override default paths using new env variable

This commit is contained in:
jenkins 2022-10-25 02:37:15 +02:00
commit d59a6edd27
5 changed files with 86 additions and 40 deletions

View File

@ -12,11 +12,11 @@
To make nymead load the plugin from the plugins build directory, run nymead with an environment variable exported To make nymead load the plugin from the plugins build directory, run nymead with an environment variable exported
\code \code
$ NYMEA_PLUGINS_PATH=/path/to/plugin/ nymead -n $ NYMEA_PLUGINS_EXTRA_PATH=/path/to/plugin/ nymead -n
\endcode \endcode
In order to easier debug things, it is advised to enable debug output for the device manager and your plugin. E.g. In order to easier debug things, it is advised to enable debug output for the device manager and your plugin. E.g.
\code \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 \endcode
*/ */

View File

@ -75,18 +75,30 @@ void ExperienceManager::loadPlugins()
QStringList ExperienceManager::pluginSearchDirs() const QStringList ExperienceManager::pluginSearchDirs() const
{ {
const char *envDefaultPath = "NYMEA_EXPERIENCE_PLUGINS_PATH";
const char *envExtraPath = "NYMEA_EXPERIENCE_PLUGINS_EXTRA_PATH";
QStringList searchDirs; QStringList searchDirs;
QByteArray envPath = qgetenv("NYMEA_EXPERIENCE_PLUGINS_PATH"); QByteArray envExtraPathData = qgetenv(envExtraPath);
if (!envPath.isEmpty()) { if (!envExtraPathData.isEmpty()) {
searchDirs << QString(envPath).split(':'); searchDirs << QString::fromUtf8(envExtraPathData).split(':');
} }
foreach (QString libraryPath, QCoreApplication::libraryPaths()) { if (qEnvironmentVariableIsSet(envDefaultPath)) {
searchDirs << libraryPath.replace("qt5", "nymea").replace("plugins", "experiences"); 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.removeDuplicates();
searchDirs << QCoreApplication::applicationDirPath() + "/../../../experiences/";
return searchDirs; return searchDirs;
} }

View File

@ -39,18 +39,29 @@ QHash<QString, ApiKey> ApiKeysProvidersLoader::allApiKeys() const
QStringList ApiKeysProvidersLoader::pluginSearchDirs() const QStringList ApiKeysProvidersLoader::pluginSearchDirs() const
{ {
const char *envDefaultPath = "NYMEA_APIKEYS_PLUGINS_PATH";
const char *envExtraPath = "NYMEA_APIKEYS_PLUGINS_EXTRA_PATH";
QStringList searchDirs; QStringList searchDirs;
QByteArray envPath = qgetenv("NYMEA_APIKEYS_PLUGINS_PATH"); QByteArray envExtraPathData = qgetenv(envExtraPath);
if (!envPath.isEmpty()) { if (!envExtraPathData.isEmpty()) {
searchDirs << QString(envPath).split(':'); searchDirs << QString::fromUtf8(envExtraPathData).split(':');
} }
foreach (QString libraryPath, QCoreApplication::libraryPaths()) { if (qEnvironmentVariableIsSet(envDefaultPath)) {
searchDirs << libraryPath.replace("qt5", "nymea").replace("plugins", "apikeysproviders"); 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(); searchDirs.removeDuplicates();
return searchDirs; return searchDirs;
} }

View File

@ -131,21 +131,32 @@ ThingManagerImplementation::~ThingManagerImplementation()
QStringList ThingManagerImplementation::pluginSearchDirs() QStringList ThingManagerImplementation::pluginSearchDirs()
{ {
const char *envDefaultPath = "NYMEA_PLUGINS_PATH";
const char *envExtraPath = "NYMEA_PLUGINS_EXTRA_PATH";
QStringList searchDirs; QStringList searchDirs;
QByteArray envPath = qgetenv("NYMEA_PLUGINS_PATH"); QByteArray envExtraPathData = qgetenv(envExtraPath);
if (!envPath.isEmpty()) { if (!envExtraPathData.isEmpty()) {
searchDirs << QString(envPath).split(':'); searchDirs << QString::fromUtf8(envExtraPathData).split(':');
} }
foreach (QString libraryPath, QCoreApplication::libraryPaths()) { if (qEnvironmentVariableIsSet(envDefaultPath)) {
searchDirs << libraryPath.replace("qt5", "nymea"); 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(); searchDirs.removeDuplicates();
return searchDirs; return searchDirs;
} }

View File

@ -101,21 +101,33 @@ PlatformZeroConfController *Platform::zeroConfController() const
QStringList Platform::pluginSearchDirs() const QStringList Platform::pluginSearchDirs() const
{ {
const char *envDefaultPath = "NYMEA_PLATFORM_PLUGINS_PATH";
const char *envExtraPath = "NYMEA_PLATFORM_PLUGINS_EXTRA_PATH";
QStringList searchDirs; QStringList searchDirs;
QByteArray envPath = qgetenv("NYMEA_PLATFORM_PLUGINS_PATH"); QByteArray envExtraPathData = qgetenv(envExtraPath);
if (!envPath.isEmpty()) { if (!envExtraPathData.isEmpty()) {
searchDirs << QString(envPath).split(':'); searchDirs << QString::fromUtf8(envExtraPathData).split(':');
} }
foreach (QString libraryPath, QCoreApplication::libraryPaths()) { if (qEnvironmentVariableIsSet(envDefaultPath)) {
searchDirs << libraryPath.replace("qt5", "nymea").replace("plugins", "platform"); 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.removeDuplicates();
}
searchDirs << QCoreApplication::applicationDirPath() + "/../lib/nymea/platform/";
searchDirs << QCoreApplication::applicationDirPath() + "/../platform/";
searchDirs << QCoreApplication::applicationDirPath() + "/../../../platform/";
return searchDirs; return searchDirs;
} }