aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/compiler/qv4compileddata.cpp3
-rw-r--r--src/qml/compiler/qv4compileddata_p.h2
-rw-r--r--src/qml/qml/qqmltypeloader.cpp4
-rw-r--r--tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp52
4 files changed, 56 insertions, 5 deletions
diff --git a/src/qml/compiler/qv4compileddata.cpp b/src/qml/compiler/qv4compileddata.cpp
index a4fffedbcd..cb5c14ebc2 100644
--- a/src/qml/compiler/qv4compileddata.cpp
+++ b/src/qml/compiler/qv4compileddata.cpp
@@ -320,7 +320,7 @@ bool CompilationUnit::verifyChecksum(QQmlEngine *engine,
sizeof(data->dependencyMD5Checksum)) == 0;
}
-bool CompilationUnit::saveToDisk(QString *errorString)
+bool CompilationUnit::saveToDisk(const QUrl &unitUrl, QString *errorString)
{
errorString->clear();
@@ -329,7 +329,6 @@ bool CompilationUnit::saveToDisk(QString *errorString)
return false;
}
- const QUrl unitUrl = url();
if (!unitUrl.isLocalFile()) {
*errorString = QStringLiteral("File has to be a local file.");
return false;
diff --git a/src/qml/compiler/qv4compileddata_p.h b/src/qml/compiler/qv4compileddata_p.h
index c79f4cf007..d6537bbab3 100644
--- a/src/qml/compiler/qv4compileddata_p.h
+++ b/src/qml/compiler/qv4compileddata_p.h
@@ -904,7 +904,7 @@ struct Q_QML_PRIVATE_EXPORT CompilationUnit : public QQmlRefCount
void destroy() Q_DECL_OVERRIDE;
- bool saveToDisk(QString *errorString);
+ bool saveToDisk(const QUrl &unitUrl, QString *errorString);
bool loadFromDisk(const QUrl &url, EvalISelFactory *iselFactory, QString *errorString);
protected:
diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp
index 538e630e98..0e1f9572e0 100644
--- a/src/qml/qml/qqmltypeloader.cpp
+++ b/src/qml/qml/qqmltypeloader.cpp
@@ -2510,7 +2510,7 @@ void QQmlTypeData::compile(const QQmlRefPointer<QQmlTypeNameCache> &importCache,
}
if (diskCache() || forceDiskCacheRefresh()) {
QString errorString;
- if (!m_compiledData->saveToDisk(&errorString)) {
+ if (!m_compiledData->saveToDisk(url(), &errorString)) {
qCDebug(DBG_DISK_CACHE) << "Error saving cached version of" << m_compiledData->url().toString() << "to disk:" << errorString;
}
}
@@ -2944,7 +2944,7 @@ void QQmlScriptBlob::dataReceived(const Data &data)
if (diskCache() || forceDiskCacheRefresh()) {
QString errorString;
- if (!unit->saveToDisk(&errorString)) {
+ if (!unit->saveToDisk(url(), &errorString)) {
qCDebug(DBG_DISK_CACHE()) << "Error saving cached version of" << unit->url().toString() << "to disk:" << errorString;
}
}
diff --git a/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp b/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp
index a4e10205bd..ca47aae92e 100644
--- a/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp
+++ b/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp
@@ -36,6 +36,7 @@
#include <private/qv4engine_p.h>
#include <QQmlComponent>
#include <QQmlEngine>
+#include <QQmlFileSelector>
#include <QThread>
class tst_qmldiskcache: public QObject
@@ -49,6 +50,7 @@ private slots:
void registerImportForImplicitComponent();
void basicVersionChecks();
void recompileAfterChange();
+ void fileSelectors();
};
// A wrapper around QQmlComponent to ensure the temporary reference counts
@@ -433,6 +435,56 @@ void tst_qmldiskcache::recompileAfterChange()
}
}
+void tst_qmldiskcache::fileSelectors()
+{
+ QQmlEngine engine;
+
+ QTemporaryDir tempDir;
+ QVERIFY(tempDir.isValid());
+
+ const QString testFilePath = tempDir.path() + "/test.qml";
+ {
+ QFile f(testFilePath);
+ QVERIFY2(f.open(QIODevice::WriteOnly), qPrintable(f.errorString()));
+ f.write(QByteArrayLiteral("import QtQml 2.0\nQtObject { property int value: 42 }"));
+ }
+
+ const QString selector = QStringLiteral("testSelector");
+ const QString selectorPath = tempDir.path() + "/+" + selector;
+ const QString selectedTestFilePath = selectorPath + "/test.qml";
+ {
+ QVERIFY(QDir::root().mkpath(selectorPath));
+ QFile f(selectorPath + "/test.qml");
+ QVERIFY2(f.open(QIODevice::WriteOnly), qPrintable(f.errorString()));
+ f.write(QByteArrayLiteral("import QtQml 2.0\nQtObject { property int value: 100 }"));
+ }
+
+ {
+ QQmlComponent component(&engine, testFilePath);
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY(!obj.isNull());
+ QCOMPARE(obj->property("value").toInt(), 42);
+
+ QFile cacheFile(testFilePath + "c");
+ QVERIFY2(cacheFile.exists(), qPrintable(cacheFile.fileName()));
+ }
+
+ QQmlFileSelector qmlSelector(&engine);
+ qmlSelector.setExtraSelectors(QStringList() << selector);
+
+ engine.clearComponentCache();
+
+ {
+ QQmlComponent component(&engine, testFilePath);
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY(!obj.isNull());
+ QCOMPARE(obj->property("value").toInt(), 100);
+
+ QFile cacheFile(selectedTestFilePath + "c");
+ QVERIFY2(cacheFile.exists(), qPrintable(cacheFile.fileName()));
+ }
+}
+
QTEST_MAIN(tst_qmldiskcache)
#include "tst_qmldiskcache.moc"