Fix interaction of files selectors with disk caching
Make sure to save the .qmlc/.jsc files to the location determined by the file selectors. Change-Id: If535bb1e4f0d20ac692b3d8e6d563f77cd00446b Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
parent
d77e544a56
commit
01575a22ea
|
@ -320,7 +320,7 @@ bool CompilationUnit::verifyChecksum(QQmlEngine *engine,
|
||||||
sizeof(data->dependencyMD5Checksum)) == 0;
|
sizeof(data->dependencyMD5Checksum)) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CompilationUnit::saveToDisk(QString *errorString)
|
bool CompilationUnit::saveToDisk(const QUrl &unitUrl, QString *errorString)
|
||||||
{
|
{
|
||||||
errorString->clear();
|
errorString->clear();
|
||||||
|
|
||||||
|
@ -329,7 +329,6 @@ bool CompilationUnit::saveToDisk(QString *errorString)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QUrl unitUrl = url();
|
|
||||||
if (!unitUrl.isLocalFile()) {
|
if (!unitUrl.isLocalFile()) {
|
||||||
*errorString = QStringLiteral("File has to be a local file.");
|
*errorString = QStringLiteral("File has to be a local file.");
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -904,7 +904,7 @@ struct Q_QML_PRIVATE_EXPORT CompilationUnit : public QQmlRefCount
|
||||||
|
|
||||||
void destroy() Q_DECL_OVERRIDE;
|
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);
|
bool loadFromDisk(const QUrl &url, EvalISelFactory *iselFactory, QString *errorString);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -2510,7 +2510,7 @@ void QQmlTypeData::compile(const QQmlRefPointer<QQmlTypeNameCache> &importCache,
|
||||||
}
|
}
|
||||||
if (diskCache() || forceDiskCacheRefresh()) {
|
if (diskCache() || forceDiskCacheRefresh()) {
|
||||||
QString errorString;
|
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;
|
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()) {
|
if (diskCache() || forceDiskCacheRefresh()) {
|
||||||
QString errorString;
|
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;
|
qCDebug(DBG_DISK_CACHE()) << "Error saving cached version of" << unit->url().toString() << "to disk:" << errorString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#include <private/qv4engine_p.h>
|
#include <private/qv4engine_p.h>
|
||||||
#include <QQmlComponent>
|
#include <QQmlComponent>
|
||||||
#include <QQmlEngine>
|
#include <QQmlEngine>
|
||||||
|
#include <QQmlFileSelector>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
|
||||||
class tst_qmldiskcache: public QObject
|
class tst_qmldiskcache: public QObject
|
||||||
|
@ -49,6 +50,7 @@ private slots:
|
||||||
void registerImportForImplicitComponent();
|
void registerImportForImplicitComponent();
|
||||||
void basicVersionChecks();
|
void basicVersionChecks();
|
||||||
void recompileAfterChange();
|
void recompileAfterChange();
|
||||||
|
void fileSelectors();
|
||||||
};
|
};
|
||||||
|
|
||||||
// A wrapper around QQmlComponent to ensure the temporary reference counts
|
// 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)
|
QTEST_MAIN(tst_qmldiskcache)
|
||||||
|
|
||||||
#include "tst_qmldiskcache.moc"
|
#include "tst_qmldiskcache.moc"
|
||||||
|
|
Loading…
Reference in New Issue