diff options
author | Eike Ziller <eike.ziller@qt.io> | 2019-03-14 15:14:40 +0100 |
---|---|---|
committer | Eike Ziller <eike.ziller@qt.io> | 2019-03-14 15:51:15 +0100 |
commit | c53ccceff1e1642b7704fa8b0681604c25a833a0 (patch) | |
tree | 7258d63fba4dabd6f9e2f2f36089ce45df7fe3af /src/tools | |
parent | 62cafc1782369cde0605fbd6b1182a83d5473a12 (diff) | |
parent | 429eb73ace5909e228a58bf8b067823e2be44212 (diff) |
Merge remote-tracking branch 'origin/4.9'
Conflicts:
qbs/modules/qtc/qtc.qbs
qtcreator.pri
src/plugins/debugger/debuggerkitinformation.cpp
src/plugins/languageclient/languageclientmanager.cpp
src/plugins/plugins.pro
src/plugins/projectexplorer/kit.cpp
src/plugins/projectexplorer/kitmanager.cpp
Change-Id: I66fb941202991f35f7d7761430b21e42dfc678a8
Diffstat (limited to 'src/tools')
30 files changed, 460 insertions, 356 deletions
diff --git a/src/tools/clangbackend/source/fulltokeninfo.cpp b/src/tools/clangbackend/source/fulltokeninfo.cpp index eb57abbbe6..fd59d25766 100644 --- a/src/tools/clangbackend/source/fulltokeninfo.cpp +++ b/src/tools/clangbackend/source/fulltokeninfo.cpp @@ -181,6 +181,7 @@ void FullTokenInfo::variableKind(const Cursor &cursor) { TokenInfo::variableKind(cursor); + m_extraInfo.accessSpecifier = cursor.accessSpecifier(); m_extraInfo.storageClass = cursor.storageClass(); } diff --git a/src/tools/clangpchmanagerbackend/clangpchmanagerbackendmain.cpp b/src/tools/clangpchmanagerbackend/clangpchmanagerbackendmain.cpp index 89567b8d38..3237aab2fb 100644 --- a/src/tools/clangpchmanagerbackend/clangpchmanagerbackendmain.cpp +++ b/src/tools/clangpchmanagerbackend/clangpchmanagerbackendmain.cpp @@ -41,7 +41,7 @@ #include <precompiledheaderstorage.h> #include <processormanager.h> #include <progresscounter.h> -#include <projectparts.h> +#include <projectpartsmanager.h> #include <filepathcaching.h> #include <refactoringdatabaseinitializer.h> #include <sqlitedatabase.h> @@ -68,7 +68,7 @@ using ClangBackEnd::PchCreator; using ClangBackEnd::PchManagerClientProxy; using ClangBackEnd::PchManagerServer; using ClangBackEnd::PrecompiledHeaderStorage; -using ClangBackEnd::ProjectParts; +using ClangBackEnd::ProjectPartsManager; using ClangBackEnd::FilePathCache; using ClangBackEnd::FilePathView; using ClangBackEnd::TimeStamp; @@ -138,12 +138,14 @@ public: ClangBackEnd::Environment &environment, Sqlite::Database &database, PchManagerServer &pchManagerServer, - ClangBackEnd::ClangPathWatcherInterface &pathWatcher) - : ProcessorManager(generatedFiles), - m_environment(environment), - m_database(database), - m_pchManagerServer(pchManagerServer), - m_pathWatcher(pathWatcher) + ClangBackEnd::ClangPathWatcherInterface &pathWatcher, + ClangBackEnd::BuildDependenciesStorageInterface &buildDependenciesStorage) + : ProcessorManager(generatedFiles) + , m_environment(environment) + , m_database(database) + , m_pchManagerServer(pchManagerServer) + , m_pathWatcher(pathWatcher) + , m_buildDependenciesStorage(buildDependenciesStorage) {} protected: @@ -152,7 +154,8 @@ protected: return std::make_unique<PchCreator>(m_environment, m_database, *m_pchManagerServer.client(), - m_pathWatcher); + m_pathWatcher, + m_buildDependenciesStorage); } private: @@ -160,6 +163,7 @@ private: Sqlite::Database &m_database; ClangBackEnd::PchManagerServer &m_pchManagerServer; ClangBackEnd::ClangPathWatcherInterface &m_pathWatcher; + ClangBackEnd::BuildDependenciesStorageInterface &m_buildDependenciesStorage; }; struct Data // because we have a cycle dependency @@ -175,13 +179,14 @@ struct Data // because we have a cycle dependency ClangBackEnd::FilePathCaching filePathCache{database}; ClangPathWatcher<QFileSystemWatcher, QTimer> includeWatcher{filePathCache}; ApplicationEnvironment environment; - ProjectParts projectParts; + ProjectPartsManager projectParts; GeneratedFiles generatedFiles; PchCreatorManager pchCreatorManager{generatedFiles, environment, database, clangPchManagerServer, - includeWatcher}; + includeWatcher, + buildDependencyStorage}; PrecompiledHeaderStorage<> preCompiledHeaderStorage{database}; ClangBackEnd::ProgressCounter pchCreationProgressCounter{[&](int progress, int total) { executeInLoop([&] { diff --git a/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.cpp b/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.cpp index d58da0f27c..a2a7a813ac 100644 --- a/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.cpp +++ b/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.cpp @@ -55,19 +55,19 @@ OutputContainer setUnion(InputContainer1 &&input1, BuildDependency BuildDependenciesProvider::create(const ProjectPartContainer &projectPart) { - SourceEntries includes = createSourceEntriesFromStorage(projectPart.sourcePathIds, - projectPart.projectPartId); + auto sourcesAndProjectPart = createSourceEntriesFromStorage( + projectPart.sourcePathIds, projectPart.projectPartId); - if (!m_modifiedTimeChecker.isUpToDate(includes)) { + if (!m_modifiedTimeChecker.isUpToDate(sourcesAndProjectPart.first)) { BuildDependency buildDependency = m_generator.create(projectPart); - storeBuildDependency(buildDependency); + storeBuildDependency(buildDependency, sourcesAndProjectPart.second); return buildDependency; } - return createBuildDependencyFromStorage(std::move(includes)); - + return createBuildDependencyFromStorage( + std::move(sourcesAndProjectPart.first)); } BuildDependency BuildDependenciesProvider::createBuildDependencyFromStorage( @@ -76,7 +76,7 @@ BuildDependency BuildDependenciesProvider::createBuildDependencyFromStorage( BuildDependency buildDependency; buildDependency.usedMacros = createUsedMacrosFromStorage(includes); - buildDependency.includes = std::move(includes); + buildDependency.sources = std::move(includes); return buildDependency; } @@ -101,16 +101,19 @@ UsedMacros BuildDependenciesProvider::createUsedMacrosFromStorage(const SourceEn return usedMacros; } -SourceEntries BuildDependenciesProvider::createSourceEntriesFromStorage( - const FilePathIds &sourcePathIds, Utils::SmallStringView projectPartId) const -{ +std::pair<SourceEntries, int> +BuildDependenciesProvider::createSourceEntriesFromStorage( + const FilePathIds &sourcePathIds, + Utils::SmallStringView projectPartName) const { SourceEntries includes; Sqlite::DeferredTransaction transaction(m_transactionBackend); + int projectPartId = m_storage.fetchProjectPartId(projectPartName); + for (FilePathId sourcePathId : sourcePathIds) { - SourceEntries entries = m_storage.fetchDependSources(sourcePathId, - projectPartId); + SourceEntries entries = + m_storage.fetchDependSources(sourcePathId, projectPartId); SourceEntries mergedEntries = setUnion<SourceEntries>(includes, entries); includes = std::move(mergedEntries); @@ -118,15 +121,14 @@ SourceEntries BuildDependenciesProvider::createSourceEntriesFromStorage( transaction.commit(); - return includes; + return {includes, projectPartId}; } -void BuildDependenciesProvider::storeBuildDependency(const BuildDependency &buildDependency) -{ +void BuildDependenciesProvider::storeBuildDependency( + const BuildDependency &buildDependency, int projectPartId) { Sqlite::ImmediateTransaction transaction(m_transactionBackend); - - m_storage.updateSources(buildDependency.includes); - m_storage.insertFileStatuses(buildDependency.fileStatuses); + m_storage.insertOrUpdateSources(buildDependency.sources, projectPartId); + m_storage.insertOrUpdateFileStatuses(buildDependency.fileStatuses); m_storage.insertOrUpdateSourceDependencies(buildDependency.sourceDependencies); m_storage.insertOrUpdateUsedMacros(buildDependency.usedMacros); diff --git a/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.h b/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.h index 4a89ace732..2eb5210518 100644 --- a/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.h +++ b/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.h @@ -55,9 +55,9 @@ public: private: BuildDependency createBuildDependencyFromStorage(SourceEntries &&includes) const; UsedMacros createUsedMacrosFromStorage(const SourceEntries &includes) const; - SourceEntries createSourceEntriesFromStorage(const FilePathIds &sourcePathIds, - Utils::SmallStringView projectPartId) const; - void storeBuildDependency(const BuildDependency &buildDependency); + std::pair<SourceEntries, int> createSourceEntriesFromStorage( + const FilePathIds &sourcePathIds, Utils::SmallStringView projectPartName) const; + void storeBuildDependency(const BuildDependency &buildDependency, int projectPartId); private: BuildDependenciesStorageInterface &m_storage; diff --git a/src/tools/clangpchmanagerbackend/source/builddependenciesstorage.h b/src/tools/clangpchmanagerbackend/source/builddependenciesstorage.h index 324552bf99..3e6d00da3f 100644 --- a/src/tools/clangpchmanagerbackend/source/builddependenciesstorage.h +++ b/src/tools/clangpchmanagerbackend/source/builddependenciesstorage.h @@ -53,25 +53,28 @@ public: transaction.commit(); } - void updateSources(const SourceEntries &sourceEntries) override + void insertOrUpdateSources(const SourceEntries &sourceEntries, int projectPartId) override { + deleteAllProjectPartsSourcesWithProjectPartNameStatement.write( + projectPartId); + for (const SourceEntry &entry : sourceEntries) { - updateBuildDependencyTimeStampStatement.write(static_cast<long long>(entry.lastModified), - entry.sourceId.filePathId); - updateSourceTypeStatement.write(static_cast<uchar>(entry.sourceType), - entry.sourceId.filePathId); + insertOrUpdateProjectPartsSourcesStatement.write( + entry.sourceId.filePathId, + projectPartId, + static_cast<uchar>(entry.sourceType), + static_cast<uchar>(entry.hasMissingIncludes)); } } - void insertFileStatuses(const FileStatuses &fileStatuses) override + void insertOrUpdateFileStatuses(const FileStatuses &fileStatuses) override { - WriteStatement &statement = insertFileStatusesStatement; + WriteStatement &statement = insertOrUpdateFileStatusesStatement; for (const FileStatus &fileStatus : fileStatuses) statement.write(fileStatus.filePathId.filePathId, fileStatus.size, - fileStatus.lastModified, - fileStatus.isInPrecompiledHeader); + fileStatus.lastModified); } long long fetchLowestLastModifiedTime(FilePathId sourceId) const override @@ -85,7 +88,8 @@ public: { WriteStatement &insertStatement = insertIntoNewUsedMacrosStatement; for (const UsedMacro &usedMacro : usedMacros) - insertStatement.write(usedMacro.filePathId.filePathId, usedMacro.macroName); + insertStatement.write(usedMacro.filePathId.filePathId, + usedMacro.macroName); syncNewUsedMacrosStatement.execute(); deleteOutdatedUsedMacrosStatement.execute(); @@ -104,18 +108,22 @@ public: deleteNewSourceDependenciesStatement.execute(); } - SourceEntries fetchDependSources(FilePathId sourceId, - Utils::SmallStringView projectPartName) const override + int fetchProjectPartId(Utils::SmallStringView projectPartName) override { auto projectPartId = fetchProjectPartIdStatement.template value<int>(projectPartName); - if (projectPartId) { - return fetchSourceDependenciesStatement.template values<SourceEntry, 3>( - 300, - sourceId.filePathId, - projectPartId.value()); - } - return {}; + if (projectPartId) + return projectPartId.value(); + + insertProjectPartNameStatement.write(projectPartName); + + return static_cast<int>(database.lastInsertedRowId()); + } + + SourceEntries fetchDependSources(FilePathId sourceId, int projectPartId) const override + { + return fetchSourceDependenciesStatement.template values<SourceEntry, 4>( + 300, sourceId.filePathId, projectPartId); } UsedMacros fetchUsedMacros(FilePathId sourceId) const override @@ -123,6 +131,17 @@ public: return fetchUsedMacrosStatement.template values<UsedMacro, 2>(128, sourceId.filePathId); } + void updatePchCreationTimeStamp( + long long pchCreationTimeStamp, + Utils::SmallStringView projectPartName) override { + Sqlite::ImmediateTransaction transaction{database}; + + updatePchCreationTimeStampStatement.write(pchCreationTimeStamp, + projectPartName); + + transaction.commit(); + } + static Utils::SmallString toJson(const Utils::SmallStringVector &strings) { QJsonDocument document; @@ -207,10 +226,11 @@ public: "INSERT INTO newSourceDependencies(sourceId, dependencySourceId) VALUES (?,?)", database }; - WriteStatement insertFileStatusesStatement{ - "INSERT OR REPLACE INTO fileStatuses(sourceId, size, lastModified, isInPrecompiledHeader) VALUES (?,?,?,?)", - database - }; + WriteStatement insertOrUpdateFileStatusesStatement{ + "INSERT INTO fileStatuses(sourceId, size, lastModified) VALUES " + "(?001,?002,?003) ON " + "CONFLICT(sourceId) DO UPDATE SET size = ?002, lastModified = ?003", + database}; WriteStatement syncNewSourceDependenciesStatement{ "INSERT INTO sourceDependencies(sourceId, dependencySourceId) SELECT sourceId, dependencySourceId FROM newSourceDependencies WHERE NOT EXISTS (SELECT sourceId FROM sourceDependencies WHERE sourceDependencies.sourceId == newSourceDependencies.sourceId AND sourceDependencies.dependencySourceId == newSourceDependencies.dependencySourceId)", database @@ -223,25 +243,37 @@ public: "DELETE FROM newSourceDependencies", database }; - WriteStatement updateBuildDependencyTimeStampStatement{ - "UPDATE fileStatuses SET buildDependencyTimeStamp = ? WHERE sourceId == ?", - database - }; - WriteStatement updateSourceTypeStatement{ - "UPDATE projectPartsSources SET sourceType = ? WHERE sourceId == ?", - database - }; + WriteStatement insertOrUpdateProjectPartsSourcesStatement{ + "INSERT INTO projectPartsSources(sourceId, projectPartId, " + "sourceType, hasMissingIncludes) VALUES (?001, ?002, ?003, ?004) ON " + "CONFLICT(sourceId, projectPartId) DO UPDATE SET sourceType = ?003, " + "hasMissingIncludes = ?004", + database}; mutable ReadStatement fetchSourceDependenciesStatement{ - "WITH RECURSIVE collectedDependencies(sourceId) AS (VALUES(?) UNION SELECT dependencySourceId FROM sourceDependencies, collectedDependencies WHERE sourceDependencies.sourceId == collectedDependencies.sourceId) SELECT sourceId, buildDependencyTimeStamp, sourceType FROM collectedDependencies NATURAL JOIN projectPartsSources NATURAL JOIN fileStatuses WHERE projectPartId = ? ORDER BY sourceId", - database - }; + "WITH RECURSIVE collectedDependencies(sourceId) AS (VALUES(?) UNION " + "SELECT dependencySourceId FROM sourceDependencies, " + "collectedDependencies WHERE sourceDependencies.sourceId == " + "collectedDependencies.sourceId) SELECT sourceId, " + "pchCreationTimeStamp, sourceType, hasMissingIncludes FROM " + "collectedDependencies NATURAL JOIN projectPartsSources WHERE " + "projectPartId = ? ORDER BY sourceId", + database}; mutable ReadStatement fetchProjectPartIdStatement{ "SELECT projectPartId FROM projectParts WHERE projectPartName = ?", database }; + WriteStatement insertProjectPartNameStatement{ + "INSERT INTO projectParts(projectPartName) VALUES (?)", database}; mutable ReadStatement fetchUsedMacrosStatement{ "SELECT macroName, sourceId FROM usedMacros WHERE sourceId = ? ORDER BY sourceId, macroName", database }; + WriteStatement updatePchCreationTimeStampStatement{ + "UPDATE projectPartsSources SET pchCreationTimeStamp = ?001 WHERE " + "projectPartId = (SELECT " + "projectPartId FROM projectParts WHERE projectPartName = ?002)", + database}; + WriteStatement deleteAllProjectPartsSourcesWithProjectPartNameStatement{ + "DELETE FROM projectPartsSources WHERE projectPartId = ?", database}; }; } diff --git a/src/tools/clangpchmanagerbackend/source/builddependenciesstorageinterface.h b/src/tools/clangpchmanagerbackend/source/builddependenciesstorageinterface.h index 445afa052f..4edc47fce1 100644 --- a/src/tools/clangpchmanagerbackend/source/builddependenciesstorageinterface.h +++ b/src/tools/clangpchmanagerbackend/source/builddependenciesstorageinterface.h @@ -33,6 +33,8 @@ #include <sourcedependency.h> #include <usedmacro.h> +#include <utils/optional.h> + namespace ClangBackEnd { class BuildDependenciesStorageInterface @@ -42,13 +44,20 @@ public: BuildDependenciesStorageInterface(const BuildDependenciesStorageInterface &) = delete; BuildDependenciesStorageInterface &operator=(const BuildDependenciesStorageInterface &) = delete; - virtual void updateSources(const SourceEntries &sourceIds) = 0; + virtual void insertOrUpdateSources(const SourceEntries &sourceIds, + int projectPartId) = 0; virtual void insertOrUpdateUsedMacros(const UsedMacros &usedMacros) = 0; - virtual void insertFileStatuses(const FileStatuses &fileStatuses) = 0; + virtual void + insertOrUpdateFileStatuses(const FileStatuses &fileStatuses) = 0; virtual void insertOrUpdateSourceDependencies(const SourceDependencies &sourceDependencies) = 0; virtual long long fetchLowestLastModifiedTime(FilePathId sourceId) const = 0; - virtual SourceEntries fetchDependSources(FilePathId sourceId, Utils::SmallStringView projectPartId) const = 0; + virtual SourceEntries fetchDependSources(FilePathId sourceId, + int projectPartId) const = 0; virtual UsedMacros fetchUsedMacros(FilePathId sourceId) const = 0; + virtual int fetchProjectPartId(Utils::SmallStringView projectPartName) = 0; + virtual void updatePchCreationTimeStamp(long long pchCreationTimeStamp, + Utils::SmallStringView projectPartName) + = 0; protected: ~BuildDependenciesStorageInterface() = default; diff --git a/src/tools/clangpchmanagerbackend/source/builddependency.h b/src/tools/clangpchmanagerbackend/source/builddependency.h index 1b649e3118..6725254e30 100644 --- a/src/tools/clangpchmanagerbackend/source/builddependency.h +++ b/src/tools/clangpchmanagerbackend/source/builddependency.h @@ -37,7 +37,7 @@ class BuildDependency public: void clear() { - includes.clear(); + sources.clear(); usedMacros.clear(); sourceFiles.clear(); fileStatuses.clear(); @@ -46,14 +46,15 @@ public: friend bool operator==(const BuildDependency &first, const BuildDependency &second) { - return first.includes == second.includes && first.usedMacros == second.usedMacros - && first.sourceFiles == second.sourceFiles - && first.sourceDependencies == second.sourceDependencies - && first.fileStatuses == second.fileStatuses; + return first.sources == second.sources && + first.usedMacros == second.usedMacros && + first.sourceFiles == second.sourceFiles && + first.sourceDependencies == second.sourceDependencies && + first.fileStatuses == second.fileStatuses; } public: - SourceEntries includes; + SourceEntries sources; UsedMacros usedMacros; FilePathIds sourceFiles; SourceDependencies sourceDependencies; diff --git a/src/tools/clangpchmanagerbackend/source/builddependencycollector.cpp b/src/tools/clangpchmanagerbackend/source/builddependencycollector.cpp index b3ebbc75ad..1d08442c51 100644 --- a/src/tools/clangpchmanagerbackend/source/builddependencycollector.cpp +++ b/src/tools/clangpchmanagerbackend/source/builddependencycollector.cpp @@ -45,8 +45,27 @@ FilePathIds operator+(const FilePathIds &first, const FilePathIds &second) return result; } + +FilePaths operator+(FilePaths &&first, FilePaths &&second) { + FilePaths result = std::move(first); + + std::copy(second.begin(), second.end(), std::back_inserter(result)); + + return result; } +FilePaths generatedFilePaths(const V2::FileContainers &containers) { + FilePaths paths; + paths.reserve(containers.size()); + std::transform(containers.begin(), + containers.end(), + std::back_inserter(paths), + [](const auto &container) { return container.filePath; }); + return paths; +} + +} // namespace + BuildDependency BuildDependencyCollector::create(const ProjectPartContainer &projectPart) { CommandLineBuilder<ProjectPartContainer, Utils::SmallStringVector> @@ -54,8 +73,9 @@ BuildDependency BuildDependencyCollector::create(const ProjectPartContainer &pro addFiles(projectPart.sourcePathIds, std::move(builder.commandLine)); - setExcludedFilePaths( - m_filePathCache.filePaths(projectPart.headerPathIds + projectPart.sourcePathIds)); + setExcludedFilePaths(m_filePathCache.filePaths(projectPart.headerPathIds + + projectPart.sourcePathIds) + + generatedFilePaths(m_generatedFiles.fileContainers())); addUnsavedFiles(m_generatedFiles.fileContainers()); diff --git a/src/tools/clangpchmanagerbackend/source/builddependencycollector.h b/src/tools/clangpchmanagerbackend/source/builddependencycollector.h index c5e41e9190..f8aaa8f07c 100644 --- a/src/tools/clangpchmanagerbackend/source/builddependencycollector.h +++ b/src/tools/clangpchmanagerbackend/source/builddependencycollector.h @@ -83,11 +83,11 @@ public: return m_buildDependency.sourceDependencies; } - const SourceEntries &includeIds() - { - std::sort(m_buildDependency.includes.begin(), m_buildDependency.includes.end()); + const SourceEntries &sourceEntries() { + std::sort(m_buildDependency.sources.begin(), + m_buildDependency.sources.end()); - return std::move(m_buildDependency.includes); + return std::move(m_buildDependency.sources); } private: diff --git a/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri b/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri index 94d9540bea..61bcedc262 100644 --- a/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri +++ b/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri @@ -3,20 +3,19 @@ INCLUDEPATH += $$PWD SOURCES += \ $$PWD/builddependenciesprovider.cpp \ $$PWD/pchmanagerserver.cpp \ - $$PWD/projectparts.cpp \ $$PWD/pchtaskgenerator.cpp \ $$PWD/pchtasksmerger.cpp \ - $$PWD/pchtaskqueue.cpp + $$PWD/pchtaskqueue.cpp \ + $$PWD/projectpartsmanager.cpp HEADERS += \ - $$PWD/pchcreatorincludes.h \ $$PWD/pchmanagerserver.h \ $$PWD/clangpchmanagerbackend_global.h \ $$PWD/pchnotcreatederror.h \ $$PWD/environment.h \ - $$PWD/projectparts.h \ $$PWD/pchcreatorinterface.h \ - $$PWD/projectpartsinterface.h \ + $$PWD/projectpartsmanager.h \ + $$PWD/projectpartsmanagerinterface.h \ $$PWD/queueinterface.h \ $$PWD/processormanagerinterface.h \ $$PWD/processorinterface.h \ diff --git a/src/tools/clangpchmanagerbackend/source/collectbuilddependencypreprocessorcallbacks.h b/src/tools/clangpchmanagerbackend/source/collectbuilddependencypreprocessorcallbacks.h index 980d065fdb..f3b365d8d5 100644 --- a/src/tools/clangpchmanagerbackend/source/collectbuilddependencypreprocessorcallbacks.h +++ b/src/tools/clangpchmanagerbackend/source/collectbuilddependencypreprocessorcallbacks.h @@ -109,36 +109,46 @@ public: clang::SrcMgr::CharacteristicKind fileType) override { clang::FileID currentFileId = m_sourceManager->getFileID(hashLocation); - if (file && currentFileId != m_mainFileId) { - addSourceDependency(file, hashLocation); - auto fileUID = file->getUID(); - auto sourceFileUID = m_sourceManager - ->getFileEntryForID(m_sourceManager->getFileID(hashLocation)) - ->getUID(); - auto notAlreadyIncluded = isNotAlreadyIncluded(fileUID); - if (notAlreadyIncluded.first) { - m_alreadyIncludedFileUIDs.insert(notAlreadyIncluded.second, fileUID); - FilePath filePath = filePathFromFile(file); - if (!filePath.empty()) { - FilePathId includeId = m_filePathCache.filePathId(filePath); - - time_t lastModified = file->getModificationTime(); - - SourceType sourceType = SourceType::UserInclude; - if (isSystem(fileType)) { - if (isInSystemHeader(hashLocation)) - sourceType = SourceType::SystemInclude; - else - sourceType = SourceType::TopSystemInclude; - } else if (isNotInExcludedIncludeUID(fileUID)) { - if (isInExcludedIncludeUID(sourceFileUID)) - sourceType = SourceType::TopProjectInclude; - else - sourceType = SourceType::ProjectInclude; + if (file) { + if (currentFileId != m_mainFileId) { + addSourceDependency(file, hashLocation); + auto fileUID = file->getUID(); + auto sourceFileUID = + m_sourceManager + ->getFileEntryForID( + m_sourceManager->getFileID(hashLocation)) + ->getUID(); + auto notAlreadyIncluded = isNotAlreadyIncluded(fileUID); + if (notAlreadyIncluded.first) { + m_alreadyIncludedFileUIDs.insert(notAlreadyIncluded.second, + fileUID); + FilePath filePath = filePathFromFile(file); + if (!filePath.empty()) { + FilePathId includeId = + m_filePathCache.filePathId(filePath); + + time_t lastModified = file->getModificationTime(); + + SourceType sourceType = SourceType::UserInclude; + if (isSystem(fileType)) { + if (isInSystemHeader(hashLocation)) + sourceType = SourceType::SystemInclude; + else + sourceType = SourceType::TopSystemInclude; + } else if (isNotInExcludedIncludeUID(fileUID)) { + if (isInExcludedIncludeUID(sourceFileUID)) + sourceType = SourceType::TopProjectInclude; + else + sourceType = SourceType::ProjectInclude; + } + + addSource({includeId, sourceType, lastModified}); } - - addInclude({includeId, sourceType, lastModified}); } + } else { + addSource({m_filePathCache.filePathId(filePathFromFile(file)), + SourceType::Source, + file->getModificationTime()}); } } else { auto sourceFileId = filePathId(hashLocation); @@ -194,10 +204,10 @@ public: void appendContainsMissingIncludes(const FilePathIds &dependentSourceFilesWithMissingIncludes) { - auto split = m_containsMissingIncludes - .insert(m_containsMissingIncludes.end(), - dependentSourceFilesWithMissingIncludes.begin(), - dependentSourceFilesWithMissingIncludes.end()); + auto split = m_containsMissingIncludes.insert( + m_containsMissingIncludes.end(), + dependentSourceFilesWithMissingIncludes.begin(), + dependentSourceFilesWithMissingIncludes.end()); std::inplace_merge(m_containsMissingIncludes.begin(), split, m_containsMissingIncludes.end()); @@ -207,11 +217,13 @@ public: { FilePathIds filteredDependentSourceFilesWithMissingIncludes; filteredDependentSourceFilesWithMissingIncludes.reserve(dependentSourceFilesWithMissingIncludes.size()); - std::set_difference(dependentSourceFilesWithMissingIncludes.begin(), - dependentSourceFilesWithMissingIncludes.end(), - m_containsMissingIncludes.begin(), - m_containsMissingIncludes.end(), - std::back_inserter(filteredDependentSourceFilesWithMissingIncludes)); + std::set_difference( + dependentSourceFilesWithMissingIncludes.begin(), + dependentSourceFilesWithMissingIncludes.end(), + m_containsMissingIncludes.begin(), + m_containsMissingIncludes.end(), + std::back_inserter( + filteredDependentSourceFilesWithMissingIncludes)); dependentSourceFilesWithMissingIncludes = filteredDependentSourceFilesWithMissingIncludes; } @@ -255,8 +267,7 @@ public: sourceDependencies); } - void removeSourceWithMissingIncludesFromIncludes() - { + void removeSourceWithMissingIncludesFromSources() { class Compare { public: @@ -270,17 +281,16 @@ public: } }; - auto &includes = m_buildDependency.includes; - SourceEntries newIncludes; - newIncludes.reserve(includes.size()); - std::set_difference(includes.begin(), - includes.end(), - m_containsMissingIncludes.begin(), - m_containsMissingIncludes.end(), - std::back_inserter(newIncludes), - Compare{}); - - m_buildDependency.includes = newIncludes; + SourceEntryReferences sourcesWithMissingIncludes; + sourcesWithMissingIncludes.reserve(m_containsMissingIncludes.size()); + std::set_intersection(m_buildDependency.sources.begin(), + m_buildDependency.sources.end(), + m_containsMissingIncludes.begin(), + m_containsMissingIncludes.end(), + std::back_inserter(sourcesWithMissingIncludes), + Compare{}); + for (SourceEntryReference entry : sourcesWithMissingIncludes) + entry.get().hasMissingIncludes = HasMissingIncludes::Yes; } SourceDependencies sourceDependenciesSortedByDependendFilePathId() const @@ -296,12 +306,12 @@ public: void filterOutIncludesWithMissingIncludes() { - sortAndMakeUnique(m_containsMissingIncludes);; + sortAndMakeUnique(m_containsMissingIncludes); collectSourceWithMissingIncludes(m_containsMissingIncludes, sourceDependenciesSortedByDependendFilePathId()); - removeSourceWithMissingIncludesFromIncludes(); + removeSourceWithMissingIncludesFromSources(); } void ensureDirectory(const QString &directory, const QString &fileName) @@ -339,16 +349,16 @@ public: return FilePath::fromNativeFilePath(absolutePath(file->getName())); } - void addInclude(SourceEntry sourceEntry) - { - auto &includes = m_buildDependency.includes; - auto found = std::lower_bound(includes.begin(), - includes.end(), - sourceEntry, - [](auto first, auto second) { return first < second; }); - - if (found == includes.end() || *found != sourceEntry) - includes.emplace(found, sourceEntry); + void addSource(SourceEntry sourceEntry) { + auto &sources = m_buildDependency.sources; + auto found = std::lower_bound( + sources.begin(), + sources.end(), + sourceEntry, + [](auto first, auto second) { return first < second; }); + + if (found == sources.end() || *found != sourceEntry) + sources.emplace(found, sourceEntry); } private: diff --git a/src/tools/clangpchmanagerbackend/source/collectusedmacrosandsourcespreprocessorcallbacks.h b/src/tools/clangpchmanagerbackend/source/collectusedmacrosandsourcespreprocessorcallbacks.h index 90108bd76b..b8ea406df0 100644 --- a/src/tools/clangpchmanagerbackend/source/collectusedmacrosandsourcespreprocessorcallbacks.h +++ b/src/tools/clangpchmanagerbackend/source/collectusedmacrosandsourcespreprocessorcallbacks.h @@ -92,8 +92,7 @@ public: m_fileStatuses.emplace(found, id, fileEntry->getSize(), - fileEntry->getModificationTime(), - fileEntry->isInPCH()); + fileEntry->getModificationTime()); } } diff --git a/src/tools/clangpchmanagerbackend/source/modifiedtimechecker.h b/src/tools/clangpchmanagerbackend/source/modifiedtimechecker.h index 88d5f140d5..d641de054c 100644 --- a/src/tools/clangpchmanagerbackend/source/modifiedtimechecker.h +++ b/src/tools/clangpchmanagerbackend/source/modifiedtimechecker.h @@ -75,21 +75,68 @@ public: private: bool compareEntries(const SourceEntries &sourceEntries) const { + class CompareSourceId + { + public: + bool operator()(SourceTimeStamp first, SourceTimeStamp second) { + return first.sourceId < second.sourceId; + } + + bool operator()(SourceEntry first, SourceEntry second) + { + return first.sourceId < second.sourceId; + } + + bool operator()(SourceTimeStamp first, SourceEntry second) + { + return first.sourceId < second.sourceId; + } + + bool operator()(SourceEntry first, SourceTimeStamp second) + { + return first.sourceId < second.sourceId; + } + }; + SourceTimeStamps currentSourceTimeStamp; currentSourceTimeStamp.reserve(sourceEntries.size()); std::set_intersection(m_currentSourceTimeStamps.begin(), m_currentSourceTimeStamps.end(), sourceEntries.begin(), sourceEntries.end(), - std::back_inserter(currentSourceTimeStamp)); - - return std::equal(currentSourceTimeStamp.begin(), - currentSourceTimeStamp.end(), - sourceEntries.begin(), - sourceEntries.end(), - [](SourceTimeStamp first, SourceTimeStamp second) { - return first.lastModified <= second.lastModified; - }); + std::back_inserter(currentSourceTimeStamp), + CompareSourceId{}); + + class CompareTime + { + public: + bool operator()(SourceTimeStamp first, SourceTimeStamp second) + { + return first.lastModified <= second.lastModified; + } + + bool operator()(SourceEntry first, SourceEntry second) + { + return first.pchCreationTimeStamp <= + second.pchCreationTimeStamp; + } + + bool operator()(SourceTimeStamp first, SourceEntry second) + { + return first.lastModified <= second.pchCreationTimeStamp; + } + + bool operator()(SourceEntry first, SourceTimeStamp second) + { + return first.pchCreationTimeStamp <= second.lastModified; + } + }; + + return std::lexicographical_compare(currentSourceTimeStamp.begin(), + currentSourceTimeStamp.end(), + sourceEntries.begin(), + sourceEntries.end(), + CompareTime{}); } void updateCurrentSourceTimeStamps(const SourceEntries &sourceEntries) const @@ -102,8 +149,8 @@ private: } auto split = sourceTimeStamps.insert(sourceTimeStamps.end(), - m_currentSourceTimeStamps.begin(), - m_currentSourceTimeStamps.end()); + m_currentSourceTimeStamps.begin(), + m_currentSourceTimeStamps.end()); std::inplace_merge(sourceTimeStamps.begin(), split, sourceTimeStamps.end()); m_currentSourceTimeStamps = sourceTimeStamps; @@ -111,14 +158,49 @@ private: SourceTimeStamps newSourceTimeStamps(const SourceEntries &sourceEntries) const { - SourceTimeStamps newTimeStamps; - newTimeStamps.reserve(sourceEntries.size() + m_currentSourceTimeStamps.size()); + SourceEntries newSourceEntries; + newSourceEntries.reserve(sourceEntries.size()); + + class CompareSourceId + { + public: + bool operator()(SourceTimeStamp first, SourceTimeStamp second) + { + return first.sourceId < second.sourceId; + } + + bool operator()(SourceEntry first, SourceEntry second) + { + return first.sourceId < second.sourceId; + } + + bool operator()(SourceTimeStamp first, SourceEntry second) + { + return first.sourceId < second.sourceId; + } + + bool operator()(SourceEntry first, SourceTimeStamp second) + { + return first.sourceId < second.sourceId; + } + }; std::set_difference(sourceEntries.begin(), sourceEntries.end(), m_currentSourceTimeStamps.begin(), m_currentSourceTimeStamps.end(), - std::back_inserter(newTimeStamps)); + std::back_inserter(newSourceEntries), + CompareSourceId{}); + + SourceTimeStamps newTimeStamps; + newTimeStamps.reserve(newSourceEntries.size()); + + std::transform(newSourceEntries.begin(), + newSourceEntries.end(), + std::back_inserter(newTimeStamps), + [](SourceEntry entry) { + return SourceTimeStamp{entry.sourceId, {}}; + }); return newTimeStamps; } diff --git a/src/tools/clangpchmanagerbackend/source/pchcreator.cpp b/src/tools/clangpchmanagerbackend/source/pchcreator.cpp index b8227ce964..3f858b50ee 100644 --- a/src/tools/clangpchmanagerbackend/source/pchcreator.cpp +++ b/src/tools/clangpchmanagerbackend/source/pchcreator.cpp @@ -31,6 +31,7 @@ #include "generatepchactionfactory.h" #include "pchnotcreatederror.h" +#include <builddependenciesstorageinterface.h> #include <clangpathwatcherinterface.h> #include <filepathcachinginterface.h> #include <generatedfiles.h> @@ -110,7 +111,7 @@ Utils::SmallStringVector PchCreator::generateClangCompilerArguments(const PchTas void PchCreator::generatePch(PchTask &&pchTask) { - long long lastModified = QDateTime::currentSecsSinceEpoch(); + m_projectPartPch.lastModified = QDateTime::currentSecsSinceEpoch(); auto content = generatePchIncludeFileContent(pchTask.includes); auto pchOutputPath = generatePchFilePath(); @@ -123,9 +124,8 @@ void PchCreator::generatePch(PchTask &&pchTask) m_projectPartPch.projectPartId = pchTask.projectPartId(); if (success) { - m_allInclues = pchTask.allIncludes; + m_sources = pchTask.sources; m_projectPartPch.pchPath = std::move(pchOutputPath); - m_projectPartPch.lastModified = lastModified; } } @@ -163,18 +163,21 @@ void PchCreator::clear() { m_clangTool = ClangTool{}; m_projectPartPch = {}; + m_sources.clear(); } void PchCreator::doInMainThreadAfterFinished() { - FilePathIds existingIncludes; - existingIncludes.reserve(m_allInclues.size()); - std::set_difference(m_allInclues.begin(), - m_allInclues.end(), + FilePathIds existingSources; + existingSources.reserve(m_sources.size()); + std::set_difference(m_sources.begin(), + m_sources.end(), m_generatedFilePathIds.begin(), m_generatedFilePathIds.end(), - std::back_inserter(existingIncludes)); - m_clangPathwatcher.updateIdPaths({{m_projectPartPch.projectPartId, existingIncludes}}); + std::back_inserter(existingSources)); + m_buildDependenciesStorage.updatePchCreationTimeStamp(m_projectPartPch.lastModified, + m_projectPartPch.projectPartId); + m_clangPathwatcher.updateIdPaths({{m_projectPartPch.projectPartId, existingSources}}); m_pchManagerClient.precompiledHeadersUpdated(ProjectPartPchs{m_projectPartPch}); } diff --git a/src/tools/clangpchmanagerbackend/source/pchcreator.h b/src/tools/clangpchmanagerbackend/source/pchcreator.h index 73f185176d..f1fadcd33a 100644 --- a/src/tools/clangpchmanagerbackend/source/pchcreator.h +++ b/src/tools/clangpchmanagerbackend/source/pchcreator.h @@ -27,7 +27,6 @@ #include "pchcreatorinterface.h" -#include "pchcreatorincludes.h" #include "idpaths.h" #include "sourceentry.h" #include "clangtool.h" @@ -49,6 +48,7 @@ class Environment; class GeneratedFiles; class PchManagerClientInterface; class ClangPathWatcherInterface; +class BuildDependenciesStorageInterface; class PchCreator final : public PchCreatorInterface { @@ -56,12 +56,12 @@ public: PchCreator(Environment &environment, Sqlite::Database &database, PchManagerClientInterface &pchManagerClient, - ClangPathWatcherInterface &clangPathwatcher) - : m_filePathCache(database) - , m_environment(environment) - , m_pchManagerClient(pchManagerClient) - , m_clangPathwatcher(clangPathwatcher) - {} + ClangPathWatcherInterface &clangPathwatcher, + BuildDependenciesStorageInterface &buildDependenciesStorage) + : m_filePathCache(database), m_environment(environment), + m_pchManagerClient(pchManagerClient), + m_clangPathwatcher(clangPathwatcher), + m_buildDependenciesStorage(buildDependenciesStorage) {} void generatePch(PchTask &&pchTask) override; const ProjectPartPch &projectPartPch() override; @@ -85,16 +85,19 @@ public: return m_clangTool; } + const FilePathIds &sources() const { return m_sources; } + private: mutable std::mt19937_64 randomNumberGenator{std::random_device{}()}; ClangTool m_clangTool; ProjectPartPch m_projectPartPch; FilePathCaching m_filePathCache; - FilePathIds m_allInclues; + FilePathIds m_sources; FilePathIds m_generatedFilePathIds; Environment &m_environment; PchManagerClientInterface &m_pchManagerClient; ClangPathWatcherInterface &m_clangPathwatcher; + BuildDependenciesStorageInterface &m_buildDependenciesStorage; bool m_isUsed = false; }; diff --git a/src/tools/clangpchmanagerbackend/source/pchcreatorincludes.h b/src/tools/clangpchmanagerbackend/source/pchcreatorincludes.h deleted file mode 100644 index 6854c59907..0000000000 --- a/src/tools/clangpchmanagerbackend/source/pchcreatorincludes.h +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#pragma once - -#include <filepathid.h> - -namespace ClangBackEnd { - -class PchCreatorIncludes -{ -public: - FilePathIds includeIds; - FilePathIds topIncludeIds; - FilePathIds topSystemIncludeIds; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/pchmanagerserver.cpp b/src/tools/clangpchmanagerbackend/source/pchmanagerserver.cpp index 999da26448..89ad912640 100644 --- a/src/tools/clangpchmanagerbackend/source/pchmanagerserver.cpp +++ b/src/tools/clangpchmanagerbackend/source/pchmanagerserver.cpp @@ -42,12 +42,12 @@ namespace ClangBackEnd { PchManagerServer::PchManagerServer(ClangPathWatcherInterface &fileSystemWatcher, PchTaskGeneratorInterface &pchTaskGenerator, - ProjectPartsInterface &projectParts, + ProjectPartsManagerInterface &projectParts, GeneratedFilesInterface &generatedFiles) - : m_fileSystemWatcher(fileSystemWatcher), - m_pchTaskGenerator(pchTaskGenerator), - m_projectParts(projectParts), - m_generatedFiles(generatedFiles) + : m_fileSystemWatcher(fileSystemWatcher) + , m_pchTaskGenerator(pchTaskGenerator) + , m_projectPartsManager(projectParts) + , m_generatedFiles(generatedFiles) { m_fileSystemWatcher.setNotifier(this); } @@ -61,13 +61,13 @@ void PchManagerServer::updateProjectParts(UpdateProjectPartsMessage &&message) { m_toolChainsArgumentsCache.update(message.projectsParts, message.toolChainArguments); - ProjectPartContainers newProjectParts = m_projectParts.update(message.takeProjectsParts()); + ProjectPartContainers newProjectParts = m_projectPartsManager.update(message.takeProjectsParts()); if (m_generatedFiles.isValid()) { m_pchTaskGenerator.addProjectParts(std::move(newProjectParts), std::move(message.toolChainArguments)); } else { - m_projectParts.updateDeferred(newProjectParts); + m_projectPartsManager.updateDeferred(newProjectParts); } } @@ -75,7 +75,7 @@ void PchManagerServer::removeProjectParts(RemoveProjectPartsMessage &&message) { m_fileSystemWatcher.removeIds(message.projectsPartIds); - m_projectParts.remove(message.projectsPartIds); + m_projectPartsManager.remove(message.projectsPartIds); m_pchTaskGenerator.removeProjectParts(message.projectsPartIds); @@ -102,7 +102,7 @@ void PchManagerServer::updateGeneratedFiles(UpdateGeneratedFilesMessage &&messag m_generatedFiles.update(message.takeGeneratedFiles()); if (m_generatedFiles.isValid()) { - ProjectPartContainers deferredProjectParts = m_projectParts.deferredUpdates(); + ProjectPartContainers deferredProjectParts = m_projectPartsManager.deferredUpdates(); ArgumentsEntries entries = m_toolChainsArgumentsCache.arguments( projectPartIds(deferredProjectParts)); @@ -123,8 +123,8 @@ void PchManagerServer::pathsWithIdsChanged(const Utils::SmallStringVector &ids) ArgumentsEntries entries = m_toolChainsArgumentsCache.arguments(ids); for (ArgumentsEntry &entry : entries) { - m_pchTaskGenerator.addProjectParts( - m_projectParts.projects(entry.ids), std::move(entry.arguments)); + m_pchTaskGenerator.addProjectParts(m_projectPartsManager.projects(entry.ids), + std::move(entry.arguments)); } } diff --git a/src/tools/clangpchmanagerbackend/source/pchmanagerserver.h b/src/tools/clangpchmanagerbackend/source/pchmanagerserver.h index bf6b5bd7e7..9cf8aa8321 100644 --- a/src/tools/clangpchmanagerbackend/source/pchmanagerserver.h +++ b/src/tools/clangpchmanagerbackend/source/pchmanagerserver.h @@ -29,7 +29,7 @@ #include "clangpathwatchernotifier.h" #include "pchcreatorinterface.h" #include "pchmanagerserverinterface.h" -#include "projectpartsinterface.h" +#include "projectpartsmanagerinterface.h" #include "toolchainargumentscache.h" #include <generatedfilesinterface.h> @@ -48,7 +48,7 @@ class PchManagerServer : public PchManagerServerInterface, public: PchManagerServer(ClangPathWatcherInterface &fileSystemWatcher, PchTaskGeneratorInterface &pchTaskGenerator, - ProjectPartsInterface &projectParts, + ProjectPartsManagerInterface &projectParts, GeneratedFilesInterface &generatedFiles); void end() override; @@ -66,7 +66,7 @@ public: private: ClangPathWatcherInterface &m_fileSystemWatcher; PchTaskGeneratorInterface &m_pchTaskGenerator; - ProjectPartsInterface &m_projectParts; + ProjectPartsManagerInterface &m_projectPartsManager; GeneratedFilesInterface &m_generatedFiles; ToolChainsArgumentsCache m_toolChainsArgumentsCache; }; diff --git a/src/tools/clangpchmanagerbackend/source/pchtask.h b/src/tools/clangpchmanagerbackend/source/pchtask.h index c94d7ac816..528d6e63f1 100644 --- a/src/tools/clangpchmanagerbackend/source/pchtask.h +++ b/src/tools/clangpchmanagerbackend/source/pchtask.h @@ -41,7 +41,7 @@ class PchTask public: PchTask(Utils::SmallString &&projectPartId, FilePathIds &&includes, - FilePathIds &&allIncludes, + FilePathIds &&sources, CompilerMacros &&compilerMacros, Utils::SmallStringVector &&usedMacros, Utils::SmallStringVector toolChainArguments, @@ -52,7 +52,7 @@ public: Utils::LanguageExtension languageExtension = Utils::LanguageExtension::None) : projectPartIds({projectPartId}) , includes(includes) - , allIncludes(allIncludes) + , sources(sources) , compilerMacros(compilerMacros) , systemIncludeSearchPaths(std::move(systemIncludeSearchPaths)) , projectIncludeSearchPaths(std::move(projectIncludeSearchPaths)) @@ -64,7 +64,7 @@ public: PchTask(Utils::SmallStringVector &&projectPartIds, FilePathIds &&includes, - FilePathIds &&allIncludes, + FilePathIds &&sources, CompilerMacros &&compilerMacros, Utils::SmallStringVector &&usedMacros, Utils::SmallStringVector toolChainArguments, @@ -75,7 +75,7 @@ public: Utils::LanguageExtension languageExtension = Utils::LanguageExtension::None) : projectPartIds(std::move(projectPartIds)) , includes(includes) - , allIncludes(allIncludes) + , sources(sources) , compilerMacros(compilerMacros) , systemIncludeSearchPaths(std::move(systemIncludeSearchPaths)) , projectIncludeSearchPaths(std::move(projectIncludeSearchPaths)) @@ -104,7 +104,7 @@ public: FilePath systemPchPath; Utils::SmallStringVector projectPartIds; FilePathIds includes; - FilePathIds allIncludes; + FilePathIds sources; CompilerMacros compilerMacros; IncludeSearchPaths systemIncludeSearchPaths; IncludeSearchPaths projectIncludeSearchPaths; diff --git a/src/tools/clangpchmanagerbackend/source/pchtaskgenerator.cpp b/src/tools/clangpchmanagerbackend/source/pchtaskgenerator.cpp index aab3bfe7d4..a44fc91b16 100644 --- a/src/tools/clangpchmanagerbackend/source/pchtaskgenerator.cpp +++ b/src/tools/clangpchmanagerbackend/source/pchtaskgenerator.cpp @@ -45,7 +45,7 @@ void PchTaskGenerator::addProjectParts(ProjectPartContainers &&projectParts, for (auto &projectPart : projectParts) { BuildDependency buildDependency = m_buildDependenciesProvider.create(projectPart); - UsedMacroFilter filter{buildDependency.includes, + UsedMacroFilter filter{buildDependency.sources, buildDependency.usedMacros, projectPart.compilerMacros}; @@ -62,7 +62,7 @@ void PchTaskGenerator::addProjectParts(ProjectPartContainers &&projectParts, projectPart.languageExtension}, PchTask{std::move(projectPart.projectPartId), std::move(filter.topProjectIncludes), - std::move(filter.allIncludes), + std::move(filter.sources), std::move(filter.projectCompilerMacros), std::move(filter.projectUsedMacros), projectPart.toolChainArguments, diff --git a/src/tools/clangpchmanagerbackend/source/pchtasksmerger.cpp b/src/tools/clangpchmanagerbackend/source/pchtasksmerger.cpp index 50851a838a..65d1a3e9fe 100644 --- a/src/tools/clangpchmanagerbackend/source/pchtasksmerger.cpp +++ b/src/tools/clangpchmanagerbackend/source/pchtasksmerger.cpp @@ -96,8 +96,8 @@ bool PchTasksMerger::mergePchTasks(PchTask &firstTask, PchTask &secondTask) firstTask.projectPartIds = merge(std::move(firstTask.projectPartIds), std::move(secondTask.projectPartIds)); firstTask.includes = merge(std::move(firstTask.includes), std::move(secondTask.includes)); - firstTask.allIncludes = merge(std::move(firstTask.allIncludes), - std::move(secondTask.allIncludes)); + firstTask.sources = merge(std::move(firstTask.sources), + std::move(secondTask.sources)); firstTask.compilerMacros = std::move(macros); firstTask.systemIncludeSearchPaths = mergeIncludeSearchPaths( std::move(firstTask.systemIncludeSearchPaths), diff --git a/src/tools/clangpchmanagerbackend/source/projectparts.cpp b/src/tools/clangpchmanagerbackend/source/projectpartsmanager.cpp index e8df25e104..8333ed9674 100644 --- a/src/tools/clangpchmanagerbackend/source/projectparts.cpp +++ b/src/tools/clangpchmanagerbackend/source/projectpartsmanager.cpp @@ -23,7 +23,7 @@ ** ****************************************************************************/ -#include "projectparts.h" +#include "projectpartsmanager.h" #include <projectpartcontainer.h> @@ -33,7 +33,7 @@ namespace ClangBackEnd { inline namespace Pch { -ProjectPartContainers ProjectParts::update(ProjectPartContainers &&projectsParts) +ProjectPartContainers ProjectPartsManager::update(ProjectPartContainers &&projectsParts) { auto updatedProjectPartContainers = newProjectParts(std::move(projectsParts)); @@ -42,7 +42,7 @@ ProjectPartContainers ProjectParts::update(ProjectPartContainers &&projectsParts return updatedProjectPartContainers; } -void ProjectParts::remove(const Utils::SmallStringVector &ids) +void ProjectPartsManager::remove(const Utils::SmallStringVector &ids) { auto shouldRemove = [&] (const ProjectPartContainer &projectPart) { return std::find(ids.begin(), ids.end(), projectPart.projectPartId) != ids.end(); @@ -52,7 +52,7 @@ void ProjectParts::remove(const Utils::SmallStringVector &ids) m_projectParts.erase(newEnd, m_projectParts.end()); } -ProjectPartContainers ProjectParts::projects(const Utils::SmallStringVector &projectPartIds) const +ProjectPartContainers ProjectPartsManager::projects(const Utils::SmallStringVector &projectPartIds) const { ProjectPartContainers projectPartsWithIds; @@ -66,7 +66,7 @@ ProjectPartContainers ProjectParts::projects(const Utils::SmallStringVector &pro return projectPartsWithIds; } -void ProjectParts::updateDeferred(const ProjectPartContainers &deferredProjectsParts) +void ProjectPartsManager::updateDeferred(const ProjectPartContainers &deferredProjectsParts) { using ProjectPartContainerReferences = std::vector<std::reference_wrapper<ProjectPartContainer>>; @@ -86,7 +86,7 @@ void ProjectParts::updateDeferred(const ProjectPartContainers &deferredProjectsP projectPart.updateIsDeferred = true; } -ProjectPartContainers ProjectParts::deferredUpdates() +ProjectPartContainers ProjectPartsManager::deferredUpdates() { ProjectPartContainers deferredProjectParts; deferredProjectParts.reserve(m_projectParts.size()); @@ -102,7 +102,7 @@ ProjectPartContainers ProjectParts::deferredUpdates() return deferredProjectParts; } -ProjectPartContainers ProjectParts::newProjectParts(ProjectPartContainers &&projectsParts) const +ProjectPartContainers ProjectPartsManager::newProjectParts(ProjectPartContainers &&projectsParts) const { ProjectPartContainers updatedProjectPartContainers; updatedProjectPartContainers.reserve(projectsParts.size()); @@ -116,7 +116,7 @@ ProjectPartContainers ProjectParts::newProjectParts(ProjectPartContainers &&proj return updatedProjectPartContainers; } -void ProjectParts::mergeProjectParts(const ProjectPartContainers &projectsParts) +void ProjectPartsManager::mergeProjectParts(const ProjectPartContainers &projectsParts) { ProjectPartContainers newProjectParts; newProjectParts.reserve(m_projectParts.size() + projectsParts.size()); @@ -135,7 +135,7 @@ void ProjectParts::mergeProjectParts(const ProjectPartContainers &projectsParts) m_projectParts = newProjectParts; } -const ProjectPartContainers &ProjectParts::projectParts() const +const ProjectPartContainers &ProjectPartsManager::projectParts() const { return m_projectParts; } diff --git a/src/tools/clangpchmanagerbackend/source/projectparts.h b/src/tools/clangpchmanagerbackend/source/projectpartsmanager.h index 4df413ce6f..2b3c43ebc8 100644 --- a/src/tools/clangpchmanagerbackend/source/projectparts.h +++ b/src/tools/clangpchmanagerbackend/source/projectpartsmanager.h @@ -27,15 +27,14 @@ #include "clangpchmanagerbackend_global.h" -#include <projectpartsinterface.h> +#include <projectpartsmanagerinterface.h> #include <utils/smallstringvector.h> namespace ClangBackEnd { inline namespace Pch { - -class ProjectParts final : public ProjectPartsInterface +class ProjectPartsManager final : public ProjectPartsManagerInterface { public: ProjectPartContainers update(ProjectPartContainers &&projectsParts) override; diff --git a/src/tools/clangpchmanagerbackend/source/projectpartsinterface.h b/src/tools/clangpchmanagerbackend/source/projectpartsmanagerinterface.h index d37673af10..f99674ddda 100644 --- a/src/tools/clangpchmanagerbackend/source/projectpartsinterface.h +++ b/src/tools/clangpchmanagerbackend/source/projectpartsmanagerinterface.h @@ -29,12 +29,12 @@ namespace ClangBackEnd { -class ProjectPartsInterface +class ProjectPartsManagerInterface { public: - ProjectPartsInterface() = default; - ProjectPartsInterface(const ProjectPartsInterface &) = delete; - ProjectPartsInterface &operator=(const ProjectPartsInterface &) = delete; + ProjectPartsManagerInterface() = default; + ProjectPartsManagerInterface(const ProjectPartsManagerInterface &) = delete; + ProjectPartsManagerInterface &operator=(const ProjectPartsManagerInterface &) = delete; virtual ProjectPartContainers update(ProjectPartContainers &&projectsParts) = 0; virtual void remove(const Utils::SmallStringVector &projectPartIds) = 0; @@ -42,7 +42,7 @@ public: virtual void updateDeferred(const ProjectPartContainers &projectsParts) = 0; virtual ProjectPartContainers deferredUpdates() = 0; protected: - ~ProjectPartsInterface() = default; + ~ProjectPartsManagerInterface() = default; }; } // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/sourceentry.h b/src/tools/clangpchmanagerbackend/source/sourceentry.h index e903baf3f6..5c45db6bde 100644 --- a/src/tools/clangpchmanagerbackend/source/sourceentry.h +++ b/src/tools/clangpchmanagerbackend/source/sourceentry.h @@ -31,19 +31,22 @@ namespace ClangBackEnd { -enum class SourceType : unsigned char -{ +enum class SourceType : unsigned char { TopProjectInclude, TopSystemInclude, UserInclude, ProjectInclude, - SystemInclude + SystemInclude, + Source }; +enum class HasMissingIncludes : unsigned char { No, Yes }; + class TimeStamp { using int64 = long long; public: + TimeStamp() = default; TimeStamp(int64 value) : value(value) {} @@ -58,7 +61,6 @@ public: class SourceTimeStamp { -protected: using int64 = long long; public: SourceTimeStamp(int sourceId, int64 lastModified) @@ -103,37 +105,47 @@ public: using SourceTimeStamps = std::vector<SourceTimeStamp>; -class SourceEntry : public SourceTimeStamp +class SourceEntry { + using int64 = long long; public: - SourceEntry(int sourceId, int64 lastModified, int sourceType) - : SourceTimeStamp(sourceId, lastModified) - , sourceType(static_cast<SourceType>(sourceType)) - {} - - SourceEntry(FilePathId sourceId, SourceType sourceType, TimeStamp lastModified) - : SourceTimeStamp(sourceId, lastModified) - , sourceType(sourceType) - {} - - friend bool operator<(SourceEntry first, SourceEntry second) - { + SourceEntry(int sourceId, + int64 pchCreationTimeStamp, + int sourceType, + int hasMissingIncludes) + : pchCreationTimeStamp(pchCreationTimeStamp), sourceId(sourceId), + sourceType(static_cast<SourceType>(sourceType)), + hasMissingIncludes( + static_cast<HasMissingIncludes>(hasMissingIncludes)) {} + + SourceEntry(FilePathId sourceId, + SourceType sourceType, + TimeStamp pchCreationTimeStamp, + HasMissingIncludes hasMissingIncludes = HasMissingIncludes::No) + : pchCreationTimeStamp(pchCreationTimeStamp), sourceId(sourceId), + sourceType(sourceType), hasMissingIncludes(hasMissingIncludes) {} + + friend bool operator<(SourceEntry first, SourceEntry second) { return first.sourceId < second.sourceId; } friend bool operator==(SourceEntry first, SourceEntry second) { return first.sourceId == second.sourceId && first.sourceType == second.sourceType - && first.lastModified == second.lastModified; + && first.pchCreationTimeStamp == second.pchCreationTimeStamp; } friend bool operator!=(SourceEntry first, SourceEntry second) { return !(first == second); } public: + TimeStamp pchCreationTimeStamp; + FilePathId sourceId; SourceType sourceType = SourceType::UserInclude; + HasMissingIncludes hasMissingIncludes = HasMissingIncludes::No; }; using SourceEntries = std::vector<SourceEntry>; - -} +using SourceEntryReference = std::reference_wrapper<SourceEntry>; +using SourceEntryReferences = std::vector<SourceEntryReference>; +} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/usedmacrofilter.h b/src/tools/clangpchmanagerbackend/source/usedmacrofilter.h index 6042895325..9db3c683b9 100644 --- a/src/tools/clangpchmanagerbackend/source/usedmacrofilter.h +++ b/src/tools/clangpchmanagerbackend/source/usedmacrofilter.h @@ -87,23 +87,22 @@ public: UsedMacroFilter(const SourceEntries &includes, const UsedMacros &usedMacros, - const CompilerMacros &compilerMacros) - { - filterIncludes(includes); + const CompilerMacros &compilerMacros) { + filterSources(includes); systemUsedMacros = filterUsedMarcos(usedMacros, systemIncludes); projectUsedMacros = filterUsedMarcos(usedMacros, projectIncludes); filter(compilerMacros); } - void filterIncludes(const SourceEntries &includes) - { - systemIncludes.reserve(includes.size()); - projectIncludes.reserve(includes.size()); - topSystemIncludes.reserve(includes.size() / 10); - topProjectIncludes.reserve(includes.size() / 10); + void filterSources(const SourceEntries &sources) { + systemIncludes.reserve(sources.size()); + projectIncludes.reserve(sources.size()); + topSystemIncludes.reserve(sources.size() / 10); + topProjectIncludes.reserve(sources.size() / 10); + this->sources.reserve(sources.size()); - for (SourceEntry include : includes) - filterInclude(include); + for (SourceEntry source : sources) + filterSource(source); } void filter(const CompilerMacros &compilerMacros) @@ -121,28 +120,31 @@ public: } private: - void filterInclude(SourceEntry include) - { - switch (include.sourceType) { - case SourceType::TopSystemInclude: - topSystemIncludes.emplace_back(include.sourceId); - systemIncludes.emplace_back(include.sourceId); - break; - case SourceType::SystemInclude: - systemIncludes.emplace_back(include.sourceId); - break; - case SourceType::TopProjectInclude: - topProjectIncludes.emplace_back(include.sourceId); - projectIncludes.emplace_back(include.sourceId); - break; - case SourceType::ProjectInclude: - projectIncludes.emplace_back(include.sourceId); - break; - case SourceType::UserInclude: - break; + void filterSource(SourceEntry source) { + if (source.hasMissingIncludes == HasMissingIncludes::Yes) + return; + + switch (source.sourceType) { + case SourceType::TopSystemInclude: + topSystemIncludes.emplace_back(source.sourceId); + systemIncludes.emplace_back(source.sourceId); + break; + case SourceType::SystemInclude: + systemIncludes.emplace_back(source.sourceId); + break; + case SourceType::TopProjectInclude: + topProjectIncludes.emplace_back(source.sourceId); + projectIncludes.emplace_back(source.sourceId); + break; + case SourceType::ProjectInclude: + projectIncludes.emplace_back(source.sourceId); + break; + case SourceType::UserInclude: + case SourceType::Source: + break; } - allIncludes.emplace_back(include.sourceId); + sources.emplace_back(source.sourceId); } static Utils::SmallStringVector filterUsedMarcos(const UsedMacros &usedMacros, @@ -209,7 +211,7 @@ private: } public: - FilePathIds allIncludes; + FilePathIds sources; FilePathIds projectIncludes; FilePathIds systemIncludes; FilePathIds topProjectIncludes; diff --git a/src/tools/clangrefactoringbackend/source/filestatus.h b/src/tools/clangrefactoringbackend/source/filestatus.h index 9ade546294..da2be4a304 100644 --- a/src/tools/clangrefactoringbackend/source/filestatus.h +++ b/src/tools/clangrefactoringbackend/source/filestatus.h @@ -36,15 +36,8 @@ namespace ClangBackEnd { class FileStatus { public: - FileStatus(FilePathId filePathId, - off_t size, - std::time_t lastModified, - bool isInPrecompiledHeader) - : filePathId(filePathId), - size(size), - lastModified(lastModified), - isInPrecompiledHeader(isInPrecompiledHeader) - {} + FileStatus(FilePathId filePathId, off_t size, std::time_t lastModified) + : filePathId(filePathId), size(size), lastModified(lastModified) {} friend bool operator==(const FileStatus &first, const FileStatus &second) @@ -64,7 +57,6 @@ public: FilePathId filePathId; off_t size; std::time_t lastModified; - bool isInPrecompiledHeader; }; using FileStatuses = std::vector<FileStatus>; diff --git a/src/tools/clangrefactoringbackend/source/symbolindexer.cpp b/src/tools/clangrefactoringbackend/source/symbolindexer.cpp index 6928e49712..aee8344fc9 100644 --- a/src/tools/clangrefactoringbackend/source/symbolindexer.cpp +++ b/src/tools/clangrefactoringbackend/source/symbolindexer.cpp @@ -120,8 +120,7 @@ void SymbolIndexer::updateProjectPart(ProjectPartContainer &&projectPart) std::vector<SymbolIndexerTask> symbolIndexerTask; symbolIndexerTask.reserve(projectPart.sourcePathIds.size()); for (FilePathId sourcePathId : projectPart.sourcePathIds) { - auto indexing = [projectPartId, - arguments = commandLineBuilder.commandLine, + auto indexing = [arguments = commandLineBuilder.commandLine, sourcePathId, this](SymbolsCollectorInterface &symbolsCollector) { symbolsCollector.setFile(sourcePathId, arguments); @@ -134,12 +133,9 @@ void SymbolIndexer::updateProjectPart(ProjectPartContainer &&projectPart) m_symbolStorage.addSymbolsAndSourceLocations(symbolsCollector.symbols(), symbolsCollector.sourceLocations()); - m_symbolStorage.updateProjectPartSources(projectPartId, - symbolsCollector.sourceFiles()); - m_buildDependencyStorage.insertOrUpdateUsedMacros(symbolsCollector.usedMacros()); - m_buildDependencyStorage.insertFileStatuses(symbolsCollector.fileStatuses()); + m_buildDependencyStorage.insertOrUpdateFileStatuses(symbolsCollector.fileStatuses()); m_buildDependencyStorage.insertOrUpdateSourceDependencies( symbolsCollector.sourceDependencies()); @@ -193,10 +189,8 @@ void SymbolIndexer::updateChangedPath(FilePathId filePathId, CommandLineBuilder<ProjectPartArtefact, Utils::SmallStringVector> builder{artefact, artefact.toolChainArguments, InputFileType::Source, {}, {}, pchPath}; - auto indexing = [projectPartId = artefact.projectPartId, - arguments = builder.commandLine, - filePathId, - this](SymbolsCollectorInterface &symbolsCollector) { + auto indexing = [arguments = builder.commandLine, filePathId, this]( + SymbolsCollectorInterface &symbolsCollector) { symbolsCollector.setFile(filePathId, arguments); bool success = symbolsCollector.collectSymbols(); @@ -207,11 +201,9 @@ void SymbolIndexer::updateChangedPath(FilePathId filePathId, m_symbolStorage.addSymbolsAndSourceLocations(symbolsCollector.symbols(), symbolsCollector.sourceLocations()); - m_symbolStorage.updateProjectPartSources(projectPartId, symbolsCollector.sourceFiles()); - m_buildDependencyStorage.insertOrUpdateUsedMacros(symbolsCollector.usedMacros()); - m_buildDependencyStorage.insertFileStatuses(symbolsCollector.fileStatuses()); + m_buildDependencyStorage.insertOrUpdateFileStatuses(symbolsCollector.fileStatuses()); m_buildDependencyStorage.insertOrUpdateSourceDependencies( symbolsCollector.sourceDependencies()); diff --git a/src/tools/clangrefactoringbackend/source/symbolstorage.h b/src/tools/clangrefactoringbackend/source/symbolstorage.h index 3b7141c783..798fa26dd0 100644 --- a/src/tools/clangrefactoringbackend/source/symbolstorage.h +++ b/src/tools/clangrefactoringbackend/source/symbolstorage.h @@ -112,17 +112,6 @@ public: return statement.template value<ProjectPartArtefact, 8>(projectPartName); } - void updateProjectPartSources(int projectPartId, - const FilePathIds &sourceFilePathIds) override - { - WriteStatement &deleteStatement = m_deleteAllProjectPartsSourcesWithProjectPartIdStatement; - deleteStatement.write(projectPartId); - - WriteStatement &insertStatement = m_insertProjectPartSourcesStatement; - for (const FilePathId &sourceFilePathId : sourceFilePathIds) - insertStatement.write(projectPartId, sourceFilePathId.filePathId); - } - static Utils::SmallString toJson(const Utils::SmallStringVector &strings) { QJsonDocument document; @@ -322,14 +311,7 @@ public: "SELECT projectPartId FROM projectParts WHERE projectPartName = ?", m_database }; - WriteStatement m_deleteAllProjectPartsSourcesWithProjectPartIdStatement{ - "DELETE FROM projectPartsSources WHERE projectPartId = ?", - m_database - }; - WriteStatement m_insertProjectPartSourcesStatement{ - "INSERT INTO projectPartsSources(projectPartId, sourceId) VALUES (?,?)", - m_database - }; + mutable ReadStatement m_getCompileArgumentsForFileIdStatement{ "SELECT toolChainArguments FROM projectParts WHERE projectPartId = (SELECT projectPartId " "FROM projectPartsSources WHERE sourceId = ?)", diff --git a/src/tools/clangrefactoringbackend/source/symbolstorageinterface.h b/src/tools/clangrefactoringbackend/source/symbolstorageinterface.h index 5f2e6c30e6..210f66f7da 100644 --- a/src/tools/clangrefactoringbackend/source/symbolstorageinterface.h +++ b/src/tools/clangrefactoringbackend/source/symbolstorageinterface.h @@ -61,7 +61,6 @@ public: Utils::LanguageVersion languageVersion, Utils::LanguageExtension languageExtension) = 0; - virtual void updateProjectPartSources(int projectPartId, const FilePathIds &sourceFilePathIds) = 0; virtual Utils::optional<ProjectPartArtefact> fetchProjectPartArtefact( FilePathId sourceId) const = 0; virtual Utils::optional<ProjectPartArtefact> fetchProjectPartArtefact( |