From eba3cd61354c2f84da2608934459e9a502b59e9b Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Wed, 13 Mar 2019 16:06:12 +0100 Subject: [PATCH] AbstractProcessStep: Re-use FileInProjectFinder Change-Id: Ifd5d24b6cac707372a95b2b31e270722a6202fc0 Reviewed-by: Antonio Di Monaco Reviewed-by: hjk --- .../projectexplorer/abstractprocessstep.cpp | 87 ++++--------------- .../projectexplorer/abstractprocessstep.h | 3 - 2 files changed, 15 insertions(+), 75 deletions(-) diff --git a/src/plugins/projectexplorer/abstractprocessstep.cpp b/src/plugins/projectexplorer/abstractprocessstep.cpp index d2c0ba87aab..fd3a22e6f89 100644 --- a/src/plugins/projectexplorer/abstractprocessstep.cpp +++ b/src/plugins/projectexplorer/abstractprocessstep.cpp @@ -35,23 +35,19 @@ #include +#include #include #include #include #include -#include #include #include +#include #include #include -namespace { -const int CACHE_SOFT_LIMIT = 500; -const int CACHE_HARD_LIMIT = 1000; -} // namespace - namespace ProjectExplorer { /*! @@ -107,10 +103,8 @@ public: std::unique_ptr m_process; std::unique_ptr m_outputParserChain; ProcessParameters m_param; - QHash> m_filesCache; - QHash m_candidates; + Utils::FileInProjectFinder m_fileFinder; QByteArray deferredText; - quint64 m_cacheCounter = 0; bool m_ignoreReturnValue = false; bool m_skipFlush = false; @@ -194,11 +188,8 @@ void AbstractProcessStep::setIgnoreReturnValue(bool b) bool AbstractProcessStep::init() { - d->m_candidates.clear(); - const Utils::FileNameList fl = project()->files(Project::AllFiles); - for (const Utils::FileName &file : fl) - d->m_candidates[file.fileName()].push_back(file); - + d->m_fileFinder.setProjectDirectory(project()->projectDirectory()); + d->m_fileFinder.setProjectFiles(project()->files(Project::AllFiles)); return !d->m_process; } @@ -437,44 +428,16 @@ void AbstractProcessStep::taskAdded(const Task &task, int linkedOutputLines, int Task editable(task); QString filePath = task.file.toString(); - - auto it = d->m_filesCache.find(filePath); - if (it != d->m_filesCache.end()) { - editable.file = it.value().first; - it.value().second = ++d->m_cacheCounter; - } else if (!filePath.isEmpty() && !filePath.startsWith('<') && !QDir::isAbsolutePath(filePath)) { - // We have no save way to decide which file in which subfolder - // is meant. Therefore we apply following heuristics: - // 1. Check if file is unique in whole project - // 2. Otherwise try again without any ../ - // 3. give up. - - QString sourceFilePath = filePath; - Utils::FileNameList possibleFiles = d->m_candidates.value(Utils::FileName::fromString(filePath).fileName()); - - if (possibleFiles.count() == 1) { - editable.file = possibleFiles.first(); - } else { - // More then one filename, so do a better compare - // Chop of any "../" - while (filePath.startsWith("../")) - filePath.remove(0, 3); - - int count = 0; - Utils::FileName possibleFilePath; - foreach (const Utils::FileName &fn, possibleFiles) { - if (fn.endsWith(filePath)) { - possibleFilePath = fn; - ++count; - } - } - if (count == 1) - editable.file = possibleFilePath; - else - qWarning() << "Could not find absolute location of file " << filePath; - } - - insertInCache(sourceFilePath, editable.file); + if (!filePath.isEmpty() && !filePath.startsWith('<') && !QDir::isAbsolutePath(filePath)) { + while (filePath.startsWith("../")) + filePath.remove(0, 3); + bool found = false; + const Utils::FileNameList candidates + = d->m_fileFinder.findFile(QUrl::fromLocalFile(filePath), &found); + if (found && candidates.size() == 1) + editable.file = candidates.first(); + else + qWarning() << "Could not find absolute location of file " << filePath; } emit addTask(editable, linkedOutputLines, skipLines); @@ -499,27 +462,7 @@ void AbstractProcessStep::slotProcessFinished(int, QProcess::ExitStatus) for (const QString &l : stdOutLine.split('\n')) stdError(l); - purgeCache(true); cleanUp(process); } -void AbstractProcessStep::purgeCache(bool useSoftLimit) -{ - const int limit = useSoftLimit ? CACHE_SOFT_LIMIT : CACHE_HARD_LIMIT; - if (d->m_filesCache.size() <= limit) - return; - - const quint64 minCounter = d->m_cacheCounter - static_cast(limit); - std::remove_if(d->m_filesCache.begin(), d->m_filesCache.end(), - [minCounter](const QPair &entry) { - return entry.second <= minCounter; - }); -} - -void AbstractProcessStep::insertInCache(const QString &relativePath, const Utils::FileName &absPath) -{ - purgeCache(false); - d->m_filesCache.insert(relativePath, qMakePair(absPath, ++d->m_cacheCounter)); -} - } // namespace ProjectExplorer diff --git a/src/plugins/projectexplorer/abstractprocessstep.h b/src/plugins/projectexplorer/abstractprocessstep.h index 769010c7afa..df31a99eb17 100644 --- a/src/plugins/projectexplorer/abstractprocessstep.h +++ b/src/plugins/projectexplorer/abstractprocessstep.h @@ -80,9 +80,6 @@ private: void outputAdded(const QString &string, BuildStep::OutputFormat format); - void purgeCache(bool useSoftLimit); - void insertInCache(const QString &relativePath, const Utils::FileName &absPath); - class Private; Private *d; };