From 83f67b09c1b2b994d1252c4494d51072d2c51435 Mon Sep 17 00:00:00 2001 From: Morten Johan Sorvig Date: Wed, 24 Oct 2012 13:04:27 +0200 Subject: [PATCH] Make plugin deployment white-list based. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Deploy specific plugins instead of deploying all plugins with exceptions. Before macdeployqt would deploy nearly all plugins. The plugins themselves weren't necessarily a problem, but this would also pull in all plugin dependencies, massively bloating the app bundle. Change-Id: Ia8d8b795101958da83b299e1d8922a01b5e8f13d Reviewed-by: Eike Ziller Reviewed-by: Morten Johan Sørvig --- src/macdeployqt/shared/shared.cpp | 100 +++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 55 deletions(-) diff --git a/src/macdeployqt/shared/shared.cpp b/src/macdeployqt/shared/shared.cpp index 55c08c9..1bb0ef6 100644 --- a/src/macdeployqt/shared/shared.cpp +++ b/src/macdeployqt/shared/shared.cpp @@ -489,75 +489,65 @@ void deployPlugins(const ApplicationBundleInfo &appBundleInfo, const QString &pl const QString pluginDestinationPath, DeploymentInfo deploymentInfo, bool useDebugLibs) { LogNormal() << "Deploying plugins from" << pluginSourcePath; - QStringList plugins = QDir(pluginSourcePath).entryList(QStringList() << "*.dylib"); - foreach (QString pluginName, plugins) { - if (pluginSourcePath.contains(deploymentInfo.pluginPath)) { - QStringList deployedFrameworks = deploymentInfo.deployedFrameworks; - - // Skip the debug versions of the plugins, unless specified otherwise. - if (!useDebugLibs && pluginName.endsWith("_debug.dylib")) - continue; - - // Skip the release versions of the plugins, unless specified otherwise. - if (useDebugLibs && !pluginName.endsWith("_debug.dylib")) - continue; - - // Skip the designer plugins - if (pluginSourcePath.contains("plugins/designer")) - continue; - -#ifndef QT_GRAPHICSSYSTEM_OPENGL - // SKip the opengl graphicssystem plugin when not in use. - if (pluginName.contains("libqglgraphicssystem")) - continue; -#endif - // Deploy accessibility for Qt3Support only if the Qt3Support.framework is in use - if (deployedFrameworks.indexOf("Qt3Support.framework") == -1 && pluginName.contains("accessiblecompatwidgets")) - continue; + if (!pluginSourcePath.contains(deploymentInfo.pluginPath)) + return; - // Deploy the svg icon plugin if QtSvg.framework is in use. - if (deployedFrameworks.indexOf("QtSvg.framework") == -1 && pluginName.contains("svg")) - continue; + // Plugin white list: + QStringList pluginList; + + // Platform plugin: + pluginList.append("platforms/libqcocoa.dylib"); + + // Cocoa print support + pluginList.append("printsupport/libcocoaprintersupport.dylib"); + + // Accessibility + if (deploymentInfo.deployedFrameworks.contains(QStringLiteral("QtWidgets.framework"))) + pluginList.append("accessible/libqtaccessiblewidgets.dylib"); + if (deploymentInfo.deployedFrameworks.contains(QStringLiteral("QtQuick.framework"))) + pluginList.append("accessible/libqtaccessiblequick.dylib"); + + // All image formats (svg if QtSvg.framework is used) + QStringList imagePlugins = QDir(pluginSourcePath + QStringLiteral("/imageformats")).entryList(QStringList() << QStringLiteral("*.dylib")); + foreach (const QString &plugin, imagePlugins) { + if (plugin.contains(QStringLiteral("qsvg"))) { + if (deploymentInfo.deployedFrameworks.contains(QStringLiteral("QtSvg.framework"))) + pluginList.append(QStringLiteral("imageformats/") + plugin); + } else if (!plugin.endsWith(QStringLiteral("_debug.dylib"))) { + pluginList.append(QStringLiteral("imageformats/") + plugin); + } + } - // Deploy the phonon plugins if phonon.framework is in use - if (deployedFrameworks.indexOf("phonon.framework") == -1 && pluginName.contains("phonon")) - continue; + // Sql plugins if QtSql.framework is in use + if (deploymentInfo.deployedFrameworks.contains(QStringLiteral("QtSql.framework"))) { + QStringList sqlPlugins = QDir(pluginSourcePath + QStringLiteral("/sqldrivers")).entryList(QStringList() << QStringLiteral("*.dylib")); + foreach (const QString &plugin, sqlPlugins) { + if (!plugin.endsWith(QStringLiteral("_debug.dylib"))) + pluginList.append(QStringLiteral("/sqldrivers") + plugin); + } + } - // Deploy the sql plugins if QtSql.framework is in use - if (deployedFrameworks.indexOf("QtSql.framework") == -1 && pluginName.contains("sql")) - continue; + foreach (const QString &plugin, pluginList) { - // Deploy the script plugins if QtScript.framework is in use - if (deployedFrameworks.indexOf("QtScript.framework") == -1 && pluginName.contains("script")) - continue; + QString sourcePath = pluginSourcePath + "/" + plugin; + if (useDebugLibs) { + // Use debug plugins if found. + QString debugSourcePath = sourcePath.replace(".dylib", "_debug.dylib"); + if (QFile::exists(debugSourcePath)) + sourcePath = debugSourcePath; } + const QString destinationPath = pluginDestinationPath + "/" + plugin; QDir dir; - dir.mkpath(pluginDestinationPath); + dir.mkpath(QFileInfo(destinationPath).path()); - const QString sourcePath = pluginSourcePath + "/" + pluginName; - const QString destinationPath = pluginDestinationPath + "/" + pluginName; if (copyFilePrintStatus(sourcePath, destinationPath)) { - runStrip(destinationPath); - - // Special case for the phonon plugin: CoreVideo is not available as a separate framework - // on panther, link against the QuartzCore framework instead. (QuartzCore contians CoreVideo.) - if (pluginName.contains("libphonon_qt7")) { - changeInstallName("/System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo", - "/System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore", - destinationPath); - } - QList frameworks = getQtFrameworks(destinationPath, useDebugLibs); deployQtFrameworks(frameworks, appBundleInfo.path, QStringList() << destinationPath, useDebugLibs, deploymentInfo.useLoaderPath); } - } // foreach plugins - - QStringList subdirs = QDir(pluginSourcePath).entryList(QStringList() << "*", QDir::Dirs | QDir::NoDotAndDotDot); - foreach (const QString &subdir, subdirs) - deployPlugins(appBundleInfo, pluginSourcePath + "/" + subdir, pluginDestinationPath + "/" + subdir, deploymentInfo, useDebugLibs); + } } void createQtConf(const QString &appBundlePath) -- 2.7.4