Allow RESOURCES to contain standalone files and collections of files

Standalone files are added by using RESOURCES += file.txt, while
collections of files are defined as collection.files = f1.txt f2.txt
and then added using RESOURCES += collection. For collections a prefix
can also be set using collection.prefix = /foo. The standalone files
are not prefixed.

Change-Id: I8236808238414da05e744f799a1bb15a72f4a46f
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
This commit is contained in:
Tor Arne Vestbø 2015-04-17 15:08:21 +02:00 committed by Oswald Buddenhagen
parent 59840faacf
commit e124ad54b8
7 changed files with 165 additions and 0 deletions

View File

@ -6,6 +6,66 @@ isEmpty(QMAKE_MOD_RCC):QMAKE_MOD_RCC = qrc
!contains(QMAKE_RESOURCE_FLAGS, -root):!isEmpty(QMAKE_RESOURCE_ROOT):QMAKE_RESOURCE_FLAGS += -root $$QMAKE_RESOURCE_ROOT
!contains(QMAKE_RESOURCE_FLAGS, -name): QMAKE_RESOURCE_FLAGS += -name ${QMAKE_FILE_BASE}
# http://www.w3.org/TR/xml/#syntax
defineReplace(xml_escape) {
1 ~= s,&,&amp;,
1 ~= s,\',&apos;,
1 ~= s,\",&quot;,
1 ~= s,<,&lt;,
1 ~= s,>,&gt;,
return($$1)
}
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
}
RESOURCES -= $$resource
next()
}
resource_file = $$RCC_DIR/qmake_$${resource}.qrc
!debug_and_release|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_)
alias = $$relative_path($$abs_path, $$abs_base)
resource_file_content += \
"<file alias=\"$$xml_escape($$alias)\">$$xml_escape($$abs_path)</file>"
}
resource_file_content += \
"</qresource>" \
"</RCC>"
!write_file($$OUT_PWD/$$resource_file, resource_file_content): \
error("Aborting.")
}
RESOURCES -= $$resource
RESOURCES += $$resource_file
}
rcc.input = RESOURCES
rcc.name = RCC ${QMAKE_FILE_IN}
rcc.depend_command = $$QMAKE_RCC_DEP -list $$QMAKE_RESOURCE_FLAGS ${QMAKE_FILE_IN}

View File

@ -8,5 +8,11 @@ SOURCES += tst_qmake.cpp testcompiler.cpp
QT = core testlib
cross_compile: DEFINES += QMAKE_CROSS_COMPILED
debug_and_release {
CONFIG(debug, debug|release): \
DEFINES += DEBUG_BUILD
else: \
DEFINES += RELEASE_BUILD
}
TESTDATA += testdata/*

View File

@ -0,0 +1,42 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <qguiapplication.h>
int main( int argc, char **argv )
{
QGuiApplication a( argc, argv );
return a.exec();
}

View File

@ -0,0 +1,10 @@
TEMPLATE = app
SOURCES = main.cpp
pro_file.files = resources.pro
pro_file.prefix = /prefix
subdir.files = subdir/file.txt
subdir.base = subdir
RESOURCES = test.qrc main.cpp pro_file subdir

View File

@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/">
<file>test.qrc</file>
</qresource>
</RCC>

View File

@ -39,6 +39,14 @@
#include <QStandardPaths>
#include <QDir>
#if defined(DEBUG_BUILD)
# define DIR_INFIX "debug/"
#elif defined(RELEASE_BUILD)
# define DIR_INFIX "release/"
#else
# define DIR_INFIX ""
#endif
class tst_qmake : public QObject
{
Q_OBJECT
@ -85,6 +93,7 @@ private slots:
void project();
void proFileCache();
void json();
void resources();
private:
TestCompiler test_compiler;
@ -583,5 +592,38 @@ void tst_qmake::json()
QVERIFY(output.contains("json.false is false"));
}
void tst_qmake::resources()
{
QString workDir = base_path + "/testdata/resources";
QVERIFY(test_compiler.qmake(workDir, "resources"));
{
QFile qrcFile(workDir + "/.rcc/" DIR_INFIX "qmake_pro_file.qrc");
QVERIFY(qrcFile.exists());
QVERIFY(qrcFile.open(QFile::ReadOnly));
QByteArray qrcXml = qrcFile.readAll();
QVERIFY(qrcXml.contains("alias=\"resources.pro\""));
QVERIFY(qrcXml.contains("prefix=\"/prefix\""));
}
{
QFile qrcFile(workDir + "/.rcc/" DIR_INFIX "qmake_subdir.qrc");
QVERIFY(qrcFile.exists());
QVERIFY(qrcFile.open(QFile::ReadOnly));
QByteArray qrcXml = qrcFile.readAll();
QVERIFY(qrcXml.contains("alias=\"file.txt\""));
}
{
QFile qrcFile(workDir + "/.rcc/" DIR_INFIX "qmake_qmake_immediate.qrc");
QVERIFY(qrcFile.exists());
QVERIFY(qrcFile.open(QFile::ReadOnly));
QByteArray qrcXml = qrcFile.readAll();
QVERIFY(qrcXml.contains("alias=\"main.cpp\""));
}
QVERIFY(test_compiler.make(workDir));
}
QTEST_MAIN(tst_qmake)
#include "tst_qmake.moc"