Make plugin deployment white-list based.
authorMorten Johan Sorvig <morten.sorvig@digia.com>
Wed, 24 Oct 2012 11:04:27 +0000 (13:04 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Thu, 15 Nov 2012 06:28:47 +0000 (07:28 +0100)
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 <eike.ziller@digia.com>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
src/macdeployqt/shared/shared.cpp

index 55c08c9..1bb0ef6 100644 (file)
@@ -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<FrameworkInfo> 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)