aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2019-01-02 13:08:40 +0100
committerUlf Hermann <ulf.hermann@qt.io>2019-01-04 14:13:49 +0000
commit21ffde85a1b4592d24785a3ba82817de05486060 (patch)
tree6d449f5df9bd6be92906f234c2438766d95c961e /tools
parent604e379338e7c9e17c929063148754a30077988c (diff)
Add option to retain sources when generating QML cache
By default any .qrc files are filtered and QML and JS sources dropped when generating the cache. The new QTQUICK_COMPILER_RETAINED_RESOURCES option allows the specification of .qrc files to be kept as they are. The source fils specified in them will be available to the application. Change-Id: If45bcd95c29fe4b91f5817573964ff55b1db8a00 Fixes: QTBUG-72430 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tools')
-rw-r--r--tools/qmlcachegen/generateloader.cpp15
-rw-r--r--tools/qmlcachegen/qmlcachegen.cpp14
-rw-r--r--tools/qmlcachegen/qtquickcompiler.prf23
3 files changed, 41 insertions, 11 deletions
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