No longer deploy image files and sources of QML imports. upstream/5.2.96+rc2
authorFriedemann Kleint <Friedemann.Kleint@digia.com>
Mon, 28 Apr 2014 12:07:51 +0000 (14:07 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 6 May 2014 06:41:45 +0000 (08:41 +0200)
These files can be omitted for the Qt Quick Controls and
Qt Quick Dialogs modules.

Task-number: QTBUG-28766
Task-number: QTBUG-31565
Change-Id: Id02939a7124cd5db83d81dcc59663ddf4d091f70
Reviewed-by: Kai Koehne <kai.koehne@digia.com>
src/windeployqt/main.cpp
src/windeployqt/utils.h

index b0972e2..6e72d56 100644 (file)
@@ -571,14 +571,23 @@ private:
 // QML import trees: DLLs (matching debgug) and .qml/,js, etc.
 class QmlDirectoryFileEntryFunction {
 public:
-    explicit QmlDirectoryFileEntryFunction(Platform platform, bool debug)
-        : m_qmlNameFilter(QStringList() << QStringLiteral("*.js") << QStringLiteral("qmldir") << QStringLiteral("*.qml") << QStringLiteral("*.qmltypes") << QStringLiteral("*.png"))
+    explicit QmlDirectoryFileEntryFunction(Platform platform, bool debug, bool skipQmlSources = false)
+        : m_qmlNameFilter(QmlDirectoryFileEntryFunction::qmlNameFilters(skipQmlSources))
         , m_dllFilter(platform, debug)
     {}
 
     QStringList operator()(const QDir &dir) const { return m_dllFilter(dir) + m_qmlNameFilter(dir);  }
 
 private:
+    static inline QStringList qmlNameFilters(bool skipQmlSources)
+    {
+        QStringList result;
+        result << QStringLiteral("qmldir") << QStringLiteral("*.qmltypes");
+        if (!skipQmlSources)
+            result << QStringLiteral("*.js") <<  QStringLiteral("*.qml") << QStringLiteral("*.png");
+        return result;
+    }
+
     NameFilterFileEntryFunction m_qmlNameFilter;
     DllDirectoryFileEntryFunction m_dllFilter;
 };
@@ -1048,7 +1057,14 @@ static DeployResult deploy(const Options &options,
                                << QDir::toNativeSeparators(installPath) << '\n';
                 if (installPath != options.directory && !createDirectory(installPath, errorMessage))
                     return result;
-                if (!updateFile(module.sourcePath, qmlFileEntryFunction, installPath, options.updateFileFlags, options.json, errorMessage))
+                const bool updateResult = module.sourcePath.contains(QLatin1String("QtQuick/Controls"))
+                    || module.sourcePath.contains(QLatin1String("QtQuick/Dialogs")) ?
+                    updateFile(module.sourcePath, QmlDirectoryFileEntryFunction(options.platform, isDebug, true),
+                               installPath, options.updateFileFlags | RemoveEmptyQmlDirectories,
+                               options.json, errorMessage) :
+                    updateFile(module.sourcePath, qmlFileEntryFunction, installPath, options.updateFileFlags,
+                               options.json, errorMessage);
+                if (!updateResult)
                     return result;
             }
         } // Quick 2
index a690361..8a520c7 100644 (file)
@@ -201,7 +201,8 @@ extern int optVerboseLevel;
 // to obtain the files.
 enum UpdateFileFlag  {
     ForceUpdateFile = 0x1,
-    SkipUpdateFile = 0x2
+    SkipUpdateFile = 0x2,
+    RemoveEmptyQmlDirectories = 0x4
 };
 
 template <class DirectoryFileEntryFunction>
@@ -257,6 +258,7 @@ bool updateFile(const QString &sourceFileName,
     } // Source is symbolic link
 
     if (sourceFileInfo.isDir()) {
+        bool created = false;
         if (targetFileInfo.exists()) {
             if (!targetFileInfo.isDir()) {
                 *errorMessage = QString::fromLatin1("%1 already exists and is not a directory.")
@@ -267,10 +269,13 @@ bool updateFile(const QString &sourceFileName,
             QDir d(targetDirectory);
             if (optVerboseLevel)
                 std::wcout << "Creating " << targetFileName << ".\n";
-            if (!(flags & SkipUpdateFile) && !d.mkdir(sourceFileInfo.fileName())) {
-                *errorMessage = QString::fromLatin1("Cannot create directory %1 under %2.")
-                                .arg(sourceFileInfo.fileName(), QDir::toNativeSeparators(targetDirectory));
-                return false;
+            if (!(flags & SkipUpdateFile)) {
+                created = d.mkdir(sourceFileInfo.fileName());
+                if (!created) {
+                    *errorMessage = QString::fromLatin1("Cannot create directory %1 under %2.")
+                            .arg(sourceFileInfo.fileName(), QDir::toNativeSeparators(targetDirectory));
+                    return false;
+                }
             }
         }
         // Recurse into directory
@@ -280,6 +285,18 @@ bool updateFile(const QString &sourceFileName,
         foreach (const QString &entry, allEntries)
             if (!updateFile(sourceFileName + QLatin1Char('/') + entry, directoryFileEntryFunction, targetFileName, flags, json, errorMessage))
                 return false;
+        // Remove empty directories, for example QML import folders for which the filter did not match.
+        if (created && (flags & RemoveEmptyQmlDirectories)) {
+            QDir d(targetFileName);
+            const QStringList entries = d.entryList(QStringList(), QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
+            if (entries.isEmpty() || (entries.size() == 1 && entries.first() == QLatin1String("qmldir"))) {
+                if (!d.removeRecursively()) {
+                    *errorMessage = QString::fromLatin1("Cannot remove empty directory %1.")
+                            .arg(QDir::toNativeSeparators(targetFileName));
+                    return false;
+                }
+            }
+        }
         return true;
     } // Source is directory.