aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Bubke <marco.bubke@qt.io>2019-06-18 18:26:27 +0200
committerMarco Bubke <marco.bubke@qt.io>2019-06-27 12:32:12 +0000
commite031ada154ba94e13af104a1e32be0f94754ba12 (patch)
treebf91a4c733dcb3c321f3cf5d80cd75fcc0762bae
parentcbfd9dc16b41176ce5a79bd9e11a336e853573a0 (diff)
Clang: Watch only PCH sources
We watched all sources but we do not want to watch the sources of the project part because they are not used to build a PCH. Change-Id: I700cd6077fc54230c9be94d620043cf3f10cf9ea Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
-rw-r--r--src/libs/clangsupport/refactoringdatabaseinitializer.h4
-rw-r--r--src/tools/clangpchmanagerbackend/source/builddependenciesstorage.h11
-rw-r--r--src/tools/clangpchmanagerbackend/source/builddependenciesstorageinterface.h2
-rw-r--r--src/tools/clangpchmanagerbackend/source/pchcreator.cpp9
-rw-r--r--src/tools/clangpchmanagerbackend/source/usedmacrofilter.h5
-rw-r--r--src/tools/clangrefactoringbackend/source/symbolindexer.cpp2
-rw-r--r--tests/unit/unittest/builddependenciesstorage-test.cpp4
-rw-r--r--tests/unit/unittest/mockbuilddependenciesstorage.h2
-rw-r--r--tests/unit/unittest/pchcreator-test.cpp24
-rw-r--r--tests/unit/unittest/pchtaskgenerator-test.cpp2
-rw-r--r--tests/unit/unittest/refactoringdatabaseinitializer-test.cpp12
-rw-r--r--tests/unit/unittest/symbolindexer-test.cpp2
-rw-r--r--tests/unit/unittest/usedmacrofilter-test.cpp7
13 files changed, 49 insertions, 37 deletions
diff --git a/src/libs/clangsupport/refactoringdatabaseinitializer.h b/src/libs/clangsupport/refactoringdatabaseinitializer.h
index a7058d3204..6042264a5d 100644
--- a/src/libs/clangsupport/refactoringdatabaseinitializer.h
+++ b/src/libs/clangsupport/refactoringdatabaseinitializer.h
@@ -144,11 +144,11 @@ public:
table.setName("projectPartsFiles");
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);
+ const Sqlite::Column &sourceType = table.addColumn("sourceType", Sqlite::ColumnType::Integer);
table.addColumn("pchCreationTimeStamp", Sqlite::ColumnType::Integer);
table.addColumn("hasMissingIncludes", Sqlite::ColumnType::Integer);
table.addUniqueIndex({sourceIdColumn, projectPartIdColumn});
- table.addIndex({projectPartIdColumn});
+ table.addIndex({projectPartIdColumn, sourceType});
table.initialize(database);
}
diff --git a/src/tools/clangpchmanagerbackend/source/builddependenciesstorage.h b/src/tools/clangpchmanagerbackend/source/builddependenciesstorage.h
index 8c8c51a6cd..187a27cf89 100644
--- a/src/tools/clangpchmanagerbackend/source/builddependenciesstorage.h
+++ b/src/tools/clangpchmanagerbackend/source/builddependenciesstorage.h
@@ -66,10 +66,9 @@ public:
}
}
- FilePathIds fetchSources(ProjectPartId projectPartId) const override
+ FilePathIds fetchPchSources(ProjectPartId projectPartId) const override
{
- return fetchProjectPartsFilesStatement.template values<FilePathId>(1024,
- projectPartId.projectPathId);
+ return fetchPchSourcesStatement.template values<FilePathId>(1024, projectPartId.projectPathId);
}
void insertOrUpdateFileStatuses(const FileStatuses &fileStatuses) override
@@ -252,8 +251,10 @@ public:
"CONFLICT(sourceId, projectPartId) DO UPDATE SET sourceType = ?003, "
"hasMissingIncludes = ?004",
database};
- mutable ReadStatement fetchProjectPartsFilesStatement{
- "SELECT sourceId FROM projectPartsFiles WHERE projectPartId = ? ORDER BY sourceId", database};
+ mutable ReadStatement fetchPchSourcesStatement{
+ "SELECT sourceId FROM projectPartsFiles WHERE projectPartId = ? AND sourceType IN (0, 1, "
+ "3, 4) ORDER BY sourceId",
+ database};
mutable ReadStatement fetchSourceDependenciesStatement{
"WITH RECURSIVE collectedDependencies(sourceId) AS (VALUES(?) UNION "
"SELECT dependencySourceId FROM sourceDependencies, "
diff --git a/src/tools/clangpchmanagerbackend/source/builddependenciesstorageinterface.h b/src/tools/clangpchmanagerbackend/source/builddependenciesstorageinterface.h
index 1166564b32..a1c20811aa 100644
--- a/src/tools/clangpchmanagerbackend/source/builddependenciesstorageinterface.h
+++ b/src/tools/clangpchmanagerbackend/source/builddependenciesstorageinterface.h
@@ -56,7 +56,7 @@ public:
virtual UsedMacros fetchUsedMacros(FilePathId sourceId) const = 0;
virtual ProjectPartId fetchProjectPartId(Utils::SmallStringView projectPartName) = 0;
virtual void updatePchCreationTimeStamp(long long pchCreationTimeStamp, ProjectPartId projectPartId) = 0;
- virtual FilePathIds fetchSources(ProjectPartId projectPartId) const = 0;
+ virtual FilePathIds fetchPchSources(ProjectPartId projectPartId) const = 0;
protected:
~BuildDependenciesStorageInterface() = default;
diff --git a/src/tools/clangpchmanagerbackend/source/pchcreator.cpp b/src/tools/clangpchmanagerbackend/source/pchcreator.cpp
index cd7b492868..15c9a19547 100644
--- a/src/tools/clangpchmanagerbackend/source/pchcreator.cpp
+++ b/src/tools/clangpchmanagerbackend/source/pchcreator.cpp
@@ -114,7 +114,7 @@ void PchCreator::generatePch(PchTask &&pchTask)
{
m_projectPartPch.projectPartId = pchTask.projectPartId();
m_projectPartPch.lastModified = QDateTime::currentSecsSinceEpoch();
-
+ m_sources = std::move(pchTask.sources);
if (pchTask.includes.empty())
return;
@@ -127,10 +127,9 @@ void PchCreator::generatePch(PchTask &&pchTask)
m_clangTool.addFile(std::move(headerFilePath), content.clone(), std::move(commandLine));
bool success = generatePch(NativeFilePath{headerFilePath}, content);
- if (success) {
- m_sources = pchTask.sources;
- m_projectPartPch.pchPath = std::move(pchOutputPath);
- }
+
+ if (success)
+ m_projectPartPch.pchPath = std::move(pchOutputPath);
}
const ProjectPartPch &PchCreator::projectPartPch()
diff --git a/src/tools/clangpchmanagerbackend/source/usedmacrofilter.h b/src/tools/clangpchmanagerbackend/source/usedmacrofilter.h
index 9db3c683b9..2d16b484a1 100644
--- a/src/tools/clangpchmanagerbackend/source/usedmacrofilter.h
+++ b/src/tools/clangpchmanagerbackend/source/usedmacrofilter.h
@@ -128,23 +128,26 @@ private:
case SourceType::TopSystemInclude:
topSystemIncludes.emplace_back(source.sourceId);
systemIncludes.emplace_back(source.sourceId);
+ sources.emplace_back(source.sourceId);
break;
case SourceType::SystemInclude:
systemIncludes.emplace_back(source.sourceId);
+ sources.emplace_back(source.sourceId);
break;
case SourceType::TopProjectInclude:
topProjectIncludes.emplace_back(source.sourceId);
projectIncludes.emplace_back(source.sourceId);
+ sources.emplace_back(source.sourceId);
break;
case SourceType::ProjectInclude:
projectIncludes.emplace_back(source.sourceId);
+ sources.emplace_back(source.sourceId);
break;
case SourceType::UserInclude:
case SourceType::Source:
break;
}
- sources.emplace_back(source.sourceId);
}
static Utils::SmallStringVector filterUsedMarcos(const UsedMacros &usedMacros,
diff --git a/src/tools/clangrefactoringbackend/source/symbolindexer.cpp b/src/tools/clangrefactoringbackend/source/symbolindexer.cpp
index 299088aa4b..4f3a6f172f 100644
--- a/src/tools/clangrefactoringbackend/source/symbolindexer.cpp
+++ b/src/tools/clangrefactoringbackend/source/symbolindexer.cpp
@@ -145,7 +145,7 @@ void SymbolIndexer::updateProjectPart(ProjectPartContainer &&projectPart)
}
m_pathWatcher.updateIdPaths(
- {{projectPartId, m_buildDependencyStorage.fetchSources(projectPartId)}});
+ {{projectPartId, m_buildDependencyStorage.fetchPchSources(projectPartId)}});
m_symbolIndexerTaskQueue.addOrUpdateTasks(std::move(symbolIndexerTask));
m_symbolIndexerTaskQueue.processEntries();
}
diff --git a/tests/unit/unittest/builddependenciesstorage-test.cpp b/tests/unit/unittest/builddependenciesstorage-test.cpp
index 052ed452f0..d14b94fe30 100644
--- a/tests/unit/unittest/builddependenciesstorage-test.cpp
+++ b/tests/unit/unittest/builddependenciesstorage-test.cpp
@@ -70,7 +70,7 @@ protected:
MockSqliteWriteStatement &updatePchCreationTimeStampStatement = storage.updatePchCreationTimeStampStatement;
MockSqliteWriteStatement &deleteAllProjectPartsFilesWithProjectPartNameStatement
= storage.deleteAllProjectPartsFilesWithProjectPartNameStatement;
- MockSqliteReadStatement &fetchProjectPartsFilesStatement = storage.fetchProjectPartsFilesStatement;
+ MockSqliteReadStatement &fetchProjectPartsFilesStatement = storage.fetchPchSourcesStatement;
};
TEST_F(BuildDependenciesStorage, ConvertStringsToJson)
@@ -238,7 +238,7 @@ TEST_F(BuildDependenciesStorage, FetchSources)
ClangBackEnd::FilePathIds result{3, 5, 7};
EXPECT_CALL(fetchProjectPartsFilesStatement, valuesReturnFilePathIds(_, 22)).WillOnce(Return(result));
- auto sources = storage.fetchSources(22);
+ auto sources = storage.fetchPchSources(22);
ASSERT_THAT(sources, result);
}
diff --git a/tests/unit/unittest/mockbuilddependenciesstorage.h b/tests/unit/unittest/mockbuilddependenciesstorage.h
index a4d34e481d..dd2850d88c 100644
--- a/tests/unit/unittest/mockbuilddependenciesstorage.h
+++ b/tests/unit/unittest/mockbuilddependenciesstorage.h
@@ -51,7 +51,7 @@ public:
ClangBackEnd::ProjectPartId(Utils::SmallStringView projectPartName));
MOCK_METHOD2(updatePchCreationTimeStamp,
void(long long pchCreationTimeStamp, ClangBackEnd::ProjectPartId projectPartId));
- MOCK_CONST_METHOD1(fetchSources,
+ MOCK_CONST_METHOD1(fetchPchSources,
ClangBackEnd::FilePathIds(ClangBackEnd::ProjectPartId projectPartId));
};
diff --git a/tests/unit/unittest/pchcreator-test.cpp b/tests/unit/unittest/pchcreator-test.cpp
index 0cf84a983d..04e198eec7 100644
--- a/tests/unit/unittest/pchcreator-test.cpp
+++ b/tests/unit/unittest/pchcreator-test.cpp
@@ -226,16 +226,21 @@ TEST_F(PchCreatorVerySlowTest, SourcesAreWatchedAfterSucess)
creator.doInMainThreadAfterFinished();
}
-TEST_F(PchCreatorVerySlowTest, SourcesAreNotWatchedAfterFail)
+TEST_F(PchCreatorVerySlowTest, SourcesAreWatchedAfterFail)
{
pchTask1.systemIncludeSearchPaths = {};
pchTask1.projectIncludeSearchPaths = {};
creator.generatePch(std::move(pchTask1));
EXPECT_CALL(mockClangPathWatcher,
- updateIdPaths(
- ElementsAre(AllOf(Field(&ClangBackEnd::IdPaths::id, 1),
- Field(&ClangBackEnd::IdPaths::filePathIds, IsEmpty())))));
+ updateIdPaths(ElementsAre(AllOf(
+ Field(&ClangBackEnd::IdPaths::id, 1),
+ 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();
}
@@ -337,9 +342,14 @@ TEST_F(PchCreatorSlowTest, NoIncludesInTheMainThreadCalls)
Field(&ClangBackEnd::PrecompiledHeadersUpdatedMessage::projectPartIds,
ElementsAre(Eq(creator.projectPartPch().projectPartId)))));
EXPECT_CALL(mockClangPathWatcher,
- updateIdPaths(
- ElementsAre(AllOf(Field(&ClangBackEnd::IdPaths::id, 1),
- Field(&ClangBackEnd::IdPaths::filePathIds, IsEmpty())))));
+ updateIdPaths(ElementsAre(AllOf(
+ Field(&ClangBackEnd::IdPaths::id, 1),
+ 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")))))));
EXPECT_CALL(mockBuildDependenciesStorage, updatePchCreationTimeStamp(Gt(0), Eq(1)));
creator.doInMainThreadAfterFinished();
diff --git a/tests/unit/unittest/pchtaskgenerator-test.cpp b/tests/unit/unittest/pchtaskgenerator-test.cpp
index 8f5f0754af..cb9df32235 100644
--- a/tests/unit/unittest/pchtaskgenerator-test.cpp
+++ b/tests/unit/unittest/pchtaskgenerator-test.cpp
@@ -117,7 +117,7 @@ TEST_F(PchTaskGenerator, AddProjectParts)
&PchTaskSet::project,
AllOf(Field(&PchTask::projectPartIds, ElementsAre(ProjectPartId{1})),
Field(&PchTask::includes, ElementsAre(3)),
- Field(&PchTask::sources, ElementsAre(1, 2, 3, 4, 5)),
+ Field(&PchTask::sources, ElementsAre(1, 3, 4, 5)),
Field(&PchTask::compilerMacros,
ElementsAre(CompilerMacro{"YI", "1", 1}, CompilerMacro{"SAN", "3", 3})),
Field(&PchTask::systemIncludeSearchPaths,
diff --git a/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp b/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp
index 7177060311..3af0fc8cfe 100644
--- a/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp
+++ b/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp
@@ -107,7 +107,10 @@ TEST_F(RefactoringDatabaseInitializer, AddProjectPartsFilesTable)
"sourceId INTEGER, sourceType INTEGER, pchCreationTimeStamp INTEGER, "
"hasMissingIncludes INTEGER)")));
EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_projectPartsFiles_sourceId_projectPartId ON projectPartsFiles(sourceId, projectPartId)")));
- EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_projectPartsFiles_projectPartId ON projectPartsFiles(projectPartId)")));
+ EXPECT_CALL(mockDatabase,
+ execute(Eq(
+ "CREATE INDEX IF NOT EXISTS index_projectPartsFiles_projectPartId_sourceType "
+ "ON projectPartsFiles(projectPartId, sourceType)")));
initializer.createProjectPartsFilesTable();
}
@@ -247,9 +250,10 @@ TEST_F(RefactoringDatabaseInitializer, CreateInTheContructor)
execute(
Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_projectPartsFiles_sourceId_projectPartId "
"ON projectPartsFiles(sourceId, projectPartId)")));
- EXPECT_CALL(mockDatabase,
- execute(Eq("CREATE INDEX IF NOT EXISTS index_projectPartsFiles_projectPartId ON "
- "projectPartsFiles(projectPartId)")));
+ EXPECT_CALL(
+ mockDatabase,
+ execute(Eq("CREATE INDEX IF NOT EXISTS index_projectPartsFiles_projectPartId_sourceType ON "
+ "projectPartsFiles(projectPartId, sourceType)")));
EXPECT_CALL(mockDatabase,
execute(Eq("CREATE TABLE IF NOT EXISTS usedMacros(usedMacroId INTEGER PRIMARY KEY, "
"sourceId INTEGER, macroName TEXT)")));
diff --git a/tests/unit/unittest/symbolindexer-test.cpp b/tests/unit/unittest/symbolindexer-test.cpp
index c7831d099f..16e0fc81b0 100644
--- a/tests/unit/unittest/symbolindexer-test.cpp
+++ b/tests/unit/unittest/symbolindexer-test.cpp
@@ -923,7 +923,7 @@ TEST_F(SymbolIndexer, SourcesAreWatched)
InSequence s;
FilePathIds sourcePathIds{4, 6, 8};
- EXPECT_CALL(mockBuildDependenciesStorage, fetchSources(projectPart1.projectPartId))
+ EXPECT_CALL(mockBuildDependenciesStorage, fetchPchSources(projectPart1.projectPartId))
.WillOnce(Return(sourcePathIds));
EXPECT_CALL(mockPathWatcher,
updateIdPaths(ElementsAre(AllOf(Field(&IdPaths::id, projectPart1.projectPartId),
diff --git a/tests/unit/unittest/usedmacrofilter-test.cpp b/tests/unit/unittest/usedmacrofilter-test.cpp
index 788a443eee..85e1bb59b5 100644
--- a/tests/unit/unittest/usedmacrofilter-test.cpp
+++ b/tests/unit/unittest/usedmacrofilter-test.cpp
@@ -98,12 +98,7 @@ TEST_F(UsedMacroFilter, Sources)
ClangBackEnd::UsedMacroFilter filter(sources, usedMacros, compileMacros);
ASSERT_THAT(filter.sources,
- ElementsAre(FilePathId{1},
- FilePathId{2},
- FilePathId{3},
- FilePathId{4},
- FilePathId{5},
- FilePathId{6}));
+ ElementsAre(FilePathId{2}, FilePathId{3}, FilePathId{4}, FilePathId{5}));
}
TEST_F(UsedMacroFilter, SystemUsedMacros)