forked from qt-creator/qt-creator
Utils: add additional search paths to FileInProjectFinder
This can be used e.g. by profilers that need to match some on-device path to a local path. Change-Id: I38e572bfbd7848cfb2e8ba9e275b99bb09692fea Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com> Reviewed-by: Ulf Hermann <ulf.hermann@theqtcompany.com>
This commit is contained in:
@@ -229,6 +229,9 @@ QString FileInProjectFinder::findFile(const QUrl &fileUrl, bool *success) const
|
||||
return matchedFilePath;
|
||||
}
|
||||
|
||||
if (findInSearchPaths(&originalPath))
|
||||
return originalPath;
|
||||
|
||||
if (debug)
|
||||
qDebug() << "FileInProjectFinder: checking absolute path in sysroot ...";
|
||||
|
||||
@@ -253,6 +256,45 @@ QString FileInProjectFinder::findFile(const QUrl &fileUrl, bool *success) const
|
||||
return originalPath;
|
||||
}
|
||||
|
||||
bool FileInProjectFinder::findInSearchPaths(QString *filePath) const
|
||||
{
|
||||
foreach (const QString &dirPath, m_searchDirectories) {
|
||||
if (findInSearchPath(dirPath, filePath))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void chopFirstDir(QString *dirPath)
|
||||
{
|
||||
int i = dirPath->indexOf(QLatin1Char('/'));
|
||||
if (i == -1)
|
||||
dirPath->clear();
|
||||
else
|
||||
dirPath->remove(0, i + 1);
|
||||
}
|
||||
|
||||
bool FileInProjectFinder::findInSearchPath(const QString &searchPath, QString *filePath)
|
||||
{
|
||||
if (debug)
|
||||
qDebug() << "FileInProjectFinder: checking search path" << searchPath;
|
||||
|
||||
QFileInfo fi;
|
||||
QString s = *filePath;
|
||||
while (!s.isEmpty()) {
|
||||
fi.setFile(searchPath + QLatin1Char('/') + s);
|
||||
if (debug)
|
||||
qDebug() << "FileInProjectFinder: trying" << fi.filePath();
|
||||
if (fi.exists() && fi.isReadable()) {
|
||||
*filePath = fi.filePath();
|
||||
return true;
|
||||
}
|
||||
chopFirstDir(&s);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
QStringList FileInProjectFinder::filesWithSameFileName(const QString &fileName) const
|
||||
{
|
||||
QStringList result;
|
||||
@@ -293,4 +335,15 @@ QString FileInProjectFinder::bestMatch(const QStringList &filePaths, const QStri
|
||||
return QString();
|
||||
}
|
||||
|
||||
QStringList FileInProjectFinder::searchDirectories() const
|
||||
{
|
||||
return m_searchDirectories;
|
||||
}
|
||||
|
||||
void FileInProjectFinder::setAdditionalSearchDirectories(const QStringList &searchDirectories)
|
||||
{
|
||||
m_searchDirectories = searchDirectories;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Utils
|
||||
|
||||
@@ -53,7 +53,12 @@ public:
|
||||
|
||||
QString findFile(const QUrl &fileUrl, bool *success = 0) const;
|
||||
|
||||
QStringList searchDirectories() const;
|
||||
void setAdditionalSearchDirectories(const QStringList &searchDirectories);
|
||||
|
||||
private:
|
||||
bool findInSearchPaths(QString *filePath) const;
|
||||
static bool findInSearchPath(const QString &searchPath, QString *filePath);
|
||||
QStringList filesWithSameFileName(const QString &fileName) const;
|
||||
static int rankFilePath(const QString &candidatePath, const QString &filePathToFind);
|
||||
static QString bestMatch(const QStringList &filePaths, const QString &filePathToFind);
|
||||
@@ -61,6 +66,7 @@ private:
|
||||
QString m_projectDir;
|
||||
QString m_sysroot;
|
||||
QStringList m_projectFiles;
|
||||
QStringList m_searchDirectories;
|
||||
mutable QHash<QString,QString> m_cache;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user