ClangPchManager: Update ClangPathWatcher after PCH creation

If the PCH creation was successful we want to watch the PCH to update the
PCH.

Task-number: QTCREATORBUG-21800
Change-Id: Ic84901bde23f60ce2f4e2781ddd1e4f895354ab1
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
Marco Bubke
2019-01-24 13:19:03 +01:00
parent f5974ad993
commit 1c77d7e1a7
11 changed files with 83 additions and 7 deletions

View File

@@ -104,7 +104,7 @@ FilePath PchCreator::generatePchFilePath() const
}
std::vector<std::string> PchCreator::generateClangCompilerArguments(
PchTask &&pchTask,
const PchTask &pchTask,
FilePathView sourceFilePath,
FilePathView pchOutputPath)
{
@@ -129,13 +129,14 @@ void PchCreator::generatePch(PchTask &&pchTask)
pchSourceFilePath.directory(),
pchSourceFilePath.name(),
"",
generateClangCompilerArguments(std::move(pchTask), pchSourceFilePath, pchOutputPath));
generateClangCompilerArguments(pchTask, pchSourceFilePath, pchOutputPath));
bool success = generatePch();
m_projectPartPch.projectPartId = pchTask.projectPartId();
if (success) {
m_allInclues = pchTask.allIncludes;
m_projectPartPch.pchPath = std::move(pchOutputPath);
m_projectPartPch.lastModified = lastModified;
}
@@ -169,6 +170,7 @@ void PchCreator::clear()
void PchCreator::doInMainThreadAfterFinished()
{
m_clangPathwatcher.updateIdPaths({{m_projectPartPch.projectPartId, m_allInclues}});
m_pchManagerClient.precompiledHeadersUpdated(ProjectPartPchs{m_projectPartPch});
}

View File

@@ -62,10 +62,12 @@ class PchCreator final : public PchCreatorInterface
public:
PchCreator(Environment &environment,
Sqlite::Database &database,
PchManagerClientInterface &pchManagerClient)
PchManagerClientInterface &pchManagerClient,
ClangPathWatcherInterface &clangPathwatcher)
: m_filePathCache(database)
, m_environment(environment)
, m_pchManagerClient(pchManagerClient)
, m_clangPathwatcher(clangPathwatcher)
{}
void generatePch(PchTask &&pchTask) override;
@@ -83,7 +85,7 @@ public:
FilePath generatePchHeaderFilePath() const;
FilePath generatePchFilePath() const;
static std::vector<std::string> generateClangCompilerArguments(PchTask &&pchTask,
static std::vector<std::string> generateClangCompilerArguments(const PchTask &pchTask,
FilePathView includePchHeaderPath,
FilePathView pchPath);
static std::unique_ptr<QFile> generateFileWithContent(const Utils::SmallString &filePath,
@@ -99,8 +101,10 @@ private:
ClangTool m_clangTool;
ProjectPartPch m_projectPartPch;
FilePathCaching m_filePathCache;
FilePathIds m_allInclues;
Environment &m_environment;
PchManagerClientInterface &m_pchManagerClient;
ClangPathWatcherInterface &m_clangPathwatcher;
bool m_isUsed = false;
};

View File

@@ -41,6 +41,7 @@ class PchTask
public:
PchTask(Utils::SmallString &&projectPartId,
FilePathIds &&includes,
FilePathIds &&allIncludes,
CompilerMacros &&compilerMacros,
UsedMacros &&usedMacros,
Utils::SmallStringVector toolChainArguments,
@@ -51,6 +52,7 @@ public:
Utils::LanguageExtension languageExtension = Utils::LanguageExtension::None)
: projectPartIds({projectPartId})
, includes(includes)
, allIncludes(allIncludes)
, compilerMacros(compilerMacros)
, usedMacros(usedMacros)
, systemIncludeSearchPaths(std::move(systemIncludeSearchPaths))
@@ -63,6 +65,7 @@ public:
PchTask(Utils::SmallStringVector &&projectPartIds,
FilePathIds &&includes,
FilePathIds &&allIncludes,
CompilerMacros &&compilerMacros,
UsedMacros &&usedMacros,
Utils::SmallStringVector toolChainArguments,
@@ -73,6 +76,7 @@ public:
Utils::LanguageExtension languageExtension = Utils::LanguageExtension::None)
: projectPartIds(std::move(projectPartIds))
, includes(includes)
, allIncludes(allIncludes)
, compilerMacros(compilerMacros)
, usedMacros(usedMacros)
, systemIncludeSearchPaths(std::move(systemIncludeSearchPaths))
@@ -103,6 +107,7 @@ public:
FilePath systemPchPath;
Utils::SmallStringVector projectPartIds;
FilePathIds includes;
FilePathIds allIncludes;
CompilerMacros compilerMacros;
UsedMacros usedMacros;
IncludeSearchPaths systemIncludeSearchPaths;

View File

@@ -48,6 +48,7 @@ void PchTaskGenerator::addProjectParts(ProjectPartContainers &&projectParts,
pchTaskSets.emplace_back(PchTask{projectPart.projectPartId.clone(),
std::move(filter.topSystemIncludes),
{},
std::move(filter.systemCompilerMacros),
std::move(filter.systemUsedMacros),
projectPart.toolChainArguments,
@@ -58,6 +59,7 @@ void PchTaskGenerator::addProjectParts(ProjectPartContainers &&projectParts,
projectPart.languageExtension},
PchTask{std::move(projectPart.projectPartId),
std::move(filter.topProjectIncludes),
std::move(filter.allIncludes),
std::move(filter.projectCompilerMacros),
std::move(filter.projectUsedMacros),
projectPart.toolChainArguments,

View File

@@ -94,6 +94,8 @@ private:
case SourceType::UserInclude:
break;
}
allIncludes.emplace_back(include.sourceId);
}
static UsedMacros filterUsedMarcos(const UsedMacros &usedMacros, const FilePathIds &filePathId)
@@ -162,6 +164,7 @@ private:
}
public:
FilePathIds allIncludes;
FilePathIds projectIncludes;
FilePathIds systemIncludes;
FilePathIds topProjectIncludes;

View File

@@ -51,8 +51,8 @@ public:
}
public:
ClangBackEnd::PchTask emptyProjectInfo{"empty", {}, {}, {}, {}, {}, {}};
ClangBackEnd::PchTask cppProjectInfo{"project1", {}, {}, {}, {}, {}, {}};
ClangBackEnd::PchTask emptyProjectInfo{"empty", {}, {}, {}, {}, {}, {}, {}};
ClangBackEnd::PchTask cppProjectInfo{"project1", {}, {}, {}, {}, {}, {}, {}};
};
template <>

View File

@@ -99,9 +99,13 @@ protected:
TestEnvironment environment;
FileContainer generatedFile{{TESTDATA_DIR, generatedFileName}, "#pragma once", {}};
NiceMock<MockPchManagerClient> mockPchManagerClient;
ClangBackEnd::PchCreator creator{environment, database, mockPchManagerClient};
NiceMock<MockClangPathWatcher> mockClangPathWatcher;
ClangBackEnd::PchCreator creator{environment, database, mockPchManagerClient, mockClangPathWatcher};
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(TESTDATA_DIR "/builddependencycollector/project/header2.h"),
id(TESTDATA_DIR "/builddependencycollector/external/external1.h"),
id(TESTDATA_DIR "/builddependencycollector/external/external2.h")},
@@ -207,6 +211,37 @@ TEST_F(PchCreatorVerySlowTest, ProjectPartPchsSendToPchManagerClient)
creator.doInMainThreadAfterFinished();
}
TEST_F(PchCreatorVerySlowTest, AllIncludesAreWatchedAfterSucess)
{
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")))))));
creator.doInMainThreadAfterFinished();
}
TEST_F(PchCreatorVerySlowTest, AllIncludesAreNotWatchedAfterFail)
{
pchTask1.systemIncludeSearchPaths = {};
pchTask1.projectIncludeSearchPaths = {};
creator.generatePch(std::move(pchTask1));
EXPECT_CALL(mockClangPathWatcher,
updateIdPaths(
ElementsAre(AllOf(Field(&ClangBackEnd::IdPaths::id, "project1"),
Field(&ClangBackEnd::IdPaths::filePathIds, IsEmpty())))));
creator.doInMainThreadAfterFinished();
}
TEST_F(PchCreatorVerySlowTest, ProjectPartPchForCreatesPchForPchTask)
{
@@ -240,6 +275,7 @@ TEST_F(PchCreatorVerySlowTest, FaultyProjectPartPchForCreatesFaultyPchForPchTask
{
PchTask faultyPchTask{"faultyProjectPart",
{id(TESTDATA_DIR "/builddependencycollector/project/faulty.cpp")},
{},
{{"DEFINE", "1", 1}},
{},
{},

View File

@@ -96,6 +96,7 @@ TEST_F(PchTaskGenerator, AddProjectParts)
AllOf(
Field(&PchTask::projectPartIds, ElementsAre("ProjectPart1")),
Field(&PchTask::includes, ElementsAre(5)),
Field(&PchTask::allIncludes, IsEmpty()),
Field(&PchTask::compilerMacros,
ElementsAre(CompilerMacro{"SE", "4", 4}, CompilerMacro{"WU", "5", 5})),
Field(&PchTask::usedMacros, ElementsAre(UsedMacro{"SE", 4}, UsedMacro{"WU", 5})),
@@ -116,6 +117,7 @@ TEST_F(PchTaskGenerator, AddProjectParts)
AllOf(
Field(&PchTask::projectPartIds, ElementsAre("ProjectPart1")),
Field(&PchTask::includes, ElementsAre(3)),
Field(&PchTask::allIncludes, ElementsAre(1, 2, 3, 4, 5)),
Field(&PchTask::compilerMacros,
ElementsAre(CompilerMacro{"YI", "1", 1}, CompilerMacro{"SAN", "3", 3})),
Field(&PchTask::usedMacros, ElementsAre(UsedMacro{"YI", 1}, UsedMacro{"SAN", 3})),

View File

@@ -62,6 +62,7 @@ protected:
{"/project/includes", 1, IncludeSearchPathType::User},
{"/other/project/includes", 2, IncludeSearchPathType::User}};
PchTask systemTask1{"ProjectPart1",
{1, 2},
{1, 2},
{{"YI", "1", 1}, {"SAN", "3", 3}},
{{"LIANG", 0}, {"YI", 1}},
@@ -69,6 +70,7 @@ protected:
systemIncludeSearchPaths,
projectIncludeSearchPaths};
PchTask systemTask2{"ProjectPart2",
{1, 2},
{1, 2},
{{"YI", "1", 1}, {"SAN", "3", 3}},
{{"LIANG", 0}, {"YI", 1}},
@@ -76,6 +78,7 @@ protected:
systemIncludeSearchPaths,
projectIncludeSearchPaths};
PchTask systemTask2b{"ProjectPart2",
{3, 4},
{3, 4},
{{"YI", "1", 1}, {"SAN", "3", 3}},
{{"LIANG", 0}, {"YI", 1}},
@@ -83,6 +86,7 @@ protected:
systemIncludeSearchPaths,
projectIncludeSearchPaths};
PchTask systemTask3{"ProjectPart3",
{1, 2},
{1, 2},
{{"YI", "1", 1}, {"SAN", "3", 3}},
{{"LIANG", 0}, {"YI", 1}},
@@ -90,6 +94,7 @@ protected:
systemIncludeSearchPaths,
projectIncludeSearchPaths};
PchTask projectTask1{"ProjectPart1",
{11, 12},
{11, 12},
{{"SE", "4", 4}, {"WU", "5", 5}},
{{"ER", 2}, {"SAN", 3}},
@@ -97,6 +102,7 @@ protected:
systemIncludeSearchPaths,
projectIncludeSearchPaths};
PchTask projectTask2{"ProjectPart2",
{11, 12},
{11, 12},
{{"SE", "4", 4}, {"WU", "5", 5}},
{{"ER", 2}, {"SAN", 3}},
@@ -105,12 +111,14 @@ protected:
projectIncludeSearchPaths};
PchTask projectTask2b{"ProjectPart2",
{21, 22},
{11, 12},
{{"SE", "4", 4}, {"WU", "5", 5}},
{{"ER", 2}, {"SAN", 3}},
{"--yi"},
systemIncludeSearchPaths,
projectIncludeSearchPaths};
PchTask projectTask3{"ProjectPart3",
{21, 22},
{21, 22},
{{"SE", "4", 4}, {"WU", "5", 5}},
{{"ER", 2}, {"SAN", 3}},
@@ -118,6 +126,7 @@ protected:
systemIncludeSearchPaths,
projectIncludeSearchPaths};
PchTask systemTask4{Utils::SmallStringVector{"ProjectPart1", "ProjectPart3"},
{1, 2},
{1, 2},
{{"YI", "1", 1}, {"SAN", "3", 3}},
{{"LIANG", 0}, {"YI", 1}},

View File

@@ -50,6 +50,7 @@ protected:
NiceMock<MockPchTaskQueue> mockPchTaskQueue;
ClangBackEnd::PchTasksMerger merger{mockPchTaskQueue};
PchTask systemTask1{"ProjectPart1",
{1, 2},
{1, 2},
{{"YI", "1", 1}, {"SAN", "3", 3}},
{{"LIANG", 0}, {"YI", 1}},
@@ -60,6 +61,7 @@ protected:
{IncludeSearchPath{"/to/path1", 1, IncludeSearchPathType::User},
IncludeSearchPath{"/to/path2", 2, IncludeSearchPathType::User}}};
PchTask projectTask1{"ProjectPart1",
{11, 12},
{11, 12},
{{"SE", "4", 4}, {"WU", "5", 5}},
{{"ER", 2}, {"SAN", 3}},
@@ -70,6 +72,7 @@ protected:
{IncludeSearchPath{"/to/path1", 1, IncludeSearchPathType::User},
IncludeSearchPath{"/to/path2", 2, IncludeSearchPathType::User}}};
PchTask systemTask2{"ProjectPart2",
{1, 2},
{1, 2},
{{"YI", "1", 1}, {"SAN", "3", 3}},
{{"LIANG", 0}, {"YI", 1}},
@@ -80,6 +83,7 @@ protected:
{IncludeSearchPath{"/to/path1", 1, IncludeSearchPathType::User},
IncludeSearchPath{"/to/path2", 2, IncludeSearchPathType::User}}};
PchTask projectTask2{"ProjectPart2",
{11, 12},
{11, 12},
{{"SE", "4", 4}, {"WU", "5", 5}},
{{"ER", 2}, {"SAN", 3}},

View File

@@ -83,6 +83,15 @@ TEST_F(UsedMacroFilter, TopProjectIncludes)
ASSERT_THAT(filter.topProjectIncludes, ElementsAre(FilePathId{5}));
}
TEST_F(UsedMacroFilter, AllIncludes)
{
ClangBackEnd::UsedMacroFilter filter(includes, usedMacros);
ASSERT_THAT(filter.allIncludes,
ElementsAre(FilePathId{1}, FilePathId{2}, FilePathId{3}, FilePathId{4}, FilePathId{5}));
}
TEST_F(UsedMacroFilter, SystemUsedMacros)
{
ClangBackEnd::UsedMacroFilter filter(includes, usedMacros);