diff options
author | Dominik Holland <dominik.holland@pelagicore.com> | 2019-09-04 11:24:55 +0200 |
---|---|---|
committer | Dominik Holland <dominik.holland@pelagicore.com> | 2019-09-10 16:41:11 +0200 |
commit | ea7811529421975182f3de519da36ea610844eb9 (patch) | |
tree | c1db53f3b9ea80bcead3404bc0b4fcd5d840563e | |
parent | f553f4aa6f656489adf56b5421df24171ec56ca4 (diff) |
Add a way to define the plugin paths in configuration files
This adds support to define pluginPaths for the system-ui,
the qml and qml-in-process runtimes in am-config.yaml.
In addition the apps can now also define their own pluginPaths
in their info.yaml
Fixes: AUTOSUITE-1219
Change-Id: I1e1ae4d8d7f53dbfb3b679910d7ec57c50f90004
Reviewed-by: Robert Griebl <robert.griebl@pelagicore.com>
-rw-r--r-- | doc/configuration.qdoc | 11 | ||||
-rw-r--r-- | doc/manifest.qdoc | 7 | ||||
-rw-r--r-- | doc/singlevsmultiprocess.qdoc | 8 | ||||
-rw-r--r-- | src/main-lib/defaultconfiguration.cpp | 10 | ||||
-rw-r--r-- | src/main-lib/defaultconfiguration.h | 1 | ||||
-rw-r--r-- | src/main-lib/main.cpp | 1 | ||||
-rw-r--r-- | src/manager-lib/qmlinprocessruntime.cpp | 11 | ||||
-rw-r--r-- | src/tools/launcher-qml/launcher-qml.cpp | 44 |
8 files changed, 84 insertions, 9 deletions
diff --git a/doc/configuration.qdoc b/doc/configuration.qdoc index 9ef3d870..4b7d646f 100644 --- a/doc/configuration.qdoc +++ b/doc/configuration.qdoc @@ -222,6 +222,10 @@ or across multiple config files, the final value is resolved based on these rule \li array<string> \li Adds additional QML import paths to the System UI. \row + \li [\c ui/pluginPaths] + \li array<string> + \li Adds additional Qt plugin paths to the System UI. + \row \li [\c ui/style] \li string \li If set, the given style is used by QtQuickControls 2. @@ -563,7 +567,12 @@ an additional column specifying which runtime a configuration option applies to: \li \c importPaths \li qml \li array<string> - \li Adds an additional QML import path for apps started via this runtime. + \li Adds additional QML import paths for apps started via this runtime. + \row + \li \c pluginPaths + \li qml + \li array<string> + \li Adds additional Qt plugin paths for apps started via this runtime. \row \li \c plugins \li qml diff --git a/doc/manifest.qdoc b/doc/manifest.qdoc index bd7a465a..14d68969 100644 --- a/doc/manifest.qdoc +++ b/doc/manifest.qdoc @@ -271,6 +271,13 @@ that specifies which runtime a configuration option applies to: \li A list of paths to add to the QML-engine's import paths. Use of this parameter is equivalent to setting \c QML2_IMPORT_PATH for a program started from the command line. \row + \li \c pluginPaths + \li qml, qml-in-process + \li array<string> + \li A list of paths to add to Qt's library paths, which are used to find plugins. Use of this + parameter is equivalent to setting \c QT_PLUGIN_PATH for a program started from the command + line. +\row \li \c arguments \li native \li array<string> diff --git a/doc/singlevsmultiprocess.qdoc b/doc/singlevsmultiprocess.qdoc index 04748c05..0fffe168 100644 --- a/doc/singlevsmultiprocess.qdoc +++ b/doc/singlevsmultiprocess.qdoc @@ -97,6 +97,14 @@ by containers and for security reasons. In general, paths defined in the configuration might be provided to QML as absolute paths in single-process mode; but as relative paths in multi-process mode. +Similarly, a custom \c pluginPath as part of \c info.yaml behaves differently in single-process +mode, than in multi-process mode. When a new process starts in multi-process mode, the new \c +pluginPath can be added to Qt very early on, before most systems are initialized. This ensures that +when a QPluginLoader is used, the \c pluginPath is correct. In comparison, with single-process +mode, we need to add an additional \c pluginPath to the QApplication already running. Whether this +change has any effect depends on how the plugin is loaded: if the \c pluginPath is reevaluated +whenever a new plugin needs to be loaded. + \note In single-process mode, some configuration options have no effect, such as: \c quicklaunch, \c quicklaunchQml, \c crashAction, and so on. diff --git a/src/main-lib/defaultconfiguration.cpp b/src/main-lib/defaultconfiguration.cpp index 6ba3bada..01ef4b13 100644 --- a/src/main-lib/defaultconfiguration.cpp +++ b/src/main-lib/defaultconfiguration.cpp @@ -230,6 +230,16 @@ QStringList DefaultConfiguration::importPaths() const return importPaths; } +QStringList DefaultConfiguration::pluginPaths() const +{ + QStringList pluginPaths = value<QStringList>(nullptr, { "ui", "pluginPaths" }); + + for (int i = 0; i < pluginPaths.size(); ++i) + pluginPaths[i] = QFileInfo(pluginPaths.at(i)).absoluteFilePath(); + + return pluginPaths; +} + bool DefaultConfiguration::verbose() const { return value<bool>("verbose") || m_forceVerbose; diff --git a/src/main-lib/defaultconfiguration.h b/src/main-lib/defaultconfiguration.h index d253d420..d61abdcc 100644 --- a/src/main-lib/defaultconfiguration.h +++ b/src/main-lib/defaultconfiguration.h @@ -74,6 +74,7 @@ public: bool noFullscreen() const; QString windowIcon() const; QStringList importPaths() const; + QStringList pluginPaths() const; bool verbose() const; void setForceVerbose(bool forceVerbose); bool slowAnimations() const; diff --git a/src/main-lib/main.cpp b/src/main-lib/main.cpp index 0ebc6211..9c493a7b 100644 --- a/src/main-lib/main.cpp +++ b/src/main-lib/main.cpp @@ -247,6 +247,7 @@ void Main::setup(const DefaultConfiguration *cfg, const QStringList &deploymentW if (!cfg->disableIntents()) setupIntents(cfg->intentTimeouts()); + setLibraryPaths(libraryPaths() + cfg->pluginPaths()); setupQmlEngine(cfg->importPaths(), cfg->style()); setupWindowTitle(QString(), cfg->windowIcon()); setupWindowManager(cfg->waylandSocketName(), cfg->slowAnimations(), cfg->noUiWatchdog()); diff --git a/src/manager-lib/qmlinprocessruntime.cpp b/src/manager-lib/qmlinprocessruntime.cpp index 788e22d2..099d0a64 100644 --- a/src/manager-lib/qmlinprocessruntime.cpp +++ b/src/manager-lib/qmlinprocessruntime.cpp @@ -110,6 +110,17 @@ bool QmlInProcessRuntime::start() loadQmlDummyDataFiles(m_inProcessQmlEngine, QFileInfo(m_app->nonAliasedInfo()->absoluteCodeFilePath()).path()); } + const QStringList pluginPaths = variantToStringList(configuration().value(qSL("pluginPaths"))) + + variantToStringList(m_app->runtimeParameters().value(qSL("pluginPaths"))); + + if (!pluginPaths.isEmpty()) { + const QString codeDir = m_app->codeDir() + QDir::separator(); + for (const QString &path : pluginPaths) + qApp->addLibraryPath(QFileInfo(path).isRelative() ? codeDir + path : path); + + qCDebug(LogSystem) << "Updated plugin paths:" << qApp->libraryPaths(); + } + const QStringList importPaths = variantToStringList(configuration().value(qSL("importPaths"))) + variantToStringList(m_app->runtimeParameters().value(qSL("importPaths"))); if (!importPaths.isEmpty()) { diff --git a/src/tools/launcher-qml/launcher-qml.cpp b/src/tools/launcher-qml/launcher-qml.cpp index 9ff121a7..12ac1ef3 100644 --- a/src/tools/launcher-qml/launcher-qml.cpp +++ b/src/tools/launcher-qml/launcher-qml.cpp @@ -207,20 +207,36 @@ Controller::Controller(LauncherMain *a, bool quickLaunched, const QString &direc m_configuration = a->runtimeConfiguration(); - QString absolutePath; + QString absolutePluginPath; + QStringList pluginPaths = variantToStringList(m_configuration.value(qSL("pluginPaths"))); + for (QString &path : pluginPaths) { + if (QFileInfo(path).isRelative()) + path.prepend(a->baseDir()); + else if (absolutePluginPath.isEmpty()) + absolutePluginPath = path; + + qApp->addLibraryPath(path); + } + + if (!absolutePluginPath.isEmpty()) { + qCWarning(LogDeployment).nospace() << "Absolute plugin path in the runtime configuration " + "can lead to problems inside containers (e.g. " << absolutePluginPath << ")"; + } + + QString absoluteImportPath; QStringList importPaths = variantToStringList(m_configuration.value(qSL("importPaths"))); for (QString &path : importPaths) { if (QFileInfo(path).isRelative()) path.prepend(a->baseDir()); - else if (absolutePath.isEmpty()) - absolutePath = path; + else if (absoluteImportPath.isEmpty()) + absoluteImportPath = path; m_engine.addImportPath(path); } - if (!absolutePath.isEmpty()) { + if (!absoluteImportPath.isEmpty()) { qCWarning(LogDeployment).nospace() << "Absolute import path in the runtime configuration " - "can lead to problems inside containers (e.g. " << absolutePath << ")"; + "can lead to problems inside containers (e.g. " << absoluteImportPath << ")"; } StartupTimer::instance()->checkpoint("after application config initialization"); @@ -401,10 +417,22 @@ void Controller::startApplication(const QString &baseDir, const QString &qmlFile loadQmlDummyDataFiles(&m_engine, QFileInfo(qmlFile).path()); } + QVariant pluginPaths = runtimeParameters.value(qSL("pluginPaths")); + const QVariantList ppvl = (pluginPaths.type() == QVariant::String) ? QVariantList{pluginPaths} + : qdbus_cast<QVariantList>(pluginPaths); + for (const QVariant &v : ppvl) { + const QString path = v.toString(); + if (QFileInfo(path).isRelative()) + qApp->addLibraryPath(QDir().absoluteFilePath(path)); + else + qCWarning(LogQmlRuntime) << "Omitting absolute plugin path in info file for safety reasons:" << path; + } + qCDebug(LogQmlRuntime) << "Plugin paths:" << qApp->libraryPaths(); + QVariant imports = runtimeParameters.value(qSL("importPaths")); - const QVariantList vl = (imports.type() == QVariant::String) ? QVariantList{imports} - : qdbus_cast<QVariantList>(imports); - for (const QVariant &v : vl) { + const QVariantList ipvl = (imports.type() == QVariant::String) ? QVariantList{imports} + : qdbus_cast<QVariantList>(imports); + for (const QVariant &v : ipvl) { const QString path = v.toString(); if (QFileInfo(path).isRelative()) m_engine.addImportPath(QDir().absoluteFilePath(path)); |