forked from qt-creator/qt-creator
CMake: Move notification on outside cmake runs into FileApiReader
Move the detection of outside cmake runs into FileApiReader and make the FileApiParser non-interactive. Change-Id: I70afc1df35fcfe90e88822569579154aabbdb1cd Fixes: QTCREATORBUG-24015 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -814,18 +814,6 @@ QString FileApiDetails::ReplyFileContents::jsonFile(const QString &kind, const Q
|
||||
// FileApi:
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
FileApiParser::FileApiParser(const FilePath &buildDirectory) : m_buildDirectory(buildDirectory)
|
||||
{
|
||||
setupCMakeFileApi(buildDirectory, m_watcher);
|
||||
|
||||
QObject::connect(&m_watcher,
|
||||
&FileSystemWatcher::directoryChanged,
|
||||
this,
|
||||
&FileApiParser::replyDirectoryHasChanged);
|
||||
}
|
||||
|
||||
FileApiParser::~FileApiParser() = default;
|
||||
|
||||
bool FileApiParser::setupCMakeFileApi(const FilePath &buildDirectory, Utils::FileSystemWatcher &watcher)
|
||||
{
|
||||
const QDir buildDir = QDir(buildDirectory.toString());
|
||||
@@ -928,20 +916,5 @@ QStringList FileApiParser::cmakeQueryFilePaths(const Utils::FilePath &buildDirec
|
||||
[&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(m_buildDirectory).toString()) {
|
||||
QFileInfo fi = scanForCMakeReplyFile(m_buildDirectory);
|
||||
if (fi.isFile() && fi.filePath() != m_lastParsedReplyFile) {
|
||||
emit dirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace CMakeProjectManager
|
||||
|
||||
@@ -241,16 +241,9 @@ public:
|
||||
std::vector<FileApiDetails::TargetDetails> targetDetails;
|
||||
};
|
||||
|
||||
class FileApiParser final : public QObject
|
||||
class FileApiParser
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FileApiParser(const Utils::FilePath &buildDirectory);
|
||||
~FileApiParser() final;
|
||||
|
||||
void setParsedReplyFilePath(const QString &filePath);
|
||||
|
||||
static FileApiData parseData(const QFileInfo &replyFileInfo, QString &errorMessage);
|
||||
|
||||
static bool setupCMakeFileApi(const Utils::FilePath &buildDirectory,
|
||||
@@ -259,16 +252,6 @@ public:
|
||||
static QStringList cmakeQueryFilePaths(const Utils::FilePath &buildDirectory);
|
||||
|
||||
static QFileInfo scanForCMakeReplyFile(const Utils::FilePath &buildDirectory);
|
||||
|
||||
signals:
|
||||
void dirty() const;
|
||||
|
||||
private:
|
||||
Utils::FilePath m_buildDirectory;
|
||||
|
||||
void replyDirectoryHasChanged(const QString &directory) const;
|
||||
Utils::FileSystemWatcher m_watcher;
|
||||
QString m_lastParsedReplyFile;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "fileapireader.h"
|
||||
|
||||
#include "fileapidataextractor.h"
|
||||
#include "fileapiparser.h"
|
||||
#include "projecttreehelper.h"
|
||||
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
@@ -50,7 +51,14 @@ using namespace FileApiDetails;
|
||||
// FileApiReader:
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
FileApiReader::FileApiReader() {}
|
||||
FileApiReader::FileApiReader()
|
||||
: m_lastReplyTimestamp()
|
||||
{
|
||||
QObject::connect(&m_watcher,
|
||||
&FileSystemWatcher::directoryChanged,
|
||||
this,
|
||||
&FileApiReader::replyDirectoryHasChanged);
|
||||
}
|
||||
|
||||
FileApiReader::~FileApiReader()
|
||||
{
|
||||
@@ -69,13 +77,13 @@ void FileApiReader::setParameters(const BuildDirParameters &p)
|
||||
m_parameters = p;
|
||||
qCDebug(cmakeFileApiMode) << "Work directory:" << m_parameters.workDirectory.toUserOutput();
|
||||
|
||||
resetData();
|
||||
// Reset watcher:
|
||||
m_watcher.removeFiles(m_watcher.files());
|
||||
m_watcher.removeDirectories(m_watcher.directories());
|
||||
|
||||
m_fileApi = std::make_unique<FileApiParser>(m_parameters.workDirectory);
|
||||
connect(m_fileApi.get(), &FileApiParser::dirty, this, [this]() {
|
||||
if (!m_isParsing)
|
||||
emit dirty();
|
||||
});
|
||||
FileApiParser::setupCMakeFileApi(m_parameters.workDirectory, m_watcher);
|
||||
|
||||
resetData();
|
||||
}
|
||||
|
||||
void FileApiReader::resetData()
|
||||
@@ -106,7 +114,7 @@ void FileApiReader::parse(bool forceCMakeRun, bool forceConfiguration)
|
||||
return;
|
||||
}
|
||||
|
||||
const QFileInfo replyFi = m_fileApi->scanForCMakeReplyFile(m_parameters.workDirectory);
|
||||
const QFileInfo replyFi = FileApiParser::scanForCMakeReplyFile(m_parameters.workDirectory);
|
||||
// Only need to update when one of the following conditions is met:
|
||||
// * The user forces the update,
|
||||
// * There is no reply file,
|
||||
@@ -207,7 +215,7 @@ void FileApiReader::endState(const QFileInfo &replyFi)
|
||||
const FilePath sourceDirectory = m_parameters.sourceDirectory;
|
||||
const FilePath buildDirectory = m_parameters.workDirectory;
|
||||
|
||||
m_fileApi->setParsedReplyFilePath(replyFi.filePath());
|
||||
m_lastReplyTimestamp = replyFi.lastModified();
|
||||
|
||||
m_future = runAsync(ProjectExplorerPlugin::sharedThreadPool(),
|
||||
[replyFi, sourceDirectory, buildDirectory]() {
|
||||
@@ -267,7 +275,22 @@ void FileApiReader::cmakeFinishedState(int code, QProcess::ExitStatus status)
|
||||
|
||||
m_cmakeProcess.release()->deleteLater();
|
||||
|
||||
endState(m_fileApi->scanForCMakeReplyFile(m_parameters.workDirectory));
|
||||
endState(FileApiParser::scanForCMakeReplyFile(m_parameters.workDirectory));
|
||||
}
|
||||
|
||||
void FileApiReader::replyDirectoryHasChanged(const QString &directory) const
|
||||
{
|
||||
if (m_isParsing)
|
||||
return; // This has been triggered by ourselves, ignore.
|
||||
|
||||
const QFileInfo fi = FileApiParser::scanForCMakeReplyFile(m_parameters.workDirectory);
|
||||
const QString dir = fi.absolutePath();
|
||||
if (dir.isEmpty())
|
||||
return; // CMake started to fill the result dir, but has not written a result file yet
|
||||
QTC_ASSERT(dir == directory, return);
|
||||
|
||||
if (m_lastReplyTimestamp.isValid() && fi.lastModified() > m_lastReplyTimestamp)
|
||||
emit dirty();
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -28,16 +28,15 @@
|
||||
#include "cmakebuildtarget.h"
|
||||
#include "cmakeprocess.h"
|
||||
#include "cmakeprojectnodes.h"
|
||||
#include "fileapiparser.h"
|
||||
|
||||
#include <projectexplorer/rawprojectpart.h>
|
||||
|
||||
#include <utils/filesystemwatcher.h>
|
||||
#include <utils/optional.h>
|
||||
|
||||
#include <QFuture>
|
||||
#include <QObject>
|
||||
|
||||
#include <memory>
|
||||
#include <QDateTime>
|
||||
|
||||
namespace ProjectExplorer {
|
||||
class ProjectNode;
|
||||
@@ -83,6 +82,8 @@ private:
|
||||
void startCMakeState(const QStringList &configurationArguments);
|
||||
void cmakeFinishedState(int code, QProcess::ExitStatus status);
|
||||
|
||||
void replyDirectoryHasChanged(const QString &directory) const;
|
||||
|
||||
std::unique_ptr<CMakeProcess> m_cmakeProcess;
|
||||
|
||||
// cmake data:
|
||||
@@ -97,10 +98,11 @@ private:
|
||||
|
||||
// Update related:
|
||||
bool m_isParsing = false;
|
||||
|
||||
std::unique_ptr<FileApiParser> m_fileApi;
|
||||
|
||||
BuildDirParameters m_parameters;
|
||||
|
||||
// Notification on changes outside of creator:
|
||||
Utils::FileSystemWatcher m_watcher;
|
||||
QDateTime m_lastReplyTimestamp;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
Reference in New Issue
Block a user