From eab0df22f98fab37585e4513de836a06e4aa05d5 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Thu, 25 Jul 2019 15:16:55 +0200 Subject: [PATCH] CMake: Make fileapi not race against its own reply file detection Fix broken logic to prevent CMake fileapi from detecting the change its own cmake run triggered via file watching. Remember the last file that was parsed and do not attempt to parse this again. Remember the file on a per-project basis, too:-) Change-Id: Ia6e155b65d77994f6e3d2a3677f770a4ba53539d Reviewed-by: Alexandru Croitor --- .../cmakeprojectmanager/fileapiparser.cpp | 17 ++++++----------- src/plugins/cmakeprojectmanager/fileapiparser.h | 3 +++ .../cmakeprojectmanager/fileapireader.cpp | 2 ++ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/fileapiparser.cpp b/src/plugins/cmakeprojectmanager/fileapiparser.cpp index e6c6bd6a500..e9586dc9c7c 100644 --- a/src/plugins/cmakeprojectmanager/fileapiparser.cpp +++ b/src/plugins/cmakeprojectmanager/fileapiparser.cpp @@ -60,16 +60,6 @@ static void reportFileApiSetupFailure() "Failed to set up cmake fileapi support. Creator can not extract project information.")); } -static bool shouldProcessFile(const QString &filePath, bool update = true) -{ - static QString lastSeenFilePath; - if (filePath == lastSeenFilePath) - return false; - if (update) - lastSeenFilePath = filePath; - return true; -} - static std::pair cmakeVersion(const QJsonObject &obj) { const QJsonObject version = obj.value("version").toObject(); @@ -946,11 +936,16 @@ QStringList FileApiParser::cmakeQueryFilePaths() const [&queryDir](const QString &name) { return queryDir.absoluteFilePath(name); }); } +void FileApiParser::setParsedReplyFilePath(const QString &filePath) +{ + m_lastParsedReplyFile = filePath; +} + void FileApiParser::replyDirectoryHasChanged(const QString &directory) const { if (directory == cmakeReplyDirectory().toString()) { QFileInfo fi = scanForCMakeReplyFile(); - if (fi.isFile() && shouldProcessFile(fi.filePath(), false)) { + if (fi.isFile() && fi.filePath() != m_lastParsedReplyFile) { emit dirty(); } } diff --git a/src/plugins/cmakeprojectmanager/fileapiparser.h b/src/plugins/cmakeprojectmanager/fileapiparser.h index 8bf7132b7f1..4524a649851 100644 --- a/src/plugins/cmakeprojectmanager/fileapiparser.h +++ b/src/plugins/cmakeprojectmanager/fileapiparser.h @@ -251,6 +251,8 @@ public: QStringList cmakeQueryFileNames() const; QStringList cmakeQueryFilePaths() const; + void setParsedReplyFilePath(const QString &filePath); + static FileApiData parseData(const QFileInfo &replyFileInfo, QString &errorMessage); signals: @@ -266,6 +268,7 @@ private: void replyDirectoryHasChanged(const QString &directory) const; Utils::FileSystemWatcher m_watcher; + QString m_lastParsedReplyFile; }; } // namespace Internal diff --git a/src/plugins/cmakeprojectmanager/fileapireader.cpp b/src/plugins/cmakeprojectmanager/fileapireader.cpp index 82aa5542c5f..377553563b7 100644 --- a/src/plugins/cmakeprojectmanager/fileapireader.cpp +++ b/src/plugins/cmakeprojectmanager/fileapireader.cpp @@ -231,6 +231,8 @@ void FileApiReader::endState(const QFileInfo &replyFi) const FilePath sourceDirectory = m_parameters.sourceDirectory; const FilePath buildDirectory = m_parameters.workDirectory; + m_fileApi->setParsedReplyFilePath(replyFi.filePath()); + m_future = runAsync(ProjectExplorerPlugin::sharedThreadPool(), [replyFi, sourceDirectory, buildDirectory]() { auto result = std::make_unique();