diff options
author | Oswald Buddenhagen <oswald.buddenhagen@qt.io> | 2016-10-24 19:30:24 +0200 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@qt.io> | 2016-11-01 17:34:55 +0000 |
commit | 424639ecac9d2e404d2bfaff7f46b45ed98664b8 (patch) | |
tree | 6ed64f844d8dca4e94e05ce2fa74e923d11220f1 | |
parent | 1589ce3ce855833a50b4e12c86f2b9b5a83d7b02 (diff) | |
download | qt-creator-424639ecac9d2e404d2bfaff7f46b45ed98664b8.tar.gz |
make resource file handling able to deal with QMakeProject's VFS
resources.prf may create virtual qrc files when RESOURCES contains
non-qrc files.
Change-Id: If591de9b32b775059d67e94bc3cb06d23ee44b08
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
-rw-r--r-- | src/libs/qmljs/qmljsmodelmanagerinterface.cpp | 5 | ||||
-rw-r--r-- | src/libs/qmljs/qmljsmodelmanagerinterface.h | 2 | ||||
-rw-r--r-- | src/libs/qmljs/qmljsqrcparser.cpp | 68 | ||||
-rw-r--r-- | src/libs/qmljs/qmljsqrcparser.h | 8 | ||||
-rw-r--r-- | src/plugins/qbsprojectmanager/qbsnodes.cpp | 2 | ||||
-rw-r--r-- | src/plugins/qmakeprojectmanager/qmakenodes.cpp | 8 | ||||
-rw-r--r-- | src/plugins/qmakeprojectmanager/qmakeproject.cpp | 5 | ||||
-rw-r--r-- | src/plugins/resourceeditor/qrceditor/resourcefile.cpp | 55 | ||||
-rw-r--r-- | src/plugins/resourceeditor/qrceditor/resourcefile_p.h | 3 | ||||
-rw-r--r-- | src/plugins/resourceeditor/resourcenode.cpp | 18 | ||||
-rw-r--r-- | src/plugins/resourceeditor/resourcenode.h | 3 | ||||
-rw-r--r-- | src/shared/proparser/profileevaluator.cpp | 16 | ||||
-rw-r--r-- | src/shared/proparser/profileevaluator.h | 1 | ||||
-rw-r--r-- | src/shared/proparser/qmakevfs.cpp | 17 | ||||
-rw-r--r-- | src/shared/proparser/qmakevfs.h | 2 | ||||
-rw-r--r-- | tests/auto/qml/qrcparser/tst_qrcparser.cpp | 12 |
16 files changed, 149 insertions, 76 deletions
diff --git a/src/libs/qmljs/qmljsmodelmanagerinterface.cpp b/src/libs/qmljs/qmljsmodelmanagerinterface.cpp index 34d1cd2495..fb015ab2e1 100644 --- a/src/libs/qmljs/qmljsmodelmanagerinterface.cpp +++ b/src/libs/qmljs/qmljsmodelmanagerinterface.cpp @@ -566,8 +566,9 @@ void ModelManagerInterface::updateProjectInfo(const ProjectInfo &pinfo, ProjectE updateSourceFiles(newFiles, false); // update qrc cache + m_qrcContents = pinfo.resourceFileContents; foreach (const QString &newQrc, pinfo.allResourceFiles) - m_qrcCache.addPath(newQrc); + m_qrcCache.addPath(newQrc, m_qrcContents.value(newQrc)); foreach (const QString &oldQrc, oldInfo.allResourceFiles) m_qrcCache.removePath(oldQrc); @@ -656,7 +657,7 @@ void ModelManagerInterface::emitDocumentChangedOnDisk(Document::Ptr doc) void ModelManagerInterface::updateQrcFile(const QString &path) { - m_qrcCache.updatePath(path); + m_qrcCache.updatePath(path, m_qrcContents.value(path)); } void ModelManagerInterface::updateDocument(Document::Ptr doc) diff --git a/src/libs/qmljs/qmljsmodelmanagerinterface.h b/src/libs/qmljs/qmljsmodelmanagerinterface.h index 2cb02083f6..b602ebb116 100644 --- a/src/libs/qmljs/qmljsmodelmanagerinterface.h +++ b/src/libs/qmljs/qmljsmodelmanagerinterface.h @@ -86,6 +86,7 @@ public: PathsAndLanguages importPaths; QStringList activeResourceFiles; QStringList allResourceFiles; + QHash<QString, QString> resourceFileContents; // whether trying to run qmldump makes sense bool tryQmlDump; @@ -273,6 +274,7 @@ private: QHash<QString, QPair<CPlusPlus::Document::Ptr, bool> > m_queuedCppDocuments; QFuture<void> m_cppQmlTypesUpdater; QrcCache m_qrcCache; + QHash<QString, QString> m_qrcContents; CppDataHash m_cppDataHash; QHash<QString, QList<CPlusPlus::Document::Ptr> > m_cppDeclarationFiles; diff --git a/src/libs/qmljs/qmljsqrcparser.cpp b/src/libs/qmljs/qmljsqrcparser.cpp index d4e0d2c40f..6242391da3 100644 --- a/src/libs/qmljs/qmljsqrcparser.cpp +++ b/src/libs/qmljs/qmljsqrcparser.cpp @@ -68,7 +68,7 @@ class QrcParserPrivate public: typedef QMap<QString,QStringList> SMap; QrcParserPrivate(QrcParser *q); - bool parseFile(const QString &path); + bool parseFile(const QString &path, const QString &contents); QString firstFileAtPath(const QString &path, const QLocale &locale) const; void collectFilesAtPath(const QString &path, QStringList *res, const QLocale *locale = 0) const; bool hasDirAtPath(const QString &path, const QLocale *locale = 0) const; @@ -94,9 +94,9 @@ class QrcCachePrivate Q_DECLARE_TR_FUNCTIONS(QmlJS::QrcCachePrivate) public: QrcCachePrivate(QrcCache *q); - QrcParser::Ptr addPath(const QString &path); + QrcParser::Ptr addPath(const QString &path, const QString &contents); void removePath(const QString &path); - QrcParser::Ptr updatePath(const QString &path); + QrcParser::Ptr updatePath(const QString &path, const QString &contents); QrcParser::Ptr parsedPath(const QString &path); void clear(); private: @@ -149,9 +149,9 @@ QrcParser::~QrcParser() delete d; } -bool QrcParser::parseFile(const QString &path) +bool QrcParser::parseFile(const QString &path, const QString &contents) { - return d->parseFile(path); + return d->parseFile(path, contents); } /*! \brief returns fs path of the first (active) file at the given qrc path @@ -217,11 +217,11 @@ bool QrcParser::isValid() const return errorMessages().isEmpty(); } -QrcParser::Ptr QrcParser::parseQrcFile(const QString &path) +QrcParser::Ptr QrcParser::parseQrcFile(const QString &path, const QString &contents) { Ptr res(new QrcParser); if (!path.isEmpty()) - res->parseFile(path); + res->parseFile(path, contents); return res; } @@ -237,9 +237,9 @@ QrcCache::~QrcCache() delete d; } -QrcParser::ConstPtr QrcCache::addPath(const QString &path) +QrcParser::ConstPtr QrcCache::addPath(const QString &path, const QString &contents) { - return d->addPath(path); + return d->addPath(path, contents); } void QrcCache::removePath(const QString &path) @@ -247,9 +247,9 @@ void QrcCache::removePath(const QString &path) d->removePath(path); } -QrcParser::ConstPtr QrcCache::updatePath(const QString &path) +QrcParser::ConstPtr QrcCache::updatePath(const QString &path, const QString &contents) { - return d->updatePath(path); + return d->updatePath(path, contents); } QrcParser::ConstPtr QrcCache::parsedPath(const QString &path) @@ -269,23 +269,35 @@ namespace Internal { QrcParserPrivate::QrcParserPrivate(QrcParser *) { } -bool QrcParserPrivate::parseFile(const QString &path) +bool QrcParserPrivate::parseFile(const QString &path, const QString &contents) { + QDomDocument doc; QDir baseDir(QFileInfo(path).path()); - QFile file(path); - if (!file.open(QIODevice::ReadOnly)) { - m_errorMessages.append(file.errorString()); - return false; - } - QDomDocument doc; + if (contents.isEmpty()) { + // Regular file + QFile file(path); + if (!file.open(QIODevice::ReadOnly)) { + m_errorMessages.append(file.errorString()); + return false; + } - QString error_msg; - int error_line, error_col; - if (!doc.setContent(&file, &error_msg, &error_line, &error_col)) { - m_errorMessages.append(tr("XML error on line %1, col %2: %3") - .arg(error_line).arg(error_col).arg(error_msg)); - return false; + QString error_msg; + int error_line, error_col; + if (!doc.setContent(&file, &error_msg, &error_line, &error_col)) { + m_errorMessages.append(tr("XML error on line %1, col %2: %3") + .arg(error_line).arg(error_col).arg(error_msg)); + return false; + } + } else { + // Virtual file from qmake evaluator + QString error_msg; + int error_line, error_col; + if (!doc.setContent(contents, &error_msg, &error_line, &error_col)) { + m_errorMessages.append(tr("XML error on line %1, col %2: %3") + .arg(error_line).arg(error_col).arg(error_msg)); + return false; + } } QDomElement root = doc.firstChildElement(QLatin1String("RCC")); @@ -470,7 +482,7 @@ QStringList QrcParserPrivate::allUiLanguages(const QLocale *locale) const QrcCachePrivate::QrcCachePrivate(QrcCache *) { } -QrcParser::Ptr QrcCachePrivate::addPath(const QString &path) +QrcParser::Ptr QrcCachePrivate::addPath(const QString &path, const QString &contents) { QPair<QrcParser::Ptr,int> currentValue; { @@ -482,7 +494,7 @@ QrcParser::Ptr QrcCachePrivate::addPath(const QString &path) return currentValue.first; } } - QrcParser::Ptr newParser = QrcParser::parseQrcFile(path); + QrcParser::Ptr newParser = QrcParser::parseQrcFile(path, contents); if (!newParser->isValid()) qCWarning(qmljsLog) << "adding invalid qrc " << path << " to the cache:" << newParser->errorMessages(); { @@ -513,9 +525,9 @@ void QrcCachePrivate::removePath(const QString &path) } } -QrcParser::Ptr QrcCachePrivate::updatePath(const QString &path) +QrcParser::Ptr QrcCachePrivate::updatePath(const QString &path, const QString &contents) { - QrcParser::Ptr newParser = QrcParser::parseQrcFile(path); + QrcParser::Ptr newParser = QrcParser::parseQrcFile(path, contents); { QMutexLocker l(&m_mutex); QPair<QrcParser::Ptr,int> currentValue = m_cache.value(path, qMakePair(QrcParser::Ptr(0), 0)); diff --git a/src/libs/qmljs/qmljsqrcparser.h b/src/libs/qmljs/qmljsqrcparser.h index 0d9e98fc2a..6973fa6d39 100644 --- a/src/libs/qmljs/qmljsqrcparser.h +++ b/src/libs/qmljs/qmljsqrcparser.h @@ -46,7 +46,7 @@ public: typedef QSharedPointer<QrcParser> Ptr; typedef QSharedPointer<const QrcParser> ConstPtr; ~QrcParser(); - bool parseFile(const QString &path); + bool parseFile(const QString &path, const QString &contents); QString firstFileAtPath(const QString &path, const QLocale &locale) const; void collectFilesAtPath(const QString &path, QStringList *res, const QLocale *locale = 0) const; bool hasDirAtPath(const QString &path, const QLocale *locale = 0) const; @@ -59,7 +59,7 @@ public: QStringList languages() const; bool isValid() const; - static Ptr parseQrcFile(const QString &path); + static Ptr parseQrcFile(const QString &path, const QString &contents); static QString normalizedQrcFilePath(const QString &path); static QString normalizedQrcDirectoryPath(const QString &path); static QString qrcDirectoryPathForQrcFilePath(const QString &file); @@ -74,9 +74,9 @@ class QMLJS_EXPORT QrcCache public: QrcCache(); ~QrcCache(); - QrcParser::ConstPtr addPath(const QString &path); + QrcParser::ConstPtr addPath(const QString &path, const QString &contents); void removePath(const QString &path); - QrcParser::ConstPtr updatePath(const QString &path); + QrcParser::ConstPtr updatePath(const QString &path, const QString &contents); QrcParser::ConstPtr parsedPath(const QString &path); void clear(); private: diff --git a/src/plugins/qbsprojectmanager/qbsnodes.cpp b/src/plugins/qbsprojectmanager/qbsnodes.cpp index 28612849c0..dd847f5bdb 100644 --- a/src/plugins/qbsprojectmanager/qbsnodes.cpp +++ b/src/plugins/qbsprojectmanager/qbsnodes.cpp @@ -527,7 +527,7 @@ void QbsGroupNode::setupFolder(ProjectExplorer::FolderNode *root, using ResourceEditor::ResourceTopLevelNode; if (!fn) { if (isQrcFile) { - fn = new ResourceTopLevelNode(Utils::FileName::fromString(c->path()), root); + fn = new ResourceTopLevelNode(Utils::FileName::fromString(c->path()), QString(), root); } else { fn = new QbsFolderNode(Utils::FileName::fromString(c->path()), ProjectExplorer::FolderNodeType, diff --git a/src/plugins/qmakeprojectmanager/qmakenodes.cpp b/src/plugins/qmakeprojectmanager/qmakenodes.cpp index a7d2cbc2e2..e19e2a7f31 100644 --- a/src/plugins/qmakeprojectmanager/qmakenodes.cpp +++ b/src/plugins/qmakeprojectmanager/qmakenodes.cpp @@ -578,8 +578,12 @@ struct InternalNode QList<FolderNode *> nodesToAdd; nodesToAdd.reserve(resourcesToAdd.size()); - foreach (const FileName &file, resourcesToAdd) - nodesToAdd.append(new ResourceEditor::ResourceTopLevelNode(file, folder)); + foreach (const FileName &file, resourcesToAdd) { + auto vfs = static_cast<QmakePriFileNode *>(folder->projectNode())->m_project->qmakeVfs(); + QString contents; + vfs->readVirtualFile(file.toString(), &contents); + nodesToAdd.append(new ResourceEditor::ResourceTopLevelNode(file, contents, folder)); + } folder->removeFolderNodes(resourcesToRemove); folder->addFolderNodes(nodesToAdd); diff --git a/src/plugins/qmakeprojectmanager/qmakeproject.cpp b/src/plugins/qmakeprojectmanager/qmakeproject.cpp index fec983b645..fe636b654b 100644 --- a/src/plugins/qmakeprojectmanager/qmakeproject.cpp +++ b/src/plugins/qmakeprojectmanager/qmakeproject.cpp @@ -566,6 +566,11 @@ void QmakeProject::updateQmlJSCodeModel() QmlJS::Dialect::Qml); projectInfo.activeResourceFiles.append(node->variableValue(ExactResourceVar)); projectInfo.allResourceFiles.append(node->variableValue(ResourceVar)); + foreach (const QString &rc, projectInfo.allResourceFiles) { + QString contents; + if (m_qmakeVfs->readVirtualFile(rc, &contents)) + projectInfo.resourceFileContents[rc] = contents; + } if (!hasQmlLib) { QStringList qtLibs = node->variableValue(QtVar); hasQmlLib = qtLibs.contains(QLatin1String("declarative")) || diff --git a/src/plugins/resourceeditor/qrceditor/resourcefile.cpp b/src/plugins/resourceeditor/qrceditor/resourcefile.cpp index d034a0556c..b139e7fda4 100644 --- a/src/plugins/resourceeditor/qrceditor/resourcefile.cpp +++ b/src/plugins/resourceeditor/qrceditor/resourcefile.cpp @@ -99,9 +99,10 @@ bool FileList::containsFile(File *file) ** ResourceFile */ -ResourceFile::ResourceFile(const QString &file_name) +ResourceFile::ResourceFile(const QString &file_name, const QString &contents) { setFileName(file_name); + m_contents = contents; } ResourceFile::~ResourceFile() @@ -118,28 +119,44 @@ Core::IDocument::OpenResult ResourceFile::load() return Core::IDocument::OpenResult::ReadError; } - QFile file(m_file_name); - if (!file.open(QIODevice::ReadOnly)) { - m_error_message = file.errorString(); - return Core::IDocument::OpenResult::ReadError; - } - QByteArray data = file.readAll(); - // Detect line ending style - m_textFileFormat = Utils::TextFileFormat::detect(data); - // we always write UTF-8 when saving - m_textFileFormat.codec = QTextCodec::codecForName("UTF-8"); - file.close(); - clearPrefixList(); QDomDocument doc; - QString error_msg; - int error_line, error_col; - if (!doc.setContent(data, &error_msg, &error_line, &error_col)) { - m_error_message = tr("XML error on line %1, col %2: %3") - .arg(error_line).arg(error_col).arg(error_msg); - return Core::IDocument::OpenResult::CannotHandle; + if (m_contents.isEmpty()) { + + // Regular file + QFile file(m_file_name); + if (!file.open(QIODevice::ReadOnly)) { + m_error_message = file.errorString(); + return Core::IDocument::OpenResult::ReadError; + } + QByteArray data = file.readAll(); + // Detect line ending style + m_textFileFormat = Utils::TextFileFormat::detect(data); + // we always write UTF-8 when saving + m_textFileFormat.codec = QTextCodec::codecForName("UTF-8"); + file.close(); + + QString error_msg; + int error_line, error_col; + if (!doc.setContent(data, &error_msg, &error_line, &error_col)) { + m_error_message = tr("XML error on line %1, col %2: %3") + .arg(error_line).arg(error_col).arg(error_msg); + return Core::IDocument::OpenResult::CannotHandle; + } + + } else { + + // Virtual file from qmake evaluator + QString error_msg; + int error_line, error_col; + if (!doc.setContent(m_contents, &error_msg, &error_line, &error_col)) { + m_error_message = tr("XML error on line %1, col %2: %3") + .arg(error_line).arg(error_col).arg(error_msg); + return Core::IDocument::OpenResult::CannotHandle; + } + } QDomElement root = doc.firstChildElement(QLatin1String("RCC")); diff --git a/src/plugins/resourceeditor/qrceditor/resourcefile_p.h b/src/plugins/resourceeditor/qrceditor/resourcefile_p.h index 3e58cb4133..f50ee9556a 100644 --- a/src/plugins/resourceeditor/qrceditor/resourcefile_p.h +++ b/src/plugins/resourceeditor/qrceditor/resourcefile_p.h @@ -127,7 +127,7 @@ class ResourceFile { Q_DECLARE_TR_FUNCTIONS(ResourceFile) public: - ResourceFile(const QString &file_name = QString()); + ResourceFile(const QString &file_name = QString(), const QString &contents = QString()); ~ResourceFile(); void setFileName(const QString &file_name) { m_file_name = file_name; } @@ -175,6 +175,7 @@ public: private: PrefixList m_prefix_list; QString m_file_name; + QString m_contents; QString m_error_message; Utils::TextFileFormat m_textFileFormat; diff --git a/src/plugins/resourceeditor/resourcenode.cpp b/src/plugins/resourceeditor/resourcenode.cpp index 49f29e3188..f76bdd11de 100644 --- a/src/plugins/resourceeditor/resourcenode.cpp +++ b/src/plugins/resourceeditor/resourcenode.cpp @@ -108,12 +108,19 @@ static bool sortNodesByPath(ProjectExplorer::Node *a, ProjectExplorer::Node *b) return a->filePath() < b->filePath(); } -ResourceTopLevelNode::ResourceTopLevelNode(const Utils::FileName &filePath, FolderNode *parent) +ResourceTopLevelNode::ResourceTopLevelNode( + const Utils::FileName &filePath, const QString &contents, + ProjectExplorer::FolderNode *parent) : ProjectExplorer::FolderNode(filePath) { setIcon(Core::FileIconProvider::icon(filePath.toString())); - m_document = new ResourceFileWatcher(this); - Core::DocumentManager::addDocument(m_document); + if (contents.isEmpty()) { + m_document = new ResourceFileWatcher(this); + Core::DocumentManager::addDocument(m_document); + } else { + m_contents = contents; + m_document = nullptr; + } Utils::FileName base = parent->filePath(); if (filePath.isChildOf(base)) @@ -124,7 +131,8 @@ ResourceTopLevelNode::ResourceTopLevelNode(const Utils::FileName &filePath, Fold ResourceTopLevelNode::~ResourceTopLevelNode() { - Core::DocumentManager::removeDocument(m_document); + if (m_document) + Core::DocumentManager::removeDocument(m_document); delete m_document; } @@ -135,7 +143,7 @@ void ResourceTopLevelNode::update() QMap<PrefixFolderLang, QList<ProjectExplorer::FolderNode *>> foldersToAddToFolders; QMap<PrefixFolderLang, QList<ProjectExplorer::FolderNode *>> foldersToAddToPrefix; - ResourceFile file(filePath().toString()); + ResourceFile file(filePath().toString(), m_contents); if (file.load() == Core::IDocument::OpenResult::Success) { QMap<PrefixFolderLang, ProjectExplorer::FolderNode *> prefixNodes; QMap<PrefixFolderLang, ProjectExplorer::FolderNode *> folderNodes; diff --git a/src/plugins/resourceeditor/resourcenode.h b/src/plugins/resourceeditor/resourcenode.h index d3d56becb9..2b9f4ab237 100644 --- a/src/plugins/resourceeditor/resourcenode.h +++ b/src/plugins/resourceeditor/resourcenode.h @@ -39,7 +39,7 @@ namespace Internal { class ResourceFileWatcher; } class RESOURCE_EXPORT ResourceTopLevelNode : public ProjectExplorer::FolderNode { public: - ResourceTopLevelNode(const Utils::FileName &filePath, FolderNode *parent); + ResourceTopLevelNode(const Utils::FileName &filePath, const QString &contents, FolderNode *parent); ~ResourceTopLevelNode() override; void update(); @@ -58,6 +58,7 @@ public: private: Internal::ResourceFileWatcher *m_document; + QString m_contents; }; namespace Internal { diff --git a/src/shared/proparser/profileevaluator.cpp b/src/shared/proparser/profileevaluator.cpp index ab11f5b6ce..5b937d3f09 100644 --- a/src/shared/proparser/profileevaluator.cpp +++ b/src/shared/proparser/profileevaluator.cpp @@ -26,6 +26,7 @@ #include "profileevaluator.h" #include "qmakeglobals.h" +#include "qmakevfs.h" #include "ioutils.h" #include <QDir> @@ -41,7 +42,8 @@ void ProFileEvaluator::initialize() ProFileEvaluator::ProFileEvaluator(QMakeGlobals *option, QMakeParser *parser, QMakeVfs *vfs, QMakeHandler *handler) - : d(new QMakeEvaluator(option, parser, vfs, handler)) + : d(new QMakeEvaluator(option, parser, vfs, handler)), + m_vfs(vfs) { } @@ -104,6 +106,7 @@ QStringList ProFileEvaluator::fixifiedValues( return result; } +// VFS note: all search paths are assumed to be real. QStringList ProFileEvaluator::absolutePathValues( const QString &variable, const QString &baseDirectory) const { @@ -124,25 +127,24 @@ QStringList ProFileEvaluator::absoluteFileValues( foreach (const QString &el, pro ? values(variable, pro) : values(variable)) { QString absEl; if (IoUtils::isAbsolutePath(el)) { - if (IoUtils::exists(el)) { + if (m_vfs->exists(el)) { result << el; goto next; } absEl = el; } else { foreach (const QString &dir, searchDirs) { - QString fn = dir + QLatin1Char('/') + el; - if (IoUtils::exists(fn)) { - result << QDir::cleanPath(fn); + QString fn = QDir::cleanPath(dir + QLatin1Char('/') + el); + if (m_vfs->exists(fn)) { + result << fn; goto next; } } if (baseDirectory.isEmpty()) goto next; - absEl = baseDirectory + QLatin1Char('/') + el; + absEl = QDir::cleanPath(baseDirectory + QLatin1Char('/') + el); } { - absEl = QDir::cleanPath(absEl); int nameOff = absEl.lastIndexOf(QLatin1Char('/')); QString absDir = d->m_tmp1.setRawData(absEl.constData(), nameOff); if (IoUtils::exists(absDir)) { diff --git a/src/shared/proparser/profileevaluator.h b/src/shared/proparser/profileevaluator.h index dd016c0911..898198e66b 100644 --- a/src/shared/proparser/profileevaluator.h +++ b/src/shared/proparser/profileevaluator.h @@ -86,6 +86,7 @@ public: private: QMakeEvaluator *d; + QMakeVfs *m_vfs; }; QT_END_NAMESPACE diff --git a/src/shared/proparser/qmakevfs.cpp b/src/shared/proparser/qmakevfs.cpp index 0231fa9a46..4d993ca2c1 100644 --- a/src/shared/proparser/qmakevfs.cpp +++ b/src/shared/proparser/qmakevfs.cpp @@ -97,6 +97,23 @@ bool QMakeVfs::writeFile(const QString &fn, QIODevice::OpenMode mode, bool exe, #endif } +#ifndef PROEVALUATOR_FULL +bool QMakeVfs::readVirtualFile(const QString &fn, QString *contents) +{ +# ifdef PROEVALUATOR_THREAD_SAFE + QMutexLocker locker(&m_mutex); +# endif + QHash<QString, QString>::ConstIterator it = m_files.constFind(fn); + if (it != m_files.constEnd() + && it->constData() != m_magicMissing.constData() + && it->constData() != m_magicExisting.constData()) { + *contents = *it; + return true; + } + return false; +} +#endif + bool QMakeVfs::readFile(const QString &fn, QString *contents, QString *errStr) { #ifndef PROEVALUATOR_FULL diff --git a/src/shared/proparser/qmakevfs.h b/src/shared/proparser/qmakevfs.h index 3ffe67c1ba..43f9e8c20c 100644 --- a/src/shared/proparser/qmakevfs.h +++ b/src/shared/proparser/qmakevfs.h @@ -48,6 +48,8 @@ public: bool exists(const QString &fn); #ifndef PROEVALUATOR_FULL + bool readVirtualFile(const QString &fn, QString *contents); + void invalidateCache(); void invalidateContents(); #endif diff --git a/tests/auto/qml/qrcparser/tst_qrcparser.cpp b/tests/auto/qml/qrcparser/tst_qrcparser.cpp index f63d0d6529..72d425a4e8 100644 --- a/tests/auto/qml/qrcparser/tst_qrcparser.cpp +++ b/tests/auto/qml/qrcparser/tst_qrcparser.cpp @@ -82,7 +82,7 @@ QStringList tst_QrcParser::allPaths(QrcParser::ConstPtr p) void tst_QrcParser::firstAtTest() { QFETCH(QString, path); - QrcParser::Ptr p = QrcParser::parseQrcFile(path); + QrcParser::Ptr p = QrcParser::parseQrcFile(path, QString()); foreach (const QString &qrcPath, allPaths(p)) { QString s1 = p->firstFileAtPath(qrcPath, m_locale); if (s1.isEmpty()) @@ -99,7 +99,7 @@ void tst_QrcParser::firstAtTest() void tst_QrcParser::firstInTest() { QFETCH(QString, path); - QrcParser::Ptr p = QrcParser::parseQrcFile(path); + QrcParser::Ptr p = QrcParser::parseQrcFile(path, QString()); foreach (const QString &qrcPath, allPaths(p)) { if (!qrcPath.endsWith(QLatin1Char('/'))) continue; @@ -137,15 +137,15 @@ void tst_QrcParser::cacheTest() { QFETCH(QString, path); QVERIFY(m_cache.parsedPath(path).isNull()); - QrcParser::ConstPtr p0 = m_cache.addPath(path); + QrcParser::ConstPtr p0 = m_cache.addPath(path, QString()); QVERIFY(!p0.isNull()); QrcParser::ConstPtr p1 = m_cache.parsedPath(path); QVERIFY(p1.data() == p0.data()); - QrcParser::ConstPtr p2 = m_cache.addPath(path); + QrcParser::ConstPtr p2 = m_cache.addPath(path, QString()); QVERIFY(p2.data() == p1.data()); QrcParser::ConstPtr p3 = m_cache.parsedPath(path); QVERIFY(p3.data() == p2.data()); - QrcParser::ConstPtr p4 = m_cache.updatePath(path); + QrcParser::ConstPtr p4 = m_cache.updatePath(path, QString()); QVERIFY(p4.data() != p3.data()); QrcParser::ConstPtr p5 = m_cache.parsedPath(path); QVERIFY(p5.data() == p4.data()); @@ -159,7 +159,7 @@ void tst_QrcParser::cacheTest() void tst_QrcParser::simpleTest() { - QrcParser::Ptr p = QrcParser::parseQrcFile(QString::fromLatin1(TESTSRCDIR).append(QLatin1String("/simple.qrc"))); + QrcParser::Ptr p = QrcParser::parseQrcFile(QString::fromLatin1(TESTSRCDIR).append(QLatin1String("/simple.qrc")), QString()); QStringList paths = allPaths(p); paths.sort(); QVERIFY(paths == QStringList() |