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