diff options
-rw-r--r-- | tests/auto/qml/qmlcachegen/Retain.qml | 2 | ||||
-rw-r--r-- | tests/auto/qml/qmlcachegen/qmlcachegen.pro | 3 | ||||
-rw-r--r-- | tests/auto/qml/qmlcachegen/retain.qrc | 5 | ||||
-rw-r--r-- | tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp | 8 | ||||
-rw-r--r-- | tools/qmlcachegen/generateloader.cpp | 15 | ||||
-rw-r--r-- | tools/qmlcachegen/qmlcachegen.cpp | 14 | ||||
-rw-r--r-- | tools/qmlcachegen/qtquickcompiler.prf | 23 |
7 files changed, 59 insertions, 11 deletions
diff --git a/tests/auto/qml/qmlcachegen/Retain.qml b/tests/auto/qml/qmlcachegen/Retain.qml new file mode 100644 index 0000000000..0e69012662 --- /dev/null +++ b/tests/auto/qml/qmlcachegen/Retain.qml @@ -0,0 +1,2 @@ +import QtQml 2.0 +QtObject {} diff --git a/tests/auto/qml/qmlcachegen/qmlcachegen.pro b/tests/auto/qml/qmlcachegen/qmlcachegen.pro index 7f7b3128cf..c7820ac1cd 100644 --- a/tests/auto/qml/qmlcachegen/qmlcachegen.pro +++ b/tests/auto/qml/qmlcachegen/qmlcachegen.pro @@ -21,4 +21,7 @@ RESOURCES += Enums.qml RESOURCES += jsmoduleimport.qml script.mjs +RESOURCES += retain.qrc +QTQUICK_COMPILER_RETAINED_RESOURCES += retain.qrc + QT += core-private qml-private testlib diff --git a/tests/auto/qml/qmlcachegen/retain.qrc b/tests/auto/qml/qmlcachegen/retain.qrc new file mode 100644 index 0000000000..af042b25d8 --- /dev/null +++ b/tests/auto/qml/qmlcachegen/retain.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>Retain.qml</file> + </qresource> +</RCC> diff --git a/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp b/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp index 97ac466e94..8cfa4cb6af 100644 --- a/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp +++ b/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp @@ -52,6 +52,7 @@ private slots: void aheadOfTimeCompilation(); void functionExpressions(); void versionChecksForAheadOfTimeUnits(); + void retainedResources(); void workerScripts(); @@ -392,6 +393,13 @@ void tst_qmlcachegen::versionChecksForAheadOfTimeUnits() QQmlMetaType::removeCachedUnitLookupFunction(testHandler); } +void tst_qmlcachegen::retainedResources() +{ + QFile file(":/Retain.qml"); + QVERIFY(file.open(QIODevice::ReadOnly)); + QVERIFY(file.readAll().startsWith("import QtQml 2.0")); +} + void tst_qmlcachegen::workerScripts() { QVERIFY(QFile::exists(":/workerscripts/worker.js")); diff --git a/tools/qmlcachegen/generateloader.cpp b/tools/qmlcachegen/generateloader.cpp index de79576d67..0027d53d00 100644 --- a/tools/qmlcachegen/generateloader.cpp +++ b/tools/qmlcachegen/generateloader.cpp @@ -36,6 +36,8 @@ #include <QFileInfo> #include <QSaveFile> +#include <algorithm> + /*! * \internal * Mangles \a str to be a unique C++ identifier. Characters that are invalid for C++ identifiers @@ -261,7 +263,8 @@ private: } }; -static QByteArray generateResourceDirectoryTree(QTextStream &code, const QStringList &qrcFiles) +static QByteArray generateResourceDirectoryTree(QTextStream &code, const QStringList &qrcFiles, + const QStringList &sortedRetainedFiles) { QByteArray call; if (qrcFiles.isEmpty()) @@ -277,7 +280,8 @@ static QByteArray generateResourceDirectoryTree(QTextStream &code, const QString for (int i = 0; i < segments.count() - 1; ++i) dirEntry = dirEntry->append(segments.at(i)); - dirEntry->appendEmptyFile(segments.last()); + if (!std::binary_search(sortedRetainedFiles.begin(), sortedRetainedFiles.end(), entry)) + dirEntry->appendEmptyFile(segments.last()); } if (resourceDirs.isEmpty()) @@ -328,7 +332,9 @@ static QString qtResourceNameForFile(const QString &fileName) return name; } -bool generateLoader(const QStringList &compiledFiles, const QString &outputFileName, const QStringList &resourceFileMappings, QString *errorString) +bool generateLoader(const QStringList &compiledFiles, const QStringList &sortedRetainedFiles, + const QString &outputFileName, const QStringList &resourceFileMappings, + QString *errorString) { QByteArray generatedLoaderCode; @@ -339,7 +345,8 @@ bool generateLoader(const QStringList &compiledFiles, const QString &outputFileN stream << "#include <QtCore/qurl.h>\n"; stream << "\n"; - QByteArray resourceRegisterCall = generateResourceDirectoryTree(stream, compiledFiles); + QByteArray resourceRegisterCall = generateResourceDirectoryTree(stream, compiledFiles, + sortedRetainedFiles); stream << "namespace QmlCacheGeneratedCode {\n"; for (int i = 0; i < compiledFiles.count(); ++i) { diff --git a/tools/qmlcachegen/qmlcachegen.cpp b/tools/qmlcachegen/qmlcachegen.cpp index 1805dde5d2..b3c55e85e0 100644 --- a/tools/qmlcachegen/qmlcachegen.cpp +++ b/tools/qmlcachegen/qmlcachegen.cpp @@ -43,8 +43,12 @@ #include "resourcefilemapper.h" +#include <algorithm> + int filterResourceFile(const QString &input, const QString &output); -bool generateLoader(const QStringList &compiledFiles, const QString &output, const QStringList &resourceFileMappings, QString *errorString); +bool generateLoader(const QStringList &compiledFiles, const QStringList &retainedFiles, + const QString &output, const QStringList &resourceFileMappings, + QString *errorString); QString symbolNamespaceForPath(const QString &relativePath); QSet<QString> illegalNames; @@ -438,6 +442,8 @@ int main(int argc, char **argv) parser.addOption(resourceFileMappingOption); QCommandLineOption resourceOption(QStringLiteral("resource"), QCoreApplication::translate("main", "Qt resource file that might later contain one of the compiled files"), QCoreApplication::translate("main", "resource-file-name")); parser.addOption(resourceOption); + QCommandLineOption retainOption(QStringLiteral("retain"), QCoreApplication::translate("main", "Qt resource file the contents of which should not be replaced by empty stubs"), QCoreApplication::translate("main", "resource-file-name")); + parser.addOption(retainOption); QCommandLineOption resourcePathOption(QStringLiteral("resource-path"), QCoreApplication::translate("main", "Qt resource file path corresponding to the file being compiled"), QCoreApplication::translate("main", "resource-path")); parser.addOption(resourcePathOption); @@ -485,9 +491,13 @@ int main(int argc, char **argv) if (target == GenerateLoader) { ResourceFileMapper mapper(sources); + ResourceFileMapper retain(parser.values(retainOption)); Error error; - if (!generateLoader(mapper.qmlCompilerFiles(), outputFileName, parser.values(resourceFileMappingOption), &error.message)) { + QStringList retainedFiles = retain.qmlCompilerFiles(); + std::sort(retainedFiles.begin(), retainedFiles.end()); + if (!generateLoader(mapper.qmlCompilerFiles(), retainedFiles, outputFileName, + parser.values(resourceFileMappingOption), &error.message)) { error.augment(QLatin1String("Error generating loader stub: ")).print(); return EXIT_FAILURE; } diff --git a/tools/qmlcachegen/qtquickcompiler.prf b/tools/qmlcachegen/qtquickcompiler.prf index 608b5c9143..c7899c5100 100644 --- a/tools/qmlcachegen/qtquickcompiler.prf +++ b/tools/qmlcachegen/qtquickcompiler.prf @@ -15,6 +15,13 @@ defineReplace(qmlCacheResourceFileOutputName) { return($${name}) } +defineTest(qtQuickRetainSources) { + for(retainedRes, QTQUICK_COMPILER_RETAINED_RESOURCES) { + equals(1, $$retainedRes): return(true) + } + return(false) +} + defineTest(qtQuickSkippedResourceFile) { for(skippedRes, QTQUICK_COMPILER_SKIPPED_RESOURCES) { equals(1, $$skippedRes): return(true) @@ -39,12 +46,18 @@ for(res, RESOURCES) { contains(rccContents,.*\\.js$)|contains(rccContents,.*\\.qml$)|contains(rccContents,.*\\.mjs$) { new_resource = $$qmlCacheResourceFileOutputName($$res) mkpath($$dirname(new_resource)) - remaining_files = $$system($$QML_CACHEGEN_FILTER -filter-resource-file -o $$system_quote($$new_resource) $$system_quote($$absRes),lines) - !isEmpty(remaining_files) { - NEWRESOURCES += $$new_resource - QMLCACHE_LOADER_FLAGS += --resource-file-mapping=$$shell_quote($$absRes=$$new_resource) + qtQuickRetainSources($$res) { + NEWRESOURCES += $$res + QMLCACHE_LOADER_FLAGS += --retain=$$shell_quote($$absRes) } else { - QMLCACHE_LOADER_FLAGS += --resource-file-mapping=$$shell_quote($$absRes) + remaining_files = $$system($$QML_CACHEGEN_FILTER -filter-resource-file \ + -o $$system_quote($$new_resource) $$system_quote($$absRes),lines) + !isEmpty(remaining_files) { + NEWRESOURCES += $$new_resource + QMLCACHE_LOADER_FLAGS += --resource-file-mapping=$$shell_quote($$absRes=$$new_resource) + } else { + QMLCACHE_LOADER_FLAGS += --resource-file-mapping=$$shell_quote($$absRes) + } } QMLCACHE_RESOURCE_FILES += $$absRes |