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 <fabian.kosmale@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
This commit is contained in:
Ulf Hermann 2021-09-20 15:01:47 +02:00
parent 5e0e933523
commit 8cddbabf6f
6 changed files with 36 additions and 1 deletions

View File

@ -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()) {

View File

@ -0,0 +1,6 @@
pragma Singleton
import QtQml
QtObject {
property int a: 10
}

View File

@ -0,0 +1,7 @@
<RCC>
<qresource prefix="/">
<file>qmldir</file>
<file>A.qml</file>
<file>b.qml</file>
</qresource>
</RCC>

View File

@ -0,0 +1,6 @@
import QtQml
QtObject {
property int b: A.a
property int e: X.a
}

View File

@ -0,0 +1,2 @@
module T
singleton X 1.0 A.qml

View File

@ -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()