forked from qt-creator/qt-creator
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:
@@ -566,8 +566,9 @@ void ModelManagerInterface::updateProjectInfo(const ProjectInfo &pinfo, ProjectE
|
|||||||
updateSourceFiles(newFiles, false);
|
updateSourceFiles(newFiles, false);
|
||||||
|
|
||||||
// update qrc cache
|
// update qrc cache
|
||||||
|
m_qrcContents = pinfo.resourceFileContents;
|
||||||
foreach (const QString &newQrc, pinfo.allResourceFiles)
|
foreach (const QString &newQrc, pinfo.allResourceFiles)
|
||||||
m_qrcCache.addPath(newQrc);
|
m_qrcCache.addPath(newQrc, m_qrcContents.value(newQrc));
|
||||||
foreach (const QString &oldQrc, oldInfo.allResourceFiles)
|
foreach (const QString &oldQrc, oldInfo.allResourceFiles)
|
||||||
m_qrcCache.removePath(oldQrc);
|
m_qrcCache.removePath(oldQrc);
|
||||||
|
|
||||||
@@ -656,7 +657,7 @@ void ModelManagerInterface::emitDocumentChangedOnDisk(Document::Ptr doc)
|
|||||||
|
|
||||||
void ModelManagerInterface::updateQrcFile(const QString &path)
|
void ModelManagerInterface::updateQrcFile(const QString &path)
|
||||||
{
|
{
|
||||||
m_qrcCache.updatePath(path);
|
m_qrcCache.updatePath(path, m_qrcContents.value(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelManagerInterface::updateDocument(Document::Ptr doc)
|
void ModelManagerInterface::updateDocument(Document::Ptr doc)
|
||||||
|
@@ -86,6 +86,7 @@ public:
|
|||||||
PathsAndLanguages importPaths;
|
PathsAndLanguages importPaths;
|
||||||
QStringList activeResourceFiles;
|
QStringList activeResourceFiles;
|
||||||
QStringList allResourceFiles;
|
QStringList allResourceFiles;
|
||||||
|
QHash<QString, QString> resourceFileContents;
|
||||||
|
|
||||||
// whether trying to run qmldump makes sense
|
// whether trying to run qmldump makes sense
|
||||||
bool tryQmlDump;
|
bool tryQmlDump;
|
||||||
@@ -273,6 +274,7 @@ private:
|
|||||||
QHash<QString, QPair<CPlusPlus::Document::Ptr, bool> > m_queuedCppDocuments;
|
QHash<QString, QPair<CPlusPlus::Document::Ptr, bool> > m_queuedCppDocuments;
|
||||||
QFuture<void> m_cppQmlTypesUpdater;
|
QFuture<void> m_cppQmlTypesUpdater;
|
||||||
QrcCache m_qrcCache;
|
QrcCache m_qrcCache;
|
||||||
|
QHash<QString, QString> m_qrcContents;
|
||||||
|
|
||||||
CppDataHash m_cppDataHash;
|
CppDataHash m_cppDataHash;
|
||||||
QHash<QString, QList<CPlusPlus::Document::Ptr> > m_cppDeclarationFiles;
|
QHash<QString, QList<CPlusPlus::Document::Ptr> > m_cppDeclarationFiles;
|
||||||
|
@@ -68,7 +68,7 @@ class QrcParserPrivate
|
|||||||
public:
|
public:
|
||||||
typedef QMap<QString,QStringList> SMap;
|
typedef QMap<QString,QStringList> SMap;
|
||||||
QrcParserPrivate(QrcParser *q);
|
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;
|
QString firstFileAtPath(const QString &path, const QLocale &locale) const;
|
||||||
void collectFilesAtPath(const QString &path, QStringList *res, const QLocale *locale = 0) const;
|
void collectFilesAtPath(const QString &path, QStringList *res, const QLocale *locale = 0) const;
|
||||||
bool hasDirAtPath(const QString &path, 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)
|
Q_DECLARE_TR_FUNCTIONS(QmlJS::QrcCachePrivate)
|
||||||
public:
|
public:
|
||||||
QrcCachePrivate(QrcCache *q);
|
QrcCachePrivate(QrcCache *q);
|
||||||
QrcParser::Ptr addPath(const QString &path);
|
QrcParser::Ptr addPath(const QString &path, const QString &contents);
|
||||||
void removePath(const QString &path);
|
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);
|
QrcParser::Ptr parsedPath(const QString &path);
|
||||||
void clear();
|
void clear();
|
||||||
private:
|
private:
|
||||||
@@ -149,9 +149,9 @@ QrcParser::~QrcParser()
|
|||||||
delete d;
|
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
|
/*! \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();
|
return errorMessages().isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
QrcParser::Ptr QrcParser::parseQrcFile(const QString &path)
|
QrcParser::Ptr QrcParser::parseQrcFile(const QString &path, const QString &contents)
|
||||||
{
|
{
|
||||||
Ptr res(new QrcParser);
|
Ptr res(new QrcParser);
|
||||||
if (!path.isEmpty())
|
if (!path.isEmpty())
|
||||||
res->parseFile(path);
|
res->parseFile(path, contents);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,9 +237,9 @@ QrcCache::~QrcCache()
|
|||||||
delete d;
|
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)
|
void QrcCache::removePath(const QString &path)
|
||||||
@@ -247,9 +247,9 @@ void QrcCache::removePath(const QString &path)
|
|||||||
d->removePath(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)
|
QrcParser::ConstPtr QrcCache::parsedPath(const QString &path)
|
||||||
@@ -269,23 +269,35 @@ namespace Internal {
|
|||||||
QrcParserPrivate::QrcParserPrivate(QrcParser *)
|
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;
|
QDomDocument doc;
|
||||||
|
QDir baseDir(QFileInfo(path).path());
|
||||||
|
|
||||||
QString error_msg;
|
if (contents.isEmpty()) {
|
||||||
int error_line, error_col;
|
// Regular file
|
||||||
if (!doc.setContent(&file, &error_msg, &error_line, &error_col)) {
|
QFile file(path);
|
||||||
m_errorMessages.append(tr("XML error on line %1, col %2: %3")
|
if (!file.open(QIODevice::ReadOnly)) {
|
||||||
.arg(error_line).arg(error_col).arg(error_msg));
|
m_errorMessages.append(file.errorString());
|
||||||
return false;
|
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"));
|
QDomElement root = doc.firstChildElement(QLatin1String("RCC"));
|
||||||
@@ -470,7 +482,7 @@ QStringList QrcParserPrivate::allUiLanguages(const QLocale *locale) const
|
|||||||
QrcCachePrivate::QrcCachePrivate(QrcCache *)
|
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;
|
QPair<QrcParser::Ptr,int> currentValue;
|
||||||
{
|
{
|
||||||
@@ -482,7 +494,7 @@ QrcParser::Ptr QrcCachePrivate::addPath(const QString &path)
|
|||||||
return currentValue.first;
|
return currentValue.first;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QrcParser::Ptr newParser = QrcParser::parseQrcFile(path);
|
QrcParser::Ptr newParser = QrcParser::parseQrcFile(path, contents);
|
||||||
if (!newParser->isValid())
|
if (!newParser->isValid())
|
||||||
qCWarning(qmljsLog) << "adding invalid qrc " << path << " to the cache:" << newParser->errorMessages();
|
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);
|
QMutexLocker l(&m_mutex);
|
||||||
QPair<QrcParser::Ptr,int> currentValue = m_cache.value(path, qMakePair(QrcParser::Ptr(0), 0));
|
QPair<QrcParser::Ptr,int> currentValue = m_cache.value(path, qMakePair(QrcParser::Ptr(0), 0));
|
||||||
|
@@ -46,7 +46,7 @@ public:
|
|||||||
typedef QSharedPointer<QrcParser> Ptr;
|
typedef QSharedPointer<QrcParser> Ptr;
|
||||||
typedef QSharedPointer<const QrcParser> ConstPtr;
|
typedef QSharedPointer<const QrcParser> ConstPtr;
|
||||||
~QrcParser();
|
~QrcParser();
|
||||||
bool parseFile(const QString &path);
|
bool parseFile(const QString &path, const QString &contents);
|
||||||
QString firstFileAtPath(const QString &path, const QLocale &locale) const;
|
QString firstFileAtPath(const QString &path, const QLocale &locale) const;
|
||||||
void collectFilesAtPath(const QString &path, QStringList *res, const QLocale *locale = 0) const;
|
void collectFilesAtPath(const QString &path, QStringList *res, const QLocale *locale = 0) const;
|
||||||
bool hasDirAtPath(const QString &path, const QLocale *locale = 0) const;
|
bool hasDirAtPath(const QString &path, const QLocale *locale = 0) const;
|
||||||
@@ -59,7 +59,7 @@ public:
|
|||||||
QStringList languages() const;
|
QStringList languages() const;
|
||||||
bool isValid() 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 normalizedQrcFilePath(const QString &path);
|
||||||
static QString normalizedQrcDirectoryPath(const QString &path);
|
static QString normalizedQrcDirectoryPath(const QString &path);
|
||||||
static QString qrcDirectoryPathForQrcFilePath(const QString &file);
|
static QString qrcDirectoryPathForQrcFilePath(const QString &file);
|
||||||
@@ -74,9 +74,9 @@ class QMLJS_EXPORT QrcCache
|
|||||||
public:
|
public:
|
||||||
QrcCache();
|
QrcCache();
|
||||||
~QrcCache();
|
~QrcCache();
|
||||||
QrcParser::ConstPtr addPath(const QString &path);
|
QrcParser::ConstPtr addPath(const QString &path, const QString &contents);
|
||||||
void removePath(const QString &path);
|
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);
|
QrcParser::ConstPtr parsedPath(const QString &path);
|
||||||
void clear();
|
void clear();
|
||||||
private:
|
private:
|
||||||
|
@@ -527,7 +527,7 @@ void QbsGroupNode::setupFolder(ProjectExplorer::FolderNode *root,
|
|||||||
using ResourceEditor::ResourceTopLevelNode;
|
using ResourceEditor::ResourceTopLevelNode;
|
||||||
if (!fn) {
|
if (!fn) {
|
||||||
if (isQrcFile) {
|
if (isQrcFile) {
|
||||||
fn = new ResourceTopLevelNode(Utils::FileName::fromString(c->path()), root);
|
fn = new ResourceTopLevelNode(Utils::FileName::fromString(c->path()), QString(), root);
|
||||||
} else {
|
} else {
|
||||||
fn = new QbsFolderNode(Utils::FileName::fromString(c->path()),
|
fn = new QbsFolderNode(Utils::FileName::fromString(c->path()),
|
||||||
ProjectExplorer::FolderNodeType,
|
ProjectExplorer::FolderNodeType,
|
||||||
|
@@ -578,8 +578,12 @@ struct InternalNode
|
|||||||
QList<FolderNode *> nodesToAdd;
|
QList<FolderNode *> nodesToAdd;
|
||||||
nodesToAdd.reserve(resourcesToAdd.size());
|
nodesToAdd.reserve(resourcesToAdd.size());
|
||||||
|
|
||||||
foreach (const FileName &file, resourcesToAdd)
|
foreach (const FileName &file, resourcesToAdd) {
|
||||||
nodesToAdd.append(new ResourceEditor::ResourceTopLevelNode(file, folder));
|
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->removeFolderNodes(resourcesToRemove);
|
||||||
folder->addFolderNodes(nodesToAdd);
|
folder->addFolderNodes(nodesToAdd);
|
||||||
|
@@ -566,6 +566,11 @@ void QmakeProject::updateQmlJSCodeModel()
|
|||||||
QmlJS::Dialect::Qml);
|
QmlJS::Dialect::Qml);
|
||||||
projectInfo.activeResourceFiles.append(node->variableValue(ExactResourceVar));
|
projectInfo.activeResourceFiles.append(node->variableValue(ExactResourceVar));
|
||||||
projectInfo.allResourceFiles.append(node->variableValue(ResourceVar));
|
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) {
|
if (!hasQmlLib) {
|
||||||
QStringList qtLibs = node->variableValue(QtVar);
|
QStringList qtLibs = node->variableValue(QtVar);
|
||||||
hasQmlLib = qtLibs.contains(QLatin1String("declarative")) ||
|
hasQmlLib = qtLibs.contains(QLatin1String("declarative")) ||
|
||||||
|
@@ -99,9 +99,10 @@ bool FileList::containsFile(File *file)
|
|||||||
** ResourceFile
|
** ResourceFile
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ResourceFile::ResourceFile(const QString &file_name)
|
ResourceFile::ResourceFile(const QString &file_name, const QString &contents)
|
||||||
{
|
{
|
||||||
setFileName(file_name);
|
setFileName(file_name);
|
||||||
|
m_contents = contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceFile::~ResourceFile()
|
ResourceFile::~ResourceFile()
|
||||||
@@ -118,28 +119,44 @@ Core::IDocument::OpenResult ResourceFile::load()
|
|||||||
return Core::IDocument::OpenResult::ReadError;
|
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();
|
clearPrefixList();
|
||||||
|
|
||||||
QDomDocument doc;
|
QDomDocument doc;
|
||||||
|
|
||||||
QString error_msg;
|
if (m_contents.isEmpty()) {
|
||||||
int error_line, error_col;
|
|
||||||
if (!doc.setContent(data, &error_msg, &error_line, &error_col)) {
|
// Regular file
|
||||||
m_error_message = tr("XML error on line %1, col %2: %3")
|
QFile file(m_file_name);
|
||||||
.arg(error_line).arg(error_col).arg(error_msg);
|
if (!file.open(QIODevice::ReadOnly)) {
|
||||||
return Core::IDocument::OpenResult::CannotHandle;
|
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"));
|
QDomElement root = doc.firstChildElement(QLatin1String("RCC"));
|
||||||
|
@@ -127,7 +127,7 @@ class ResourceFile
|
|||||||
{
|
{
|
||||||
Q_DECLARE_TR_FUNCTIONS(ResourceFile)
|
Q_DECLARE_TR_FUNCTIONS(ResourceFile)
|
||||||
public:
|
public:
|
||||||
ResourceFile(const QString &file_name = QString());
|
ResourceFile(const QString &file_name = QString(), const QString &contents = QString());
|
||||||
~ResourceFile();
|
~ResourceFile();
|
||||||
|
|
||||||
void setFileName(const QString &file_name) { m_file_name = file_name; }
|
void setFileName(const QString &file_name) { m_file_name = file_name; }
|
||||||
@@ -175,6 +175,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
PrefixList m_prefix_list;
|
PrefixList m_prefix_list;
|
||||||
QString m_file_name;
|
QString m_file_name;
|
||||||
|
QString m_contents;
|
||||||
QString m_error_message;
|
QString m_error_message;
|
||||||
Utils::TextFileFormat m_textFileFormat;
|
Utils::TextFileFormat m_textFileFormat;
|
||||||
|
|
||||||
|
@@ -108,12 +108,19 @@ static bool sortNodesByPath(ProjectExplorer::Node *a, ProjectExplorer::Node *b)
|
|||||||
return a->filePath() < b->filePath();
|
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)
|
: ProjectExplorer::FolderNode(filePath)
|
||||||
{
|
{
|
||||||
setIcon(Core::FileIconProvider::icon(filePath.toString()));
|
setIcon(Core::FileIconProvider::icon(filePath.toString()));
|
||||||
m_document = new ResourceFileWatcher(this);
|
if (contents.isEmpty()) {
|
||||||
Core::DocumentManager::addDocument(m_document);
|
m_document = new ResourceFileWatcher(this);
|
||||||
|
Core::DocumentManager::addDocument(m_document);
|
||||||
|
} else {
|
||||||
|
m_contents = contents;
|
||||||
|
m_document = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
Utils::FileName base = parent->filePath();
|
Utils::FileName base = parent->filePath();
|
||||||
if (filePath.isChildOf(base))
|
if (filePath.isChildOf(base))
|
||||||
@@ -124,7 +131,8 @@ ResourceTopLevelNode::ResourceTopLevelNode(const Utils::FileName &filePath, Fold
|
|||||||
|
|
||||||
ResourceTopLevelNode::~ResourceTopLevelNode()
|
ResourceTopLevelNode::~ResourceTopLevelNode()
|
||||||
{
|
{
|
||||||
Core::DocumentManager::removeDocument(m_document);
|
if (m_document)
|
||||||
|
Core::DocumentManager::removeDocument(m_document);
|
||||||
delete m_document;
|
delete m_document;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +143,7 @@ void ResourceTopLevelNode::update()
|
|||||||
QMap<PrefixFolderLang, QList<ProjectExplorer::FolderNode *>> foldersToAddToFolders;
|
QMap<PrefixFolderLang, QList<ProjectExplorer::FolderNode *>> foldersToAddToFolders;
|
||||||
QMap<PrefixFolderLang, QList<ProjectExplorer::FolderNode *>> foldersToAddToPrefix;
|
QMap<PrefixFolderLang, QList<ProjectExplorer::FolderNode *>> foldersToAddToPrefix;
|
||||||
|
|
||||||
ResourceFile file(filePath().toString());
|
ResourceFile file(filePath().toString(), m_contents);
|
||||||
if (file.load() == Core::IDocument::OpenResult::Success) {
|
if (file.load() == Core::IDocument::OpenResult::Success) {
|
||||||
QMap<PrefixFolderLang, ProjectExplorer::FolderNode *> prefixNodes;
|
QMap<PrefixFolderLang, ProjectExplorer::FolderNode *> prefixNodes;
|
||||||
QMap<PrefixFolderLang, ProjectExplorer::FolderNode *> folderNodes;
|
QMap<PrefixFolderLang, ProjectExplorer::FolderNode *> folderNodes;
|
||||||
|
@@ -39,7 +39,7 @@ namespace Internal { class ResourceFileWatcher; }
|
|||||||
class RESOURCE_EXPORT ResourceTopLevelNode : public ProjectExplorer::FolderNode
|
class RESOURCE_EXPORT ResourceTopLevelNode : public ProjectExplorer::FolderNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ResourceTopLevelNode(const Utils::FileName &filePath, FolderNode *parent);
|
ResourceTopLevelNode(const Utils::FileName &filePath, const QString &contents, FolderNode *parent);
|
||||||
~ResourceTopLevelNode() override;
|
~ResourceTopLevelNode() override;
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
@@ -58,6 +58,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Internal::ResourceFileWatcher *m_document;
|
Internal::ResourceFileWatcher *m_document;
|
||||||
|
QString m_contents;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
#include "profileevaluator.h"
|
#include "profileevaluator.h"
|
||||||
|
|
||||||
#include "qmakeglobals.h"
|
#include "qmakeglobals.h"
|
||||||
|
#include "qmakevfs.h"
|
||||||
#include "ioutils.h"
|
#include "ioutils.h"
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
@@ -41,7 +42,8 @@ void ProFileEvaluator::initialize()
|
|||||||
|
|
||||||
ProFileEvaluator::ProFileEvaluator(QMakeGlobals *option, QMakeParser *parser, QMakeVfs *vfs,
|
ProFileEvaluator::ProFileEvaluator(QMakeGlobals *option, QMakeParser *parser, QMakeVfs *vfs,
|
||||||
QMakeHandler *handler)
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// VFS note: all search paths are assumed to be real.
|
||||||
QStringList ProFileEvaluator::absolutePathValues(
|
QStringList ProFileEvaluator::absolutePathValues(
|
||||||
const QString &variable, const QString &baseDirectory) const
|
const QString &variable, const QString &baseDirectory) const
|
||||||
{
|
{
|
||||||
@@ -124,25 +127,24 @@ QStringList ProFileEvaluator::absoluteFileValues(
|
|||||||
foreach (const QString &el, pro ? values(variable, pro) : values(variable)) {
|
foreach (const QString &el, pro ? values(variable, pro) : values(variable)) {
|
||||||
QString absEl;
|
QString absEl;
|
||||||
if (IoUtils::isAbsolutePath(el)) {
|
if (IoUtils::isAbsolutePath(el)) {
|
||||||
if (IoUtils::exists(el)) {
|
if (m_vfs->exists(el)) {
|
||||||
result << el;
|
result << el;
|
||||||
goto next;
|
goto next;
|
||||||
}
|
}
|
||||||
absEl = el;
|
absEl = el;
|
||||||
} else {
|
} else {
|
||||||
foreach (const QString &dir, searchDirs) {
|
foreach (const QString &dir, searchDirs) {
|
||||||
QString fn = dir + QLatin1Char('/') + el;
|
QString fn = QDir::cleanPath(dir + QLatin1Char('/') + el);
|
||||||
if (IoUtils::exists(fn)) {
|
if (m_vfs->exists(fn)) {
|
||||||
result << QDir::cleanPath(fn);
|
result << fn;
|
||||||
goto next;
|
goto next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (baseDirectory.isEmpty())
|
if (baseDirectory.isEmpty())
|
||||||
goto next;
|
goto next;
|
||||||
absEl = baseDirectory + QLatin1Char('/') + el;
|
absEl = QDir::cleanPath(baseDirectory + QLatin1Char('/') + el);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
absEl = QDir::cleanPath(absEl);
|
|
||||||
int nameOff = absEl.lastIndexOf(QLatin1Char('/'));
|
int nameOff = absEl.lastIndexOf(QLatin1Char('/'));
|
||||||
QString absDir = d->m_tmp1.setRawData(absEl.constData(), nameOff);
|
QString absDir = d->m_tmp1.setRawData(absEl.constData(), nameOff);
|
||||||
if (IoUtils::exists(absDir)) {
|
if (IoUtils::exists(absDir)) {
|
||||||
|
@@ -86,6 +86,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QMakeEvaluator *d;
|
QMakeEvaluator *d;
|
||||||
|
QMakeVfs *m_vfs;
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@@ -97,6 +97,23 @@ bool QMakeVfs::writeFile(const QString &fn, QIODevice::OpenMode mode, bool exe,
|
|||||||
#endif
|
#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)
|
bool QMakeVfs::readFile(const QString &fn, QString *contents, QString *errStr)
|
||||||
{
|
{
|
||||||
#ifndef PROEVALUATOR_FULL
|
#ifndef PROEVALUATOR_FULL
|
||||||
|
@@ -48,6 +48,8 @@ public:
|
|||||||
bool exists(const QString &fn);
|
bool exists(const QString &fn);
|
||||||
|
|
||||||
#ifndef PROEVALUATOR_FULL
|
#ifndef PROEVALUATOR_FULL
|
||||||
|
bool readVirtualFile(const QString &fn, QString *contents);
|
||||||
|
|
||||||
void invalidateCache();
|
void invalidateCache();
|
||||||
void invalidateContents();
|
void invalidateContents();
|
||||||
#endif
|
#endif
|
||||||
|
@@ -82,7 +82,7 @@ QStringList tst_QrcParser::allPaths(QrcParser::ConstPtr p)
|
|||||||
void tst_QrcParser::firstAtTest()
|
void tst_QrcParser::firstAtTest()
|
||||||
{
|
{
|
||||||
QFETCH(QString, path);
|
QFETCH(QString, path);
|
||||||
QrcParser::Ptr p = QrcParser::parseQrcFile(path);
|
QrcParser::Ptr p = QrcParser::parseQrcFile(path, QString());
|
||||||
foreach (const QString &qrcPath, allPaths(p)) {
|
foreach (const QString &qrcPath, allPaths(p)) {
|
||||||
QString s1 = p->firstFileAtPath(qrcPath, m_locale);
|
QString s1 = p->firstFileAtPath(qrcPath, m_locale);
|
||||||
if (s1.isEmpty())
|
if (s1.isEmpty())
|
||||||
@@ -99,7 +99,7 @@ void tst_QrcParser::firstAtTest()
|
|||||||
void tst_QrcParser::firstInTest()
|
void tst_QrcParser::firstInTest()
|
||||||
{
|
{
|
||||||
QFETCH(QString, path);
|
QFETCH(QString, path);
|
||||||
QrcParser::Ptr p = QrcParser::parseQrcFile(path);
|
QrcParser::Ptr p = QrcParser::parseQrcFile(path, QString());
|
||||||
foreach (const QString &qrcPath, allPaths(p)) {
|
foreach (const QString &qrcPath, allPaths(p)) {
|
||||||
if (!qrcPath.endsWith(QLatin1Char('/')))
|
if (!qrcPath.endsWith(QLatin1Char('/')))
|
||||||
continue;
|
continue;
|
||||||
@@ -137,15 +137,15 @@ void tst_QrcParser::cacheTest()
|
|||||||
{
|
{
|
||||||
QFETCH(QString, path);
|
QFETCH(QString, path);
|
||||||
QVERIFY(m_cache.parsedPath(path).isNull());
|
QVERIFY(m_cache.parsedPath(path).isNull());
|
||||||
QrcParser::ConstPtr p0 = m_cache.addPath(path);
|
QrcParser::ConstPtr p0 = m_cache.addPath(path, QString());
|
||||||
QVERIFY(!p0.isNull());
|
QVERIFY(!p0.isNull());
|
||||||
QrcParser::ConstPtr p1 = m_cache.parsedPath(path);
|
QrcParser::ConstPtr p1 = m_cache.parsedPath(path);
|
||||||
QVERIFY(p1.data() == p0.data());
|
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());
|
QVERIFY(p2.data() == p1.data());
|
||||||
QrcParser::ConstPtr p3 = m_cache.parsedPath(path);
|
QrcParser::ConstPtr p3 = m_cache.parsedPath(path);
|
||||||
QVERIFY(p3.data() == p2.data());
|
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());
|
QVERIFY(p4.data() != p3.data());
|
||||||
QrcParser::ConstPtr p5 = m_cache.parsedPath(path);
|
QrcParser::ConstPtr p5 = m_cache.parsedPath(path);
|
||||||
QVERIFY(p5.data() == p4.data());
|
QVERIFY(p5.data() == p4.data());
|
||||||
@@ -159,7 +159,7 @@ void tst_QrcParser::cacheTest()
|
|||||||
|
|
||||||
void tst_QrcParser::simpleTest()
|
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);
|
QStringList paths = allPaths(p);
|
||||||
paths.sort();
|
paths.sort();
|
||||||
QVERIFY(paths == QStringList()
|
QVERIFY(paths == QStringList()
|
||||||
|
Reference in New Issue
Block a user