ClangPchManager: Improve handling of no include in project PCH

We were doing simply nothing but we should call
PchCreator::doInMainThreadAfterFinished().

Change-Id: Ia21d2cf4af53121d9e401f6e9a5b432a4daed00f
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2019-05-22 15:08:55 +02:00
parent b213dee013
commit b36e9d0e95
3 changed files with 36 additions and 9 deletions

View File

@@ -113,8 +113,11 @@ Utils::SmallStringVector PchCreator::generateClangCompilerArguments(const PchTas
void PchCreator::generatePch(PchTask &&pchTask) void PchCreator::generatePch(PchTask &&pchTask)
{ {
m_projectPartPch.projectPartId = pchTask.projectPartId(); m_projectPartPch.projectPartId = pchTask.projectPartId();
m_projectPartPch.lastModified = QDateTime::currentSecsSinceEpoch(); m_projectPartPch.lastModified = QDateTime::currentSecsSinceEpoch();
if (pchTask.includes.empty())
return;
auto content = generatePchIncludeFileContent(pchTask.includes); auto content = generatePchIncludeFileContent(pchTask.includes);
auto pchOutputPath = generatePchFilePath(); auto pchOutputPath = generatePchFilePath();

View File

@@ -33,6 +33,8 @@
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <iostream>
namespace ClangBackEnd { namespace ClangBackEnd {
void PchTaskQueue::addPchTasks(PchTasks &&newPchTasks, PchTasks &destination) void PchTaskQueue::addPchTasks(PchTasks &&newPchTasks, PchTasks &destination)
@@ -145,7 +147,6 @@ std::vector<PchTaskQueue::Task> PchTaskQueue::createProjectTasks(PchTasks &&pchT
auto convert = [this](auto &&pchTask) { auto convert = [this](auto &&pchTask) {
return [pchTask = std::move(pchTask), this](PchCreatorInterface &pchCreator) mutable { return [pchTask = std::move(pchTask), this](PchCreatorInterface &pchCreator) mutable {
const auto projectPartId = pchTask.projectPartId(); const auto projectPartId = pchTask.projectPartId();
if (pchTask.includes.size()) {
pchTask.systemPchPath = m_precompiledHeaderStorage.fetchSystemPrecompiledHeaderPath( pchTask.systemPchPath = m_precompiledHeaderStorage.fetchSystemPrecompiledHeaderPath(
projectPartId); projectPartId);
pchTask.preIncludeSearchPath = m_environment.preIncludeSearchPath(); pchTask.preIncludeSearchPath = m_environment.preIncludeSearchPath();
@@ -157,9 +158,6 @@ std::vector<PchTaskQueue::Task> PchTaskQueue::createProjectTasks(PchTasks &&pchT
m_precompiledHeaderStorage.insertProjectPrecompiledHeader( m_precompiledHeaderStorage.insertProjectPrecompiledHeader(
projectPartId, projectPartPch.pchPath, projectPartPch.lastModified); projectPartId, projectPartPch.pchPath, projectPartPch.lastModified);
} }
} else {
m_precompiledHeaderStorage.deleteProjectPrecompiledHeader(projectPartId);
}
}; };
}; };
@@ -179,7 +177,6 @@ std::vector<PchTaskQueue::Task> PchTaskQueue::createSystemTasks(PchTasks &&pchTa
auto convert = [this](auto &&pchTask) { auto convert = [this](auto &&pchTask) {
return [pchTask = std::move(pchTask), this](PchCreatorInterface &pchCreator) mutable { return [pchTask = std::move(pchTask), this](PchCreatorInterface &pchCreator) mutable {
const auto projectPartIds = pchTask.projectPartIds; const auto projectPartIds = pchTask.projectPartIds;
if (pchTask.includes.size()) {
pchTask.preIncludeSearchPath = m_environment.preIncludeSearchPath(); pchTask.preIncludeSearchPath = m_environment.preIncludeSearchPath();
pchCreator.generatePch(std::move(pchTask)); pchCreator.generatePch(std::move(pchTask));
const auto &projectPartPch = pchCreator.projectPartPch(); const auto &projectPartPch = pchCreator.projectPartPch();
@@ -189,9 +186,6 @@ std::vector<PchTaskQueue::Task> PchTaskQueue::createSystemTasks(PchTasks &&pchTa
m_precompiledHeaderStorage.insertSystemPrecompiledHeaders( m_precompiledHeaderStorage.insertSystemPrecompiledHeaders(
projectPartIds, projectPartPch.pchPath, projectPartPch.lastModified); projectPartIds, projectPartPch.pchPath, projectPartPch.lastModified);
} }
} else {
m_precompiledHeaderStorage.deleteSystemPrecompiledHeaders(projectPartIds);
}
}; };
}; };

View File

@@ -315,6 +315,36 @@ TEST_F(PchCreatorVerySlowTest, FaultyProjectPartPchForCreatesFaultyPchForPchTask
Field(&ProjectPartPch::lastModified, Gt(0)))); Field(&ProjectPartPch::lastModified, Gt(0))));
} }
TEST_F(PchCreatorSlowTest, NoIncludes)
{
pchTask1.includes = {};
creator.generatePch(std::move(pchTask1));
ASSERT_THAT(creator.projectPartPch(),
AllOf(Field(&ProjectPartPch::projectPartId, Eq(pchTask1.projectPartId())),
Field(&ProjectPartPch::pchPath, IsEmpty()),
Field(&ProjectPartPch::lastModified, Gt(0))));
}
TEST_F(PchCreatorSlowTest, NoIncludesInTheMainThreadCalls)
{
pchTask1.includes = {};
creator.generatePch(std::move(pchTask1));
EXPECT_CALL(mockPchManagerClient,
precompiledHeadersUpdated(
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())))));
EXPECT_CALL(mockBuildDependenciesStorage, updatePchCreationTimeStamp(Gt(0), Eq(1)));
creator.doInMainThreadAfterFinished();
}
TEST_F(PchCreatorVerySlowTest, GeneratedFile) TEST_F(PchCreatorVerySlowTest, GeneratedFile)
{ {
creator.clear(); creator.clear();