diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-10-20 13:57:38 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-10-20 17:19:26 +0200 |
commit | 51f6d418fa803a37e8a1e3bcfdd7f7e02b7bdcad (patch) | |
tree | 389324f114b1172d97fb9d7fbf6073a36628d16e /tools/qmlcachegen | |
parent | 14cd261513174e0006ebdd5b3605347621c7e36b (diff) |
qmlcachegen: Move resourcefilter.cpp into QmlCompiler
For backwards compatibility, a replacement for qmlcachegen will need to
provide the same functionality.
Change-Id: I22664230ea636d384190122223d15819ebee930c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tools/qmlcachegen')
-rw-r--r-- | tools/qmlcachegen/.prev_CMakeLists.txt | 1 | ||||
-rw-r--r-- | tools/qmlcachegen/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tools/qmlcachegen/qmlcachegen.cpp | 7 | ||||
-rw-r--r-- | tools/qmlcachegen/qmlcachegen.pro | 1 | ||||
-rw-r--r-- | tools/qmlcachegen/resourcefilter.cpp | 172 |
5 files changed, 3 insertions, 179 deletions
diff --git a/tools/qmlcachegen/.prev_CMakeLists.txt b/tools/qmlcachegen/.prev_CMakeLists.txt index 78e63898ac..687ece89a1 100644 --- a/tools/qmlcachegen/.prev_CMakeLists.txt +++ b/tools/qmlcachegen/.prev_CMakeLists.txt @@ -10,7 +10,6 @@ qt_internal_add_tool(${target_name} SOURCES generateloader.cpp qmlcachegen.cpp - resourcefilter.cpp DEFINES QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII diff --git a/tools/qmlcachegen/CMakeLists.txt b/tools/qmlcachegen/CMakeLists.txt index 9903406fab..e81eae7dfb 100644 --- a/tools/qmlcachegen/CMakeLists.txt +++ b/tools/qmlcachegen/CMakeLists.txt @@ -11,7 +11,6 @@ qt_internal_add_tool(${target_name} SOURCES generateloader.cpp qmlcachegen.cpp - resourcefilter.cpp DEFINES QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII diff --git a/tools/qmlcachegen/qmlcachegen.cpp b/tools/qmlcachegen/qmlcachegen.cpp index 04d31d8887..ca68e7e450 100644 --- a/tools/qmlcachegen/qmlcachegen.cpp +++ b/tools/qmlcachegen/qmlcachegen.cpp @@ -41,12 +41,12 @@ #include <private/qqmljsparser_p.h> #include <private/qqmljslexer_p.h> #include <private/qqmljsresourcefilemapper_p.h> +#include <private/qresourcerelocater_p.h> #include <algorithm> using namespace QQmlJS; -int filterResourceFile(const QString &input, const QString &output); bool generateLoader(const QStringList &compiledFiles, const QString &output, const QStringList &resourceFileMappings, QString *errorString); QString symbolNamespaceForPath(const QString &relativePath); @@ -507,9 +507,8 @@ int main(int argc, char **argv) if (outputFileName.isEmpty()) outputFileName = inputFile + QLatin1Char('c'); - if (parser.isSet(filterResourceFileOption)) { - return filterResourceFile(inputFile, outputFileName); - } + if (parser.isSet(filterResourceFileOption)) + return qRelocateResourceFile(inputFile, outputFileName); if (target == GenerateLoader) { QQmlJSResourceFileMapper mapper(sources); diff --git a/tools/qmlcachegen/qmlcachegen.pro b/tools/qmlcachegen/qmlcachegen.pro index 530a0d54a1..1305d8fe65 100644 --- a/tools/qmlcachegen/qmlcachegen.pro +++ b/tools/qmlcachegen/qmlcachegen.pro @@ -5,7 +5,6 @@ DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII SOURCES = \ qmlcachegen.cpp \ - resourcefilter.cpp \ generateloader.cpp TARGET = qmlcachegen diff --git a/tools/qmlcachegen/resourcefilter.cpp b/tools/qmlcachegen/resourcefilter.cpp deleted file mode 100644 index 37c027c365..0000000000 --- a/tools/qmlcachegen/resourcefilter.cpp +++ /dev/null @@ -1,172 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtQml module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include <QString> -#include <QXmlStreamReader> -#include <QFile> -#include <QDir> - -int filterResourceFile(const QString &input, const QString &output) -{ - enum State { - InitialState, - InRCC, - InResource, - InFile - }; - State state = InitialState; - - QString prefix; - QString currentFileName; - QXmlStreamAttributes fileAttributes; - - QFile file(input); - if (!file.open(QIODevice::ReadOnly)) { - fprintf(stderr, "Cannot open %s for reading.\n", qPrintable(input)); - return EXIT_FAILURE; - } - - QDir inputDirectory = QFileInfo(file).absoluteDir(); - QDir outputDirectory = QFileInfo(output).absoluteDir(); - - QString outputString; - QXmlStreamWriter writer(&outputString); - writer.setAutoFormatting(true); - - QXmlStreamReader reader(&file); - while (!reader.atEnd()) { - switch (reader.readNext()) { - case QXmlStreamReader::StartDocument: { - QStringView version = reader.documentVersion(); - if (!version.isEmpty()) - writer.writeStartDocument(version.toString()); - else - writer.writeStartDocument(); - break; - } - case QXmlStreamReader::EndDocument: - writer.writeEndDocument(); - break; - case QXmlStreamReader::StartElement: - if (reader.name() == QStringLiteral("RCC")) { - if (state != InitialState) { - fprintf(stderr, "Unexpected RCC tag in line %d\n", int(reader.lineNumber())); - return EXIT_FAILURE; - } - state = InRCC; - } else if (reader.name() == QStringLiteral("qresource")) { - if (state != InRCC) { - fprintf(stderr, "Unexpected qresource tag in line %d\n", int(reader.lineNumber())); - return EXIT_FAILURE; - } - state = InResource; - QXmlStreamAttributes attributes = reader.attributes(); - if (attributes.hasAttribute(QStringLiteral("prefix"))) - prefix = attributes.value(QStringLiteral("prefix")).toString(); - if (!prefix.startsWith(QLatin1Char('/'))) - prefix.prepend(QLatin1Char('/')); - if (!prefix.endsWith(QLatin1Char('/'))) - prefix.append(QLatin1Char('/')); - } else if (reader.name() == QStringLiteral("file")) { - if (state != InResource) { - fprintf(stderr, "Unexpected file tag in line %d\n", int(reader.lineNumber())); - return EXIT_FAILURE; - } - state = InFile; - fileAttributes = reader.attributes(); - continue; - } - writer.writeStartElement(reader.name().toString()); - writer.writeAttributes(reader.attributes()); - continue; - - case QXmlStreamReader::EndElement: - if (reader.name() == QStringLiteral("file")) { - if (state != InFile) { - fprintf(stderr, "Unexpected end of file tag in line %d\n", int(reader.lineNumber())); - return EXIT_FAILURE; - } - state = InResource; - continue; - } else if (reader.name() == QStringLiteral("qresource")) { - if (state != InResource) { - fprintf(stderr, "Unexpected end of qresource tag in line %d\n", int(reader.lineNumber())); - return EXIT_FAILURE; - } - state = InRCC; - } else if (reader.name() == QStringLiteral("RCC")) { - if (state != InRCC) { - fprintf(stderr, "Unexpected end of RCC tag in line %d\n", int(reader.lineNumber())); - return EXIT_FAILURE; - } - state = InitialState; - } - writer.writeEndElement(); - continue; - - case QXmlStreamReader::Characters: - if (reader.isWhitespace()) - break; - if (state != InFile) - return EXIT_FAILURE; - currentFileName = reader.text().toString(); - if (currentFileName.isEmpty()) - continue; - - writer.writeStartElement(QStringLiteral("file")); - - if (!fileAttributes.hasAttribute(QStringLiteral("alias"))) - fileAttributes.append(QStringLiteral("alias"), currentFileName); - - currentFileName = inputDirectory.absoluteFilePath(currentFileName); - currentFileName = outputDirectory.relativeFilePath(currentFileName); - - writer.writeAttributes(fileAttributes); - writer.writeCharacters(currentFileName); - writer.writeEndElement(); - continue; - - default: break; - } - } - - QFile outputFile(output); - if (!outputFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) { - fprintf(stderr, "Cannot open %s for writing.\n", qPrintable(output)); - return EXIT_FAILURE; - } - const QByteArray outputStringUtf8 = outputString.toUtf8(); - if (outputFile.write(outputStringUtf8) != outputStringUtf8.size()) - return EXIT_FAILURE; - - outputFile.close(); - if (outputFile.error() != QFileDevice::NoError) - return EXIT_FAILURE; - - - return EXIT_SUCCESS; -} |