From c6e31fc743eb7dd4bda5eae502c5ebfda59d8b3d Mon Sep 17 00:00:00 2001 From: Denis Klychkov Date: Fri, 25 Nov 2016 23:25:53 +0300 Subject: Accurate handling of Qt.core.resourcePrefix Previously the value of this property was taken only from the first input. That value became the only prefix for the whole qrc file. Now every unique value of resourcePrefix generates new tag with the corresponding prefix. Change-Id: I2177b3bc38085014c41107225bcb4bd4c51ba58b Reviewed-by: Christian Kandeler Reviewed-by: Jake Petroules --- doc/reference/modules/qt-modules.qdoc | 3 +-- src/lib/qtprofilesetup/templates/core.qbs | 29 +++++++++++++++------- tests/auto/blackbox/testdata/auto-qrc/auto-qrc.qbs | 8 ++++++ tests/auto/blackbox/testdata/auto-qrc/main.cpp | 5 +++- .../auto-qrc/qrc-base/subdir/resource3.txt | 1 + 5 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 tests/auto/blackbox/testdata/auto-qrc/qrc-base/subdir/resource3.txt diff --git a/doc/reference/modules/qt-modules.qdoc b/doc/reference/modules/qt-modules.qdoc index 7d9a7e47b..5e40e7107 100644 --- a/doc/reference/modules/qt-modules.qdoc +++ b/doc/reference/modules/qt-modules.qdoc @@ -345,8 +345,7 @@ \li \c{string} \li \c{"/"} \li For files tagged as \c{qt.core.resource_data}, this property determines the prefix - under which they will be available in the generated \c qrc file. The value of this - property needs to be the same for all such files in a product. + under which they will be available in the generated \c qrc file. \row \li staticBuild \li \c{bool} diff --git a/src/lib/qtprofilesetup/templates/core.qbs b/src/lib/qtprofilesetup/templates/core.qbs index ba84ead91..98b3d3b3a 100644 --- a/src/lib/qtprofilesetup/templates/core.qbs +++ b/src/lib/qtprofilesetup/templates/core.qbs @@ -293,18 +293,29 @@ Module { try { qrcFile.writeLine(''); qrcFile.writeLine(''); - var prefix = inputs["qt.core.resource_data"][0].moduleProperty("Qt.core", - "resourcePrefix"); - qrcFile.writeLine(''); + + var inputsByPrefix = {} for (var i = 0; i < inputs["qt.core.resource_data"].length; ++i) { var inp = inputs["qt.core.resource_data"][i]; - var fullResPath = inp.filePath; - var baseDir = inp.moduleProperty("Qt.core", "resourceSourceBase"); - var relResPath = FileInfo.relativePath(baseDir, fullResPath); - qrcFile.writeLine('' - + fullResPath + ''); + var prefix = inp.moduleProperty("Qt.core", "resourcePrefix"); + var inputsList = inputsByPrefix[prefix] || []; + inputsList.push(inp); + inputsByPrefix[prefix] = inputsList; + } + + for (var prefix in inputsByPrefix) { + qrcFile.writeLine(''); + for (var i = 0; i < inputsByPrefix[prefix].length; ++i) { + var inp = inputsByPrefix[prefix][i]; + var fullResPath = inp.filePath; + var baseDir = inp.moduleProperty("Qt.core", "resourceSourceBase"); + var relResPath = FileInfo.relativePath(baseDir, fullResPath); + qrcFile.writeLine('' + + fullResPath + ''); + } + qrcFile.writeLine(''); } - qrcFile.writeLine(''); + qrcFile.writeLine(''); } finally { qrcFile.close(); diff --git a/tests/auto/blackbox/testdata/auto-qrc/auto-qrc.qbs b/tests/auto/blackbox/testdata/auto-qrc/auto-qrc.qbs index 2d0452d49..3055e51b8 100644 --- a/tests/auto/blackbox/testdata/auto-qrc/auto-qrc.qbs +++ b/tests/auto/blackbox/testdata/auto-qrc/auto-qrc.qbs @@ -20,6 +20,14 @@ Project { Qt.core.resourceSourceBase: "qrc-base/subdir" files: ["resource2.txt"] + + Group { + prefix: "qrc-base/subdir/" + + Qt.core.resourcePrefix: "/theOtherPrefix" + + files: ["resource3.txt"] + } } } } diff --git a/tests/auto/blackbox/testdata/auto-qrc/main.cpp b/tests/auto/blackbox/testdata/auto-qrc/main.cpp index bbfcd8fee..53a33854d 100644 --- a/tests/auto/blackbox/testdata/auto-qrc/main.cpp +++ b/tests/auto/blackbox/testdata/auto-qrc/main.cpp @@ -10,6 +10,9 @@ int main() QFile resource2(":/thePrefix/resource2.txt"); if (!resource2.open(QIODevice::ReadOnly)) return 2; + QFile resource3(":/theOtherPrefix/resource3.txt"); + if (!resource3.open(QIODevice::ReadOnly)) + return 3; std::cout << "resource data: " << resource1.readAll().constData() - << resource2.readAll().constData() << std::endl; + << resource2.readAll().constData() << resource3.readAll().constData() << std::endl; } diff --git a/tests/auto/blackbox/testdata/auto-qrc/qrc-base/subdir/resource3.txt b/tests/auto/blackbox/testdata/auto-qrc/qrc-base/subdir/resource3.txt new file mode 100644 index 000000000..6df9761da --- /dev/null +++ b/tests/auto/blackbox/testdata/auto-qrc/qrc-base/subdir/resource3.txt @@ -0,0 +1 @@ +resource3 -- cgit v1.2.3