diff --git a/src/tools/clangpchmanagerbackend/source/pchcreator.cpp b/src/tools/clangpchmanagerbackend/source/pchcreator.cpp index f10c620a897..935e446f53c 100644 --- a/src/tools/clangpchmanagerbackend/source/pchcreator.cpp +++ b/src/tools/clangpchmanagerbackend/source/pchcreator.cpp @@ -104,7 +104,7 @@ FilePath PchCreator::generatePchFilePath() const } std::vector 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}); } diff --git a/src/tools/clangpchmanagerbackend/source/pchcreator.h b/src/tools/clangpchmanagerbackend/source/pchcreator.h index 7e5eb36d77d..0d55adbcdd4 100644 --- a/src/tools/clangpchmanagerbackend/source/pchcreator.h +++ b/src/tools/clangpchmanagerbackend/source/pchcreator.h @@ -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 generateClangCompilerArguments(PchTask &&pchTask, + static std::vector generateClangCompilerArguments(const PchTask &pchTask, FilePathView includePchHeaderPath, FilePathView pchPath); static std::unique_ptr 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; }; diff --git a/src/tools/clangpchmanagerbackend/source/pchtask.h b/src/tools/clangpchmanagerbackend/source/pchtask.h index 071cbfcb6bd..46c3bf2503f 100644 --- a/src/tools/clangpchmanagerbackend/source/pchtask.h +++ b/src/tools/clangpchmanagerbackend/source/pchtask.h @@ -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; diff --git a/src/tools/clangpchmanagerbackend/source/pchtaskgenerator.cpp b/src/tools/clangpchmanagerbackend/source/pchtaskgenerator.cpp index 8159dbeb127..569e4a1d8a3 100644 --- a/src/tools/clangpchmanagerbackend/source/pchtaskgenerator.cpp +++ b/src/tools/clangpchmanagerbackend/source/pchtaskgenerator.cpp @@ -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, diff --git a/src/tools/clangpchmanagerbackend/source/usedmacrofilter.h b/src/tools/clangpchmanagerbackend/source/usedmacrofilter.h index 43af0b6488b..e7969c4ea1b 100644 --- a/src/tools/clangpchmanagerbackend/source/usedmacrofilter.h +++ b/src/tools/clangpchmanagerbackend/source/usedmacrofilter.h @@ -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; diff --git a/tests/unit/unittest/commandlinebuilder-test.cpp b/tests/unit/unittest/commandlinebuilder-test.cpp index 4548b57a9bd..f51a4f6a714 100644 --- a/tests/unit/unittest/commandlinebuilder-test.cpp +++ b/tests/unit/unittest/commandlinebuilder-test.cpp @@ -51,8 +51,8 @@ public: } public: - ClangBackEnd::PchTask emptyProjectInfo{"empty", {}, {}, {}, {}, {}, {}}; - ClangBackEnd::PchTask cppProjectInfo{"project1", {}, {}, {}, {}, {}, {}}; + ClangBackEnd::PchTask emptyProjectInfo{"empty", {}, {}, {}, {}, {}, {}, {}}; + ClangBackEnd::PchTask cppProjectInfo{"project1", {}, {}, {}, {}, {}, {}, {}}; }; template <> diff --git a/tests/unit/unittest/pchcreator-test.cpp b/tests/unit/unittest/pchcreator-test.cpp index b03371794c9..0da712d9836 100644 --- a/tests/unit/unittest/pchcreator-test.cpp +++ b/tests/unit/unittest/pchcreator-test.cpp @@ -99,9 +99,13 @@ protected: TestEnvironment environment; FileContainer generatedFile{{TESTDATA_DIR, generatedFileName}, "#pragma once", {}}; NiceMock mockPchManagerClient; - ClangBackEnd::PchCreator creator{environment, database, mockPchManagerClient}; + NiceMock 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}}, {}, {}, diff --git a/tests/unit/unittest/pchtaskgenerator-test.cpp b/tests/unit/unittest/pchtaskgenerator-test.cpp index 74610f51701..0b2ec3968e3 100644 --- a/tests/unit/unittest/pchtaskgenerator-test.cpp +++ b/tests/unit/unittest/pchtaskgenerator-test.cpp @@ -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})), diff --git a/tests/unit/unittest/pchtaskqueue-test.cpp b/tests/unit/unittest/pchtaskqueue-test.cpp index aacd881553d..61892811c5c 100644 --- a/tests/unit/unittest/pchtaskqueue-test.cpp +++ b/tests/unit/unittest/pchtaskqueue-test.cpp @@ -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}}, diff --git a/tests/unit/unittest/pchtasksmerger-test.cpp b/tests/unit/unittest/pchtasksmerger-test.cpp index 6319389e731..f54e7aca582 100644 --- a/tests/unit/unittest/pchtasksmerger-test.cpp +++ b/tests/unit/unittest/pchtasksmerger-test.cpp @@ -50,6 +50,7 @@ protected: NiceMock 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}}, diff --git a/tests/unit/unittest/usedmacrofilter-test.cpp b/tests/unit/unittest/usedmacrofilter-test.cpp index 871d4a8535e..bc5b79cccf5 100644 --- a/tests/unit/unittest/usedmacrofilter-test.cpp +++ b/tests/unit/unittest/usedmacrofilter-test.cpp @@ -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);