Commit b9661b03 authored by Kai Koehne's avatar Kai Koehne
Browse files

FileInProjectFinder: Add (optional) debugging output



Change-Id: Icfb36086543bd9e66778a4569bd4838bb4b31a5e
Reviewed-by: default avatarKai Koehne <kai.koehne@nokia.com>
parent f495d2e8
......@@ -36,6 +36,8 @@
#include <QFileInfo>
#include <QUrl>
enum { debug = false };
namespace Utils {
/*!
......@@ -121,20 +123,29 @@ void FileInProjectFinder::setSysroot(const QString &sysroot)
*/
QString FileInProjectFinder::findFile(const QUrl &fileUrl, bool *success) const
{
if (debug)
qDebug() << "FileInProjectFinder: trying to find file" << fileUrl.toString() << "...";
QString originalPath = fileUrl.toLocalFile();
if (originalPath.isEmpty()) // e.g. qrc://
originalPath = fileUrl.path();
if (originalPath.isEmpty()) {
if (debug)
qDebug() << "FileInProjectFinder: malformed url, returning";
if (success)
*success = false;
return originalPath;
}
if (!m_projectDir.isEmpty()) {
if (debug)
qDebug() << "FileInProjectFinder: checking project directory ...";
int prefixToIgnore = -1;
const QChar separator = QLatin1Char('/');
if (originalPath.startsWith(m_projectDir + separator)) {
#ifdef Q_OS_MAC
// starting with the project path is not sufficient if the file was
// copied in an insource build, e.g. into MyApp.app/Contents/Resources
......@@ -145,6 +156,8 @@ QString FileInProjectFinder::findFile(const QUrl &fileUrl, bool *success) const
prefixToIgnore = originalPath.indexOf(appResourcePath) + appResourcePath.length();
} else {
#endif
if (debug)
qDebug() << "FileInProjectFinder: found" << originalPath << "in project directory";
if (success)
*success = true;
return originalPath;
......@@ -154,16 +167,23 @@ QString FileInProjectFinder::findFile(const QUrl &fileUrl, bool *success) const
}
if (m_cache.contains(originalPath)) {
if (debug)
qDebug() << "FileInProjectFinder: checking cache ...";
// check if cached path is still there
QString candidate = m_cache.value(originalPath);
QFileInfo candidateInfo(candidate);
if (candidateInfo.exists() && candidateInfo.isFile()) {
if (success)
*success = true;
if (debug)
qDebug() << "FileInProjectFinder: found" << candidate << "in the cache";
return candidate;
}
}
if (debug)
qDebug() << "FileInProjectFinder: checking stripped paths in project directory ...";
// Strip directories one by one from the beginning of the path,
// and see if the new relative path exists in the build directory.
if (prefixToIgnore < 0) {
......@@ -183,6 +203,9 @@ QString FileInProjectFinder::findFile(const QUrl &fileUrl, bool *success) const
if (success)
*success = true;
if (debug)
qDebug() << "FileInProjectFinder: found" << candidate << "in project directory";
m_cache.insert(originalPath, candidate);
return candidate;
}
......@@ -191,16 +214,24 @@ QString FileInProjectFinder::findFile(const QUrl &fileUrl, bool *success) const
}
// find (solely by filename) in project files
if (debug)
qDebug() << "FileInProjectFinder: checking project files ...";
const QString fileName = QFileInfo(originalPath).fileName();
foreach (const QString &f, m_projectFiles) {
if (QFileInfo(f).fileName() == fileName) {
m_cache.insert(originalPath, f);
if (success)
*success = true;
if (debug)
qDebug() << "FileInProjectFinder: found" << f << "in project files";
return f;
}
}
if (debug)
qDebug() << "FileInProjectFinder: checking absolute path in sysroot ...";
// check if absolute path is found in sysroot
if (!m_sysroot.isEmpty()) {
const QString sysrootPath = m_sysroot + originalPath;
......@@ -208,6 +239,8 @@ QString FileInProjectFinder::findFile(const QUrl &fileUrl, bool *success) const
if (success)
*success = true;
m_cache.insert(originalPath, sysrootPath);
if (debug)
qDebug() << "FileInProjectFinder: found" << sysrootPath << "in sysroot";
return sysrootPath;
}
}
......@@ -215,6 +248,8 @@ QString FileInProjectFinder::findFile(const QUrl &fileUrl, bool *success) const
if (success)
*success = false;
if (debug)
qDebug() << "FileInProjectFinder: couldn't find file!";
return originalPath;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment