diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2023-07-11 13:42:47 +0200 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2023-07-24 21:26:57 +0200 |
| commit | fb4cc245e042d8c1d4c93aea3a68ca9f1fcf4e58 (patch) | |
| tree | 9bc6de4a62c05d1975e2dc99ce99b26ba1336885 /tests/auto/qml/qmlcppcodegen/data | |
| parent | 1b48e1c5a51e1c455e1078d7ad714425f91c642b (diff) | |
QmlCompiler: Optimize storage for register variables
We don't need nested hashes there. A single hash is enough, and we also
don't need to key it by pointers. Keying it by internalName instead
makes the ordering deterministic. We also don't need to duplicate-track
the variable names when outputting the declarations anymore.
Verify that qmlcachegen's output is actually stable by compiling the
entire test data for tst_qmlcppcodegen twice, packaging the generated
code into the resource file system, and comparing it in a separate test.
Pick-to: 6.5 6.6
Fixes: QTBUG-115159
Change-Id: I659661e58a52ed9ff308c83d6c821cf016f2e94e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/data')
| -rw-r--r-- | tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt | 74 | ||||
| -rw-r--r-- | tests/auto/qml/qmlcppcodegen/data/tst_qmlcppcodegen_verify.cpp | 47 |
2 files changed, 121 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt index 1a2181215a..e571a0aa7f 100644 --- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt +++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt @@ -283,3 +283,77 @@ qt6_add_qml_module(codegen_test_module add_dependencies(codegen_test_module Qt::Quick Qt::QuickTemplates2 Qt::QuickShapesPrivate) qt_autogen_tools_initial_setup(codegen_test_moduleplugin) + + +qt_add_library(codegen_test_module_verify STATIC) +qt_autogen_tools_initial_setup(codegen_test_module_verify) + +set_target_properties(codegen_test_module_verify PROPERTIES + # We really want qmlcachegen here, even if qmlsc is available + QT_QMLCACHEGEN_EXECUTABLE qmlcachegen +) + + +qt6_add_qml_module(codegen_test_module_verify + VERSION 1.5 + URI TestTypes + IMPORT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/imports/" + DEPENDENCIES + QtQuick + QtQuick.Templates + QtQuick.Shapes + SOURCES + ${cpp_sources} + QML_FILES + ${qml_files} + RESOURCES + ${resource_files} + OUTPUT_DIRECTORY verify/TestTypes # Make sure tst_qmlcachegen doesn't see our output + TARGET_PATH verify/TestTypes # Different target path to avoid resource file name clashes +) + +add_dependencies(codegen_test_module_verify Qt::Quick Qt::QuickTemplates2 Qt::QuickShapesPrivate) + +qt_autogen_tools_initial_setup(codegen_test_module_verifyplugin) + + +qt_internal_add_test(tst_qmlcppcodegen_verify + SOURCES + tst_qmlcppcodegen_verify.cpp +) + +add_dependencies(tst_qmlcppcodegen_verify codegen_test_module codegen_test_module_verify) + +set(a_files "") +set(b_files "") + +foreach(qml_file IN LISTS qml_files) + string(REGEX REPLACE "\\.(js|mjs|qml)$" "_\\1" compiled_file ${qml_file}) + string(REGEX REPLACE "[$#?]+" "_" compiled_file ${compiled_file}) + + list(APPEND + a_files + "${CMAKE_CURRENT_BINARY_DIR}/.rcc/qmlcache/codegen_test_module_${compiled_file}.cpp") + + list(APPEND + b_files + "${CMAKE_CURRENT_BINARY_DIR}/.rcc/qmlcache/codegen_test_module_verify_${compiled_file}.cpp") +endforeach() + +qt_add_resources(tst_qmlcppcodegen_verify "a" + PREFIX + "/a" + FILES + ${a_files} + BASE + "${CMAKE_CURRENT_BINARY_DIR}/.rcc/qmlcache/" +) + +qt_add_resources(tst_qmlcppcodegen_verify "b" + PREFIX + "/b" + FILES + ${b_files} + BASE + "${CMAKE_CURRENT_BINARY_DIR}/.rcc/qmlcache/" +) diff --git a/tests/auto/qml/qmlcppcodegen/data/tst_qmlcppcodegen_verify.cpp b/tests/auto/qml/qmlcppcodegen/data/tst_qmlcppcodegen_verify.cpp new file mode 100644 index 0000000000..02629ad7f6 --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/tst_qmlcppcodegen_verify.cpp @@ -0,0 +1,47 @@ +// Copyright (C) 2023 The Qt Company Ltd. + +#include <QtTest> +#include <QtCore/qobject.h> +#include <QtCore/qdir.h> +#include <QtCore/qfile.h> +#include <QtCore/qstring.h> +#include <QtCore/qbytearray.h> + +class tst_QmlCppCodegenVerify : public QObject +{ + Q_OBJECT +private slots: + void verifyGeneratedSources_data(); + void verifyGeneratedSources(); +}; + +void tst_QmlCppCodegenVerify::verifyGeneratedSources_data() +{ + QTest::addColumn<QString>("file"); + + QDir a(":/a"); + const QStringList entries = a.entryList(QDir::Files); + for (const QString &entry : entries) + QTest::addRow("%s", entry.toUtf8().constData()) << entry; +} + +void tst_QmlCppCodegenVerify::verifyGeneratedSources() +{ + QFETCH(QString, file); + QFile a(":/a/" + file); + QFile b(":/b/" + file.replace("codegen_test_module", "codegen_test_module_verify")); + + QVERIFY(a.open(QIODevice::ReadOnly)); + QVERIFY(b.open(QIODevice::ReadOnly)); + + const QByteArray aData = a.readAll(); + const QByteArray bData = b.readAll() + .replace("verify/TestTypes", "TestTypes") + .replace("verify_TestTypes", "TestTypes"); + + QCOMPARE(aData, bData); +} + +QTEST_MAIN(tst_QmlCppCodegenVerify) + +#include "tst_qmlcppcodegen_verify.moc" |
