diff options
author | Marco Bubke <marco.bubke@qt.io> | 2018-11-20 16:20:41 +0100 |
---|---|---|
committer | Marco Bubke <marco.bubke@qt.io> | 2018-11-21 15:05:23 +0000 |
commit | e43aa08ebedae93168c5d7027124abda05445951 (patch) | |
tree | 7e1ed2d3f2e5764e4ac2136f7f5260587b998b96 | |
parent | 10f15f5d1a299a3a9c3931a1549db566a85718a7 (diff) |
ClangPchManager: Store collected build dependencies
Task-number: QTCREATORBUG-21289
Task-number: QTCREATORBUG-21377
Change-Id: Idba57ac09bc5a1f1ccef87f5e33f1ceeaccea372
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
8 files changed, 180 insertions, 97 deletions
diff --git a/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.cpp b/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.cpp index c3146408f8..7f97599fac 100644 --- a/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.cpp +++ b/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.cpp @@ -29,6 +29,8 @@ #include "modifiedtimecheckerinterface.h" #include "builddependencygeneratorinterface.h" +#include <sqlitetransaction.h> + #include <algorithm> namespace ClangBackEnd { @@ -51,19 +53,25 @@ OutputContainer setUnion(InputContainer1 &&input1, return results; } -BuildDependency BuildDependenciesProvider::create(const V2::ProjectPartContainer &projectPart) const +BuildDependency BuildDependenciesProvider::create(const V2::ProjectPartContainer &projectPart) { SourceEntries includes = createSourceEntriesFromStorage(projectPart.sourcePathIds, projectPart.projectPartId); - if (!m_modifiedTimeChecker.isUpToDate(includes)) - return m_buildDependenciesGenerator.create(projectPart); + if (!m_modifiedTimeChecker.isUpToDate(includes)) { + BuildDependency buildDependency = m_generator.create(projectPart); + + storeBuildDependency(buildDependency); + + return buildDependency; + } return createBuildDependencyFromStorage(std::move(includes)); } -BuildDependency BuildDependenciesProvider::createBuildDependencyFromStorage(SourceEntries &&includes) const +BuildDependency BuildDependenciesProvider::createBuildDependencyFromStorage( + SourceEntries &&includes) const { BuildDependency buildDependency; @@ -78,14 +86,18 @@ UsedMacros BuildDependenciesProvider::createUsedMacrosFromStorage(const SourceEn UsedMacros usedMacros; usedMacros.reserve(1024); + Sqlite::DeferredTransaction transaction(m_transactionBackend); + for (const SourceEntry &entry : includes) { - UsedMacros macros = m_buildDependenciesStorage.fetchUsedMacros(entry.sourceId); + UsedMacros macros = m_storage.fetchUsedMacros(entry.sourceId); std::sort(macros.begin(), macros.end()); usedMacros.insert(usedMacros.end(), std::make_move_iterator(macros.begin()), std::make_move_iterator(macros.end())); } + transaction.commit(); + return usedMacros; } @@ -94,15 +106,31 @@ SourceEntries BuildDependenciesProvider::createSourceEntriesFromStorage( { SourceEntries includes; + Sqlite::DeferredTransaction transaction(m_transactionBackend); + for (FilePathId sourcePathId : sourcePathIds) { - SourceEntries entries = m_buildDependenciesStorage.fetchDependSources(sourcePathId, + SourceEntries entries = m_storage.fetchDependSources(sourcePathId, projectPartId); SourceEntries mergedEntries = setUnion<SourceEntries>(includes, entries); includes = std::move(mergedEntries); } + transaction.commit(); + return includes; } +void BuildDependenciesProvider::storeBuildDependency(const BuildDependency &buildDependency) +{ + Sqlite::ImmediateTransaction transaction(m_transactionBackend); + + m_storage.updateSources(buildDependency.includes); + m_storage.insertFileStatuses(buildDependency.fileStatuses); + m_storage.insertOrUpdateSourceDependencies(buildDependency.sourceDependencies); + m_storage.insertOrUpdateUsedMacros(buildDependency.usedMacros); + + transaction.commit(); +} + } // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.h b/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.h index 8c22077e81..386eca587e 100644 --- a/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.h +++ b/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.h @@ -27,6 +27,10 @@ #include "builddependenciesproviderinterface.h" +namespace Sqlite { +class TransactionInterface; +} + namespace ClangBackEnd { class BuildDependenciesStorageInterface; @@ -38,25 +42,28 @@ class BuildDependenciesProvider : public BuildDependenciesProviderInterface public: BuildDependenciesProvider(BuildDependenciesStorageInterface &buildDependenciesStorage, ModifiedTimeCheckerInterface &modifiedTimeChecker, - BuildDependencyGeneratorInterface &buildDependenciesGenerator) - : m_buildDependenciesStorage(buildDependenciesStorage), - m_modifiedTimeChecker(modifiedTimeChecker), - m_buildDependenciesGenerator(buildDependenciesGenerator) - { - } + BuildDependencyGeneratorInterface &buildDependenciesGenerator, + Sqlite::TransactionInterface &transactionBackend) + : m_storage(buildDependenciesStorage) + , m_modifiedTimeChecker(modifiedTimeChecker) + , m_generator(buildDependenciesGenerator) + , m_transactionBackend(transactionBackend) + {} - BuildDependency create(const V2::ProjectPartContainer &projectPart) const override; + BuildDependency create(const V2::ProjectPartContainer &projectPart) override; 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); private: - BuildDependenciesStorageInterface &m_buildDependenciesStorage; + BuildDependenciesStorageInterface &m_storage; ModifiedTimeCheckerInterface &m_modifiedTimeChecker; - BuildDependencyGeneratorInterface &m_buildDependenciesGenerator; + BuildDependencyGeneratorInterface &m_generator; + Sqlite::TransactionInterface &m_transactionBackend; }; } // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/builddependenciesproviderinterface.h b/src/tools/clangpchmanagerbackend/source/builddependenciesproviderinterface.h index f596b83da9..0bfaeed06c 100644 --- a/src/tools/clangpchmanagerbackend/source/builddependenciesproviderinterface.h +++ b/src/tools/clangpchmanagerbackend/source/builddependenciesproviderinterface.h @@ -34,7 +34,7 @@ namespace ClangBackEnd { class BuildDependenciesProviderInterface { public: - virtual BuildDependency create(const V2::ProjectPartContainer &projectPart) const = 0; + virtual BuildDependency create(const V2::ProjectPartContainer &projectPart) = 0; protected: ~BuildDependenciesProviderInterface() = default; diff --git a/src/tools/clangpchmanagerbackend/source/builddependenciesstorage.h b/src/tools/clangpchmanagerbackend/source/builddependenciesstorage.h index ecb2d7cc7d..f894ed8ecd 100644 --- a/src/tools/clangpchmanagerbackend/source/builddependenciesstorage.h +++ b/src/tools/clangpchmanagerbackend/source/builddependenciesstorage.h @@ -47,25 +47,25 @@ class BuildDependenciesStorage final : public BuildDependenciesStorageInterface using WriteStatement = typename Database::WriteStatement; public: BuildDependenciesStorage(Database &database) - : m_transaction(database), - m_database(database) + : transaction(database), + database(database) { - m_transaction.commit(); + transaction.commit(); } void updateSources(const SourceEntries &sourceEntries) override { for (const SourceEntry &entry : sourceEntries) { - m_updateBuildDependencyTimeStampStatement.write(static_cast<long long>(entry.lastModified), + updateBuildDependencyTimeStampStatement.write(static_cast<long long>(entry.lastModified), entry.sourceId.filePathId); - m_updateSourceTypeStatement.write(static_cast<uchar>(entry.sourceType), + updateSourceTypeStatement.write(static_cast<uchar>(entry.sourceType), entry.sourceId.filePathId); } } void insertFileStatuses(const FileStatuses &fileStatuses) override { - WriteStatement &statement = m_insertFileStatusesStatement; + WriteStatement &statement = insertFileStatusesStatement; for (const FileStatus &fileStatus : fileStatuses) statement.write(fileStatus.filePathId.filePathId, @@ -76,41 +76,41 @@ public: long long fetchLowestLastModifiedTime(FilePathId sourceId) const override { - ReadStatement &statement = m_getLowestLastModifiedTimeOfDependencies; + ReadStatement &statement = getLowestLastModifiedTimeOfDependencies; return statement.template value<long long>(sourceId.filePathId).value_or(0); } void insertOrUpdateUsedMacros(const UsedMacros &usedMacros) override { - WriteStatement &insertStatement = m_insertIntoNewUsedMacrosStatement; + WriteStatement &insertStatement = insertIntoNewUsedMacrosStatement; for (const UsedMacro &usedMacro : usedMacros) insertStatement.write(usedMacro.filePathId.filePathId, usedMacro.macroName); - m_syncNewUsedMacrosStatement.execute(); - m_deleteOutdatedUsedMacrosStatement.execute(); - m_deleteNewUsedMacrosTableStatement.execute(); + syncNewUsedMacrosStatement.execute(); + deleteOutdatedUsedMacrosStatement.execute(); + deleteNewUsedMacrosTableStatement.execute(); } void insertOrUpdateSourceDependencies(const SourceDependencies &sourceDependencies) override { - WriteStatement &insertStatement = m_insertIntoNewSourceDependenciesStatement; + WriteStatement &insertStatement = insertIntoNewSourceDependenciesStatement; for (SourceDependency sourceDependency : sourceDependencies) insertStatement.write(sourceDependency.filePathId.filePathId, sourceDependency.dependencyFilePathId.filePathId); - m_syncNewSourceDependenciesStatement.execute(); - m_deleteOutdatedSourceDependenciesStatement.execute(); - m_deleteNewSourceDependenciesStatement.execute(); + syncNewSourceDependenciesStatement.execute(); + deleteOutdatedSourceDependenciesStatement.execute(); + deleteNewSourceDependenciesStatement.execute(); } SourceEntries fetchDependSources(FilePathId sourceId, Utils::SmallStringView projectPartName) const override { - auto projectPartId = m_fetchProjectPartIdStatement.template value<int>(projectPartName); + auto projectPartId = fetchProjectPartIdStatement.template value<int>(projectPartName); if (projectPartId) { - return m_fetchSourceDependenciesStatement.template values<SourceEntry, 3>( + return fetchSourceDependenciesStatement.template values<SourceEntry, 3>( 300, sourceId.filePathId, projectPartId.value()); @@ -120,7 +120,7 @@ public: UsedMacros fetchUsedMacros(FilePathId sourceId) const override { - return m_fetchUsedMacrosStatement.template values<UsedMacro, 2>(128, sourceId.filePathId); + return fetchUsedMacrosStatement.template values<UsedMacro, 2>(128, sourceId.filePathId); } static Utils::SmallString toJson(const Utils::SmallStringVector &strings) @@ -159,7 +159,7 @@ public: const Sqlite::Column ¯oNameColumn = table.addColumn("macroName", Sqlite::ColumnType::Text); table.addIndex({sourceIdColumn, macroNameColumn}); - table.initialize(m_database); + table.initialize(database); return table; } @@ -173,75 +173,75 @@ public: const Sqlite::Column &dependencySourceIdColumn = table.addColumn("dependencySourceId", Sqlite::ColumnType::Text); table.addIndex({sourceIdColumn, dependencySourceIdColumn}); - table.initialize(m_database); + table.initialize(database); return table; } public: - Sqlite::ImmediateNonThrowingDestructorTransaction m_transaction; - Database &m_database; + Sqlite::ImmediateNonThrowingDestructorTransaction transaction; + Database &database; Sqlite::Table newUsedMacroTable{createNewUsedMacrosTable()}; Sqlite::Table newNewSourceDependenciesTable{createNewSourceDependenciesTable()}; - WriteStatement m_insertIntoNewUsedMacrosStatement{ + WriteStatement insertIntoNewUsedMacrosStatement{ "INSERT INTO newUsedMacros(sourceId, macroName) VALUES (?,?)", - m_database + database }; - WriteStatement m_syncNewUsedMacrosStatement{ + WriteStatement syncNewUsedMacrosStatement{ "INSERT INTO usedMacros(sourceId, macroName) SELECT sourceId, macroName FROM newUsedMacros WHERE NOT EXISTS (SELECT sourceId FROM usedMacros WHERE usedMacros.sourceId == newUsedMacros.sourceId AND usedMacros.macroName == newUsedMacros.macroName)", - m_database + database }; - WriteStatement m_deleteOutdatedUsedMacrosStatement{ + WriteStatement deleteOutdatedUsedMacrosStatement{ "DELETE FROM usedMacros WHERE sourceId IN (SELECT sourceId FROM newUsedMacros) AND NOT EXISTS (SELECT sourceId FROM newUsedMacros WHERE newUsedMacros.sourceId == usedMacros.sourceId AND newUsedMacros.macroName == usedMacros.macroName)", - m_database + database }; - WriteStatement m_deleteNewUsedMacrosTableStatement{ + WriteStatement deleteNewUsedMacrosTableStatement{ "DELETE FROM newUsedMacros", - m_database + database }; - mutable ReadStatement m_getLowestLastModifiedTimeOfDependencies{ + mutable ReadStatement getLowestLastModifiedTimeOfDependencies{ "WITH RECURSIVE sourceIds(sourceId) AS (VALUES(?) UNION SELECT dependencySourceId FROM sourceDependencies, sourceIds WHERE sourceDependencies.sourceId = sourceIds.sourceId) SELECT min(lastModified) FROM fileStatuses, sourceIds WHERE fileStatuses.sourceId = sourceIds.sourceId", - m_database + database }; - WriteStatement m_insertIntoNewSourceDependenciesStatement{ + WriteStatement insertIntoNewSourceDependenciesStatement{ "INSERT INTO newSourceDependencies(sourceId, dependencySourceId) VALUES (?,?)", - m_database + database }; - WriteStatement m_insertFileStatusesStatement{ + WriteStatement insertFileStatusesStatement{ "INSERT OR REPLACE INTO fileStatuses(sourceId, size, lastModified, isInPrecompiledHeader) VALUES (?,?,?,?)", - m_database + database }; - WriteStatement m_syncNewSourceDependenciesStatement{ + 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)", - m_database + database }; - WriteStatement m_deleteOutdatedSourceDependenciesStatement{ + WriteStatement deleteOutdatedSourceDependenciesStatement{ "DELETE FROM sourceDependencies WHERE sourceId IN (SELECT sourceId FROM newSourceDependencies) AND NOT EXISTS (SELECT sourceId FROM newSourceDependencies WHERE newSourceDependencies.sourceId == sourceDependencies.sourceId AND newSourceDependencies.dependencySourceId == sourceDependencies.dependencySourceId)", - m_database + database }; - WriteStatement m_deleteNewSourceDependenciesStatement{ + WriteStatement deleteNewSourceDependenciesStatement{ "DELETE FROM newSourceDependencies", - m_database + database }; - WriteStatement m_updateBuildDependencyTimeStampStatement{ + WriteStatement updateBuildDependencyTimeStampStatement{ "UPDATE fileStatuses SET buildDependencyTimeStamp = ? WHERE sourceId == ?", - m_database + database }; - WriteStatement m_updateSourceTypeStatement{ + WriteStatement updateSourceTypeStatement{ "UPDATE projectPartsSources SET sourceType = ? WHERE sourceId == ?", - m_database + database }; - mutable ReadStatement m_fetchSourceDependenciesStatement{ + 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 = ?", - m_database + database }; - mutable ReadStatement m_fetchProjectPartIdStatement{ + mutable ReadStatement fetchProjectPartIdStatement{ "SELECT projectPartId FROM projectParts WHERE projectPartName = ?", - m_database + database }; - mutable ReadStatement m_fetchUsedMacrosStatement{ + mutable ReadStatement fetchUsedMacrosStatement{ "SELECT macroName, sourceId FROM usedMacros WHERE sourceId = ?", - m_database + database }; }; } diff --git a/src/tools/clangpchmanagerbackend/source/collectbuilddependencypreprocessorcallbacks.h b/src/tools/clangpchmanagerbackend/source/collectbuilddependencypreprocessorcallbacks.h index 07c163c92b..0962129cb6 100644 --- a/src/tools/clangpchmanagerbackend/source/collectbuilddependencypreprocessorcallbacks.h +++ b/src/tools/clangpchmanagerbackend/source/collectbuilddependencypreprocessorcallbacks.h @@ -44,8 +44,9 @@ namespace ClangBackEnd { -class CollectBuildDependencyPreprocessorCallbacks final : public clang::PPCallbacks, - public CollectUsedMacrosAndSourcesPreprocessorCallbacksBase +class CollectBuildDependencyPreprocessorCallbacks final + : public clang::PPCallbacks, + public CollectUsedMacrosAndSourcesPreprocessorCallbacksBase { public: CollectBuildDependencyPreprocessorCallbacks(BuildDependency &buildDependency, diff --git a/tests/unit/unittest/builddependenciesprovider-test.cpp b/tests/unit/unittest/builddependenciesprovider-test.cpp index e829b52d60..64a9247828 100644 --- a/tests/unit/unittest/builddependenciesprovider-test.cpp +++ b/tests/unit/unittest/builddependenciesprovider-test.cpp @@ -28,6 +28,7 @@ #include "mockbuilddependenciesstorage.h" #include "mockmodifiedtimechecker.h" #include "mockbuilddependencygenerator.h" +#include "mocksqlitetransactionbackend.h" #include <builddependenciesprovider.h> @@ -54,38 +55,67 @@ MATCHER_P(HasSourceId, sourceId, std::string(negation ? "hasn't" : "has") class BuildDependenciesProvider : public testing::Test { protected: + NiceMock<MockSqliteTransactionBackend> mockSqliteTransactionBackend; NiceMock<MockBuildDependenciesStorage> mockBuildDependenciesStorage; NiceMock<MockModifiedTimeChecker> mockModifiedTimeChecker; NiceMock<MockBuildDependencyGenerator> mockBuildDependenciesGenerator; - ClangBackEnd::BuildDependenciesProvider provider{mockBuildDependenciesStorage, mockModifiedTimeChecker, mockBuildDependenciesGenerator}; + ClangBackEnd::BuildDependenciesProvider provider{mockBuildDependenciesStorage, + mockModifiedTimeChecker, + mockBuildDependenciesGenerator, + mockSqliteTransactionBackend}; ClangBackEnd::V2::ProjectPartContainer projectPart1{"ProjectPart1", {"--yi"}, - {{"YI","1"}}, + {{"YI", "1"}}, {"/yi"}, {1}, {2}}; ClangBackEnd::V2::ProjectPartContainer projectPart2{"ProjectPart2", {"--er"}, - {{"ER","2"}}, + {{"ER", "2"}}, {"/er"}, {1}, {2, 3, 4}}; - SourceEntries firstSources{{1, SourceType::UserInclude, 1}, {2, SourceType::UserInclude, 1}, {10, SourceType::UserInclude, 1}}; - SourceEntries secondSources{{1, SourceType::UserInclude, 1}, {3, SourceType::UserInclude, 1}, {8, SourceType::UserInclude, 1}}; - SourceEntries thirdSources{{4, SourceType::UserInclude, 1}, {8, SourceType::UserInclude, 1}, {10, SourceType::UserInclude, 1}}; + SourceEntries firstSources{{1, SourceType::UserInclude, 1}, + {2, SourceType::UserInclude, 1}, + {10, SourceType::UserInclude, 1}}; + SourceEntries secondSources{{1, SourceType::UserInclude, 1}, + {3, SourceType::UserInclude, 1}, + {8, SourceType::UserInclude, 1}}; + SourceEntries thirdSources{{4, SourceType::UserInclude, 1}, + {8, SourceType::UserInclude, 1}, + {10, SourceType::UserInclude, 1}}; UsedMacros firstUsedMacros{{"YI", 1}}; UsedMacros secondUsedMacros{{"LIANG", 2}, {"ER", 2}}; UsedMacros thirdUsedMacros{{"SAN", 10}}; - BuildDependency buildDependency{secondSources, {}}; + 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}}; + BuildDependency buildDependency{ + secondSources, + secondUsedMacros, + sourceFiles, + sourceDependencies, + fileStatuses + }; }; TEST_F(BuildDependenciesProvider, CreateCallsFetchDependSourcesFromStorageIfTimeStampsAreUpToDate) { InSequence s; - EXPECT_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, TypedEq<Utils::SmallStringView>("ProjectPart1"))).WillRepeatedly(Return(firstSources)); + EXPECT_CALL(mockSqliteTransactionBackend, deferredBegin()); + EXPECT_CALL(mockBuildDependenciesStorage, + fetchDependSources({2}, TypedEq<Utils::SmallStringView>("ProjectPart1"))) + .WillRepeatedly(Return(firstSources)); + EXPECT_CALL(mockSqliteTransactionBackend, commit()); EXPECT_CALL(mockModifiedTimeChecker, isUpToDate(firstSources)).WillRepeatedly(Return(true)); EXPECT_CALL(mockBuildDependenciesGenerator, create(projectPart1)).Times(0); + EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()).Times(0); + EXPECT_CALL(mockSqliteTransactionBackend, commit()).Times(0); + EXPECT_CALL(mockSqliteTransactionBackend, deferredBegin()); + EXPECT_CALL(mockSqliteTransactionBackend, commit()); provider.create(projectPart1); } @@ -95,6 +125,7 @@ TEST_F(BuildDependenciesProvider, FetchDependSourcesFromStorage) ON_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, TypedEq<Utils::SmallStringView>("ProjectPart2"))).WillByDefault(Return(firstSources)); ON_CALL(mockBuildDependenciesStorage, fetchDependSources({3}, TypedEq<Utils::SmallStringView>("ProjectPart2"))).WillByDefault(Return(secondSources)); ON_CALL(mockBuildDependenciesStorage, fetchDependSources({4}, TypedEq<Utils::SmallStringView>("ProjectPart2"))).WillByDefault(Return(thirdSources)); + ON_CALL(mockModifiedTimeChecker, isUpToDate(_)).WillByDefault(Return(true)); auto buildDependency = provider.create(projectPart2); @@ -106,9 +137,20 @@ TEST_F(BuildDependenciesProvider, CreateCallsFetchDependSourcesFromGeneratorIfTi { InSequence s; - EXPECT_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, TypedEq<Utils::SmallStringView>("ProjectPart1"))).WillRepeatedly(Return(firstSources)); + EXPECT_CALL(mockSqliteTransactionBackend, deferredBegin()); + EXPECT_CALL(mockBuildDependenciesStorage, + fetchDependSources({2}, TypedEq<Utils::SmallStringView>("ProjectPart1"))) + .WillRepeatedly(Return(firstSources)); + EXPECT_CALL(mockSqliteTransactionBackend, commit()); EXPECT_CALL(mockModifiedTimeChecker, isUpToDate(firstSources)).WillRepeatedly(Return(false)); - EXPECT_CALL(mockBuildDependenciesGenerator, create(projectPart1)); + 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, insertOrUpdateSourceDependencies(Eq(sourceDependencies))); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(Eq(secondUsedMacros))); + EXPECT_CALL(mockSqliteTransactionBackend, commit()); provider.create(projectPart1); } @@ -128,11 +170,15 @@ TEST_F(BuildDependenciesProvider, CreateCallsFetchUsedMacrosFromStorageIfTimeSta { InSequence s; + EXPECT_CALL(mockSqliteTransactionBackend, deferredBegin()); EXPECT_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, TypedEq<Utils::SmallStringView>("ProjectPart1"))).WillRepeatedly(Return(firstSources)); + EXPECT_CALL(mockSqliteTransactionBackend, commit()); EXPECT_CALL(mockModifiedTimeChecker, isUpToDate(firstSources)).WillRepeatedly(Return(true)); + EXPECT_CALL(mockSqliteTransactionBackend, deferredBegin()); EXPECT_CALL(mockBuildDependenciesStorage, fetchUsedMacros({1})); EXPECT_CALL(mockBuildDependenciesStorage, fetchUsedMacros({2})); EXPECT_CALL(mockBuildDependenciesStorage, fetchUsedMacros({10})); + EXPECT_CALL(mockSqliteTransactionBackend, commit()); provider.create(projectPart1); } diff --git a/tests/unit/unittest/builddependenciesstorage-test.cpp b/tests/unit/unittest/builddependenciesstorage-test.cpp index 1100f1a634..77feb21bd7 100644 --- a/tests/unit/unittest/builddependenciesstorage-test.cpp +++ b/tests/unit/unittest/builddependenciesstorage-test.cpp @@ -51,21 +51,21 @@ class BuildDependenciesStorage : public testing::Test protected: NiceMock<MockSqliteDatabase> mockDatabase; Storage storage{mockDatabase}; - MockSqliteWriteStatement &insertIntoNewUsedMacrosStatement = storage.m_insertIntoNewUsedMacrosStatement; - MockSqliteWriteStatement &syncNewUsedMacrosStatement =storage.m_syncNewUsedMacrosStatement; - MockSqliteWriteStatement &deleteOutdatedUsedMacrosStatement = storage.m_deleteOutdatedUsedMacrosStatement; - MockSqliteWriteStatement &deleteNewUsedMacrosTableStatement = storage.m_deleteNewUsedMacrosTableStatement; - MockSqliteWriteStatement &insertFileStatuses = storage.m_insertFileStatusesStatement; - MockSqliteWriteStatement &insertIntoNewSourceDependenciesStatement = storage.m_insertIntoNewSourceDependenciesStatement; - MockSqliteWriteStatement &syncNewSourceDependenciesStatement = storage.m_syncNewSourceDependenciesStatement; - MockSqliteWriteStatement &deleteOutdatedSourceDependenciesStatement = storage.m_deleteOutdatedSourceDependenciesStatement; - MockSqliteWriteStatement &deleteNewSourceDependenciesStatement = storage.m_deleteNewSourceDependenciesStatement; - MockSqliteReadStatement &getLowestLastModifiedTimeOfDependencies = storage.m_getLowestLastModifiedTimeOfDependencies; - MockSqliteWriteStatement &updateBuildDependencyTimeStampStatement = storage.m_updateBuildDependencyTimeStampStatement; - MockSqliteWriteStatement &updateSourceTypeStatement = storage.m_updateSourceTypeStatement; - MockSqliteReadStatement &fetchSourceDependenciesStatement = storage.m_fetchSourceDependenciesStatement; - MockSqliteReadStatement &fetchProjectPartIdStatement = storage.m_fetchProjectPartIdStatement; - MockSqliteReadStatement &fetchUsedMacrosStatement = storage.m_fetchUsedMacrosStatement; + MockSqliteWriteStatement &insertIntoNewUsedMacrosStatement = storage.insertIntoNewUsedMacrosStatement; + MockSqliteWriteStatement &syncNewUsedMacrosStatement =storage.syncNewUsedMacrosStatement; + MockSqliteWriteStatement &deleteOutdatedUsedMacrosStatement = storage.deleteOutdatedUsedMacrosStatement; + MockSqliteWriteStatement &deleteNewUsedMacrosTableStatement = storage.deleteNewUsedMacrosTableStatement; + MockSqliteWriteStatement &insertFileStatuses = storage.insertFileStatusesStatement; + 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; + MockSqliteReadStatement &fetchSourceDependenciesStatement = storage.fetchSourceDependenciesStatement; + MockSqliteReadStatement &fetchProjectPartIdStatement = storage.fetchProjectPartIdStatement; + MockSqliteReadStatement &fetchUsedMacrosStatement = storage.fetchUsedMacrosStatement; }; TEST_F(BuildDependenciesStorage, ConvertStringsToJson) diff --git a/tests/unit/unittest/mockbuilddependenciesprovider.h b/tests/unit/unittest/mockbuilddependenciesprovider.h index 8bb048bd24..2a1fd8f93f 100644 --- a/tests/unit/unittest/mockbuilddependenciesprovider.h +++ b/tests/unit/unittest/mockbuilddependenciesprovider.h @@ -32,6 +32,7 @@ class MockBuildDependenciesProvider : public ClangBackEnd::BuildDependenciesProviderInterface { public: - MOCK_CONST_METHOD1(create, - ClangBackEnd::BuildDependency (const ClangBackEnd::V2::ProjectPartContainer &projectPart)); + MOCK_METHOD1( + create, + ClangBackEnd::BuildDependency(const ClangBackEnd::V2::ProjectPartContainer &projectPart)); }; |