From 3c14450a3e08fdaf6fb4933e354e17e4944a084f Mon Sep 17 00:00:00 2001 From: Richard Weickelt Date: Thu, 14 Jun 2018 23:40:47 +0200 Subject: Always generate QML cache files in the cache directory, never in sources This patch eliminates the annoying behavior of the QML compiler that .qmlc cache files are stored alongside the sources. When cache files are generated at run-time, then they are always stored in the application's local cache directory defined by QStandardPaths::CacheLocation (qmlcache subfolder). The application's uninstaller is responsible for cleaning up the cache directory during removal. If explicitly precompiled QML files exist at the source location, then they are loaded from there and no cache file is being generated. Storing cache files in the source directory is as problematic as an in-tree build. The cache files pollute the source directory and create unnecessary inconvenience with version control systems. [ChangeLog][QtQml][QQmlEngine] QML cache files are now always stored in the application's cache directory when being generated at run-time. If precompiled QML files exist at the source location, then they are loaded and no cache file is being generated. The application's uninstaller is responsible for cleaning up the cache during removal. Task-number: QTBUG-56150 Change-Id: I5a64b7f958e782e03c71873a82cef4b07011cbf1 Reviewed-by: Simon Hausmann --- src/qml/compiler/qv4compileddata.cpp | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'src/qml/compiler/qv4compileddata.cpp') diff --git a/src/qml/compiler/qv4compileddata.cpp b/src/qml/compiler/qv4compileddata.cpp index e72bbe1f5e..c809d497fd 100644 --- a/src/qml/compiler/qv4compileddata.cpp +++ b/src/qml/compiler/qv4compileddata.cpp @@ -78,23 +78,6 @@ namespace CompiledData { static_assert(sizeof(Unit::libraryVersionHash) >= QML_COMPILE_HASH_LENGTH + 1, "Compile hash length exceeds reserved size in data structure. Please adjust and bump the format version"); -#if !defined(V4_BOOTSTRAP) -static QString cacheFilePath(const QUrl &url) -{ - const QString localSourcePath = QQmlFile::urlToLocalFileOrQrc(url); - const QString localCachePath = localSourcePath + QLatin1Char('c'); -#ifndef Q_OS_ANDROID - if (QFile::exists(localCachePath) || QFileInfo(QFileInfo(localSourcePath).dir().absolutePath()).isWritable()) - return localCachePath; -#endif - QCryptographicHash fileNameHash(QCryptographicHash::Sha1); - fileNameHash.addData(localSourcePath.toUtf8()); - QString directory = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QLatin1String("/qmlcache/"); - QDir::root().mkpath(directory); - return directory + QString::fromUtf8(fileNameHash.result().toHex()) + QLatin1Char('.') + QFileInfo(localCachePath).completeSuffix(); -} -#endif - CompilationUnit::CompilationUnit(const Unit *unitData) { data = unitData; @@ -109,6 +92,17 @@ CompilationUnit::~CompilationUnit() data = nullptr; } +QString CompilationUnit::localCacheFilePath(const QUrl &url) +{ + const QString localSourcePath = QQmlFile::urlToLocalFileOrQrc(url); + const QString cacheFileSuffix = QFileInfo(localSourcePath + QLatin1Char('c')).completeSuffix(); + QCryptographicHash fileNameHash(QCryptographicHash::Sha1); + fileNameHash.addData(localSourcePath.toUtf8()); + QString directory = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QLatin1String("/qmlcache/"); + QDir::root().mkpath(directory); + return directory + QString::fromUtf8(fileNameHash.result().toHex()) + QLatin1Char('.') + cacheFileSuffix; +} + QV4::Function *CompilationUnit::linkToEngine(ExecutionEngine *engine) { this->engine = engine; @@ -361,7 +355,11 @@ bool CompilationUnit::loadFromDisk(const QUrl &url, const QDateTime &sourceTimeS const QString sourcePath = QQmlFile::urlToLocalFileOrQrc(url); QScopedPointer cacheFile(new CompilationUnitMapper()); - CompiledData::Unit *mappedUnit = cacheFile->open(cacheFilePath(url), sourceTimeStamp, errorString); + QString cachePath = sourcePath + QLatin1Char('c'); + if (!QFile::exists(cachePath)) + cachePath = localCacheFilePath(url); + + CompiledData::Unit *mappedUnit = cacheFile->open(cachePath, sourceTimeStamp, errorString); if (!mappedUnit) return false; @@ -423,7 +421,7 @@ bool CompilationUnit::saveToDisk(const QUrl &unitUrl, QString *errorString) *errorString = QStringLiteral("File has to be a local file."); return false; } - const QString outputFileName = cacheFilePath(unitUrl); + const QString outputFileName = localCacheFilePath(unitUrl); #endif #if QT_CONFIG(temporaryfile) -- cgit v1.2.3