From 8cddbabf6f96250918383c03d24f95dafaab22b0 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 20 Sep 2021 15:01:47 +0200 Subject: [PATCH] qmllint: Read qmldir files from resources where applicable Otherwise we cannot reliably resolve composite singletons. Also we'd end up with really interesting paths passed to QFile. Change-Id: I2187fd4103914cff3f12f0780c428af8b56bf287 Reviewed-by: Fabian Kosmale Reviewed-by: Andrei Golubev --- src/qmlcompiler/qqmljsimporter.cpp | 14 +++++++++++++- tests/auto/qml/qmllint/data/T/A.qml | 6 ++++++ tests/auto/qml/qmllint/data/T/a.qrc | 7 +++++++ tests/auto/qml/qmllint/data/T/b.qml | 6 ++++++ tests/auto/qml/qmllint/data/T/qmldir | 2 ++ tests/auto/qml/qmllint/tst_qmllint.cpp | 2 ++ 6 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 tests/auto/qml/qmllint/data/T/A.qml create mode 100644 tests/auto/qml/qmllint/data/T/a.qrc create mode 100644 tests/auto/qml/qmllint/data/T/b.qml create mode 100644 tests/auto/qml/qmllint/data/T/qmldir diff --git a/src/qmlcompiler/qqmljsimporter.cpp b/src/qmlcompiler/qqmljsimporter.cpp index b1dbe74f0c..c338728ac8 100644 --- a/src/qmlcompiler/qqmljsimporter.cpp +++ b/src/qmlcompiler/qqmljsimporter.cpp @@ -450,7 +450,19 @@ bool QQmlJSImporter::importHelper(const QString &module, AvailableTypes *types, : qQmlResolveImportPaths(module, m_importPaths, version); for (auto const &modulePath : modulePaths) { - const QString qmldirPath = modulePath + SlashQmldir; + QString qmldirPath; + if (modulePath.startsWith(u':')) { + if (m_mapper) { + const QString resourcePath = modulePath.mid( + 1, modulePath.endsWith(u'/') ? modulePath.length() - 2 : -1) + + SlashQmldir; + const auto entry = m_mapper->entry( + QQmlJSResourceFileMapper::resourceFileFilter(resourcePath)); + qmldirPath = entry.filePath; + } + } else { + qmldirPath = modulePath + SlashQmldir; + } const auto it = m_seenQmldirFiles.constFind(qmldirPath); if (it != m_seenQmldirFiles.constEnd()) { diff --git a/tests/auto/qml/qmllint/data/T/A.qml b/tests/auto/qml/qmllint/data/T/A.qml new file mode 100644 index 0000000000..2b8d2ad52f --- /dev/null +++ b/tests/auto/qml/qmllint/data/T/A.qml @@ -0,0 +1,6 @@ +pragma Singleton +import QtQml + +QtObject { + property int a: 10 +} diff --git a/tests/auto/qml/qmllint/data/T/a.qrc b/tests/auto/qml/qmllint/data/T/a.qrc new file mode 100644 index 0000000000..a419534a08 --- /dev/null +++ b/tests/auto/qml/qmllint/data/T/a.qrc @@ -0,0 +1,7 @@ + + + qmldir + A.qml + b.qml + + diff --git a/tests/auto/qml/qmllint/data/T/b.qml b/tests/auto/qml/qmllint/data/T/b.qml new file mode 100644 index 0000000000..10d3c755cf --- /dev/null +++ b/tests/auto/qml/qmllint/data/T/b.qml @@ -0,0 +1,6 @@ +import QtQml + +QtObject { + property int b: A.a + property int e: X.a +} diff --git a/tests/auto/qml/qmllint/data/T/qmldir b/tests/auto/qml/qmllint/data/T/qmldir new file mode 100644 index 0000000000..656fafd9bb --- /dev/null +++ b/tests/auto/qml/qmllint/data/T/qmldir @@ -0,0 +1,2 @@ +module T +singleton X 1.0 A.qml diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index 263ec81376..bd417940ce 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -302,6 +302,8 @@ void TestQmllint::resources() {QStringLiteral("--resource"), testFile("resource.qrc")}); runQmllint(testFile("resource.qml"), false, {}); runQmllint(testFile("badResource.qml"), true, {}); + runQmllint(testFile("T/b.qml"), true, + {QStringLiteral("--resource"), testFile("T/a.qrc")}); } void TestQmllint::dirtyQmlCode_data()