diff options
author | Marco Bubke <marco.bubke@qt.io> | 2018-12-17 12:06:57 +0100 |
---|---|---|
committer | Marco Bubke <marco.bubke@qt.io> | 2019-01-21 15:27:10 +0000 |
commit | dd366b68dea11eebb0b1c53f3cff1902ce2bfefa (patch) | |
tree | b919ffd70c5e3677244d2475381f6fb8defdd3eb /src/tools/clangrefactoringbackend/source | |
parent | a78e3e5dd5f882a28a3152f2e63ae986a9f2a8c5 (diff) | |
download | qt-creator-dd366b68dea11eebb0b1c53f3cff1902ce2bfefa.tar.gz |
PchManager: Split pch tasks in project and system pch tasks
Like you can see in the task numbers this patch is touching many different
areas. So I will only touch the main parts. It is using a clang action
instead of an extra process which will be enabling the handling of
generated files in PCHs. The flags from the project part are now not
anymore transformed in a command line but they are saved in the container
semantically aware so that they can later be merged. Most of this patch is
simply polishing of other patches.
Task-number: QTCREATORBUG-21346
Task-number: QTCREATORBUG-21380
Task-number: QTCREATORBUG-21382
Task-number: QTCREATORBUG-21383
Task-number: QTCREATORBUG-21693
Task-number: QTCREATORBUG-21778
Change-Id: I9b0c02d8149b554254e819448fbc61eeaa5b7494
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
Diffstat (limited to 'src/tools/clangrefactoringbackend/source')
11 files changed, 208 insertions, 140 deletions
diff --git a/src/tools/clangrefactoringbackend/source/clangtool.cpp b/src/tools/clangrefactoringbackend/source/clangtool.cpp index e2df298c8d..dea6e1190a 100644 --- a/src/tools/clangrefactoringbackend/source/clangtool.cpp +++ b/src/tools/clangrefactoringbackend/source/clangtool.cpp @@ -50,9 +50,9 @@ void ClangTool::addFile(std::string &&directory, std::vector<std::string> &&commandLine) { m_fileContents.emplace_back(toNativePath(std::move(directory)), - std::move(fileName), - std::move(content), - std::move(commandLine)); + std::move(fileName), + std::move(content), + std::move(commandLine)); const auto &fileContent = m_fileContents.back(); @@ -140,4 +140,13 @@ clang::tooling::ClangTool ClangTool::createTool() const return tool; } +clang::tooling::ClangTool ClangTool::createOutputTool() const +{ + clang::tooling::ClangTool tool = createTool(); + + tool.clearArgumentsAdjusters(); + + return tool; +} + } // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/clangtool.h b/src/tools/clangrefactoringbackend/source/clangtool.h index 9f0676a397..deee71599b 100644 --- a/src/tools/clangrefactoringbackend/source/clangtool.h +++ b/src/tools/clangrefactoringbackend/source/clangtool.h @@ -91,6 +91,7 @@ public: void addUnsavedFiles(const V2::FileContainers &unsavedFiles); clang::tooling::ClangTool createTool() const; + clang::tooling::ClangTool createOutputTool() const; private: RefactoringCompilationDatabase m_compilationDatabase; diff --git a/src/tools/clangrefactoringbackend/source/projectpartartefact.cpp b/src/tools/clangrefactoringbackend/source/projectpartartefact.cpp index 13856e1411..1c62bec8fe 100644 --- a/src/tools/clangrefactoringbackend/source/projectpartartefact.cpp +++ b/src/tools/clangrefactoringbackend/source/projectpartartefact.cpp @@ -33,16 +33,7 @@ namespace ClangBackEnd { -ProjectPartArtefact::ProjectPartArtefact(Utils::SmallStringView compilerArgumentsText, - Utils::SmallStringView compilerMacrosText, - Utils::SmallStringView includeSearchPaths, - int projectPartId) - : compilerArguments(toStringVector(compilerArgumentsText)), - compilerMacros(toCompilerMacros(compilerMacrosText)), - includeSearchPaths(toStringVector(includeSearchPaths)), - projectPartId(projectPartId) -{ -} + Utils::SmallStringVector ProjectPartArtefact::toStringVector(Utils::SmallStringView jsonText) { @@ -58,19 +49,35 @@ Utils::SmallStringVector ProjectPartArtefact::toStringVector(Utils::SmallStringV CompilerMacros ProjectPartArtefact::createCompilerMacrosFromDocument(const QJsonDocument &document) { - QJsonObject object = document.object(); + QJsonArray array = document.array(); CompilerMacros macros; - macros.reserve(object.size()); + macros.reserve(array.size()); - int index = 0; - for (auto current = object.constBegin(); current != object.constEnd(); ++current) - macros.emplace_back(current.key(), current.value().toString(), ++index); + for (const QJsonValueRef entry : array) { + const QJsonArray entryArray = entry.toArray(); + macros.emplace_back( + entryArray[0].toString(), entryArray[1].toString(), entryArray[2].toInt()); + } std::sort(macros.begin(), macros.end()); return macros; } +IncludeSearchPaths ProjectPartArtefact::createIncludeSearchPathsFromDocument(const QJsonDocument &document) +{ + QJsonArray array = document.array(); + IncludeSearchPaths paths; + paths.reserve(array.size()); + + for (const QJsonValueRef entry : array) { + const QJsonArray entryArray = entry.toArray(); + paths.emplace_back(entryArray[0].toString(), entryArray[1].toInt(), entryArray[2].toInt()); + } + + return paths; +} + CompilerMacros ProjectPartArtefact::toCompilerMacros(Utils::SmallStringView jsonText) { if (jsonText.isEmpty()) @@ -93,6 +100,17 @@ QJsonDocument ProjectPartArtefact::createJsonDocument(Utils::SmallStringView jso return document; } +IncludeSearchPaths ProjectPartArtefact::toIncludeSearchPaths(Utils::SmallStringView jsonText) +{ + + if (jsonText.isEmpty()) + return {}; + + QJsonDocument document = createJsonDocument(jsonText, "Include search paths parsing error"); + + return createIncludeSearchPathsFromDocument(document); +} + void ProjectPartArtefact::checkError(const char *whatError, const QJsonParseError &error) { if (error.error != QJsonParseError::NoError) { @@ -104,7 +122,9 @@ void ProjectPartArtefact::checkError(const char *whatError, const QJsonParseErro bool operator==(const ProjectPartArtefact &first, const ProjectPartArtefact &second) { return first.compilerArguments == second.compilerArguments - && first.compilerMacros == second.compilerMacros; + && first.compilerMacros == second.compilerMacros + && first.systemIncludeSearchPaths == second.systemIncludeSearchPaths + && first.projectIncludeSearchPaths == second.projectIncludeSearchPaths; } } // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/projectpartartefact.h b/src/tools/clangrefactoringbackend/source/projectpartartefact.h index ee508abe27..44ca9acadb 100644 --- a/src/tools/clangrefactoringbackend/source/projectpartartefact.h +++ b/src/tools/clangrefactoringbackend/source/projectpartartefact.h @@ -30,6 +30,7 @@ #include <utils/smallstringvector.h> #include <compilermacro.h> +#include <includesearchpath.h> QT_FORWARD_DECLARE_CLASS(QJsonDocument) QT_FORWARD_DECLARE_STRUCT(QJsonParseError) @@ -41,27 +42,30 @@ class ProjectPartArtefact public: ProjectPartArtefact(Utils::SmallStringView compilerArgumentsText, Utils::SmallStringView compilerMacrosText, - Utils::SmallStringView includeSearchPaths, - int projectPartId); + Utils::SmallStringView systemIncludeSearchPathsText, + Utils::SmallStringView projectIncludeSearchPathsText, + int projectPartId) + : compilerArguments(toStringVector(compilerArgumentsText)) + , compilerMacros(toCompilerMacros(compilerMacrosText)) + , systemIncludeSearchPaths(toIncludeSearchPaths(systemIncludeSearchPathsText)) + , projectIncludeSearchPaths(toIncludeSearchPaths(projectIncludeSearchPathsText)) + , projectPartId(projectPartId) + {} - static - Utils::SmallStringVector toStringVector(Utils::SmallStringView jsonText); - static - CompilerMacros createCompilerMacrosFromDocument(const QJsonDocument &document); - static - CompilerMacros toCompilerMacros(Utils::SmallStringView jsonText); - static - QJsonDocument createJsonDocument(Utils::SmallStringView jsonText, - const char *whatError); - static - void checkError(const char *whatError, const QJsonParseError &error); - friend - bool operator==(const ProjectPartArtefact &first, const ProjectPartArtefact &second); + static Utils::SmallStringVector toStringVector(Utils::SmallStringView jsonText); + static CompilerMacros createCompilerMacrosFromDocument(const QJsonDocument &document); + static IncludeSearchPaths createIncludeSearchPathsFromDocument(const QJsonDocument &document); + static CompilerMacros toCompilerMacros(Utils::SmallStringView jsonText); + static QJsonDocument createJsonDocument(Utils::SmallStringView jsonText, const char *whatError); + static IncludeSearchPaths toIncludeSearchPaths(Utils::SmallStringView jsonText); + static void checkError(const char *whatError, const QJsonParseError &error); + friend bool operator==(const ProjectPartArtefact &first, const ProjectPartArtefact &second); public: Utils::SmallStringVector compilerArguments; CompilerMacros compilerMacros; - Utils::SmallStringVector includeSearchPaths; + IncludeSearchPaths systemIncludeSearchPaths; + IncludeSearchPaths projectIncludeSearchPaths; int projectPartId = -1; }; diff --git a/src/tools/clangrefactoringbackend/source/symbolindexer.cpp b/src/tools/clangrefactoringbackend/source/symbolindexer.cpp index 47a02e9fa3..0a45d361d9 100644 --- a/src/tools/clangrefactoringbackend/source/symbolindexer.cpp +++ b/src/tools/clangrefactoringbackend/source/symbolindexer.cpp @@ -25,8 +25,10 @@ #include "symbolindexer.h" -#include <symbolscollectorinterface.h> -#include <symbolindexertaskqueue.h> +#include "symbolscollectorinterface.h" +#include "symbolindexertaskqueue.h" + +#include <commandlinebuilder.h> #include <chrono> #include <iostream> @@ -65,7 +67,7 @@ SymbolIndexer::SymbolIndexer(SymbolIndexerTaskQueueInterface &symbolIndexerTaskQ Sqlite::TransactionInterface &transactionInterface) : m_symbolIndexerTaskQueue(symbolIndexerTaskQueue), m_symbolStorage(symbolStorage), - m_usedMacroAndSourceStorage(usedMacroAndSourceStorage), + m_buildDependencyStorage(usedMacroAndSourceStorage), m_pathWatcher(pathWatcher), m_filePathCache(filePathCache), m_fileStatusCache(fileStatusCache), @@ -74,20 +76,22 @@ SymbolIndexer::SymbolIndexer(SymbolIndexerTaskQueueInterface &symbolIndexerTaskQ pathWatcher.setNotifier(this); } -void SymbolIndexer::updateProjectParts(V2::ProjectPartContainers &&projectParts) +void SymbolIndexer::updateProjectParts(ProjectPartContainers &&projectParts) { - for (V2::ProjectPartContainer &projectPart : projectParts) + for (ProjectPartContainer &projectPart : projectParts) updateProjectPart(std::move(projectPart)); } -void SymbolIndexer::updateProjectPart(V2::ProjectPartContainer &&projectPart) +void SymbolIndexer::updateProjectPart(ProjectPartContainer &&projectPart) { Sqlite::ImmediateTransaction transaction{m_transactionInterface}; const auto optionalArtefact = m_symbolStorage.fetchProjectPartArtefact(projectPart.projectPartId); - int projectPartId = m_symbolStorage.insertOrUpdateProjectPart(projectPart.projectPartId, - projectPart.arguments, - projectPart.compilerMacros, - projectPart.includeSearchPaths); + int projectPartId = m_symbolStorage.insertOrUpdateProjectPart( + projectPart.projectPartId, + projectPart.toolChainArguments, + projectPart.compilerMacros, + projectPart.systemIncludeSearchPaths, + projectPart.projectIncludeSearchPaths); if (optionalArtefact) projectPartId = optionalArtefact->projectPartId; const Utils::optional<ProjectPartPch> optionalProjectPartPch = m_symbolStorage.fetchPrecompiledHeader(projectPartId); @@ -97,14 +101,20 @@ void SymbolIndexer::updateProjectPart(V2::ProjectPartContainer &&projectPart) if (sourcePathIds.empty()) return; - const Utils::SmallStringVector arguments = compilerArguments(projectPart.arguments, - optionalProjectPartPch); + using Builder = CommandLineBuilder<ProjectPartContainer, Utils::SmallStringVector>; + Builder commandLineBuilder{projectPart, + projectPart.toolChainArguments, + {}, + {}, + optionalProjectPartPch + ? FilePathView{optionalProjectPartPch.value().pchPath} + : FilePathView{}}; std::vector<SymbolIndexerTask> symbolIndexerTask; symbolIndexerTask.reserve(projectPart.sourcePathIds.size()); for (FilePathId sourcePathId : projectPart.sourcePathIds) { - auto indexing = [projectPartId, arguments, sourcePathId, this] - (SymbolsCollectorInterface &symbolsCollector) { + auto indexing = [projectPartId, arguments = commandLineBuilder.commandLine, sourcePathId, this]( + SymbolsCollectorInterface &symbolsCollector) { symbolsCollector.setFile(sourcePathId, arguments); symbolsCollector.collectSymbols(); @@ -114,14 +124,14 @@ void SymbolIndexer::updateProjectPart(V2::ProjectPartContainer &&projectPart) m_symbolStorage.addSymbolsAndSourceLocations(symbolsCollector.symbols(), symbolsCollector.sourceLocations()); - m_symbolStorage.updateProjectPartSources(projectPartId, - symbolsCollector.sourceFiles()); + m_symbolStorage.updateProjectPartSources(projectPartId, symbolsCollector.sourceFiles()); - m_usedMacroAndSourceStorage.insertOrUpdateUsedMacros(symbolsCollector.usedMacros()); + m_buildDependencyStorage.insertOrUpdateUsedMacros(symbolsCollector.usedMacros()); - m_usedMacroAndSourceStorage.insertFileStatuses(symbolsCollector.fileStatuses()); + m_buildDependencyStorage.insertFileStatuses(symbolsCollector.fileStatuses()); - m_usedMacroAndSourceStorage.insertOrUpdateSourceDependencies(symbolsCollector.sourceDependencies()); + m_buildDependencyStorage.insertOrUpdateSourceDependencies( + symbolsCollector.sourceDependencies()); transaction.commit(); }; @@ -155,22 +165,23 @@ void SymbolIndexer::updateChangedPath(FilePathId filePathId, m_fileStatusCache.update(filePathId); Sqlite::DeferredTransaction transaction{m_transactionInterface}; - const Utils::optional<ProjectPartArtefact> optionalArtefact = m_symbolStorage.fetchProjectPartArtefact(filePathId); + const Utils::optional<ProjectPartArtefact> optionalArtefact = m_symbolStorage.fetchProjectPartArtefact( + filePathId); if (!optionalArtefact) return; - const Utils::optional<ProjectPartPch> optionalProjectPartPch = m_symbolStorage.fetchPrecompiledHeader(optionalArtefact->projectPartId); + const Utils::optional<ProjectPartPch> optionalProjectPartPch = m_symbolStorage.fetchPrecompiledHeader( + optionalArtefact->projectPartId); transaction.commit(); if (!optionalArtefact.value().compilerArguments.empty()) { - const ProjectPartArtefact &artefact = optionalArtefact.value(); const Utils::SmallStringVector arguments = compilerArguments(artefact.compilerArguments, optionalProjectPartPch); - auto indexing = [projectPartId=artefact.projectPartId, arguments, filePathId, this] - (SymbolsCollectorInterface &symbolsCollector) { + auto indexing = [projectPartId = artefact.projectPartId, arguments, filePathId, this]( + SymbolsCollectorInterface &symbolsCollector) { symbolsCollector.setFile(filePathId, arguments); symbolsCollector.collectSymbols(); @@ -182,39 +193,43 @@ void SymbolIndexer::updateChangedPath(FilePathId filePathId, m_symbolStorage.updateProjectPartSources(projectPartId, symbolsCollector.sourceFiles()); - m_usedMacroAndSourceStorage.insertOrUpdateUsedMacros(symbolsCollector.usedMacros()); + m_buildDependencyStorage.insertOrUpdateUsedMacros(symbolsCollector.usedMacros()); - m_usedMacroAndSourceStorage.insertFileStatuses(symbolsCollector.fileStatuses()); + m_buildDependencyStorage.insertFileStatuses(symbolsCollector.fileStatuses()); - m_usedMacroAndSourceStorage.insertOrUpdateSourceDependencies(symbolsCollector.sourceDependencies()); + m_buildDependencyStorage.insertOrUpdateSourceDependencies( + symbolsCollector.sourceDependencies()); transaction.commit(); }; - symbolIndexerTask.emplace_back(filePathId, optionalArtefact->projectPartId, std::move(indexing)); + symbolIndexerTask.emplace_back(filePathId, + optionalArtefact->projectPartId, + std::move(indexing)); } } bool SymbolIndexer::compilerMacrosOrIncludeSearchPathsAreDifferent( - const V2::ProjectPartContainer &projectPart, + const ProjectPartContainer &projectPart, const Utils::optional<ProjectPartArtefact> &optionalArtefact) const { if (optionalArtefact) { const ProjectPartArtefact &artefact = optionalArtefact.value(); return projectPart.compilerMacros != artefact.compilerMacros - || projectPart.includeSearchPaths != artefact.includeSearchPaths; + || projectPart.systemIncludeSearchPaths != artefact.systemIncludeSearchPaths + || projectPart.projectIncludeSearchPaths != artefact.projectIncludeSearchPaths; } return true; } -FilePathIds SymbolIndexer::filterChangedFiles(const V2::ProjectPartContainer &projectPart) const +FilePathIds SymbolIndexer::filterChangedFiles(const ProjectPartContainer &projectPart) const { FilePathIds ids; ids.reserve(projectPart.sourcePathIds.size()); for (const FilePathId &sourceId : projectPart.sourcePathIds) { - long long oldLastModified = m_usedMacroAndSourceStorage.fetchLowestLastModifiedTime(sourceId); + long long oldLastModified = m_buildDependencyStorage.fetchLowestLastModifiedTime(sourceId); long long currentLastModified = m_fileStatusCache.lastModifiedTime(sourceId); if (oldLastModified < currentLastModified) ids.push_back(sourceId); @@ -223,7 +238,7 @@ FilePathIds SymbolIndexer::filterChangedFiles(const V2::ProjectPartContainer &pr return ids; } -FilePathIds SymbolIndexer::updatableFilePathIds(const V2::ProjectPartContainer &projectPart, +FilePathIds SymbolIndexer::updatableFilePathIds(const ProjectPartContainer &projectPart, const Utils::optional<ProjectPartArtefact> &optionalArtefact) const { if (compilerMacrosOrIncludeSearchPathsAreDifferent(projectPart, optionalArtefact)) @@ -233,8 +248,8 @@ FilePathIds SymbolIndexer::updatableFilePathIds(const V2::ProjectPartContainer & } Utils::SmallStringVector SymbolIndexer::compilerArguments( - Utils::SmallStringVector arguments, - const Utils::optional<ProjectPartPch> optionalProjectPartPch) const + Utils::SmallStringVector arguments, + const Utils::optional<ProjectPartPch> optionalProjectPartPch) const { if (optionalProjectPartPch) { arguments.emplace_back("-Xclang"); diff --git a/src/tools/clangrefactoringbackend/source/symbolindexer.h b/src/tools/clangrefactoringbackend/source/symbolindexer.h index d9070005ce..55f62ffa5f 100644 --- a/src/tools/clangrefactoringbackend/source/symbolindexer.h +++ b/src/tools/clangrefactoringbackend/source/symbolindexer.h @@ -31,7 +31,7 @@ #include "builddependenciesstorageinterface.h" #include "clangpathwatcher.h" -#include <projectpartcontainerv2.h> +#include <projectpartcontainer.h> #include <filecontainerv2.h> namespace ClangBackEnd { @@ -49,8 +49,8 @@ public: FileStatusCache &fileStatusCache, Sqlite::TransactionInterface &transactionInterface); - void updateProjectParts(V2::ProjectPartContainers &&projectParts); - void updateProjectPart(V2::ProjectPartContainer &&projectPart); + void updateProjectParts(ProjectPartContainers &&projectParts); + void updateProjectPart(ProjectPartContainer &&projectPart); void pathsWithIdsChanged(const Utils::SmallStringVector &ids) override; void pathsChanged(const FilePathIds &filePathIds) override; @@ -58,22 +58,23 @@ public: std::vector<SymbolIndexerTask> &symbolIndexerTask); bool compilerMacrosOrIncludeSearchPathsAreDifferent( - const V2::ProjectPartContainer &projectPart, + const ProjectPartContainer &projectPart, const Utils::optional<ProjectPartArtefact> &optionalArtefact) const; FilePathIds filterChangedFiles( - const V2::ProjectPartContainer &projectPart) const; + const ProjectPartContainer &projectPart) const; - FilePathIds updatableFilePathIds(const V2::ProjectPartContainer &projectPart, + FilePathIds updatableFilePathIds(const ProjectPartContainer &projectPart, const Utils::optional<ProjectPartArtefact> &optionalArtefact) const; - Utils::SmallStringVector compilerArguments(Utils::SmallStringVector arguments, - const Utils::optional<ProjectPartPch> optionalProjectPartPch) const; + Utils::SmallStringVector compilerArguments( + Utils::SmallStringVector arguments, + const Utils::optional<ProjectPartPch> optionalProjectPartPch) const; private: SymbolIndexerTaskQueueInterface &m_symbolIndexerTaskQueue; SymbolStorageInterface &m_symbolStorage; - BuildDependenciesStorageInterface &m_usedMacroAndSourceStorage; + BuildDependenciesStorageInterface &m_buildDependencyStorage; ClangPathWatcherInterface &m_pathWatcher; FilePathCachingInterface &m_filePathCache; FileStatusCache &m_fileStatusCache; diff --git a/src/tools/clangrefactoringbackend/source/symbolindexing.cpp b/src/tools/clangrefactoringbackend/source/symbolindexing.cpp index 4f62b859f0..529396e9fa 100644 --- a/src/tools/clangrefactoringbackend/source/symbolindexing.cpp +++ b/src/tools/clangrefactoringbackend/source/symbolindexing.cpp @@ -27,7 +27,7 @@ namespace ClangBackEnd { -void SymbolIndexing::updateProjectParts(V2::ProjectPartContainers &&projectParts) +void SymbolIndexing::updateProjectParts(ProjectPartContainers &&projectParts) { m_indexer.updateProjectParts(std::move(projectParts)); } diff --git a/src/tools/clangrefactoringbackend/source/symbolindexing.h b/src/tools/clangrefactoringbackend/source/symbolindexing.h index 10e1be0358..6f52f863d8 100644 --- a/src/tools/clangrefactoringbackend/source/symbolindexing.h +++ b/src/tools/clangrefactoringbackend/source/symbolindexing.h @@ -81,12 +81,16 @@ public: FilePathCachingInterface &filePathCache, const GeneratedFiles &generatedFiles, ProgressCounter::SetProgressCallback &&setProgressCallback) - : m_filePathCache(filePathCache), - m_usedMacroAndSourceStorage(database), - m_symbolStorage(database), - m_collectorManger(generatedFiles, database), - m_progressCounter(std::move(setProgressCallback)), - m_indexerScheduler(m_collectorManger, m_indexerQueue, m_progressCounter, std::thread::hardware_concurrency()) + : m_filePathCache(filePathCache) + , m_buildDependencyStorage(database) + , m_symbolStorage(database) + , m_collectorManger(generatedFiles, database) + , m_progressCounter(std::move(setProgressCallback)) + , m_indexerScheduler(m_collectorManger, + m_indexerQueue, + m_progressCounter, + std::thread::hardware_concurrency(), + CallDoInMainThreadAfterFinished::Yes) { } @@ -109,12 +113,12 @@ public: } } - void updateProjectParts(V2::ProjectPartContainers &&projectParts) override; + void updateProjectParts(ProjectPartContainers &&projectParts) override; private: using SymbolIndexerTaskScheduler = TaskScheduler<SymbolsCollectorManager, SymbolIndexerTask::Callable>; FilePathCachingInterface &m_filePathCache; - BuildDependenciesStorage m_usedMacroAndSourceStorage; + BuildDependenciesStorage m_buildDependencyStorage; SymbolStorage m_symbolStorage; ClangPathWatcher<QFileSystemWatcher, QTimer> m_sourceWatcher{m_filePathCache}; FileStatusCache m_fileStatusCache{m_filePathCache}; @@ -124,7 +128,7 @@ private: SymbolIndexerTaskQueue m_indexerQueue{m_indexerScheduler, m_progressCounter}; SymbolIndexer m_indexer{m_indexerQueue, m_symbolStorage, - m_usedMacroAndSourceStorage, + m_buildDependencyStorage, m_sourceWatcher, m_filePathCache, m_fileStatusCache, diff --git a/src/tools/clangrefactoringbackend/source/symbolindexinginterface.h b/src/tools/clangrefactoringbackend/source/symbolindexinginterface.h index 70e16d7429..3feb9e1b9f 100644 --- a/src/tools/clangrefactoringbackend/source/symbolindexinginterface.h +++ b/src/tools/clangrefactoringbackend/source/symbolindexinginterface.h @@ -25,7 +25,7 @@ #pragma once -#include <projectpartcontainerv2.h> +#include <projectpartcontainer.h> #include <filecontainerv2.h> namespace ClangBackEnd { @@ -37,7 +37,7 @@ public: SymbolIndexingInterface(const SymbolIndexingInterface&) = delete; SymbolIndexingInterface &operator=(const SymbolIndexingInterface&) = delete; - virtual void updateProjectParts(V2::ProjectPartContainers &&projectParts) = 0; + virtual void updateProjectParts(ProjectPartContainers &&projectParts) = 0; protected: ~SymbolIndexingInterface() = default; diff --git a/src/tools/clangrefactoringbackend/source/symbolstorage.h b/src/tools/clangrefactoringbackend/source/symbolstorage.h index 02d52bfb50..0be04c04b6 100644 --- a/src/tools/clangrefactoringbackend/source/symbolstorage.h +++ b/src/tools/clangrefactoringbackend/source/symbolstorage.h @@ -31,6 +31,7 @@ #include <sqliteexception.h> #include <sqlitetransaction.h> #include <sqlitetable.h> +#include <includesearchpath.h> #include <QJsonArray> #include <QJsonDocument> @@ -68,45 +69,39 @@ public: } int insertOrUpdateProjectPart(Utils::SmallStringView projectPartName, - const Utils::SmallStringVector &commandLineArguments, - const CompilerMacros &compilerMacros, - const Utils::SmallStringVector &includeSearchPaths) override + const Utils::SmallStringVector &commandLineArguments, + const CompilerMacros &compilerMacros, + const IncludeSearchPaths &systemIncludeSearchPaths, + const IncludeSearchPaths &projectIncludeSearchPaths) override { - m_database.setLastInsertedRowId(-1); - Utils::SmallString compilerArguementsAsJson = toJson(commandLineArguments); Utils::SmallString compilerMacrosAsJson = toJson(compilerMacros); - Utils::SmallString includeSearchPathsAsJason = toJson(includeSearchPaths); - - WriteStatement &insertStatement = m_insertProjectPartStatement; - insertStatement.write(projectPartName, - compilerArguementsAsJson, - compilerMacrosAsJson, - includeSearchPathsAsJason); - - if (m_database.lastInsertedRowId() == -1) { - WriteStatement &updateStatement = m_updateProjectPartStatement; - updateStatement.write(compilerArguementsAsJson, - compilerMacrosAsJson, - includeSearchPathsAsJason, - projectPartName); - } + Utils::SmallString systemIncludeSearchPathsAsJason = toJson(systemIncludeSearchPaths); + Utils::SmallString projectIncludeSearchPathsAsJason = toJson(projectIncludeSearchPaths); + + m_insertOrUpdateProjectPartStatement.write(projectPartName, + compilerArguementsAsJson, + compilerMacrosAsJson, + systemIncludeSearchPathsAsJason, + projectIncludeSearchPathsAsJason); + + auto projectPartId = m_getProjectPartIdStatement.template value<int>(projectPartName); - return int(m_database.lastInsertedRowId()); + return projectPartId.value(); } Utils::optional<ProjectPartArtefact> fetchProjectPartArtefact(FilePathId sourceId) const override { ReadStatement &statement = m_getProjectPartArtefactsBySourceId; - return statement.template value<ProjectPartArtefact, 4>(sourceId.filePathId); + return statement.template value<ProjectPartArtefact, 5>(sourceId.filePathId); } Utils::optional<ProjectPartArtefact> fetchProjectPartArtefact(Utils::SmallStringView projectPartName) const override { ReadStatement &statement = m_getProjectPartArtefactsByProjectPartName; - return statement.template value<ProjectPartArtefact, 4>(projectPartName); + return statement.template value<ProjectPartArtefact, 5>(projectPartName); } void updateProjectPartSources(int projectPartId, @@ -137,12 +132,25 @@ public: static Utils::SmallString toJson(const CompilerMacros &compilerMacros) { QJsonDocument document; - QJsonObject object; + QJsonArray array; for (const CompilerMacro ¯o : compilerMacros) - object.insert(QString(macro.key), QString(macro.value)); + array.push_back(QJsonArray{{QString(macro.key), QString(macro.value), macro.index}}); - document.setObject(object); + document.setArray(array); + + return document.toJson(QJsonDocument::Compact); + } + + static Utils::SmallString toJson(const IncludeSearchPaths &includeSearchPaths) + { + QJsonDocument document; + QJsonArray array; + + for (const IncludeSearchPath &path : includeSearchPaths) + array.push_back(QJsonArray{{path.path.data(), path.index, int(path.type)}}); + + document.setArray(array); return document.toJson(QJsonDocument::Compact); } @@ -299,14 +307,12 @@ public: "DELETE FROM newLocations", m_database }; - WriteStatement m_insertProjectPartStatement{ - "INSERT OR IGNORE INTO projectParts(projectPartName, compilerArguments, compilerMacros, includeSearchPaths) VALUES (?,?,?,?)", - m_database - }; - WriteStatement m_updateProjectPartStatement{ - "UPDATE projectParts SET compilerArguments = ?, compilerMacros = ?, includeSearchPaths = ? WHERE projectPartName = ?", - m_database - }; + WriteStatement m_insertOrUpdateProjectPartStatement{ + "INSERT INTO projectParts(projectPartName, compilerArguments, compilerMacros, " + "systemIncludeSearchPaths, projectIncludeSearchPaths) VALUES (?001,?002,?003,?004,?005) ON " + "CONFLICT(projectPartName) DO UPDATE SET compilerArguments=?002, compilerMacros=?003, " + "systemIncludeSearchPaths=?004, projectIncludeSearchPaths=?005", + m_database}; mutable ReadStatement m_getProjectPartIdStatement{ "SELECT projectPartId FROM projectParts WHERE projectPartName = ?", m_database @@ -324,13 +330,14 @@ public: m_database }; mutable ReadStatement m_getProjectPartArtefactsBySourceId{ - "SELECT compilerArguments, compilerMacros, includeSearchPaths, projectPartId FROM projectParts WHERE projectPartId = (SELECT projectPartId FROM projectPartsSources WHERE sourceId = ?)", - m_database - }; + "SELECT compilerArguments, compilerMacros, systemIncludeSearchPaths, projectIncludeSearchPaths, " + "projectPartId FROM projectParts WHERE projectPartId = (SELECT projectPartId FROM " + "projectPartsSources WHERE sourceId = ?)", + m_database}; mutable ReadStatement m_getProjectPartArtefactsByProjectPartName{ - "SELECT compilerArguments, compilerMacros, includeSearchPaths, projectPartId FROM projectParts WHERE projectPartName = ?", - m_database - }; + "SELECT compilerArguments, compilerMacros, systemIncludeSearchPaths, " + "projectIncludeSearchPaths, projectPartId FROM projectParts WHERE projectPartName = ?", + m_database}; mutable ReadStatement m_getPrecompiledHeader{ "SELECT projectPchPath, projectPchBuildTime FROM precompiledHeaders WHERE projectPartId = ?", m_database diff --git a/src/tools/clangrefactoringbackend/source/symbolstorageinterface.h b/src/tools/clangrefactoringbackend/source/symbolstorageinterface.h index 0cb1dafd4f..3e51302c20 100644 --- a/src/tools/clangrefactoringbackend/source/symbolstorageinterface.h +++ b/src/tools/clangrefactoringbackend/source/symbolstorageinterface.h @@ -34,6 +34,8 @@ #include "symbolentry.h" #include "usedmacro.h" +#include <includesearchpath.h> + #include <sqlitetransaction.h> #include <compilermacro.h> @@ -48,15 +50,20 @@ public: SymbolStorageInterface &operator=(const SymbolStorageInterface &) = delete; virtual void addSymbolsAndSourceLocations(const SymbolEntries &symbolEntries, - const SourceLocationEntries &sourceLocations) = 0; - virtual int insertOrUpdateProjectPart(Utils::SmallStringView projectPartName, - const Utils::SmallStringVector &commandLineArguments, - const CompilerMacros &compilerMacros, - const Utils::SmallStringVector &includeSearchPaths) = 0; - virtual void updateProjectPartSources(int projectPartId, - const FilePathIds &sourceFilePathIds) = 0; - virtual Utils::optional<ProjectPartArtefact> fetchProjectPartArtefact(FilePathId sourceId) const = 0; - virtual Utils::optional<ProjectPartArtefact> fetchProjectPartArtefact(Utils::SmallStringView projectPartName) const = 0; + const SourceLocationEntries &sourceLocations) + = 0; + virtual int insertOrUpdateProjectPart( + Utils::SmallStringView projectPartName, + const Utils::SmallStringVector &commandLineArguments, + const CompilerMacros &compilerMacros, + const ClangBackEnd::IncludeSearchPaths &systemIncludeSearchPaths, + const ClangBackEnd::IncludeSearchPaths &projectIncludeSearchPaths) + = 0; + virtual void updateProjectPartSources(int projectPartId, const FilePathIds &sourceFilePathIds) = 0; + virtual Utils::optional<ProjectPartArtefact> fetchProjectPartArtefact( + FilePathId sourceId) const = 0; + virtual Utils::optional<ProjectPartArtefact> fetchProjectPartArtefact( + Utils::SmallStringView projectPartName) const = 0; virtual Utils::optional<ProjectPartPch> fetchPrecompiledHeader(int projectPartId) const = 0; protected: |