diff options
author | Christian Kandeler <[email protected]> | 2019-10-22 09:43:24 +0200 |
---|---|---|
committer | Christian Kandeler <[email protected]> | 2019-10-22 13:00:42 +0000 |
commit | 61bb28cdc07b4f488585ea23476e3b074df77fb3 (patch) | |
tree | 27de4d8f2c7a6f1850d8a8f498acf9becac26fec /src/plugins/compilationdatabaseprojectmanager/compilationdbparser.cpp | |
parent | 70e8954402168d4a9fc5a3ebcad563b288021e26 (diff) |
CompilationDB: Reparse only on actual project file change
Fixes: QTCREATORBUG-22574
Change-Id: I39fe58f96c1ff9118405be225f39e5348304222e
Reviewed-by: Nikolai Kosjar <[email protected]>
Diffstat (limited to 'src/plugins/compilationdatabaseprojectmanager/compilationdbparser.cpp')
-rw-r--r-- | src/plugins/compilationdatabaseprojectmanager/compilationdbparser.cpp | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/src/plugins/compilationdatabaseprojectmanager/compilationdbparser.cpp b/src/plugins/compilationdatabaseprojectmanager/compilationdbparser.cpp index 6c913118985..374c245b23b 100644 --- a/src/plugins/compilationdatabaseprojectmanager/compilationdbparser.cpp +++ b/src/plugins/compilationdatabaseprojectmanager/compilationdbparser.cpp @@ -31,6 +31,7 @@ #include <utils/mimetypes/mimetype.h> #include <utils/runextensions.h> +#include <QCryptographicHash> #include <QDir> #include <QFileInfo> #include <QJsonArray> @@ -59,12 +60,27 @@ CompilationDbParser::CompilationDbParser(const QString &projectName, connect(&m_parserWatcher, &QFutureWatcher<void>::finished, this, [this] { m_dbContents = m_parserWatcher.result(); if (!m_treeScanner || m_treeScanner->isFinished()) - finish(); + finish(ParseResult::Success); }); } void CompilationDbParser::start() { + // Check hash first. + QFile file(m_projectFilePath.toString()); + if (!file.open(QIODevice::ReadOnly)) { + finish(ParseResult::Failure); + return; + } + m_projectFileContents = file.readAll(); + const QByteArray newHash = QCryptographicHash::hash(m_projectFileContents, + QCryptographicHash::Sha1); + if (m_projectFileHash == newHash) { + finish(ParseResult::Cached); + return; + } + m_projectFileHash = newHash; + // Thread 1: Scan disk. if (!m_rootPath.isEmpty()) { m_treeScanner = new TreeScanner(this); @@ -95,7 +111,7 @@ void CompilationDbParser::start() "CompilationDatabase.Scan.Tree"); connect(m_treeScanner, &TreeScanner::finished, this, [this] { if (m_parserWatcher.isFinished()) - finish(); + finish(ParseResult::Success); }); } @@ -126,9 +142,9 @@ QList<FileNode *> CompilationDbParser::scannedFiles() const ? m_treeScanner->release() : QList<FileNode *>(); } -void CompilationDbParser::finish() +void CompilationDbParser::finish(ParseResult result) { - emit finished(true); + emit finished(result); deleteLater(); } @@ -158,24 +174,20 @@ static FilePath jsonObjectFilename(const QJsonObject &object) return fileName; } -static std::vector<DbEntry> readJsonObjects(const QString &filePath) +std::vector<DbEntry> CompilationDbParser::readJsonObjects() const { std::vector<DbEntry> result; - QFile file(filePath); - if (!file.open(QIODevice::ReadOnly)) - return result; - const QByteArray contents = file.readAll(); - int objectStart = contents.indexOf('{'); - int objectEnd = contents.indexOf('}', objectStart + 1); + int objectStart = m_projectFileContents.indexOf('{'); + int objectEnd = m_projectFileContents.indexOf('}', objectStart + 1); QSet<QString> flagsCache; while (objectStart >= 0 && objectEnd >= 0) { const QJsonDocument document = QJsonDocument::fromJson( - contents.mid(objectStart, objectEnd - objectStart + 1)); + m_projectFileContents.mid(objectStart, objectEnd - objectStart + 1)); if (document.isNull()) { // The end was found incorrectly, search for the next one. - objectEnd = contents.indexOf('}', objectEnd + 1); + objectEnd = m_projectFileContents.indexOf('}', objectEnd + 1); continue; } @@ -185,8 +197,8 @@ static std::vector<DbEntry> readJsonObjects(const QString &filePath) fileName.toFileInfo().baseName()); result.push_back({flags, fileName, object["directory"].toString()}); - objectStart = contents.indexOf('{', objectEnd + 1); - objectEnd = contents.indexOf('}', objectStart + 1); + objectStart = m_projectFileContents.indexOf('{', objectEnd + 1); + objectEnd = m_projectFileContents.indexOf('}', objectStart + 1); } return result; @@ -217,7 +229,7 @@ QStringList readExtraFiles(const QString &filePath) DbContents CompilationDbParser::parseProject() { DbContents dbContents; - dbContents.entries = readJsonObjects(m_projectFilePath.toString()); + dbContents.entries = readJsonObjects(); dbContents.extraFileName = m_projectFilePath.toString() + Constants::COMPILATIONDATABASEPROJECT_FILES_SUFFIX; dbContents.extras = readExtraFiles(dbContents.extraFileName); |