aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/utils/fileinprojectfinder.cpp
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@theqtcompany.com>2015-03-06 18:21:11 +0100
committerJoerg Bornemann <joerg.bornemann@theqtcompany.com>2015-03-19 11:34:13 +0000
commit2ae8ae5d875e00eb883e02111996e6024c5ac79c (patch)
tree75c02f19dd513e38d16cf47c0f082f477ed8c327 /src/libs/utils/fileinprojectfinder.cpp
parente44378e942b82dfad136d5203536f635fea15ccf (diff)
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>
Diffstat (limited to 'src/libs/utils/fileinprojectfinder.cpp')
-rw-r--r--src/libs/utils/fileinprojectfinder.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/libs/utils/fileinprojectfinder.cpp b/src/libs/utils/fileinprojectfinder.cpp
index e40b33136b7..1f31d912673 100644
--- a/src/libs/utils/fileinprojectfinder.cpp
+++ b/src/libs/utils/fileinprojectfinder.cpp
@@ -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