Allow plugins to be skipped at runtime (#7691)
Allows plugins (such as carla) to be skipped when not installed
This commit is contained in:
@@ -23,7 +23,8 @@ if command -v carla > /dev/null 2>&1; then
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo "[$ME] Carla does not appear to be installed. That's OK, please ignore any related library errors." >&2
|
||||
echo "[$ME] Carla does not appear to be installed, we'll remove it from the plugin listing." >&2
|
||||
export "LMMS_EXCLUDE_PLUGINS=libcarla,${LMMS_EXCLUDE_PLUGINS}"
|
||||
fi
|
||||
|
||||
# Additional workarounds for library conflicts
|
||||
|
||||
@@ -104,6 +104,8 @@ private:
|
||||
QHash<QString, QString> m_errors;
|
||||
|
||||
static std::unique_ptr<PluginFactory> s_instance;
|
||||
|
||||
static void filterPlugins(QSet<QFileInfo>& files);
|
||||
};
|
||||
|
||||
//Short-hand function
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QLibrary>
|
||||
#include <QRegularExpression>
|
||||
#include <memory>
|
||||
#include "lmmsconfig.h"
|
||||
|
||||
@@ -157,6 +158,9 @@ void PluginFactory::discoverPlugins()
|
||||
#endif
|
||||
}
|
||||
|
||||
// Apply any plugin filters from environment LMMS_EXCLUDE_PLUGINS
|
||||
filterPlugins(files);
|
||||
|
||||
// Cheap dependency handling: zynaddsubfx needs ZynAddSubFxCore. By loading
|
||||
// all libraries twice we ensure that libZynAddSubFxCore is found.
|
||||
for (const QFileInfo& file : files)
|
||||
@@ -245,7 +249,47 @@ void PluginFactory::discoverPlugins()
|
||||
m_descriptors = descriptors;
|
||||
}
|
||||
|
||||
// Filter plugins based on environment variable, e.g. export LMMS_EXCLUDE_PLUGINS="libcarla"
|
||||
void PluginFactory::filterPlugins(QSet<QFileInfo>& files) {
|
||||
// Get filter
|
||||
QList<QRegularExpression> excludedPatterns;
|
||||
QString excludePatternString = std::getenv("LMMS_EXCLUDE_PLUGINS");
|
||||
|
||||
if (!excludePatternString.isEmpty()) {
|
||||
QStringList patterns = excludePatternString.split(',');
|
||||
for (const QString& pattern : patterns) {
|
||||
QRegularExpression regex(pattern.trimmed());
|
||||
if (!pattern.trimmed().isEmpty() && regex.isValid()) {
|
||||
excludedPatterns << regex;
|
||||
} else {
|
||||
qWarning() << "Invalid regular expression:" << pattern;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get files to remove
|
||||
QSet<QFileInfo> filesToRemove;
|
||||
for (const QFileInfo& fileInfo : files) {
|
||||
bool excluded = false;
|
||||
QString filePath = fileInfo.filePath();
|
||||
|
||||
for (const QRegularExpression& pattern : excludedPatterns) {
|
||||
if (pattern.match(filePath).hasMatch()) {
|
||||
excluded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (excluded) {
|
||||
filesToRemove.insert(fileInfo);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove them
|
||||
for (const QFileInfo& fileInfo : filesToRemove) {
|
||||
files.remove(fileInfo);
|
||||
}
|
||||
}
|
||||
|
||||
QString PluginFactory::PluginInfo::name() const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user