From 3b3bd48dcdf3a1532f6c2008fba6f1c4934f25a0 Mon Sep 17 00:00:00 2001 From: tresf Date: Sat, 8 Feb 2025 03:34:14 -0500 Subject: [PATCH] Allow carla plugins to be conditionally skipped --- cmake/linux/apprun-hooks/carla-hook.sh | 3 +- include/PluginFactory.h | 2 ++ src/core/PluginFactory.cpp | 44 ++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/cmake/linux/apprun-hooks/carla-hook.sh b/cmake/linux/apprun-hooks/carla-hook.sh index c505267bbf7..5ac9803a048 100644 --- a/cmake/linux/apprun-hooks/carla-hook.sh +++ b/cmake/linux/apprun-hooks/carla-hook.sh @@ -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=*carla*,${LMMS_EXCLUDE_PLUGINS}" fi # Additional workarounds for library conflicts diff --git a/include/PluginFactory.h b/include/PluginFactory.h index 7221f2b097b..41ce486d7f9 100644 --- a/include/PluginFactory.h +++ b/include/PluginFactory.h @@ -104,6 +104,8 @@ public slots: QHash m_errors; static std::unique_ptr s_instance; + + static QList filterPlugins(QSet& files); }; //Short-hand function diff --git a/src/core/PluginFactory.cpp b/src/core/PluginFactory.cpp index ec0f4ec4e7d..6664d9d8052 100644 --- a/src/core/PluginFactory.cpp +++ b/src/core/PluginFactory.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #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="*carla*" +QSet filterPlugins(QSet& files) { + // Get filter + QList 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 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 {