aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Kosmale <[email protected]>2024-05-13 13:53:31 +0200
committerSami Shalayel <[email protected]>2024-06-25 19:37:12 +0200
commit52cd181777d0578d8ea06eb592242a58b20e995c (patch)
treeb66206673247f72d685cc3a296e9482eb65741dd
parent8f5d31246515eede033d828ce0d7e91a110f4d61 (diff)
qqmljsimporter always use "safe" builtins
Always use safe builtins, to avoid asserts and troubles when loading builtins from another Qt version. Adapt tests to the new builtins selection behavior. Picking back because this fixes qmlls crashes when there are bad built-ins (e.g. from QDS). Pick-to: 6.8 Change-Id: Ibb784f30b9029ef4cef700b9cabf0602ed1db4c9 Reviewed-by: Ulf Hermann <[email protected]>
-rw-r--r--src/qmlcompiler/qqmljsimporter.cpp27
-rw-r--r--tests/auto/qml/qmllint/tst_qmllint.cpp11
-rw-r--r--tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp24
3 files changed, 13 insertions, 49 deletions
diff --git a/src/qmlcompiler/qqmljsimporter.cpp b/src/qmlcompiler/qqmljsimporter.cpp
index ae5d1654f0..21837b78eb 100644
--- a/src/qmlcompiler/qqmljsimporter.cpp
+++ b/src/qmlcompiler/qqmljsimporter.cpp
@@ -632,26 +632,13 @@ QQmlJSImporter::AvailableTypes QQmlJSImporter::builtinImportHelper()
return false;
};
- // If the same name (such as "Qt") appears in the JS root and in the builtins,
- // we want the builtins to override the JS root. Therefore, process jsroot first.
- QStringList qmltypesFiles;
- for (QString qmltypesFile : { "jsroot.qmltypes"_L1, "builtins.qmltypes"_L1 }) {
- if (!importBuiltins(qmltypesFile, m_importPaths))
- qmltypesFiles.append(std::move(qmltypesFile));
- }
-
- if (!qmltypesFiles.isEmpty()) {
- const QString pathsString =
- m_importPaths.isEmpty() ? u"<empty>"_s : m_importPaths.join(u"\n\t");
- m_warnings.append({ QStringLiteral("Failed to find the following builtins: %1 (so will use "
- "qrc). Import paths used:\n\t%2")
- .arg(qmltypesFiles.join(u", "), pathsString),
- QtWarningMsg, QQmlJS::SourceLocation() });
-
- // use qrc as a "last resort"
- for (const QString &qmltypesFile : std::as_const(qmltypesFiles)) {
- const bool found = importBuiltins(qmltypesFile, { u":/qt-project.org/qml/builtins"_s });
- Q_ASSERT(found); // since qrc must cover it in all the bad cases
+ {
+ // If the same name (such as "Qt") appears in the JS root and in the builtins,
+ // we want the builtins to override the JS root. Therefore, process jsroot first.
+ const QStringList builtinsPath{ u":/qt-project.org/qml/builtins"_s };
+ for (const QString qmltypesFile : { "jsroot.qmltypes"_L1, "builtins.qmltypes"_L1 }) {
+ if (!importBuiltins(qmltypesFile, builtinsPath))
+ qFatal() << u"Failed to find the following builtin:" << qmltypesFile;
}
}
diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp
index 6925fc4f81..7374a767b9 100644
--- a/tests/auto/qml/qmllint/tst_qmllint.cpp
+++ b/tests/auto/qml/qmllint/tst_qmllint.cpp
@@ -1814,8 +1814,8 @@ void TestQmllint::settingsFile()
.contains(QStringLiteral("Warning: %1:2:1: Unused import")
.arg(testFile("settings/unusedImportWarning/unused.qml"))));
QVERIFY(runQmllint("settings/bare/bare.qml", false, warningsShouldFailArgs(), false, false)
- .contains(QStringLiteral("Failed to find the following builtins: "
- "jsroot.qmltypes, builtins.qmltypes")));
+ .contains(
+ u"Failed to import QtQuick. Are your import paths set up properly?"_s));
QVERIFY(runQmllint("settings/qmltypes/qmltypes.qml", false, warningsShouldFailArgs(), false)
.contains(QStringLiteral("not a qmldir file. Assuming qmltypes.")));
QVERIFY(runQmllint("settings/qmlimports/qmlimports.qml", true, warningsShouldFailArgs(), false).isEmpty());
@@ -1921,9 +1921,10 @@ void TestQmllint::missingBuiltinsNoCrash()
QVERIFY2(jsonOutput.size() == 1, QJsonDocument(jsonOutput).toJson());
warnings = jsonOutput.at(0)[u"warnings"_s].toArray();
- checkResult(warnings,
- Result { { Message { QStringLiteral("Failed to find the following builtins: "
- "jsroot.qmltypes, builtins.qmltypes") } } });
+ checkResult(
+ warnings,
+ Result{ { Message{
+ u"Failed to import QtQuick. Are your import paths set up properly?"_s } } });
}
void TestQmllint::absolutePath()
diff --git a/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp b/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp
index cdbd9695fd..ea7da5a01c 100644
--- a/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp
+++ b/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp
@@ -42,7 +42,6 @@ private slots:
void cleanupTestCase();
void sanity();
- void noBuiltins();
void noQtQml();
void inlineComponent();
void singleton();
@@ -144,29 +143,6 @@ void tst_qmltc_qprocess::sanity()
QVERIFY2(output.isEmpty(), qPrintable(output));
}
-void tst_qmltc_qprocess::noBuiltins()
-{
- const auto renameBack = [&](const QString &original) {
- const auto current = modifiedPath(original);
- QFile file(current);
- QVERIFY(file.exists());
- QVERIFY(file.rename(original));
- };
-
- for (QString builtin : { u"jsroot.qmltypes"_s, u"builtins.qmltypes"_s }) {
- const auto path = QLibraryInfo::path(QLibraryInfo::QmlImportsPath) + u"/"_s + builtin;
-
- QScopeGuard scope(std::bind(renameBack, path));
- QFile file(path);
- QVERIFY(file.exists());
- QVERIFY(file.rename(modifiedPath(path)));
-
- // test that qmltc exits gracefully
- const auto errors = runQmltc(u"dummy.qml"_s, false);
- QVERIFY(errors.contains(u"Failed to find the following builtins: %1"_s.arg(builtin)));
- }
-}
-
void tst_qmltc_qprocess::noQtQml()
{
const auto renameBack = [&](const QString &original) {