diff options
author | Joerg Bornemann <joerg.bornemann@theqtcompany.com> | 2015-03-06 18:21:11 +0100 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@theqtcompany.com> | 2015-03-19 11:34:13 +0000 |
commit | 2ae8ae5d875e00eb883e02111996e6024c5ac79c (patch) | |
tree | 75c02f19dd513e38d16cf47c0f082f477ed8c327 /src/libs/utils | |
parent | e44378e942b82dfad136d5203536f635fea15ccf (diff) | |
download | qt-creator-2ae8ae5d875e00eb883e02111996e6024c5ac79c.tar.gz |
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')
-rw-r--r-- | src/libs/utils/fileinprojectfinder.cpp | 53 | ||||
-rw-r--r-- | src/libs/utils/fileinprojectfinder.h | 6 |
2 files changed, 59 insertions, 0 deletions
diff --git a/src/libs/utils/fileinprojectfinder.cpp b/src/libs/utils/fileinprojectfinder.cpp index e40b33136b..1f31d91267 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 diff --git a/src/libs/utils/fileinprojectfinder.h b/src/libs/utils/fileinprojectfinder.h index c208ba2ecf..ba632febed 100644 --- a/src/libs/utils/fileinprojectfinder.h +++ b/src/libs/utils/fileinprojectfinder.h @@ -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; }; |