forked from qt-creator/qt-creator
CMake: Update code to decide whether to run cmake in fileapi mode
Change-Id: Iea841bb49876a580abc80cc7ea21a88b153cc224 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -858,7 +858,7 @@ void FileApiParser::setupCMakeFileApi() const
|
|||||||
QTC_ASSERT(queryDir.exists(), );
|
QTC_ASSERT(queryDir.exists(), );
|
||||||
|
|
||||||
bool failedBefore = false;
|
bool failedBefore = false;
|
||||||
for (const QString &fileName : QStringList({"cache-v2", "codemodel-v2", "cmakeFiles-v1"})) {
|
for (const QString &fileName : cmakeQueryFileNames()) {
|
||||||
const QString filePath = queryDir.filePath(fileName);
|
const QString filePath = queryDir.filePath(fileName);
|
||||||
|
|
||||||
QFile f(filePath);
|
QFile f(filePath);
|
||||||
@@ -933,6 +933,19 @@ QFileInfo FileApiParser::scanForCMakeReplyFile() const
|
|||||||
return fis.isEmpty() ? QFileInfo() : fis.last();
|
return fis.isEmpty() ? QFileInfo() : fis.last();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList FileApiParser::cmakeQueryFileNames() const
|
||||||
|
{
|
||||||
|
return {"cache-v2", "codemodel-v2", "cmakeFiles-v1"};
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList FileApiParser::cmakeQueryFilePaths() const
|
||||||
|
{
|
||||||
|
QDir queryDir(QDir::cleanPath(m_sourceDirectory.toString() + "/"
|
||||||
|
+ QString::fromLatin1(CMAKE_RELATIVE_QUERY_PATH)));
|
||||||
|
return transform(cmakeQueryFileNames(),
|
||||||
|
[&queryDir](const QString &name) { return queryDir.absoluteFilePath(name); });
|
||||||
|
}
|
||||||
|
|
||||||
void FileApiParser::replyDirectoryHasChanged(const QString &directory) const
|
void FileApiParser::replyDirectoryHasChanged(const QString &directory) const
|
||||||
{
|
{
|
||||||
if (directory == cmakeReplyDirectory().toString()) {
|
if (directory == cmakeReplyDirectory().toString()) {
|
||||||
|
|||||||
@@ -248,6 +248,9 @@ public:
|
|||||||
Utils::FilePath cmakeReplyDirectory() const;
|
Utils::FilePath cmakeReplyDirectory() const;
|
||||||
QFileInfo scanForCMakeReplyFile() const;
|
QFileInfo scanForCMakeReplyFile() const;
|
||||||
|
|
||||||
|
QStringList cmakeQueryFileNames() const;
|
||||||
|
QStringList cmakeQueryFilePaths() const;
|
||||||
|
|
||||||
static FileApiData parseData(const QFileInfo &replyFileInfo, QString &errorMessage);
|
static FileApiData parseData(const QFileInfo &replyFileInfo, QString &errorMessage);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|||||||
@@ -69,8 +69,7 @@ FileApiReader::FileApiReader()
|
|||||||
&Core::EditorManager::aboutToSave,
|
&Core::EditorManager::aboutToSave,
|
||||||
this,
|
this,
|
||||||
[this](const Core::IDocument *document) {
|
[this](const Core::IDocument *document) {
|
||||||
if (m_cmakeFiles.contains(document->filePath()) || !m_parameters.cmakeTool()
|
if (m_cmakeFiles.contains(document->filePath())) {
|
||||||
|| !m_parameters.cmakeTool()->isAutoRun()) {
|
|
||||||
qCDebug(cmakeFileApiMode) << "FileApiReader: DIRTY SIGNAL";
|
qCDebug(cmakeFileApiMode) << "FileApiReader: DIRTY SIGNAL";
|
||||||
emit dirty();
|
emit dirty();
|
||||||
}
|
}
|
||||||
@@ -139,9 +138,21 @@ void FileApiReader::parse(bool forceCMakeRun, bool forceConfiguration)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const QFileInfo replyFi = m_fileApi->scanForCMakeReplyFile();
|
const QFileInfo replyFi = m_fileApi->scanForCMakeReplyFile();
|
||||||
const bool mustUpdate = forceCMakeRun || !replyFi.exists() || m_cmakeFiles.isEmpty()
|
// Only need to update when one of the following conditions is met:
|
||||||
|| anyOf(m_cmakeFiles, [&replyFi](const FilePath &f) {
|
// * The user forces the update,
|
||||||
return f.toFileInfo().lastModified() > replyFi.lastModified();
|
// * There is no reply file,
|
||||||
|
// * One of the cmakefiles is newer than the replyFile and the user asked
|
||||||
|
// for creator to run CMake as needed,
|
||||||
|
// * A query files are newer than the reply file
|
||||||
|
const bool mustUpdate = forceCMakeRun || !replyFi.exists()
|
||||||
|
|| (m_parameters.cmakeTool() && m_parameters.cmakeTool()->isAutoRun()
|
||||||
|
&& anyOf(m_cmakeFiles,
|
||||||
|
[&replyFi](const FilePath &f) {
|
||||||
|
return f.toFileInfo().lastModified()
|
||||||
|
> replyFi.lastModified();
|
||||||
|
}))
|
||||||
|
|| anyOf(m_fileApi->cmakeQueryFilePaths(), [&replyFi](const QString &qf) {
|
||||||
|
return QFileInfo(qf).lastModified() > replyFi.lastModified();
|
||||||
});
|
});
|
||||||
|
|
||||||
if (mustUpdate) {
|
if (mustUpdate) {
|
||||||
|
|||||||
Reference in New Issue
Block a user