diff --git a/src/libs/clangsupport/refactoringdatabaseinitializer.h b/src/libs/clangsupport/refactoringdatabaseinitializer.h index cce203f0d44..6bbb650af7f 100644 --- a/src/libs/clangsupport/refactoringdatabaseinitializer.h +++ b/src/libs/clangsupport/refactoringdatabaseinitializer.h @@ -143,6 +143,7 @@ public: const Sqlite::Column &projectPartIdColumn = table.addColumn("projectPartId", Sqlite::ColumnType::Integer); const Sqlite::Column &sourceIdColumn = table.addColumn("sourceId", Sqlite::ColumnType::Integer); table.addColumn("sourceType", Sqlite::ColumnType::Integer); + table.addColumn("pchCreationTimeStamp", Sqlite::ColumnType::Integer); table.addUniqueIndex({sourceIdColumn, projectPartIdColumn}); table.addIndex({projectPartIdColumn}); @@ -168,11 +169,11 @@ public: Sqlite::Table table; table.setUseIfNotExists(true); table.setName("fileStatuses"); - table.addColumn("sourceId", Sqlite::ColumnType::Integer, Sqlite::Contraint::PrimaryKey); + table.addColumn("sourceId", + Sqlite::ColumnType::Integer, + Sqlite::Contraint::PrimaryKey); table.addColumn("size", Sqlite::ColumnType::Integer); table.addColumn("lastModified", Sqlite::ColumnType::Integer); - table.addColumn("buildDependencyTimeStamp", Sqlite::ColumnType::Integer); - table.addColumn("isInPrecompiledHeader", Sqlite::ColumnType::Integer); table.initialize(database); } diff --git a/src/tools/clangpchmanagerbackend/clangpchmanagerbackendmain.cpp b/src/tools/clangpchmanagerbackend/clangpchmanagerbackendmain.cpp index 89567b8d386..0bc807a03d2 100644 --- a/src/tools/clangpchmanagerbackend/clangpchmanagerbackendmain.cpp +++ b/src/tools/clangpchmanagerbackend/clangpchmanagerbackendmain.cpp @@ -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(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 @@ -181,7 +185,8 @@ struct Data // because we have a cycle dependency 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 d58da0f27c2..a2a7a813ac4 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 +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(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 4a89ace732a..2eb52105185 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 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 324552bf996..c164e7a727f 100644 --- a/src/tools/clangpchmanagerbackend/source/builddependenciesstorage.h +++ b/src/tools/clangpchmanagerbackend/source/builddependenciesstorage.h @@ -53,25 +53,26 @@ 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(entry.lastModified), - entry.sourceId.filePathId); - updateSourceTypeStatement.write(static_cast(entry.sourceType), - entry.sourceId.filePathId); + insertOrUpdateSourceTypeStatement.write(entry.sourceId.filePathId, + projectPartId, + static_cast(entry.sourceType)); } } - 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 +86,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 +106,23 @@ public: deleteNewSourceDependenciesStatement.execute(); } - SourceEntries fetchDependSources(FilePathId sourceId, - Utils::SmallStringView projectPartName) const override + int fetchProjectPartId(Utils::SmallStringView projectPartName) override { auto projectPartId = fetchProjectPartIdStatement.template value(projectPartName); - if (projectPartId) { - return fetchSourceDependenciesStatement.template values( - 300, - sourceId.filePathId, - projectPartId.value()); - } - return {}; + if (projectPartId) + return projectPartId.value(); + + insertProjectPartNameStatement.write(projectPartName); + + return static_cast(database.lastInsertedRowId()); + } + + SourceEntries fetchDependSources(FilePathId sourceId, int projectPartId) const override + { + return fetchSourceDependenciesStatement.template values(300, + sourceId.filePathId, + projectPartId); } UsedMacros fetchUsedMacros(FilePathId sourceId) const override @@ -123,6 +130,17 @@ public: return fetchUsedMacrosStatement.template values(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 +225,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 +242,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 insertOrUpdateSourceTypeStatement{ + "INSERT INTO projectPartsSources(sourceId, projectPartId, " + "sourceType) VALUES (?001, ?002, ?003) ON CONFLICT(sourceId, " + "projectPartId) DO UPDATE SET sourceType = ?003", + 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 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 445afa052f2..4edc47fce1b 100644 --- a/src/tools/clangpchmanagerbackend/source/builddependenciesstorageinterface.h +++ b/src/tools/clangpchmanagerbackend/source/builddependenciesstorageinterface.h @@ -33,6 +33,8 @@ #include #include +#include + 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 1b649e3118d..6725254e308 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 b3ebbc75ad7..1d08442c517 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 @@ -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 c5e41e91907..f8aaa8f07cd 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 94d9540beae..fa8d6e527a6 100644 --- a/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri +++ b/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri @@ -9,7 +9,6 @@ SOURCES += \ $$PWD/pchtaskqueue.cpp HEADERS += \ - $$PWD/pchcreatorincludes.h \ $$PWD/pchmanagerserver.h \ $$PWD/clangpchmanagerbackend_global.h \ $$PWD/pchnotcreatederror.h \ diff --git a/src/tools/clangpchmanagerbackend/source/collectbuilddependencypreprocessorcallbacks.h b/src/tools/clangpchmanagerbackend/source/collectbuilddependencypreprocessorcallbacks.h index 980d065fdbc..658c51cb1a3 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); + 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(); + 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; + 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); @@ -270,7 +280,7 @@ public: } }; - auto &includes = m_buildDependency.includes; + auto &includes = m_buildDependency.sources; SourceEntries newIncludes; newIncludes.reserve(includes.size()); std::set_difference(includes.begin(), @@ -280,7 +290,7 @@ public: std::back_inserter(newIncludes), Compare{}); - m_buildDependency.includes = newIncludes; + m_buildDependency.sources = newIncludes; } SourceDependencies sourceDependenciesSortedByDependendFilePathId() const @@ -296,7 +306,7 @@ public: void filterOutIncludesWithMissingIncludes() { - sortAndMakeUnique(m_containsMissingIncludes);; + sortAndMakeUnique(m_containsMissingIncludes); collectSourceWithMissingIncludes(m_containsMissingIncludes, sourceDependenciesSortedByDependendFilePathId()); @@ -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; }); + 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 == includes.end() || *found != sourceEntry) - includes.emplace(found, sourceEntry); + 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 90108bd76b1..b8ea406df0f 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 88d5f140d53..d641de054cb 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)); + std::back_inserter(currentSourceTimeStamp), + CompareSourceId{}); - return std::equal(currentSourceTimeStamp.begin(), - currentSourceTimeStamp.end(), - sourceEntries.begin(), - sourceEntries.end(), - [](SourceTimeStamp first, SourceTimeStamp second) { - return first.lastModified <= second.lastModified; - }); + 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 b8227ce9645..3f858b50ee3 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 #include #include #include @@ -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 73f185176d7..f1fadcd33a9 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 6854c599070..00000000000 --- 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 - -namespace ClangBackEnd { - -class PchCreatorIncludes -{ -public: - FilePathIds includeIds; - FilePathIds topIncludeIds; - FilePathIds topSystemIncludeIds; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/pchtask.h b/src/tools/clangpchmanagerbackend/source/pchtask.h index c94d7ac8164..528d6e63f13 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 aab3bfe7d48..a44fc91b168 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 50851a838a0..65d1a3e9fed 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/sourceentry.h b/src/tools/clangpchmanagerbackend/source/sourceentry.h index e903baf3f6b..d5bb28d904f 100644 --- a/src/tools/clangpchmanagerbackend/source/sourceentry.h +++ b/src/tools/clangpchmanagerbackend/source/sourceentry.h @@ -31,19 +31,20 @@ namespace ClangBackEnd { -enum class SourceType : unsigned char -{ +enum class SourceType : unsigned char { TopProjectInclude, TopSystemInclude, UserInclude, ProjectInclude, - SystemInclude + SystemInclude, + Source }; class TimeStamp { using int64 = long long; public: + TimeStamp() = default; TimeStamp(int64 value) : value(value) {} @@ -58,7 +59,6 @@ public: class SourceTimeStamp { -protected: using int64 = long long; public: SourceTimeStamp(int sourceId, int64 lastModified) @@ -103,17 +103,20 @@ public: using SourceTimeStamps = std::vector; -class SourceEntry : public SourceTimeStamp +class SourceEntry { + using int64 = long long; public: - SourceEntry(int sourceId, int64 lastModified, int sourceType) - : SourceTimeStamp(sourceId, lastModified) + SourceEntry(int sourceId, int64 pchCreationTimeStamp, int sourceType) + : pchCreationTimeStamp(pchCreationTimeStamp) + , sourceId(sourceId) , sourceType(static_cast(sourceType)) {} - SourceEntry(FilePathId sourceId, SourceType sourceType, TimeStamp lastModified) - : SourceTimeStamp(sourceId, lastModified) + SourceEntry(FilePathId sourceId, SourceType sourceType, TimeStamp pchCreationTimeStamp) + : pchCreationTimeStamp(pchCreationTimeStamp) + , sourceId(sourceId) , sourceType(sourceType) {} @@ -125,12 +128,14 @@ public: 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; }; diff --git a/src/tools/clangpchmanagerbackend/source/usedmacrofilter.h b/src/tools/clangpchmanagerbackend/source/usedmacrofilter.h index 6042895325a..bd9788e61cb 100644 --- a/src/tools/clangpchmanagerbackend/source/usedmacrofilter.h +++ b/src/tools/clangpchmanagerbackend/source/usedmacrofilter.h @@ -139,10 +139,11 @@ private: projectIncludes.emplace_back(include.sourceId); break; case SourceType::UserInclude: + case SourceType::Source: break; } - allIncludes.emplace_back(include.sourceId); + sources.emplace_back(include.sourceId); } static Utils::SmallStringVector filterUsedMarcos(const UsedMacros &usedMacros, @@ -209,7 +210,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 9ade5462948..da2be4a304e 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; diff --git a/src/tools/clangrefactoringbackend/source/symbolindexer.cpp b/src/tools/clangrefactoringbackend/source/symbolindexer.cpp index 6928e497125..aee8344fc90 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.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 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 3b7141c7838..798fa26dd06 100644 --- a/src/tools/clangrefactoringbackend/source/symbolstorage.h +++ b/src/tools/clangrefactoringbackend/source/symbolstorage.h @@ -112,17 +112,6 @@ public: return statement.template value(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 5f2e6c30e68..210f66f7da1 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 fetchProjectPartArtefact( FilePathId sourceId) const = 0; virtual Utils::optional fetchProjectPartArtefact( diff --git a/tests/unit/unittest/builddependenciesprovider-test.cpp b/tests/unit/unittest/builddependenciesprovider-test.cpp index 2a5372c55dc..b69965cc56f 100644 --- a/tests/unit/unittest/builddependenciesprovider-test.cpp +++ b/tests/unit/unittest/builddependenciesprovider-test.cpp @@ -99,9 +99,7 @@ protected: UsedMacros thirdUsedMacros{{"SAN", 10}}; FilePathIds sourceFiles{1, 3, 8}; ClangBackEnd::SourceDependencies sourceDependencies{{1, 3}, {1, 8}}; - ClangBackEnd::FileStatuses fileStatuses{{1, 21, 12, false}, - {3, 21, 12, false}, - {8, 21, 12, false}}; + ClangBackEnd::FileStatuses fileStatuses{{1, 21, 12}, {3, 21, 12}, {8, 21, 12}}; BuildDependency buildDependency{ secondSources, secondUsedMacros, @@ -117,7 +115,9 @@ TEST_F(BuildDependenciesProvider, CreateCallsFetchDependSourcesFromStorageIfTime EXPECT_CALL(mockSqliteTransactionBackend, deferredBegin()); EXPECT_CALL(mockBuildDependenciesStorage, - fetchDependSources({2}, TypedEq("ProjectPart1"))) + fetchProjectPartId(TypedEq("ProjectPart1"))) + .WillOnce(Return(11)); + EXPECT_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, 11)) .WillRepeatedly(Return(firstSources)); EXPECT_CALL(mockSqliteTransactionBackend, commit()); EXPECT_CALL(mockModifiedTimeChecker, isUpToDate(firstSources)).WillRepeatedly(Return(true)); @@ -132,15 +132,24 @@ TEST_F(BuildDependenciesProvider, CreateCallsFetchDependSourcesFromStorageIfTime TEST_F(BuildDependenciesProvider, FetchDependSourcesFromStorage) { - ON_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, TypedEq("ProjectPart2"))).WillByDefault(Return(firstSources)); - ON_CALL(mockBuildDependenciesStorage, fetchDependSources({3}, TypedEq("ProjectPart2"))).WillByDefault(Return(secondSources)); - ON_CALL(mockBuildDependenciesStorage, fetchDependSources({4}, TypedEq("ProjectPart2"))).WillByDefault(Return(thirdSources)); + ON_CALL(mockBuildDependenciesStorage, + fetchProjectPartId(TypedEq("ProjectPart2"))) + .WillByDefault(Return(11)); + ON_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, 11)).WillByDefault(Return(firstSources)); + ON_CALL(mockBuildDependenciesStorage, fetchDependSources({3}, 11)).WillByDefault(Return(secondSources)); + ON_CALL(mockBuildDependenciesStorage, fetchDependSources({4}, 11)).WillByDefault(Return(thirdSources)); ON_CALL(mockModifiedTimeChecker, isUpToDate(_)).WillByDefault(Return(true)); auto buildDependency = provider.create(projectPart2); - ASSERT_THAT(buildDependency.includes, ElementsAre(HasSourceId(1), HasSourceId(2), HasSourceId(3), HasSourceId(4), HasSourceId(8), HasSourceId(10))); + ASSERT_THAT(buildDependency.sources, + ElementsAre(HasSourceId(1), + HasSourceId(2), + HasSourceId(3), + HasSourceId(4), + HasSourceId(8), + HasSourceId(10))); } TEST_F(BuildDependenciesProvider, CreateCallsFetchDependSourcesFromGeneratorIfTimeStampsAreNotUpToDate) @@ -149,15 +158,17 @@ TEST_F(BuildDependenciesProvider, CreateCallsFetchDependSourcesFromGeneratorIfTi EXPECT_CALL(mockSqliteTransactionBackend, deferredBegin()); EXPECT_CALL(mockBuildDependenciesStorage, - fetchDependSources({2}, TypedEq("ProjectPart1"))) + fetchProjectPartId(TypedEq("ProjectPart1"))) + .WillOnce(Return(11)); + EXPECT_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, TypedEq(11))) .WillRepeatedly(Return(firstSources)); EXPECT_CALL(mockSqliteTransactionBackend, commit()); EXPECT_CALL(mockModifiedTimeChecker, isUpToDate(firstSources)).WillRepeatedly(Return(false)); EXPECT_CALL(mockBuildDependenciesGenerator, create(projectPart1)) .WillOnce(Return(buildDependency)); EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()); - EXPECT_CALL(mockBuildDependenciesStorage, updateSources(Eq(secondSources))); - EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(Eq(fileStatuses))); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSources(Eq(secondSources), 11)); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateFileStatuses(Eq(fileStatuses))); EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies))); EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(Eq(secondUsedMacros))); EXPECT_CALL(mockSqliteTransactionBackend, commit()); @@ -167,13 +178,16 @@ TEST_F(BuildDependenciesProvider, CreateCallsFetchDependSourcesFromGeneratorIfTi TEST_F(BuildDependenciesProvider, FetchDependSourcesFromGenerator) { - ON_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, TypedEq("ProjectPart1"))).WillByDefault(Return(firstSources)); + ON_CALL(mockBuildDependenciesStorage, + fetchProjectPartId(TypedEq("ProjectPart1"))) + .WillByDefault(Return(11)); + ON_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, 11)).WillByDefault(Return(firstSources)); ON_CALL(mockModifiedTimeChecker, isUpToDate(_)).WillByDefault(Return(false)); ON_CALL(mockBuildDependenciesGenerator, create(projectPart1)).WillByDefault(Return(buildDependency)); auto buildDependency = provider.create(projectPart1); - ASSERT_THAT(buildDependency.includes, ElementsAre(HasSourceId(1), HasSourceId(3), HasSourceId(8))); + ASSERT_THAT(buildDependency.sources, ElementsAre(HasSourceId(1), HasSourceId(3), HasSourceId(8))); } TEST_F(BuildDependenciesProvider, CreateCallsFetchUsedMacrosFromStorageIfTimeStampsAreUpToDate) @@ -181,7 +195,11 @@ TEST_F(BuildDependenciesProvider, CreateCallsFetchUsedMacrosFromStorageIfTimeSta InSequence s; EXPECT_CALL(mockSqliteTransactionBackend, deferredBegin()); - EXPECT_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, TypedEq("ProjectPart1"))).WillRepeatedly(Return(firstSources)); + EXPECT_CALL(mockBuildDependenciesStorage, + fetchProjectPartId(TypedEq("ProjectPart1"))) + .WillOnce(Return(11)); + EXPECT_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, 11)) + .WillRepeatedly(Return(firstSources)); EXPECT_CALL(mockSqliteTransactionBackend, commit()); EXPECT_CALL(mockModifiedTimeChecker, isUpToDate(firstSources)).WillRepeatedly(Return(true)); EXPECT_CALL(mockSqliteTransactionBackend, deferredBegin()); @@ -195,7 +213,10 @@ TEST_F(BuildDependenciesProvider, CreateCallsFetchUsedMacrosFromStorageIfTimeSta TEST_F(BuildDependenciesProvider, FetchUsedMacrosFromStorageIfDependSourcesAreUpToDate) { - ON_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, TypedEq("ProjectPart1"))).WillByDefault(Return(firstSources)); + ON_CALL(mockBuildDependenciesStorage, + fetchProjectPartId(TypedEq("ProjectPart1"))) + .WillByDefault(Return(11)); + ON_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, 11)).WillByDefault(Return(firstSources)); ON_CALL(mockModifiedTimeChecker, isUpToDate(firstSources)).WillByDefault(Return(true)); ON_CALL(mockBuildDependenciesStorage, fetchUsedMacros({1})).WillByDefault(Return(firstUsedMacros)); ON_CALL(mockBuildDependenciesStorage, fetchUsedMacros({2})).WillByDefault(Return(secondUsedMacros)); diff --git a/tests/unit/unittest/builddependenciesstorage-test.cpp b/tests/unit/unittest/builddependenciesstorage-test.cpp index d69f8b868a2..8112107e2b5 100644 --- a/tests/unit/unittest/builddependenciesstorage-test.cpp +++ b/tests/unit/unittest/builddependenciesstorage-test.cpp @@ -55,17 +55,20 @@ protected: MockSqliteWriteStatement &syncNewUsedMacrosStatement =storage.syncNewUsedMacrosStatement; MockSqliteWriteStatement &deleteOutdatedUsedMacrosStatement = storage.deleteOutdatedUsedMacrosStatement; MockSqliteWriteStatement &deleteNewUsedMacrosTableStatement = storage.deleteNewUsedMacrosTableStatement; - MockSqliteWriteStatement &insertFileStatuses = storage.insertFileStatusesStatement; + MockSqliteWriteStatement &insertOrUpdateFileStatusesStatement = storage.insertOrUpdateFileStatusesStatement; MockSqliteWriteStatement &insertIntoNewSourceDependenciesStatement = storage.insertIntoNewSourceDependenciesStatement; MockSqliteWriteStatement &syncNewSourceDependenciesStatement = storage.syncNewSourceDependenciesStatement; MockSqliteWriteStatement &deleteOutdatedSourceDependenciesStatement = storage.deleteOutdatedSourceDependenciesStatement; MockSqliteWriteStatement &deleteNewSourceDependenciesStatement = storage.deleteNewSourceDependenciesStatement; MockSqliteReadStatement &getLowestLastModifiedTimeOfDependencies = storage.getLowestLastModifiedTimeOfDependencies; - MockSqliteWriteStatement &updateBuildDependencyTimeStampStatement = storage.updateBuildDependencyTimeStampStatement; - MockSqliteWriteStatement &updateSourceTypeStatement = storage.updateSourceTypeStatement; + MockSqliteWriteStatement &insertOrUpdateSourceTypeStatement = storage.insertOrUpdateSourceTypeStatement; MockSqliteReadStatement &fetchSourceDependenciesStatement = storage.fetchSourceDependenciesStatement; MockSqliteReadStatement &fetchProjectPartIdStatement = storage.fetchProjectPartIdStatement; MockSqliteReadStatement &fetchUsedMacrosStatement = storage.fetchUsedMacrosStatement; + MockSqliteWriteStatement &insertProjectPartNameStatement = storage.insertProjectPartNameStatement; + MockSqliteWriteStatement &updatePchCreationTimeStampStatement = storage.updatePchCreationTimeStampStatement; + MockSqliteWriteStatement &deleteAllProjectPartsSourcesWithProjectPartNameStatement + = storage.deleteAllProjectPartsSourcesWithProjectPartNameStatement; }; TEST_F(BuildDependenciesStorage, ConvertStringsToJson) @@ -81,8 +84,10 @@ TEST_F(BuildDependenciesStorage, InsertOrUpdateUsedMacros) { InSequence sequence; - EXPECT_CALL(insertIntoNewUsedMacrosStatement, write(TypedEq(42u), TypedEq("FOO"))); - EXPECT_CALL(insertIntoNewUsedMacrosStatement, write(TypedEq(43u), TypedEq("BAR"))); + EXPECT_CALL(insertIntoNewUsedMacrosStatement, + write(TypedEq(42), TypedEq("FOO"))); + EXPECT_CALL(insertIntoNewUsedMacrosStatement, + write(TypedEq(43), TypedEq("BAR"))); EXPECT_CALL(syncNewUsedMacrosStatement, execute()); EXPECT_CALL(deleteOutdatedUsedMacrosStatement, execute()); EXPECT_CALL(deleteNewUsedMacrosTableStatement, execute()); @@ -90,12 +95,14 @@ TEST_F(BuildDependenciesStorage, InsertOrUpdateUsedMacros) storage.insertOrUpdateUsedMacros({{"FOO", 42}, {"BAR", 43}}); } -TEST_F(BuildDependenciesStorage, InsertFileStatuses) +TEST_F(BuildDependenciesStorage, InsertOrUpdateFileStatuses) { - EXPECT_CALL(insertFileStatuses, write(TypedEq(42), TypedEq(1), TypedEq(2), TypedEq(false))); - EXPECT_CALL(insertFileStatuses, write(TypedEq(43), TypedEq(4), TypedEq(5), TypedEq(true))); + EXPECT_CALL(insertOrUpdateFileStatusesStatement, + write(TypedEq(42), TypedEq(1), TypedEq(2))); + EXPECT_CALL(insertOrUpdateFileStatusesStatement, + write(TypedEq(43), TypedEq(4), TypedEq(5))); - storage.insertFileStatuses({{42, 1, 2, false}, {43, 4, 5, true}}); + storage.insertOrUpdateFileStatuses({{42, 1, 2}, {43, 4, 5}}); } TEST_F(BuildDependenciesStorage, InsertOrUpdateSourceDependencies) @@ -125,7 +132,6 @@ TEST_F(BuildDependenciesStorage, AddTablesInConstructor) Storage storage{mockDatabase}; } - TEST_F(BuildDependenciesStorage, FetchLowestLastModifiedTimeIfNoModificationTimeExists) { EXPECT_CALL(getLowestLastModifiedTimeOfDependencies, valueReturnInt64(Eq(1))); @@ -168,48 +174,82 @@ TEST_F(BuildDependenciesStorage, AddNewSourceDependenciesTable) TEST_F(BuildDependenciesStorage, UpdateSources) { InSequence s; - SourceEntries entries{{1, SourceType::TopProjectInclude, 10}, {2, SourceType::TopSystemInclude, 20}}; + SourceEntries entries{{1, SourceType::TopProjectInclude, 10}, + {2, SourceType::TopSystemInclude, 20}}; - EXPECT_CALL(updateBuildDependencyTimeStampStatement, write(TypedEq(10), TypedEq(1))); - EXPECT_CALL(updateSourceTypeStatement, write(TypedEq(0), TypedEq(1))); - EXPECT_CALL(updateBuildDependencyTimeStampStatement, write(TypedEq(20), TypedEq(2))); - EXPECT_CALL(updateSourceTypeStatement, write(TypedEq(1), TypedEq(2))); + EXPECT_CALL(deleteAllProjectPartsSourcesWithProjectPartNameStatement, write(TypedEq(22))); + EXPECT_CALL(insertOrUpdateSourceTypeStatement, + write(TypedEq(1), TypedEq(22), TypedEq(0))); + EXPECT_CALL(insertOrUpdateSourceTypeStatement, + write(TypedEq(2), TypedEq(22), TypedEq(1))); - storage.updateSources(entries); + storage.insertOrUpdateSources(entries, 22); } -TEST_F(BuildDependenciesStorage, CallsFetchDependSourcesWithNonExistingProjectPartDontFetchesSourceDependencies) +TEST_F(BuildDependenciesStorage, UpdatePchCreationTimeStamp) { - EXPECT_CALL(fetchProjectPartIdStatement, valueReturnInt32(TypedEq("test"))).WillOnce(Return(Utils::optional{})); - EXPECT_CALL(fetchSourceDependenciesStatement, valuesReturnSourceEntries(_, _, _)).Times(0); + InSequence s; - storage.fetchDependSources(22, "test"); + EXPECT_CALL(mockDatabase, immediateBegin()); + EXPECT_CALL(updatePchCreationTimeStampStatement, + write(TypedEq(101), TypedEq("project1"))); + EXPECT_CALL(mockDatabase, commit()); + + storage.updatePchCreationTimeStamp(101, "project1"); } -TEST_F(BuildDependenciesStorage, CallsFetchDependSourcesWithExistingProjectPartFetchesSourceDependencies) +TEST_F(BuildDependenciesStorage, CallsFetchProjectIdWithNonExistingProjectPartName) +{ + EXPECT_CALL(fetchProjectPartIdStatement, + valueReturnInt32(TypedEq("test"))); + EXPECT_CALL(insertProjectPartNameStatement, write(TypedEq("test"))); + + storage.fetchProjectPartId("test"); +} + +TEST_F(BuildDependenciesStorage, CallsFetchProjectIdWithExistingProjectPart) +{ + EXPECT_CALL(fetchProjectPartIdStatement, valueReturnInt32(TypedEq("test"))) + .WillOnce(Return(Utils::optional{20})); + EXPECT_CALL(insertProjectPartNameStatement, write(TypedEq("test"))).Times(0); + + storage.fetchProjectPartId("test"); +} + +TEST_F(BuildDependenciesStorage, FetchProjectIdWithNonExistingProjectPartName) +{ + ON_CALL(fetchProjectPartIdStatement, valueReturnInt32(TypedEq("test"))) + .WillByDefault(Return(Utils::optional{})); + ON_CALL(mockDatabase, lastInsertedRowId()).WillByDefault(Return(21)); + + int id = storage.fetchProjectPartId("test"); + + ASSERT_THAT(id, 21); +} + +TEST_F(BuildDependenciesStorage, FetchProjectIdWithExistingProjectPartName) +{ + ON_CALL(fetchProjectPartIdStatement, valueReturnInt32(TypedEq("test"))) + .WillByDefault(Return(Utils::optional{20})); + + int id = storage.fetchProjectPartId("test"); + + ASSERT_THAT(id, 20); +} + +TEST_F(BuildDependenciesStorage, CallsFetchDependSources) { - EXPECT_CALL(fetchProjectPartIdStatement, valueReturnInt32(TypedEq("test"))).WillOnce(Return(Utils::optional{20})); EXPECT_CALL(fetchSourceDependenciesStatement, valuesReturnSourceEntries(_, 22, 20)); - storage.fetchDependSources(22, "test"); + storage.fetchDependSources(22, 20); } -TEST_F(BuildDependenciesStorage, FetchDependSourcesWithNonExistingProjectPartReturnsEmptySourceEntries) -{ - EXPECT_CALL(fetchProjectPartIdStatement, valueReturnInt32(TypedEq("test"))).WillOnce(Return(Utils::optional{})); - - auto entries = storage.fetchDependSources(22, "test"); - - ASSERT_THAT(entries, IsEmpty()); -} - -TEST_F(BuildDependenciesStorage, FetchDependSourcesWithExistingProjectPartReturnsSourceEntries) +TEST_F(BuildDependenciesStorage, FetchDependSources) { SourceEntries sourceEntries{{1, SourceType::TopProjectInclude, 10}, {2, SourceType::TopSystemInclude, 20}}; - EXPECT_CALL(fetchProjectPartIdStatement, valueReturnInt32(TypedEq("test"))).WillOnce(Return(Utils::optional{20})); EXPECT_CALL(fetchSourceDependenciesStatement, valuesReturnSourceEntries(_, 22, 20)).WillOnce(Return(sourceEntries)); - auto entries = storage.fetchDependSources(22, "test"); + auto entries = storage.fetchDependSources(22, 20); ASSERT_THAT(entries, sourceEntries); } diff --git a/tests/unit/unittest/builddependencycollector-test.cpp b/tests/unit/unittest/builddependencycollector-test.cpp index aa46fc77bb1..d8965c0a9f8 100644 --- a/tests/unit/unittest/builddependencycollector-test.cpp +++ b/tests/unit/unittest/builddependencycollector-test.cpp @@ -53,7 +53,9 @@ using ClangBackEnd::UsedMacro; namespace { -MATCHER_P2(HasInclude, sourceId, sourceType, +MATCHER_P2(HasSource, + sourceId, + sourceType, std::string(negation ? "hasn't " : "has ") + PrintToString(ClangBackEnd::SourceEntry(sourceId, sourceType, -1))) { @@ -107,50 +109,50 @@ protected: ClangBackEnd::FileStatus fileStatus(Utils::SmallStringView filePath) const { - return {id(filePath), fileSize(filePath), lastModified(filePath), false}; + return {id(filePath), fileSize(filePath), lastModified(filePath)}; } - static FilePathIds filteredIncludes(const ClangBackEnd::SourceEntries &includes, - ClangBackEnd::SourceType includeType) + static FilePathIds filteredSources(const ClangBackEnd::SourceEntries &sources, + ClangBackEnd::SourceType sourceType) { - FilePathIds filteredIncludes; + FilePathIds filteredSources; - for (const ClangBackEnd::SourceEntry &include : includes) { - if (include.sourceType == includeType) - filteredIncludes.push_back(include.sourceId); + for (const ClangBackEnd::SourceEntry &source : sources) { + if (source.sourceType == sourceType) + filteredSources.push_back(source.sourceId); } - return filteredIncludes; + return filteredSources; } - static FilePathIds topIncludes(const ClangBackEnd::SourceEntries &includes) + static FilePathIds topSources(const ClangBackEnd::SourceEntries &sources) { - return filteredIncludes(includes, ClangBackEnd::SourceType::TopProjectInclude); + return filteredSources(sources, ClangBackEnd::SourceType::TopProjectInclude); } - static FilePathIds systemTopIncludes(const ClangBackEnd::SourceEntries &includes) + static FilePathIds systemTopSources(const ClangBackEnd::SourceEntries &sources) { - return filteredIncludes(includes, ClangBackEnd::SourceType::TopSystemInclude); + return filteredSources(sources, ClangBackEnd::SourceType::TopSystemInclude); } - static FilePathIds userIncludes(const ClangBackEnd::SourceEntries &includes) + static FilePathIds userSources(const ClangBackEnd::SourceEntries &sources) { - return filteredIncludes(includes, ClangBackEnd::SourceType::UserInclude); + return filteredSources(sources, ClangBackEnd::SourceType::UserInclude); } - static FilePathIds projectPartIncludes(const ClangBackEnd::SourceEntries &includes) + static FilePathIds projectPartSources(const ClangBackEnd::SourceEntries &sources) { - return filteredIncludes(includes, ClangBackEnd::SourceType::ProjectInclude); + return filteredSources(sources, ClangBackEnd::SourceType::ProjectInclude); } - static FilePathIds allIncludes(const ClangBackEnd::SourceEntries &includes) + static FilePathIds sources(const ClangBackEnd::SourceEntries &sources) { - FilePathIds filteredIncludes; + FilePathIds filteredSources; - for (const ClangBackEnd::SourceEntry &include : includes) - filteredIncludes.push_back(include.sourceId); + for (const ClangBackEnd::SourceEntry &source : sources) + filteredSources.push_back(source.sourceId); - return filteredIncludes; + return filteredSources; } protected: @@ -173,26 +175,30 @@ TEST_F(BuildDependencyCollector, IncludesExternalHeader) { collector.collect(); - ASSERT_THAT(allIncludes(collector.includeIds()), + ASSERT_THAT(sources(collector.sourceEntries()), AllOf(Contains(id(TESTDATA_DIR "/builddependencycollector/external/external1.h")), Contains(id(TESTDATA_DIR "/builddependencycollector/external/external2.h")), - Contains(id(TESTDATA_DIR "/builddependencycollector/external/indirect_external.h")), - Contains(id(TESTDATA_DIR "/builddependencycollector/external/indirect_external2.h")))); + Contains(id(TESTDATA_DIR + "/builddependencycollector/external/indirect_external.h")), + Contains(id(TESTDATA_DIR + "/builddependencycollector/external/indirect_external2.h")))); } TEST_F(BuildDependencyCollector, InternalHeaderAreUserIncludes) { collector.collect(); - ASSERT_THAT(userIncludes(collector.includeIds()), Contains(id(TESTDATA_DIR "/builddependencycollector/project/header1.h"))); + ASSERT_THAT(userSources(collector.sourceEntries()), + Contains(id(TESTDATA_DIR "/builddependencycollector/project/header1.h"))); } TEST_F(BuildDependencyCollector, NoDuplicate) { collector.collect(); - ASSERT_THAT(allIncludes(collector.includeIds()), + ASSERT_THAT(sources(collector.sourceEntries()), UnorderedElementsAre( + id(TESTDATA_DIR "/builddependencycollector/project/main.cpp"), id(TESTDATA_DIR "/builddependencycollector/project/header1.h"), id(TESTDATA_DIR "/builddependencycollector/project/header2.h"), id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), @@ -206,15 +212,17 @@ TEST_F(BuildDependencyCollector, IncludesAreSorted) { collector.collect(); - ASSERT_THAT(allIncludes(collector.includeIds()), - ElementsAre( - id(TESTDATA_DIR "/builddependencycollector/project/header1.h"), - id(TESTDATA_DIR "/builddependencycollector/project/header2.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external3.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), - id(TESTDATA_DIR "/builddependencycollector/external/indirect_external.h"), - id(TESTDATA_DIR "/builddependencycollector/external/indirect_external2.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external2.h"))); + ASSERT_THAT(sources(collector.sourceEntries()), + ElementsAre(id(TESTDATA_DIR "/builddependencycollector/project/main.cpp"), + id(TESTDATA_DIR "/builddependencycollector/project/header1.h"), + id(TESTDATA_DIR "/builddependencycollector/project/header2.h"), + id(TESTDATA_DIR "/builddependencycollector/external/external3.h"), + id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), + id(TESTDATA_DIR + "/builddependencycollector/external/indirect_external.h"), + id(TESTDATA_DIR + "/builddependencycollector/external/indirect_external2.h"), + id(TESTDATA_DIR "/builddependencycollector/external/external2.h"))); } TEST_F(BuildDependencyCollector, If) @@ -223,8 +231,9 @@ TEST_F(BuildDependencyCollector, If) emptyCollector.collect(); - ASSERT_THAT(allIncludes(emptyCollector.includeIds()), - ElementsAre(id(TESTDATA_DIR "/builddependencycollector/project/true.h"))); + ASSERT_THAT(sources(emptyCollector.sourceEntries()), + ElementsAre(id(TESTDATA_DIR "/builddependencycollector/project/if.cpp"), + id(TESTDATA_DIR "/builddependencycollector/project/true.h"))); } TEST_F(BuildDependencyCollector, LocalPath) @@ -233,8 +242,9 @@ TEST_F(BuildDependencyCollector, LocalPath) emptyCollector.collect(); - ASSERT_THAT(allIncludes(emptyCollector.includeIds()), + ASSERT_THAT(sources(emptyCollector.sourceEntries()), UnorderedElementsAre( + id(TESTDATA_DIR "/builddependencycollector/project/main.cpp"), id(TESTDATA_DIR "/builddependencycollector/project/header1.h"), id(TESTDATA_DIR "/builddependencycollector/project/header2.h"), id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), @@ -250,20 +260,22 @@ TEST_F(BuildDependencyCollector, IgnoreMissingFile) emptyCollector.collect(); - ASSERT_THAT(allIncludes(emptyCollector.includeIds()), - UnorderedElementsAre(id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), - id(TESTDATA_DIR "/builddependencycollector/external/indirect_external.h"), - id(TESTDATA_DIR "/builddependencycollector/external/indirect_external2.h"))); + ASSERT_THAT(sources(emptyCollector.sourceEntries()), + UnorderedElementsAre( + id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), + id(TESTDATA_DIR "/builddependencycollector/external/indirect_external.h"), + id(TESTDATA_DIR "/builddependencycollector/external/indirect_external2.h"))); } TEST_F(BuildDependencyCollector, IncludesOnlyTopExternalHeader) { collector.collect(); - ASSERT_THAT(topIncludes(collector.includeIds()), - UnorderedElementsAre(id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external2.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external3.h"))); + ASSERT_THAT( + topSources(collector.sourceEntries()), + UnorderedElementsAre(id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), + id(TESTDATA_DIR "/builddependencycollector/external/external2.h"), + id(TESTDATA_DIR "/builddependencycollector/external/external3.h"))); } TEST_F(BuildDependencyCollector, TopIncludeInIfMacro) @@ -273,7 +285,7 @@ TEST_F(BuildDependencyCollector, TopIncludeInIfMacro) emptyCollector.collect(); - ASSERT_THAT(topIncludes(emptyCollector.includeIds()), + ASSERT_THAT(topSources(emptyCollector.sourceEntries()), ElementsAre(id(TESTDATA_DIR "/builddependencycollector/project/true.h"))); } @@ -283,10 +295,11 @@ TEST_F(BuildDependencyCollector, TopIncludeWithLocalPath) emptyCollector.collect(); - ASSERT_THAT(topIncludes(emptyCollector.includeIds()), - UnorderedElementsAre(id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external2.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external3.h"))); + ASSERT_THAT( + topSources(emptyCollector.sourceEntries()), + UnorderedElementsAre(id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), + id(TESTDATA_DIR "/builddependencycollector/external/external2.h"), + id(TESTDATA_DIR "/builddependencycollector/external/external3.h"))); } TEST_F(BuildDependencyCollector, TopIncludesIgnoreMissingFile) @@ -296,8 +309,9 @@ TEST_F(BuildDependencyCollector, TopIncludesIgnoreMissingFile) emptyCollector.collect(); - ASSERT_THAT(topIncludes(emptyCollector.includeIds()), - UnorderedElementsAre(id(TESTDATA_DIR "/builddependencycollector/external/external1.h"))); + ASSERT_THAT(topSources(emptyCollector.sourceEntries()), + UnorderedElementsAre( + id(TESTDATA_DIR "/builddependencycollector/external/external1.h"))); } TEST_F(BuildDependencyCollector, SourceFiles) @@ -620,10 +634,10 @@ TEST_F(BuildDependencyCollector, MissingInclude) emptyCollector.collect(); - ASSERT_THAT(emptyCollector.includeIds(), + ASSERT_THAT(emptyCollector.sourceEntries(), ElementsAre( - HasInclude(id(TESTDATA_DIR "/builddependencycollector/project/header1.h"), - SourceType::UserInclude))); + HasSource(id(TESTDATA_DIR "/builddependencycollector/project/header1.h"), + SourceType::UserInclude))); } @@ -643,10 +657,12 @@ TEST_F(BuildDependencyCollector, GeneratedFile) emptyCollector.collect(); - ASSERT_THAT(emptyCollector.includeIds(), - ElementsAre( - HasInclude(id(TESTDATA_DIR "/builddependencycollector/project/generated_file.h"), - SourceType::UserInclude))); + ASSERT_THAT( + emptyCollector.sourceEntries(), + ElementsAre(HasSource(id(TESTDATA_DIR "/builddependencycollector/project/main6.cpp"), + SourceType::Source), + HasSource(id(TESTDATA_DIR "/builddependencycollector/project/generated_file.h"), + SourceType::UserInclude))); } TEST_F(BuildDependencyCollector, CreateFakeFileContent) @@ -715,41 +731,37 @@ TEST_F(BuildDependencyCollector, Create) fileStatus(TESTDATA_DIR "/builddependencycollector/project/missingfile.h"), fileStatus(TESTDATA_DIR "/builddependencycollector/project/macros.h"), ClangBackEnd::FileStatus( - id(TESTDATA_DIR "/builddependencycollector/project/generated_file.h"), - 12, - 0, - false))), - Field(&BuildDependency::includes, - UnorderedElementsAre( - HasInclude(id(TESTDATA_DIR "/builddependencycollector/project/header1.h"), - SourceType::UserInclude), - HasInclude(id(TESTDATA_DIR "/builddependencycollector/project/header2.h"), - SourceType::UserInclude), - HasInclude(id(TESTDATA_DIR "/builddependencycollector/external/external3.h"), - SourceType::TopProjectInclude), - HasInclude(id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), - SourceType::TopProjectInclude), - HasInclude(id(TESTDATA_DIR - "/builddependencycollector/external/indirect_external.h"), - SourceType::ProjectInclude), - HasInclude(id(TESTDATA_DIR - "/builddependencycollector/external/indirect_external2.h"), - SourceType::ProjectInclude), - HasInclude(id(TESTDATA_DIR "/builddependencycollector/external/external2.h"), - SourceType::TopProjectInclude), - HasInclude(id(TESTDATA_DIR "/builddependencycollector/system/system1.h"), - SourceType::TopSystemInclude), - HasInclude(id(TESTDATA_DIR - "/builddependencycollector/system/indirect_system.h"), - SourceType::SystemInclude), - HasInclude(id(TESTDATA_DIR - "/builddependencycollector/system/indirect_system2.h"), - SourceType::SystemInclude), - HasInclude(id(TESTDATA_DIR "/builddependencycollector/project/macros.h"), - SourceType::UserInclude), - HasInclude(id(TESTDATA_DIR - "/builddependencycollector/project/generated_file.h"), - SourceType::TopProjectInclude))), + id(TESTDATA_DIR "/builddependencycollector/project/generated_file.h"), 12, 0))), + Field( + &BuildDependency::sources, + UnorderedElementsAre( + HasSource(id(TESTDATA_DIR "/builddependencycollector/project/header1.h"), + SourceType::UserInclude), + HasSource(id(TESTDATA_DIR "/builddependencycollector/project/header2.h"), + SourceType::UserInclude), + HasSource(id(TESTDATA_DIR "/builddependencycollector/external/external3.h"), + SourceType::TopProjectInclude), + HasSource(id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), + SourceType::TopProjectInclude), + HasSource(id(TESTDATA_DIR + "/builddependencycollector/external/indirect_external.h"), + SourceType::ProjectInclude), + HasSource(id(TESTDATA_DIR + "/builddependencycollector/external/indirect_external2.h"), + SourceType::ProjectInclude), + HasSource(id(TESTDATA_DIR "/builddependencycollector/external/external2.h"), + SourceType::TopProjectInclude), + HasSource(id(TESTDATA_DIR "/builddependencycollector/system/system1.h"), + SourceType::TopSystemInclude), + HasSource(id(TESTDATA_DIR "/builddependencycollector/system/indirect_system.h"), + SourceType::SystemInclude), + HasSource(id(TESTDATA_DIR + "/builddependencycollector/system/indirect_system2.h"), + SourceType::SystemInclude), + HasSource(id(TESTDATA_DIR "/builddependencycollector/project/macros.h"), + SourceType::UserInclude), + HasSource(id(TESTDATA_DIR "/builddependencycollector/project/generated_file.h"), + SourceType::UserInclude))), Field(&BuildDependency::usedMacros, UnorderedElementsAre( UsedMacro{"IFDEF", id(TESTDATA_DIR "/builddependencycollector/project/macros.h")}, @@ -843,6 +855,6 @@ TEST_F(BuildDependencyCollector, Clear) auto buildDependency = collector.create(projectPart); - ASSERT_THAT(buildDependency.includes, IsEmpty()); + ASSERT_THAT(buildDependency.sources, IsEmpty()); } } // namespace diff --git a/tests/unit/unittest/filepathstorage-test.cpp b/tests/unit/unittest/filepathstorage-test.cpp index be689b44f32..c08c84e9132 100644 --- a/tests/unit/unittest/filepathstorage-test.cpp +++ b/tests/unit/unittest/filepathstorage-test.cpp @@ -189,7 +189,8 @@ TEST_F(FilePathStorage, CallWriteForWriteDirectory) TEST_F(FilePathStorage, CallWriteForWriteSource) { - EXPECT_CALL(insertIntoSources, write(5, TypedEq("unknownfile.h"))); + EXPECT_CALL(insertIntoSources, + write(TypedEq(5), TypedEq("unknownfile.h"))); storage.writeSourceId(5, "unknownfile.h"); } @@ -280,7 +281,8 @@ TEST_F(FilePathStorage, CallSelectAndWriteForFetchingSourceIdForUnknownEntry) EXPECT_CALL(mockDatabase, deferredBegin()); EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, valueReturnInt32(5, Eq("unknownfile.h"))); - EXPECT_CALL(insertIntoSources, write(5, TypedEq("unknownfile.h"))); + EXPECT_CALL(insertIntoSources, + write(TypedEq(5), TypedEq("unknownfile.h"))); EXPECT_CALL(mockDatabase, commit()); storage.fetchSourceId(5, "unknownfile.h"); @@ -347,7 +349,8 @@ TEST_F(FilePathStorage, RestartFetchSourceIdIfTheDatabaseIsBusyInBeginBecauseThe EXPECT_CALL(mockDatabase, deferredBegin()); EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, valueReturnInt32(5, Eq("otherunknownfile.h"))); - EXPECT_CALL(insertIntoSources, write(5, TypedEq("otherunknownfile.h"))); + EXPECT_CALL(insertIntoSources, + write(TypedEq(5), TypedEq("otherunknownfile.h"))); EXPECT_CALL(mockDatabase, commit()); storage.fetchSourceId(5, "otherunknownfile.h"); @@ -360,13 +363,16 @@ TEST_F(FilePathStorage, CallSelectAndWriteForFetchingSourceTwoTimesIfTheDatabase EXPECT_CALL(mockDatabase, deferredBegin()); EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, valueReturnInt32(5, Eq("otherunknownfile.h"))); - EXPECT_CALL(insertIntoSources, write(5, TypedEq("otherunknownfile.h"))) - .WillOnce(Throw(Sqlite::StatementIsBusy("busy")));; + EXPECT_CALL(insertIntoSources, + write(TypedEq(5), TypedEq("otherunknownfile.h"))) + .WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); + ; EXPECT_CALL(mockDatabase, rollback()); EXPECT_CALL(mockDatabase, deferredBegin()); EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, valueReturnInt32(5, Eq("otherunknownfile.h"))); - EXPECT_CALL(insertIntoSources, write(5, TypedEq("otherunknownfile.h"))); + EXPECT_CALL(insertIntoSources, + write(TypedEq(5), TypedEq("otherunknownfile.h"))); EXPECT_CALL(mockDatabase, commit()); storage.fetchSourceId(5, "otherunknownfile.h"); @@ -379,12 +385,14 @@ TEST_F(FilePathStorage, CallSelectAndWriteForFetchingSourceTwoTimesIfTheIndexIsC EXPECT_CALL(mockDatabase,deferredBegin()); EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, valueReturnInt32(5, Eq("otherunknownfile.h"))); - EXPECT_CALL(insertIntoSources, write(5, TypedEq("otherunknownfile.h"))) - .WillOnce(Throw(Sqlite::ConstraintPreventsModification("busy")));; + EXPECT_CALL(insertIntoSources, + write(TypedEq(5), TypedEq("otherunknownfile.h"))) + .WillOnce(Throw(Sqlite::ConstraintPreventsModification("busy"))); EXPECT_CALL(mockDatabase, rollback()); EXPECT_CALL(mockDatabase,deferredBegin()); EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, - valueReturnInt32(5, Eq("otherunknownfile.h"))); + valueReturnInt32(5, Eq("otherunknownfile.h"))) + .WillOnce(Return(Utils::optional(42))); EXPECT_CALL(mockDatabase, commit()); storage.fetchSourceId(5, "otherunknownfile.h"); diff --git a/tests/unit/unittest/gtest-creator-printing.cpp b/tests/unit/unittest/gtest-creator-printing.cpp index 60f5e526cb6..63dde52dc21 100644 --- a/tests/unit/unittest/gtest-creator-printing.cpp +++ b/tests/unit/unittest/gtest-creator-printing.cpp @@ -45,7 +45,6 @@ #include #include #include -#include #include #include #include @@ -1151,11 +1150,6 @@ std::ostream &operator<<(std::ostream &out, const ProgressMessage &message) << message.total << ")"; } -std::ostream &operator<<(std::ostream &out, const PchCreatorIncludes &includes) -{ - return out << "(" << includes.includeIds << ", " << includes.topIncludeIds << ", " - << includes.topSystemIncludeIds << ")"; -} std::ostream &operator<<(std::ostream &out, const PchTask &task) { return out << "(" << task.projectPartIds << ", " << task.includes << ", " << task.compilerMacros @@ -1172,11 +1166,11 @@ std::ostream &operator<<(std::ostream &out, const PchTaskSet &taskSet) std::ostream &operator<<(std::ostream &out, const BuildDependency &dependency) { return out << "(\n" - << "includes: " << dependency.includes << ",\n" - << "usedMacros: " << dependency.usedMacros << ",\n" - << "fileStatuses: " << dependency.fileStatuses << ",\n" - << "sourceFiles: " << dependency.sourceFiles << ",\n" - << "sourceDependencies: " << dependency.sourceDependencies << ",\n" + << "includes: " << dependency.sources << ",\n" + << "usedMacros: " << dependency.usedMacros << ",\n" + << "fileStatuses: " << dependency.fileStatuses << ",\n" + << "sourceFiles: " << dependency.sourceFiles << ",\n" + << "sourceDependencies: " << dependency.sourceDependencies << ",\n" << ")"; } @@ -1200,6 +1194,8 @@ const char *sourceTypeString(SourceType sourceType) return "ProjectInclude"; case SourceType::UserInclude: return "UserInclude"; + case SourceType::Source: + return "Source"; } return ""; diff --git a/tests/unit/unittest/gtest-creator-printing.h b/tests/unit/unittest/gtest-creator-printing.h index cb63fd56bb9..75eae281ae4 100644 --- a/tests/unit/unittest/gtest-creator-printing.h +++ b/tests/unit/unittest/gtest-creator-printing.h @@ -186,7 +186,6 @@ class SuspendResumeJobsEntry; class ReferencesResult; class SymbolIndexerTask; class ProgressMessage; -class PchCreatorIncludes; class PchTask; class PchTaskSet; class BuildDependency; @@ -277,7 +276,6 @@ std::ostream &operator<<(std::ostream &os, const SuspendResumeJobsEntry &entry); std::ostream &operator<<(std::ostream &os, const ReferencesResult &value); std::ostream &operator<<(std::ostream &out, const SymbolIndexerTask &task); std::ostream &operator<<(std::ostream &out, const ProgressMessage &message); -std::ostream &operator<<(std::ostream &out, const PchCreatorIncludes &includes); std::ostream &operator<<(std::ostream &out, const PchTask &task); std::ostream &operator<<(std::ostream &out, const PchTaskSet &taskSet); std::ostream &operator<<(std::ostream &out, const BuildDependency &dependency); diff --git a/tests/unit/unittest/mockbuilddependenciesstorage.h b/tests/unit/unittest/mockbuilddependenciesstorage.h index a654579a831..739c13cf8da 100644 --- a/tests/unit/unittest/mockbuilddependenciesstorage.h +++ b/tests/unit/unittest/mockbuilddependenciesstorage.h @@ -32,19 +32,22 @@ class MockBuildDependenciesStorage : public ClangBackEnd::BuildDependenciesStorageInterface { public: - MOCK_METHOD1(updateSources, - void (const ClangBackEnd::SourceEntries &sources)); + MOCK_METHOD2(insertOrUpdateSources, + void(const ClangBackEnd::SourceEntries &sources, int projectPartId)); MOCK_METHOD1(insertOrUpdateUsedMacros, void (const ClangBackEnd::UsedMacros &usedMacros)); - MOCK_METHOD1(insertFileStatuses, - void (const ClangBackEnd::FileStatuses &fileStatuses)); + MOCK_METHOD1(insertOrUpdateFileStatuses, void(const ClangBackEnd::FileStatuses &fileStatuses)); MOCK_METHOD1(insertOrUpdateSourceDependencies, void (const ClangBackEnd::SourceDependencies &sourceDependencies)); MOCK_CONST_METHOD1(fetchLowestLastModifiedTime, long long (ClangBackEnd::FilePathId sourceId)); MOCK_CONST_METHOD2(fetchDependSources, - ClangBackEnd::SourceEntries (ClangBackEnd::FilePathId sourceId, Utils::SmallStringView)); + ClangBackEnd::SourceEntries(ClangBackEnd::FilePathId sourceId, + int projectPartId)); MOCK_CONST_METHOD1(fetchUsedMacros, ClangBackEnd::UsedMacros (ClangBackEnd::FilePathId sourceId)); + MOCK_METHOD1(fetchProjectPartId, int(Utils::SmallStringView projectPartName)); + MOCK_METHOD2(updatePchCreationTimeStamp, + void(long long pchCreationTimeStamp, Utils::SmallStringView projectPartName)); }; diff --git a/tests/unit/unittest/mocksqlitedatabase.h b/tests/unit/unittest/mocksqlitedatabase.h index 0b890e01f0a..5bef2ba8c51 100644 --- a/tests/unit/unittest/mocksqlitedatabase.h +++ b/tests/unit/unittest/mocksqlitedatabase.h @@ -39,8 +39,8 @@ class MockSqliteDatabase : public MockSqliteTransactionBackend { public: - using ReadStatement = MockSqliteReadStatement; - using WriteStatement = MockSqliteWriteStatement; + using ReadStatement = NiceMock; + using WriteStatement = NiceMock; MOCK_METHOD1(execute, void (Utils::SmallStringView sqlStatement)); diff --git a/tests/unit/unittest/mocksqlitewritestatement.h b/tests/unit/unittest/mocksqlitewritestatement.h index ee7df6362f7..edaea7d7e18 100644 --- a/tests/unit/unittest/mocksqlitewritestatement.h +++ b/tests/unit/unittest/mocksqlitewritestatement.h @@ -42,8 +42,7 @@ public: MOCK_METHOD0(execute, void ()); - MOCK_METHOD2(bind, - void (int index, Utils::SmallStringView value)); + MOCK_METHOD2(bind, void(int, Utils::SmallStringView)); MOCK_METHOD2(bindValues, void (Utils::SmallStringView, Utils::SmallStringView)); @@ -60,11 +59,11 @@ public: MOCK_METHOD5(write, void (long long, int, int, int, int)); - MOCK_METHOD2(write, - void (uint, Utils::SmallStringView)); + MOCK_METHOD2(write, void(uint, Utils::SmallStringView)); - MOCK_METHOD2(write, - void (Utils::SmallStringView, Utils::SmallStringView)); + MOCK_METHOD2(write, void(int, Utils::SmallStringView)); + + MOCK_METHOD2(write, void(Utils::SmallStringView, Utils::SmallStringView)); MOCK_METHOD3(write, void (Utils::SmallStringView, Utils::SmallStringView, long long)); @@ -103,17 +102,16 @@ public: MOCK_METHOD3(write, void (uint, uint, uint)); - MOCK_METHOD4(write, - void (int, off_t, time_t, bool)); + MOCK_METHOD3(write, void(int, off_t, time_t)); MOCK_METHOD2(write, void (uint, uint)); MOCK_METHOD2(write, void (uchar, int)); - + MOCK_METHOD3(write, void(int, int, uchar)); MOCK_METHOD2(write, void (long long, int)); - + MOCK_METHOD2(write, void(long long, Utils::SmallStringView)); Utils::SmallString sqlStatement; }; diff --git a/tests/unit/unittest/mocksymbolstorage.h b/tests/unit/unittest/mocksymbolstorage.h index 325e18b1c97..c4b55fcfe41 100644 --- a/tests/unit/unittest/mocksymbolstorage.h +++ b/tests/unit/unittest/mocksymbolstorage.h @@ -46,9 +46,6 @@ public: Utils::Language language, Utils::LanguageVersion languageVersion, Utils::LanguageExtension languageExtension)); - MOCK_METHOD2(updateProjectPartSources, - void(int projectPartId, - const ClangBackEnd::FilePathIds &sourceFilePathIds)); MOCK_CONST_METHOD1(fetchProjectPartArtefact, Utils::optional (ClangBackEnd::FilePathId sourceId)); MOCK_CONST_METHOD1(fetchProjectPartArtefact, diff --git a/tests/unit/unittest/pchcreator-test.cpp b/tests/unit/unittest/pchcreator-test.cpp index d891a089871..b28769b51bb 100644 --- a/tests/unit/unittest/pchcreator-test.cpp +++ b/tests/unit/unittest/pchcreator-test.cpp @@ -28,6 +28,7 @@ #include "fakeprocess.h" #include "filesystem-utilities.h" +#include "mockbuilddependenciesstorage.h" #include "mockclangpathwatcher.h" #include "mockpchmanagerclient.h" #include "testenvironment.h" @@ -97,16 +98,22 @@ protected: FileContainer generatedFile{generatedFilePath.clone(), "#pragma once", {}}; NiceMock mockPchManagerClient; NiceMock mockClangPathWatcher; - ClangBackEnd::PchCreator creator{environment, database, mockPchManagerClient, mockClangPathWatcher}; + NiceMock mockBuildDependenciesStorage; + ClangBackEnd::PchCreator creator{environment, + database, + mockPchManagerClient, + mockClangPathWatcher, + mockBuildDependenciesStorage}; PchTask pchTask1{ "project1", {id(TESTDATA_DIR "/builddependencycollector/project/header2.h"), id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), id(TESTDATA_DIR "/builddependencycollector/external/external2.h")}, - {id(generatedFilePath), - id(TESTDATA_DIR "/builddependencycollector/project/header2.h"), + {id(TESTDATA_DIR "/builddependencycollector/project/header2.h"), id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external2.h")}, + id(TESTDATA_DIR "/builddependencycollector/external/external2.h"), + id(generatedFilePath), + id(main2Path)}, {}, {}, {}, @@ -190,25 +197,24 @@ TEST_F(PchCreatorVerySlowTest, ProjectPartPchsSendToPchManagerClient) creator.doInMainThreadAfterFinished(); } -TEST_F(PchCreatorVerySlowTest, AllIncludesAreWatchedAfterSucess) +TEST_F(PchCreatorVerySlowTest, SourcesAreWatchedAfterSucess) { creator.generatePch(std::move(pchTask1)); - EXPECT_CALL( - mockClangPathWatcher, - updateIdPaths(ElementsAre( - AllOf(Field(&ClangBackEnd::IdPaths::id, "project1"), - Field(&ClangBackEnd::IdPaths::filePathIds, - UnorderedElementsAre( - id(TESTDATA_DIR "/builddependencycollector/project/header2.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external2.h"))))))); + EXPECT_CALL(mockClangPathWatcher, + updateIdPaths(ElementsAre(AllOf( + Field(&ClangBackEnd::IdPaths::id, "project1"), + Field(&ClangBackEnd::IdPaths::filePathIds, + UnorderedElementsAre( + id(TESTDATA_DIR "/builddependencycollector/project/header2.h"), + id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), + id(TESTDATA_DIR "/builddependencycollector/external/external2.h"), + id(TESTDATA_DIR "/builddependencycollector/project/main2.cpp"))))))); creator.doInMainThreadAfterFinished(); } - -TEST_F(PchCreatorVerySlowTest, AllIncludesAreNotWatchedAfterFail) +TEST_F(PchCreatorVerySlowTest, SourcesAreNotWatchedAfterFail) { pchTask1.systemIncludeSearchPaths = {}; pchTask1.projectIncludeSearchPaths = {}; @@ -222,6 +228,15 @@ TEST_F(PchCreatorVerySlowTest, AllIncludesAreNotWatchedAfterFail) creator.doInMainThreadAfterFinished(); } +TEST_F(PchCreatorVerySlowTest, PchCreationTimeStampsAreUpdated) +{ + creator.generatePch(std::move(pchTask1)); + + EXPECT_CALL(mockBuildDependenciesStorage, updatePchCreationTimeStamp(_, Eq("project1"))); + + creator.doInMainThreadAfterFinished(); +} + TEST_F(PchCreatorVerySlowTest, ProjectPartPchForCreatesPchForPchTask) { creator.generatePch(std::move(pchTask1)); @@ -241,6 +256,15 @@ TEST_F(PchCreatorVerySlowTest, ProjectPartPchCleared) ASSERT_THAT(creator.projectPartPch(), ClangBackEnd::ProjectPartPch{}); } +TEST_F(PchCreatorVerySlowTest, SourcesCleared) +{ + creator.generatePch(std::move(pchTask1)); + + creator.clear(); + + ASSERT_THAT(creator.sources(), IsEmpty()); +} + TEST_F(PchCreatorVerySlowTest, ClangToolCleared) { creator.generatePch(std::move(pchTask1)); @@ -266,7 +290,7 @@ TEST_F(PchCreatorVerySlowTest, FaultyProjectPartPchForCreatesFaultyPchForPchTask ASSERT_THAT(creator.projectPartPch(), AllOf(Field(&ProjectPartPch::projectPartId, Eq("faultyProjectPart")), Field(&ProjectPartPch::pchPath, IsEmpty()), - Field(&ProjectPartPch::lastModified, Eq(-1)))); + Field(&ProjectPartPch::lastModified, Gt(0)))); } TEST_F(PchCreatorVerySlowTest, GeneratedFile) diff --git a/tests/unit/unittest/pchtaskgenerator-test.cpp b/tests/unit/unittest/pchtaskgenerator-test.cpp index d85432baf25..a6946f7ccff 100644 --- a/tests/unit/unittest/pchtaskgenerator-test.cpp +++ b/tests/unit/unittest/pchtaskgenerator-test.cpp @@ -99,7 +99,7 @@ TEST_F(PchTaskGenerator, AddProjectParts) Field(&PchTaskSet::system, AllOf(Field(&PchTask::projectPartIds, ElementsAre("ProjectPart1")), Field(&PchTask::includes, ElementsAre(5)), - Field(&PchTask::allIncludes, IsEmpty()), + Field(&PchTask::sources, IsEmpty()), Field(&PchTask::compilerMacros, ElementsAre(CompilerMacro{"SE", "4", 4}, CompilerMacro{"WU", "5", 5})), Field(&PchTask::systemIncludeSearchPaths, @@ -116,7 +116,7 @@ TEST_F(PchTaskGenerator, AddProjectParts) &PchTaskSet::project, AllOf(Field(&PchTask::projectPartIds, ElementsAre("ProjectPart1")), Field(&PchTask::includes, ElementsAre(3)), - Field(&PchTask::allIncludes, ElementsAre(1, 2, 3, 4, 5)), + Field(&PchTask::sources, ElementsAre(1, 2, 3, 4, 5)), Field(&PchTask::compilerMacros, ElementsAre(CompilerMacro{"YI", "1", 1}, CompilerMacro{"SAN", "3", 3})), Field(&PchTask::systemIncludeSearchPaths, diff --git a/tests/unit/unittest/pchtasksmerger-test.cpp b/tests/unit/unittest/pchtasksmerger-test.cpp index c279da505e7..da61d14adbd 100644 --- a/tests/unit/unittest/pchtasksmerger-test.cpp +++ b/tests/unit/unittest/pchtasksmerger-test.cpp @@ -272,14 +272,14 @@ TEST_F(PchTasksMerger, MergeAllIncludes) { Merger::mergePchTasks(systemTask1, systemTask2); - ASSERT_THAT(systemTask1.allIncludes, ElementsAre(1, 2, 3, 11, 12, 13)); + ASSERT_THAT(systemTask1.sources, ElementsAre(1, 2, 3, 11, 12, 13)); } TEST_F(PchTasksMerger, DontAllMergeIncludes) { Merger::mergePchTasks(systemTask1, systemTask3); - ASSERT_THAT(systemTask1.allIncludes, ElementsAre(1, 2, 3)); + ASSERT_THAT(systemTask1.sources, ElementsAre(1, 2, 3)); } TEST_F(PchTasksMerger, MergeProjectIds) diff --git a/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp b/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp index 7e1e730b179..34eaec10bdd 100644 --- a/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp +++ b/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp @@ -102,7 +102,9 @@ TEST_F(RefactoringDatabaseInitializer, AddProjectPartsSourcesTable) { InSequence s; - EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsSources(projectPartId INTEGER, sourceId INTEGER, sourceType INTEGER)"))); + EXPECT_CALL(mockDatabase, + execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsSources(projectPartId INTEGER, " + "sourceId INTEGER, sourceType INTEGER, pchCreationTimeStamp INTEGER)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_projectPartsSources_sourceId_projectPartId ON projectPartsSources(sourceId, projectPartId)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_projectPartsSources_projectPartId ON projectPartsSources(projectPartId)"))); @@ -124,7 +126,11 @@ TEST_F(RefactoringDatabaseInitializer, AddFileStatusesTable) { InSequence s; - EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS fileStatuses(sourceId INTEGER PRIMARY KEY, size INTEGER, lastModified INTEGER, buildDependencyTimeStamp INTEGER, isInPrecompiledHeader INTEGER)"))); + EXPECT_CALL( + mockDatabase, + execute(Eq( + "CREATE TABLE IF NOT EXISTS fileStatuses(sourceId INTEGER PRIMARY KEY, size INTEGER, " + "lastModified INTEGER)"))); initializer.createFileStatusesTable(); } @@ -171,13 +177,19 @@ TEST_F(RefactoringDatabaseInitializer, CreateInTheContructor) "TEXT, systemIncludeSearchPaths TEXT, projectIncludeSearchPaths TEXT, " "language INTEGER, languageVersion INTEGER, languageExtension INTEGER)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_projectParts_projectPartName ON projectParts(projectPartName)"))); - EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsSources(projectPartId INTEGER, sourceId INTEGER, sourceType INTEGER)"))); + EXPECT_CALL(mockDatabase, + execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsSources(projectPartId INTEGER, " + "sourceId INTEGER, sourceType INTEGER, pchCreationTimeStamp INTEGER)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_projectPartsSources_sourceId_projectPartId ON projectPartsSources(sourceId, projectPartId)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_projectPartsSources_projectPartId ON projectPartsSources(projectPartId)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS usedMacros(usedMacroId INTEGER PRIMARY KEY, sourceId INTEGER, macroName TEXT)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_usedMacros_sourceId_macroName ON usedMacros(sourceId, macroName)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_usedMacros_macroName ON usedMacros(macroName)"))); - EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS fileStatuses(sourceId INTEGER PRIMARY KEY, size INTEGER, lastModified INTEGER, buildDependencyTimeStamp INTEGER, isInPrecompiledHeader INTEGER)"))); + EXPECT_CALL( + mockDatabase, + execute(Eq( + "CREATE TABLE IF NOT EXISTS fileStatuses(sourceId INTEGER PRIMARY KEY, size INTEGER, " + "lastModified INTEGER)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS sourceDependencies(sourceId INTEGER, dependencySourceId INTEGER)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_sourceDependencies_sourceId_dependencySourceId ON sourceDependencies(sourceId, dependencySourceId)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS precompiledHeaders(projectPartId INTEGER PRIMARY KEY, projectPchPath TEXT, projectPchBuildTime INTEGER, systemPchPath TEXT, systemPchBuildTime INTEGER)"))); @@ -215,7 +227,10 @@ TEST_F(RefactoringDatabaseInitializer, DontCreateIfAlreadyInitialized) EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS usedMacros(usedMacroId INTEGER PRIMARY KEY, sourceId INTEGER, macroName TEXT)"))).Times(0); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_usedMacros_sourceId_macroName ON usedMacros(sourceId, macroName)"))).Times(0); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_usedMacros_macroName ON usedMacros(macroName)"))).Times(0); - EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS fileStatuses(sourceId INTEGER PRIMARY KEY, size INTEGER, lastModified INTEGER, isInPrecompiledHeader INTEGER)"))).Times(0); + EXPECT_CALL(mockDatabase, + execute(Eq("CREATE TABLE IF NOT EXISTS fileStatuses(sourceId INTEGER PRIMARY KEY, " + "size INTEGER, lastModified INTEGER, isInPrecompiledHeader INTEGER)"))) + .Times(0); EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS sourceDependencies(sourceId INTEGER, dependencySourceId INTEGER)"))).Times(0); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_sourceDependencies_sourceId_dependencySourceId ON sourceDependencies(sourceId, dependencySourceId)"))).Times(0); EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS precompiledHeaders(projectPartId INTEGER PRIMARY KEY, pchPath TEXT, pchBuildTime INTEGER)"))).Times(0); diff --git a/tests/unit/unittest/symbolindexer-test.cpp b/tests/unit/unittest/symbolindexer-test.cpp index eecd388f024..1e73f8a71b2 100644 --- a/tests/unit/unittest/symbolindexer-test.cpp +++ b/tests/unit/unittest/symbolindexer-test.cpp @@ -73,13 +73,6 @@ using ClangBackEnd::SourceLocationKind; using ClangBackEnd::UsedMacros; using OptionalProjectPartArtefact = Utils::optional; -MATCHER_P(IsFileId, fileNameId, - std::string(negation ? "isn't " : "is ") - + PrintToString(ClangBackEnd::FilePathId(fileNameId))) -{ - return arg == ClangBackEnd::FilePathId(fileNameId); -} - struct Data { Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; @@ -211,7 +204,7 @@ protected: SourceLocationEntries sourceLocations{{1, 1, {42, 23}, SourceLocationKind::Declaration}}; FilePathIds sourceFileIds{1, 23}; UsedMacros usedMacros{{"Foo", 1}}; - FileStatuses fileStatus{{2, 3, 4, false}}; + FileStatuses fileStatus{{2, 3, 4}}; SourceDependencies sourceDependencies{{1, 2}, {1, 3}}; Utils::SmallString systemIncludeSearchPathsText{ R"([["/includes", 1, 2], [")" TESTDATA_DIR R"(" ,2 , 3], ["/other/includes", 3, 3]])"}; @@ -442,26 +435,6 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsUpdateProjectPartsInStorage) indexer.updateProjectParts({projectPart1, projectPart2}); } -TEST_F(SymbolIndexer, UpdateProjectPartsCallsUpdateProjectPartSourcesWithArtifact) -{ - ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq("project1"))).WillByDefault(Return(artefact)); - ON_CALL(mockSymbolStorage, insertOrUpdateProjectPart(Eq("project1"), _, _, _, _, _, _, _)).WillByDefault(Return(-1)); - - EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(_, _)); - - indexer.updateProjectParts({projectPart1}); -} - -TEST_F(SymbolIndexer, UpdateProjectPartsCallsUpdateProjectPartSourcesWithoutArtifact) -{ - ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq("project2"))).WillByDefault(Return(nullArtefact)); - ON_CALL(mockSymbolStorage, insertOrUpdateProjectPart(Eq("project2"), _, _, _, _, _, _, _)).WillByDefault(Return(3)); - - EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(3, ElementsAre(IsFileId(1), IsFileId(23)))); - - indexer.updateProjectParts({projectPart2}); -} - TEST_F(SymbolIndexer, UpdateProjectPartsCallsInsertOrUpdateUsedMacros) { EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(Eq(usedMacros))) @@ -472,7 +445,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInsertOrUpdateUsedMacros) TEST_F(SymbolIndexer, UpdateProjectPartsCallsInsertFileStatuses) { - EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(Eq(fileStatus))) + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateFileStatuses(Eq(fileStatus))) .Times(2); indexer.updateProjectParts({projectPart1, projectPart2}); @@ -538,9 +511,8 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrderWithoutProjectPartArtifact) EXPECT_CALL(mockCollector, collectSymbols()); EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()); EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)); - EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(TypedEq(12), Eq(sourceFileIds))); EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(Eq(usedMacros))); - EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(Eq(fileStatus))); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateFileStatuses(Eq(fileStatus))); EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies))); EXPECT_CALL(mockSqliteTransactionBackend, commit()); @@ -591,9 +563,8 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrderWithProjectPartArtifact) EXPECT_CALL(mockCollector, collectSymbols()); EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()); EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)); - EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(TypedEq(artefact.projectPartId), Eq(sourceFileIds))); EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(Eq(usedMacros))); - EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(Eq(fileStatus))); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateFileStatuses(Eq(fileStatus))); EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies))); EXPECT_CALL(mockSqliteTransactionBackend, commit()); @@ -646,9 +617,8 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrderButGetsAnErrorForCollectingS EXPECT_CALL(mockCollector, collectSymbols()).WillOnce(Return(false)); EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()).Times(0); EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)).Times(0); - EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(TypedEq(12), Eq(sourceFileIds))).Times(0); EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(Eq(usedMacros))).Times(0); - EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(Eq(fileStatus))).Times(0); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateFileStatuses(Eq(fileStatus))).Times(0); EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies))) .Times(0); EXPECT_CALL(mockSqliteTransactionBackend, commit()).Times(0); @@ -711,9 +681,8 @@ TEST_F(SymbolIndexer, UpdateChangedPathCallsInOrder) EXPECT_CALL(mockCollector, collectSymbols()); EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()); EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)); - EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(artefact.projectPartId, Eq(sourceFileIds))); EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(Eq(usedMacros))); - EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(Eq(fileStatus))); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateFileStatuses(Eq(fileStatus))); EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies))); EXPECT_CALL(mockSqliteTransactionBackend, commit()); @@ -732,9 +701,8 @@ TEST_F(SymbolIndexer, HandleEmptyOptionalArtifactInUpdateChangedPath) EXPECT_CALL(mockCollector, collectSymbols()).Times(0); EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()).Times(0); EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(_, _)).Times(0); - EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(An(), _)).Times(0); EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(_)).Times(0); - EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(_)).Times(0); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateFileStatuses(_)).Times(0); EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSourceDependencies(_)).Times(0); EXPECT_CALL(mockSqliteTransactionBackend, commit()).Times(0); @@ -775,10 +743,8 @@ TEST_F(SymbolIndexer, UpdateChangedPathCallsInOrderButGetsAnErrorForCollectingSy EXPECT_CALL(mockCollector, collectSymbols()).WillOnce(Return(false)); EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()).Times(0); EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)).Times(0); - EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(artefact.projectPartId, Eq(sourceFileIds))) - .Times(0); EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(Eq(usedMacros))).Times(0); - EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(Eq(fileStatus))).Times(0); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateFileStatuses(Eq(fileStatus))).Times(0); EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies))) .Times(0); EXPECT_CALL(mockSqliteTransactionBackend, commit()).Times(0); @@ -950,9 +916,8 @@ TEST_F(SymbolIndexer, DontReparseInUpdateProjectPartsIfDefinesAreTheSame) EXPECT_CALL(mockCollector, collectSymbols()).Times(0); EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()).Times(0); EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(_, _)).Times(0); - EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(An(), _)).Times(0); EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(_)).Times(0); - EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(_)).Times(0); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateFileStatuses(_)).Times(0); EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSourceDependencies(_)).Times(0); EXPECT_CALL(mockSqliteTransactionBackend, commit()).Times(0); diff --git a/tests/unit/unittest/symbolscollector-test.cpp b/tests/unit/unittest/symbolscollector-test.cpp index 2d7025373f3..48e4420dc12 100644 --- a/tests/unit/unittest/symbolscollector-test.cpp +++ b/tests/unit/unittest/symbolscollector-test.cpp @@ -147,7 +147,7 @@ protected: ClangBackEnd::FileStatus fileStatus(Utils::SmallStringView filePath) const { - return {filePathId(filePath), fileSize(filePath), lastModified(filePath), false}; + return {filePathId(filePath), fileSize(filePath), lastModified(filePath)}; } SymbolIndex symbolId(const Utils::SmallString &symbolName) diff --git a/tests/unit/unittest/symbolstorage-test.cpp b/tests/unit/unittest/symbolstorage-test.cpp index f9a3d0a7dee..ddd71362523 100644 --- a/tests/unit/unittest/symbolstorage-test.cpp +++ b/tests/unit/unittest/symbolstorage-test.cpp @@ -70,8 +70,6 @@ protected: MockSqliteWriteStatement &deleteNewLocationsTableStatement = storage.m_deleteNewLocationsTableStatement; MockSqliteWriteStatement &insertOrUpdateProjectPartStatement = storage.m_insertOrUpdateProjectPartStatement; MockSqliteReadStatement &getProjectPartIdStatement = storage.m_getProjectPartIdStatement; - MockSqliteWriteStatement &deleteAllProjectPartsSourcesWithProjectPartIdStatement = storage.m_deleteAllProjectPartsSourcesWithProjectPartIdStatement; - MockSqliteWriteStatement &insertProjectPartSourcesStatement = storage.m_insertProjectPartSourcesStatement; MockSqliteReadStatement &getProjectPartArtefactsBySourceId = storage.m_getProjectPartArtefactsBySourceId; MockSqliteReadStatement &getProjectPartArtefactsByProjectPartName = storage.m_getProjectPartArtefactsByProjectPartName; @@ -212,18 +210,6 @@ TEST_F(SymbolStorage, InsertOrUpdateProjectPart) Utils::LanguageExtension::None); } - -TEST_F(SymbolStorage, UpdateProjectPartSources) -{ - InSequence sequence; - - EXPECT_CALL(deleteAllProjectPartsSourcesWithProjectPartIdStatement, write(TypedEq(42))); - EXPECT_CALL(insertProjectPartSourcesStatement, write(TypedEq(42), TypedEq(1))); - EXPECT_CALL(insertProjectPartSourcesStatement, write(TypedEq(42), TypedEq(2))); - - storage.updateProjectPartSources(42, {1, 2}); -} - TEST_F(SymbolStorage, FetchProjectPartArtefactBySourceIdCallsValueInStatement) { EXPECT_CALL(getProjectPartArtefactsBySourceId, valueReturnProjectPartArtefact(1)) diff --git a/tests/unit/unittest/usedmacrocollector-test.cpp b/tests/unit/unittest/usedmacrocollector-test.cpp index 61f7fcd99b4..31aa4fab382 100644 --- a/tests/unit/unittest/usedmacrocollector-test.cpp +++ b/tests/unit/unittest/usedmacrocollector-test.cpp @@ -68,7 +68,7 @@ protected: ClangBackEnd::FileStatus fileStatus(Utils::SmallStringView filePath) const { - return {filePathId(filePath), fileSize(filePath), lastModified(filePath), false}; + return {filePathId(filePath), fileSize(filePath), lastModified(filePath)}; } protected: Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; diff --git a/tests/unit/unittest/usedmacrofilter-test.cpp b/tests/unit/unittest/usedmacrofilter-test.cpp index bdde5417afb..bfbbd7adb70 100644 --- a/tests/unit/unittest/usedmacrofilter-test.cpp +++ b/tests/unit/unittest/usedmacrofilter-test.cpp @@ -41,11 +41,12 @@ using ClangBackEnd::CompilerMacros; class UsedMacroFilter : public testing::Test { protected: - SourceEntries includes{{1, SourceType::UserInclude, 0}, - {2, SourceType::SystemInclude, 0}, - {3, SourceType::ProjectInclude, 0}, - {4, SourceType::TopSystemInclude, 0}, - {5, SourceType::TopProjectInclude, 0}}; + SourceEntries sources{{1, SourceType::UserInclude, 0}, + {2, SourceType::SystemInclude, 0}, + {3, SourceType::ProjectInclude, 0}, + {4, SourceType::TopSystemInclude, 0}, + {5, SourceType::TopProjectInclude, 0}, + {6, SourceType::Source, 0}}; UsedMacros usedMacros{{"YI", 1}, {"ER", 2}, {"SE", 2}, @@ -65,57 +66,62 @@ protected: TEST_F(UsedMacroFilter, SystemIncludes) { - ClangBackEnd::UsedMacroFilter filter(includes, usedMacros, compileMacros); + ClangBackEnd::UsedMacroFilter filter(sources, usedMacros, compileMacros); ASSERT_THAT(filter.systemIncludes, ElementsAre(FilePathId{2}, FilePathId{4})); } TEST_F(UsedMacroFilter, ProjectIncludes) { - ClangBackEnd::UsedMacroFilter filter(includes, usedMacros, compileMacros); + ClangBackEnd::UsedMacroFilter filter(sources, usedMacros, compileMacros); ASSERT_THAT(filter.projectIncludes, ElementsAre(FilePathId{3}, FilePathId{5})); } TEST_F(UsedMacroFilter, TopSystemIncludes) { - ClangBackEnd::UsedMacroFilter filter(includes, usedMacros, compileMacros); + ClangBackEnd::UsedMacroFilter filter(sources, usedMacros, compileMacros); ASSERT_THAT(filter.topSystemIncludes, ElementsAre(FilePathId{4})); } TEST_F(UsedMacroFilter, TopProjectIncludes) { - ClangBackEnd::UsedMacroFilter filter(includes, usedMacros, compileMacros); + ClangBackEnd::UsedMacroFilter filter(sources, usedMacros, compileMacros); ASSERT_THAT(filter.topProjectIncludes, ElementsAre(FilePathId{5})); } -TEST_F(UsedMacroFilter, AllIncludes) +TEST_F(UsedMacroFilter, Sources) { - ClangBackEnd::UsedMacroFilter filter(includes, usedMacros, compileMacros); + ClangBackEnd::UsedMacroFilter filter(sources, usedMacros, compileMacros); - ASSERT_THAT(filter.allIncludes, - ElementsAre(FilePathId{1}, FilePathId{2}, FilePathId{3}, FilePathId{4}, FilePathId{5})); + ASSERT_THAT(filter.sources, + ElementsAre(FilePathId{1}, + FilePathId{2}, + FilePathId{3}, + FilePathId{4}, + FilePathId{5}, + FilePathId{6})); } TEST_F(UsedMacroFilter, SystemUsedMacros) { - ClangBackEnd::UsedMacroFilter filter(includes, usedMacros, compileMacros); + ClangBackEnd::UsedMacroFilter filter(sources, usedMacros, compileMacros); ASSERT_THAT(filter.systemUsedMacros, ElementsAre("ER", "SE", "LIU")); } TEST_F(UsedMacroFilter, ProjectUsedMacros) { - ClangBackEnd::UsedMacroFilter filter(includes, usedMacros, compileMacros); + ClangBackEnd::UsedMacroFilter filter(sources, usedMacros, compileMacros); ASSERT_THAT(filter.projectUsedMacros, ElementsAre("QI", "WU", "SAN")); } TEST_F(UsedMacroFilter, SystemCompileMacros) { - ClangBackEnd::UsedMacroFilter filter(includes, usedMacros, compileMacros); + ClangBackEnd::UsedMacroFilter filter(sources, usedMacros, compileMacros); ASSERT_THAT(filter.systemCompilerMacros, ElementsAre(CompilerMacro{"ER", "2", 2}, @@ -125,7 +131,7 @@ TEST_F(UsedMacroFilter, SystemCompileMacros) TEST_F(UsedMacroFilter, ProjectCompileMacros) { - ClangBackEnd::UsedMacroFilter filter(includes, usedMacros, compileMacros); + ClangBackEnd::UsedMacroFilter filter(sources, usedMacros, compileMacros); ASSERT_THAT(filter.projectCompilerMacros, ElementsAre(CompilerMacro{"QI"},