diff options
author | Ulf Hermann <[email protected]> | 2020-10-20 15:07:59 +0200 |
---|---|---|
committer | Ulf Hermann <[email protected]> | 2020-10-23 13:31:14 +0200 |
commit | 2458f07eb568dc13f1f92b77adc047ef129a5636 (patch) | |
tree | 3a0c2081d39465dc24399704eb7e2c6db4c2718b | |
parent | f263e6ac9321d1f1b0fc4e46371642a2dbe85262 (diff) |
Move generateloader.cpp to QmlCompiler
We need to be able to generate the loader code from multiple places.
Change-Id: I9e04fd3583b535bc5f7d5fb293cb61309c1e199a
Reviewed-by: Fabian Kosmale <[email protected]>
-rw-r--r-- | src/qmlcompiler/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/qmlcompiler/qmlcompiler.pro | 2 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljsloadergenerator.cpp (renamed from tools/qmlcachegen/generateloader.cpp) | 17 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljsloadergenerator_p.h | 53 | ||||
-rw-r--r-- | tools/qmlcachegen/.prev_CMakeLists.txt | 1 | ||||
-rw-r--r-- | tools/qmlcachegen/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tools/qmlcachegen/qmlcachegen.cpp | 15 | ||||
-rw-r--r-- | tools/qmlcachegen/qmlcachegen.pro | 3 |
8 files changed, 75 insertions, 18 deletions
diff --git a/src/qmlcompiler/CMakeLists.txt b/src/qmlcompiler/CMakeLists.txt index f2180f35cd..82810165a9 100644 --- a/src/qmlcompiler/CMakeLists.txt +++ b/src/qmlcompiler/CMakeLists.txt @@ -11,6 +11,7 @@ qt_internal_add_module(QmlCompiler qdeferredpointer_p.h qqmljsimporter.cpp qqmljsimporter_p.h qqmljsimportvisitor.cpp qqmljsimportvisitor_p.h + qqmljsloadergenerator.cpp qqmljsloadergenerator_p.h qqmljsmetatypes_p.h qqmljsresourcefilemapper.cpp qqmljsresourcefilemapper_p.h qqmljsscope.cpp qqmljsscope_p.h diff --git a/src/qmlcompiler/qmlcompiler.pro b/src/qmlcompiler/qmlcompiler.pro index a8c81af081..1b2e617809 100644 --- a/src/qmlcompiler/qmlcompiler.pro +++ b/src/qmlcompiler/qmlcompiler.pro @@ -11,6 +11,7 @@ SOURCES = \ qqmljsscope.cpp \ qqmljstypedescriptionreader.cpp \ qqmljsstreamwriter.cpp \ + qqmljsloadergenerator.cpp \ qresourcerelocater.cpp HEADERS = \ @@ -23,6 +24,7 @@ HEADERS = \ qqmljsscope_p.h \ qqmljstypedescriptionreader_p.h \ qqmljsstreamwriter_p.h \ + qqmljsloadergenerator_p.h \ qresourcerelocater_p.h load(qt_module) diff --git a/tools/qmlcachegen/generateloader.cpp b/src/qmlcompiler/qqmljsloadergenerator.cpp index a2b3f91322..bd560e6266 100644 --- a/tools/qmlcachegen/generateloader.cpp +++ b/src/qmlcompiler/qqmljsloadergenerator.cpp @@ -25,6 +25,9 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + +#include "qqmljsloadergenerator_p.h" + #include <QByteArray> #include <QRegularExpression> #include <QString> @@ -38,6 +41,8 @@ #include <algorithm> +QT_BEGIN_NAMESPACE + /*! * \internal * Mangles \a str to be a unique C++ identifier. Characters that are invalid for C++ identifiers @@ -84,7 +89,7 @@ QString mangledIdentifier(const QString &str) return mangled; } -QString symbolNamespaceForPath(const QString &relativePath) +QString qQmlJSSymbolNamespaceForPath(const QString &relativePath) { QFileInfo fi(relativePath); QString symbol = fi.path(); @@ -110,8 +115,8 @@ static QString qtResourceNameForFile(const QString &fileName) return name; } -bool generateLoader(const QStringList &compiledFiles, const QString &outputFileName, - const QStringList &resourceFileMappings, QString *errorString) +bool qQmlJSGenerateLoader(const QStringList &compiledFiles, const QString &outputFileName, + const QStringList &resourceFileMappings, QString *errorString) { QByteArray generatedLoaderCode; @@ -125,7 +130,7 @@ bool generateLoader(const QStringList &compiledFiles, const QString &outputFileN stream << "namespace QmlCacheGeneratedCode {\n"; for (int i = 0; i < compiledFiles.count(); ++i) { const QString compiledFile = compiledFiles.at(i); - const QString ns = symbolNamespaceForPath(compiledFile); + const QString ns = qQmlJSSymbolNamespaceForPath(compiledFile); stream << "namespace " << ns << " { \n"; stream << " extern const unsigned char qmlData[];\n"; stream << " const QQmlPrivate::CachedQmlUnit unit = {\n"; @@ -150,7 +155,7 @@ bool generateLoader(const QStringList &compiledFiles, const QString &outputFileN for (int i = 0; i < compiledFiles.count(); ++i) { const QString qrcFile = compiledFiles.at(i); - const QString ns = symbolNamespaceForPath(qrcFile); + const QString ns = qQmlJSSymbolNamespaceForPath(qrcFile); stream << " resourcePathToCachedUnit.insert(QStringLiteral(\"" << qrcFile << "\"), &QmlCacheGeneratedCode::" << ns << "::unit);\n"; } @@ -229,3 +234,5 @@ bool generateLoader(const QStringList &compiledFiles, const QString &outputFileN return true; } + +QT_END_NAMESPACE diff --git a/src/qmlcompiler/qqmljsloadergenerator_p.h b/src/qmlcompiler/qqmljsloadergenerator_p.h new file mode 100644 index 0000000000..a8f00d30d0 --- /dev/null +++ b/src/qmlcompiler/qqmljsloadergenerator_p.h @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the tools applications 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$ +** +****************************************************************************/ + +#ifndef QQMLJSLOADERGENERATOR_P_H +#define QQMLJSLOADERGENERATOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. + +#include <QtCore/qstring.h> +#include <QtCore/qlist.h> + +QT_BEGIN_NAMESPACE + +bool qQmlJSGenerateLoader(const QStringList &compiledFiles, const QString &outputFileName, + const QStringList &resourceFileMappings, QString *errorString); +QString qQmlJSSymbolNamespaceForPath(const QString &relativePath); + +QT_END_NAMESPACE + +#endif // QQMLJSLOADERGENERATOR_P_H diff --git a/tools/qmlcachegen/.prev_CMakeLists.txt b/tools/qmlcachegen/.prev_CMakeLists.txt index 687ece89a1..a33e080bbe 100644 --- a/tools/qmlcachegen/.prev_CMakeLists.txt +++ b/tools/qmlcachegen/.prev_CMakeLists.txt @@ -8,7 +8,6 @@ qt_get_tool_target_name(target_name qmlcachegen) qt_internal_add_tool(${target_name} TARGET_DESCRIPTION "QML Cache Generator" SOURCES - generateloader.cpp qmlcachegen.cpp DEFINES QT_NO_CAST_FROM_ASCII diff --git a/tools/qmlcachegen/CMakeLists.txt b/tools/qmlcachegen/CMakeLists.txt index e81eae7dfb..e0ae4c4092 100644 --- a/tools/qmlcachegen/CMakeLists.txt +++ b/tools/qmlcachegen/CMakeLists.txt @@ -9,7 +9,6 @@ qt_internal_add_tool(${target_name} TARGET_DESCRIPTION "QML Cache Generator" TOOLS_TARGET Qml # special case SOURCES - generateloader.cpp qmlcachegen.cpp DEFINES QT_NO_CAST_FROM_ASCII diff --git a/tools/qmlcachegen/qmlcachegen.cpp b/tools/qmlcachegen/qmlcachegen.cpp index ca68e7e450..33a77bc835 100644 --- a/tools/qmlcachegen/qmlcachegen.cpp +++ b/tools/qmlcachegen/qmlcachegen.cpp @@ -41,16 +41,13 @@ #include <private/qqmljsparser_p.h> #include <private/qqmljslexer_p.h> #include <private/qqmljsresourcefilemapper_p.h> +#include <private/qqmljsloadergenerator_p.h> #include <private/qresourcerelocater_p.h> #include <algorithm> using namespace QQmlJS; -bool generateLoader(const QStringList &compiledFiles, const QString &output, - const QStringList &resourceFileMappings, QString *errorString); -QString symbolNamespaceForPath(const QString &relativePath); - QSet<QString> illegalNames; void setupIllegalNames() @@ -392,7 +389,7 @@ static bool saveUnitAsCpp(const QString &inputFileName, const QString &outputFil if (!writeStr(QByteArrayLiteral("namespace QmlCacheGeneratedCode {\nnamespace "))) return false; - if (!writeStr(symbolNamespaceForPath(inputFileName).toUtf8())) + if (!writeStr(qQmlJSSymbolNamespaceForPath(inputFileName).toUtf8())) return false; if (!writeStr(QByteArrayLiteral(" {\nextern const unsigned char qmlData alignas(16) [] = {\n"))) @@ -514,8 +511,8 @@ int main(int argc, char **argv) QQmlJSResourceFileMapper mapper(sources); Error error; - if (!generateLoader(mapper.qmlCompilerFiles(), outputFileName, - parser.values(resourceFileMappingOption), &error.message)) { + if (!qQmlJSGenerateLoader(mapper.qmlCompilerFiles(), outputFileName, + parser.values(resourceFileMappingOption), &error.message)) { error.augment(QLatin1String("Error generating loader stub: ")).print(); return EXIT_FAILURE; } @@ -524,8 +521,8 @@ int main(int argc, char **argv) if (target == GenerateLoaderStandAlone) { Error error; - if (!generateLoader(sources, outputFileName, - parser.values(resourceNameOption), &error.message)) { + if (!qQmlJSGenerateLoader(sources, outputFileName, + parser.values(resourceNameOption), &error.message)) { error.augment(QLatin1String("Error generating loader stub: ")).print(); return EXIT_FAILURE; } diff --git a/tools/qmlcachegen/qmlcachegen.pro b/tools/qmlcachegen/qmlcachegen.pro index 1305d8fe65..62846ddd1c 100644 --- a/tools/qmlcachegen/qmlcachegen.pro +++ b/tools/qmlcachegen/qmlcachegen.pro @@ -4,8 +4,7 @@ QT = qmldevtools-private qmlcompiler-private DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII SOURCES = \ - qmlcachegen.cpp \ - generateloader.cpp + qmlcachegen.cpp TARGET = qmlcachegen |