// 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;
};
<< 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
// to obtain the files.
enum UpdateFileFlag {
ForceUpdateFile = 0x1,
- SkipUpdateFile = 0x2
+ SkipUpdateFile = 0x2,
+ RemoveEmptyQmlDirectories = 0x4
};
template <class DirectoryFileEntryFunction>
} // 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.")
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
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.