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>
This commit is contained in:
Oswald Buddenhagen
2016-10-24 19:30:24 +02:00
parent 1589ce3ce8
commit 424639ecac
16 changed files with 150 additions and 77 deletions

View File

@@ -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)

View File

@@ -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;

View File

@@ -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)
{
QDir baseDir(QFileInfo(path).path());
QFile file(path);
if (!file.open(QIODevice::ReadOnly)) {
m_errorMessages.append(file.errorString());
return false;
}
QDomDocument doc;
QDir baseDir(QFileInfo(path).path());
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;
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;
}
} 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));

View File

@@ -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: