diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2019-11-04 13:34:36 +0100 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2019-11-05 14:51:29 +0100 |
commit | 577b6554f0d48a8d6e178cab52676d961f6bb997 (patch) | |
tree | cfb5728ca7d8bf4b6ef89ef4f4650af531dcbcf6 /mkspecs/features/resources_functions.prf | |
parent | b1004c7d0a5d7abbacd687fd41a5b2683e62b27d (diff) |
Move RESOURCE flattening code to dedicated function
Introduce resources_functions.prf with the test function
qtFlattenResources which ensures that RESOURCES has a flat structure,
e.g. only contains *.qrc entries.
This can be called by other .prf files like qtquickcompiler.prf
without disturbing the ability to extend RESOURCES in other .prf files.
Task-number: QTBUG-79672
Change-Id: I43246e40f5ea52a9d9c917a1bd781aeeb1304acc
Reviewed-by: Kai Koehne <kai.koehne@qt.io>
Diffstat (limited to 'mkspecs/features/resources_functions.prf')
-rw-r--r-- | mkspecs/features/resources_functions.prf | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/mkspecs/features/resources_functions.prf b/mkspecs/features/resources_functions.prf new file mode 100644 index 0000000000..f7fed9e524 --- /dev/null +++ b/mkspecs/features/resources_functions.prf @@ -0,0 +1,63 @@ +defineTest(qtFlattenResources) { + RESOURCES += qmake_immediate + for(resource, RESOURCES) { + # Regular case of user qrc file + contains(resource, ".*\\.qrc$"): \ + next() + + # Fallback for stand-alone files/directories + !defined($${resource}.files, var) { + !equals(resource, qmake_immediate) { + !exists($$absolute_path($$resource, $$_PRO_FILE_PWD_)): \ + warning("Failure to find: $$resource") + qmake_immediate.files += $$resource + OTHER_FILES *= $$resource + } + RESOURCES -= $$resource + next() + } + + resource_file = $$absolute_path($$RCC_DIR/qmake_$${resource}.qrc, $$OUT_PWD) + + isEmpty(BUILDS)|build_pass { + # Collection of files, generate qrc file + prefix = $$eval($${resource}.prefix) + isEmpty(prefix): \ + prefix = "/" + + resource_file_content = \ + "<!DOCTYPE RCC><RCC version=\"1.0\">" \ + "<qresource prefix=\"$$xml_escape($$prefix)\">" + + abs_base = $$absolute_path($$eval($${resource}.base), $$_PRO_FILE_PWD_) + + for(file, $${resource}.files) { + abs_path = $$absolute_path($$file, $$_PRO_FILE_PWD_) + files = $$files($$abs_path/*, true) + isEmpty(files): \ + files = $$abs_path + for (file, files) { + exists($$file/*): next() # exclude directories + alias = $$relative_path($$file, $$abs_base) + resource_file_content += \ + "<file alias=\"$$xml_escape($$alias)\">$$xml_escape($$file)</file>" + OTHER_FILES *= $$file + } + } + + resource_file_content += \ + "</qresource>" \ + "</RCC>" + + !write_file($$resource_file, resource_file_content): \ + error() + } + + RESOURCES -= $$resource + RESOURCES += $$resource_file + } + export(RESOURCES) + export(OTHER_FILES) + export(qmake_immediate.files) + return(true) +} |