1commit 26d6c76d5a51504ebabec5f4ea2643069743f962
2Author: Boudewijn Rempt <boud@valdyas.org>
3Date:   Sat Nov 4 14:15:25 2017 +0100
4
5    Fix macdeployqt
6
7diff --git a/qttools/src/macdeployqt/macdeployqt/main.cpp b/qttools/src/macdeployqt/macdeployqt/main.cpp
8index 5488a5f..1e90c72 100644
9--- a/qttools/src/macdeployqt/macdeployqt/main.cpp
10+++ b/qttools/src/macdeployqt/macdeployqt/main.cpp
11@@ -53,6 +53,7 @@ int main(int argc, char **argv)
12         qDebug() << "   -codesign=<ident>  : Run codesign with the given identity on all executables";
13         qDebug() << "   -appstore-compliant: Skip deployment of components that use private API";
14         qDebug() << "   -libpath=<path>    : Add the given path to the library search path";
15+        qDebug() << "   -extra-plugins=<d> : Deploy plugins from given extra directory";
16         qDebug() << "";
17         qDebug() << "macdeployqt takes an application bundle as input and makes it";
18         qDebug() << "self-contained by copying in the Qt frameworks and plugins that";
19@@ -94,6 +95,7 @@ int main(int argc, char **argv)
20     extern QString codesignIdentiy;
21     extern bool appstoreCompliant;
22     extern bool deployFramework;
23+    QStringList extraPluginDirectories;
24
25     for (int i = 2; i < argc; ++i) {
26         QByteArray argument = QByteArray(argv[i]);
27@@ -162,6 +164,14 @@ int main(int argc, char **argv)
28             LogDebug() << "Argument found:" << argument;
29             deployFramework = true;
30
31+         } else if (argument.startsWith(QByteArray("-extra-plugins"))) {
32+             LogDebug() << "Argument found:" << argument;
33+             int index = argument.indexOf('=');
34+             if (index == -1)
35+                 LogError() << "Missing extra plugins directory";
36+             else
37+                 extraPluginDirectories << argument.mid(index+1);
38+
39         } else if (argument.startsWith("-")) {
40             LogError() << "Unknown argument" << argument << "\n";
41             return 1;
42@@ -192,10 +202,13 @@ int main(int argc, char **argv)
43         deploymentInfo.deployedFrameworks = deploymentInfo.deployedFrameworks.toSet().toList();
44     }
45
46-    if (plugins && !deploymentInfo.qtPath.isEmpty()) {
47+    if ((plugins && !deploymentInfo.qtPath.isEmpty()) || !extraPluginDirectories.isEmpty()) {
48         deploymentInfo.pluginPath = deploymentInfo.qtPath + "/plugins";
49         LogNormal();
50-        deployPlugins(appBundlePath, deploymentInfo, useDebugLibs);
51+        if (plugins && !deploymentInfo.qtPath.isEmpty())
52+            deployPlugins(appBundlePath, deploymentInfo, useDebugLibs);
53+        if (!extraPluginDirectories.isEmpty())
54+            deployExtraPlugins(appBundlePath, deploymentInfo, useDebugLibs, extraPluginDirectories);
55         createQtConf(appBundlePath);
56     }
57
58diff --git a/qttools/src/macdeployqt/shared/shared.cpp b/qttools/src/macdeployqt/shared/shared.cpp
59index 9575090..477f7a0 100644
60--- a/qttools/src/macdeployqt/shared/shared.cpp
61+++ b/qttools/src/macdeployqt/shared/shared.cpp
62@@ -1120,6 +1120,43 @@ void deployPlugins(const ApplicationBundleInfo &appBundleInfo, const QString &pl
63     }
64 }
65
66+void deployExtraPlugins(const ApplicationBundleInfo &appBundleInfo,
67+        const QString pluginDestinationPath, DeploymentInfo deploymentInfo, bool useDebugLibs, const QStringList &extraPluginDirectories)
68+{
69+    foreach (const QString &extraPluginDir, extraPluginDirectories) {
70+        LogNormal() << "Deploying plugins from" << extraPluginDir;
71+
72+        // search for dylib and so files, both work as plugins on mac os
73+        QDir dir(extraPluginDir);
74+        dir.setFilter(QDir::Files);
75+        dir.setNameFilters(QStringList() << "*.dylib" << "*.so");
76+        QDirIterator dirIterator(dir, QDirIterator::Subdirectories);
77+        QStringList pluginList;
78+        while (dirIterator.hasNext()) {
79+            dirIterator.next();
80+            if (!QFileInfo(dirIterator.filePath()).isFile())
81+                continue;
82+            pluginList.append(dir.relativeFilePath(dirIterator.filePath()));
83+        }
84+
85+        // deploy all found plugins
86+        foreach (const QString &plugin, pluginList) {
87+            QString sourcePath = extraPluginDir + "/" + plugin;
88+            const QString destinationPath = pluginDestinationPath + "/" + plugin;
89+            QDir dir;
90+            dir.mkpath(QFileInfo(destinationPath).path());
91+
92+            if (copyFilePrintStatus(sourcePath, destinationPath)) {
93+                runStrip(destinationPath);
94+
95+                QList<FrameworkInfo> frameworks = getQtFrameworks(destinationPath, appBundleInfo.path, deploymentInfo.rpathsUsed, useDebugLibs);
96+                deployQtFrameworks(frameworks, appBundleInfo.path, QStringList() << destinationPath, useDebugLibs, deploymentInfo.useLoaderPath);
97+
98+            }
99+        }
100+    }
101+}
102+
103 void createQtConf(const QString &appBundlePath)
104 {
105     // Set Plugins and imports paths. These are relative to App.app/Contents.
106@@ -1161,6 +1198,16 @@ void deployPlugins(const QString &appBundlePath, DeploymentInfo deploymentInfo,
107     deployPlugins(applicationBundle, deploymentInfo.pluginPath, pluginDestinationPath, deploymentInfo, useDebugLibs);
108 }
109
110+void deployExtraPlugins(const QString &appBundlePath, DeploymentInfo deploymentInfo, bool useDebugLibs, const QStringList &extraPluginDirectories)
111+{
112+    ApplicationBundleInfo applicationBundle;
113+    applicationBundle.path = appBundlePath;
114+    applicationBundle.binaryPath = findAppBinary(appBundlePath);
115+
116+    const QString pluginDestinationPath = appBundlePath + "/" + "Contents/PlugIns";
117+    deployExtraPlugins(applicationBundle, pluginDestinationPath, deploymentInfo, useDebugLibs, extraPluginDirectories);
118+}
119+
120 void deployQmlImport(const QString &appBundlePath, const QSet<QString> &rpaths, const QString &importSourcePath, const QString &importName)
121 {
122     QString importDestinationPath = appBundlePath + "/Contents/Resources/qml/" + importName;
123diff --git a/qttools/src/macdeployqt/shared/shared.h b/qttools/src/macdeployqt/shared/shared.h
124index c173846..cceac3a 100644
125--- a/qttools/src/macdeployqt/shared/shared.h
126+++ b/qttools/src/macdeployqt/shared/shared.h
127@@ -116,6 +116,7 @@ DeploymentInfo deployQtFrameworks(const QString &appBundlePath, const QStringLis
128 DeploymentInfo deployQtFrameworks(QList<FrameworkInfo> frameworks,const QString &bundlePath, const QStringList &binaryPaths, bool useDebugLibs, bool useLoaderPath);
129 void createQtConf(const QString &appBundlePath);
130 void deployPlugins(const QString &appBundlePath, DeploymentInfo deploymentInfo, bool useDebugLibs);
131+void deployExtraPlugins(const QString &appBundlePath, DeploymentInfo deploymentInfo, bool useDebugLibs, const QStringList &extraPluginDirectories);
132 bool deployQmlImports(const QString &appBundlePath, DeploymentInfo deploymentInfo, QStringList &qmlDirs);
133 void changeIdentification(const QString &id, const QString &binaryPath);
134 void changeInstallName(const QString &oldName, const QString &newName, const QString &binaryPath);
135