From 7d9ea2a9d5da2efce49bd066057a71973dedb23f Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Wed, 19 Feb 2025 10:46:01 +0100 Subject: [PATCH] CMakePM: Only watch for CMake index json file reply chages Previously the whole directory was watched, and the directory can have lots of json files that would change. And since we are only interested in the index file, make sure to just watch for the index file changes. Change-Id: Ifda794dbd0c4012a1551dfbe8ecaa4f13e16259a Reviewed-by: Eike Ziller Reviewed-by: David Schulz --- .../cmakeprojectmanager/fileapireader.cpp | 28 ++++++++++--------- .../cmakeprojectmanager/fileapireader.h | 3 +- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/fileapireader.cpp b/src/plugins/cmakeprojectmanager/fileapireader.cpp index 53239b40d68..df542f13dfc 100644 --- a/src/plugins/cmakeprojectmanager/fileapireader.cpp +++ b/src/plugins/cmakeprojectmanager/fileapireader.cpp @@ -40,9 +40,9 @@ FileApiReader::FileApiReader() : m_lastReplyTimestamp() { QObject::connect(&m_watcher, - &FileSystemWatcher::directoryChanged, + &FileSystemWatcher::fileChanged, this, - &FileApiReader::handleReplyDirectoryChange); + &FileApiReader::handleReplyIndexFileChange); } FileApiReader::~FileApiReader() @@ -60,11 +60,7 @@ void FileApiReader::setParameters(const BuildDirParameters &p) m_parameters = p; qCDebug(cmakeFileApiMode) << "Work directory:" << m_parameters.buildDirectory.toUserOutput(); - FileApiParser::setupCMakeFileApi(m_parameters.buildDirectory); - - const FilePath replyDirectory = FileApiParser::cmakeReplyDirectory(m_parameters.buildDirectory); - if (!m_watcher.watchesDirectory(replyDirectory)) - m_watcher.addDirectory(replyDirectory.path(), FileSystemWatcher::WatchAllChanges); + setupCMakeFileApi(); resetData(); } @@ -351,6 +347,15 @@ void FileApiReader::writeConfigurationIntoBuildDirectory(const QStringList &conf QTC_ASSERT_EXPECTED(settingsFile.writeFileContents(contents), return); } +void FileApiReader::setupCMakeFileApi() +{ + FileApiParser::setupCMakeFileApi(m_parameters.buildDirectory); + + const FilePath replyIndexfile = FileApiParser::scanForCMakeReplyFile(m_parameters.buildDirectory); + if (!replyIndexfile.isEmpty() && !m_watcher.watchesFile(replyIndexfile)) + m_watcher.addFile(replyIndexfile.path(), FileSystemWatcher::WatchAllChanges); +} + QString FileApiReader::cmakeGenerator() const { return m_cmakeGenerator; @@ -403,16 +408,13 @@ void FileApiReader::cmakeFinishedState(int exitCode) if (m_lastCMakeExitCode != 0) makeBackupConfiguration(false); - FileApiParser::setupCMakeFileApi(m_parameters.buildDirectory); - - m_watcher.addDirectory(FileApiParser::cmakeReplyDirectory(m_parameters.buildDirectory).path(), - FileSystemWatcher::WatchAllChanges); + setupCMakeFileApi(); endState(FileApiParser::scanForCMakeReplyFile(m_parameters.buildDirectory), m_lastCMakeExitCode != 0); } -void FileApiReader::handleReplyDirectoryChange(const QString &directory) +void FileApiReader::handleReplyIndexFileChange(const QString &indexFile) { if (m_isParsing) return; // This has been triggered by ourselves, ignore. @@ -422,7 +424,7 @@ void FileApiReader::handleReplyDirectoryChange(const QString &directory) if (dir.isEmpty()) return; // CMake started to fill the result dir, but has not written a result file yet QTC_CHECK(dir.isLocal()); - QTC_ASSERT(dir.path() == directory, return); + QTC_ASSERT(dir == FilePath::fromString(indexFile).parentDir(), return); if (m_lastReplyTimestamp.isValid() && reply.lastModified() > m_lastReplyTimestamp) { m_lastReplyTimestamp = reply.lastModified(); diff --git a/src/plugins/cmakeprojectmanager/fileapireader.h b/src/plugins/cmakeprojectmanager/fileapireader.h index de56ad900d8..56908313a5f 100644 --- a/src/plugins/cmakeprojectmanager/fileapireader.h +++ b/src/plugins/cmakeprojectmanager/fileapireader.h @@ -78,10 +78,11 @@ private: void startCMakeState(const QStringList &configurationArguments); void cmakeFinishedState(int exitCode); - void handleReplyDirectoryChange(const QString &directory); + void handleReplyIndexFileChange(const QString &indexFile); void makeBackupConfiguration(bool store); void writeConfigurationIntoBuildDirectory(const QStringList &configuration); + void setupCMakeFileApi(); std::unique_ptr m_cmakeProcess;