diff --git a/src/libs/utils/fileinprojectfinder.cpp b/src/libs/utils/fileinprojectfinder.cpp index e40b33136b734257e5675a56d499d212d4a10f8d..1f31d912673df8ffac794622848b93c9bce06acd 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 c208ba2ecfd6885e7550ce2b53e4ab2e0aff7edc..ba632febede7902bed385c86a00165967c8a959f 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; };