diff --git a/src/tools/clangpchmanagerbackend/source/collectincludesaction.h b/src/tools/clangpchmanagerbackend/source/collectincludesaction.h index d55559b41e0..3a0f00b31cb 100644 --- a/src/tools/clangpchmanagerbackend/source/collectincludesaction.h +++ b/src/tools/clangpchmanagerbackend/source/collectincludesaction.h @@ -41,11 +41,13 @@ class CollectIncludesAction final : public clang::PreprocessOnlyAction public: CollectIncludesAction(FilePathIds &includeIds, FilePathIds &topIncludeIds, + FilePathIds &topsSystemIncludeIds, const FilePathCachingInterface &filePathCache, std::vector &excludedIncludeUID, std::vector &alreadyIncludedFileUIDs) : m_includeIds(includeIds), m_topIncludeIds(topIncludeIds), + m_topsSystemIncludeIds(topsSystemIncludeIds), m_filePathCache(filePathCache), m_excludedIncludeUID(excludedIncludeUID), m_alreadyIncludedFileUIDs(alreadyIncludedFileUIDs) @@ -62,6 +64,7 @@ public: auto macroPreprocessorCallbacks = new CollectIncludesPreprocessorCallbacks( m_includeIds, m_topIncludeIds, + m_topsSystemIncludeIds, m_filePathCache, m_excludedIncludeUID, m_alreadyIncludedFileUIDs, @@ -83,6 +86,7 @@ public: private: FilePathIds &m_includeIds; FilePathIds &m_topIncludeIds; + FilePathIds &m_topsSystemIncludeIds; const FilePathCachingInterface &m_filePathCache; std::vector &m_excludedIncludeUID; std::vector &m_alreadyIncludedFileUIDs; diff --git a/src/tools/clangpchmanagerbackend/source/collectincludespreprocessorcallbacks.h b/src/tools/clangpchmanagerbackend/source/collectincludespreprocessorcallbacks.h index 2754847711b..4eeaa408773 100644 --- a/src/tools/clangpchmanagerbackend/source/collectincludespreprocessorcallbacks.h +++ b/src/tools/clangpchmanagerbackend/source/collectincludespreprocessorcallbacks.h @@ -50,12 +50,14 @@ class CollectIncludesPreprocessorCallbacks final : public clang::PPCallbacks public: CollectIncludesPreprocessorCallbacks(FilePathIds &includeIds, FilePathIds &topIncludeIds, + FilePathIds &topsSystemIncludeIds, const FilePathCachingInterface &filePathCache, const std::vector &excludedIncludeUID, std::vector &alreadyIncludedFileUIDs, clang::SourceManager &sourceManager) : m_includeIds(includeIds), m_topIncludeIds(topIncludeIds), + m_topsSystemIncludeIds(topsSystemIncludeIds), m_filePathCache(filePathCache), m_excludedIncludeUID(excludedIncludeUID), m_alreadyIncludedFileUIDs(alreadyIncludedFileUIDs), @@ -70,11 +72,8 @@ public: const clang::FileEntry *file, llvm::StringRef /*searchPath*/, llvm::StringRef /*relativePath*/, - const clang::Module * /*imported*/ -#if LLVM_VERSION_MAJOR >= 7 - , clang::SrcMgr::CharacteristicKind /*fileType*/ -#endif - ) override + const clang::Module * /*imported*/, + clang::SrcMgr::CharacteristicKind fileType) override { if (!m_skipInclude && file) { auto fileUID = file->getUID(); @@ -87,6 +86,8 @@ public: if (!filePath.empty()) { FilePathId includeId = m_filePathCache.filePathId(filePath); m_includeIds.emplace_back(includeId); + if (isSystem(fileType) && !isInSystemHeader(hashLocation)) + m_topsSystemIncludeIds.emplace_back(includeId); if (isInExcludedIncludeUID(sourceFileUID)) m_topIncludeIds.emplace_back(includeId); } @@ -116,6 +117,16 @@ public: return true; } + bool isSystem(clang::SrcMgr::CharacteristicKind kind) + { + return kind != clang::SrcMgr::C_User && kind != clang::SrcMgr::C_User_ModuleMap; + } + + bool isInSystemHeader(clang::SourceLocation location) + { + return m_sourceManager.isInSystemHeader(location); + } + void ensureDirectory(const QString &directory, const QString &fileName) { QStringList directoryEntries = fileName.split('/'); @@ -163,6 +174,7 @@ public: private: FilePathIds &m_includeIds; FilePathIds &m_topIncludeIds; + FilePathIds &m_topsSystemIncludeIds; const FilePathCachingInterface &m_filePathCache; const std::vector &m_excludedIncludeUID; std::vector &m_alreadyIncludedFileUIDs; diff --git a/src/tools/clangpchmanagerbackend/source/collectincludestoolaction.h b/src/tools/clangpchmanagerbackend/source/collectincludestoolaction.h index a9c6e9717e2..6130a049ad5 100644 --- a/src/tools/clangpchmanagerbackend/source/collectincludestoolaction.h +++ b/src/tools/clangpchmanagerbackend/source/collectincludestoolaction.h @@ -39,10 +39,12 @@ class CollectIncludesToolAction final : public clang::tooling::FrontendActionFac public: CollectIncludesToolAction(FilePathIds &includeIds, FilePathIds &topIncludeIds, + FilePathIds &topsSystemIncludeIds, const FilePathCachingInterface &filePathCache, const Utils::PathStringVector &excludedIncludes) : m_includeIds(includeIds), m_topIncludeIds(topIncludeIds), + m_topsSystemIncludeIds(topsSystemIncludeIds), m_filePathCache(filePathCache), m_excludedIncludes(excludedIncludes) {} @@ -66,6 +68,7 @@ public: { return new CollectIncludesAction(m_includeIds, m_topIncludeIds, + m_topsSystemIncludeIds, m_filePathCache, m_excludedIncludeUIDs, m_alreadyIncludedFileUIDs); @@ -93,6 +96,7 @@ private: std::vector m_excludedIncludeUIDs; FilePathIds &m_includeIds; FilePathIds &m_topIncludeIds; + FilePathIds &m_topsSystemIncludeIds; const FilePathCachingInterface &m_filePathCache; const Utils::PathStringVector &m_excludedIncludes; }; diff --git a/src/tools/clangpchmanagerbackend/source/includecollector.cpp b/src/tools/clangpchmanagerbackend/source/includecollector.cpp index 6be1533353d..338491cffcb 100644 --- a/src/tools/clangpchmanagerbackend/source/includecollector.cpp +++ b/src/tools/clangpchmanagerbackend/source/includecollector.cpp @@ -45,6 +45,7 @@ void IncludeCollector::collectIncludes() auto action = std::unique_ptr( new CollectIncludesToolAction(m_includeIds, m_topIncludeIds, + m_topsSystemIncludeIds, m_filePathCache, m_excludedIncludes)); @@ -84,6 +85,11 @@ FilePathIds IncludeCollector::takeTopIncludeIds() return std::move(m_topIncludeIds); } +FilePathIds IncludeCollector::takeTopsSystemIncludeIds() +{ + return std::move(m_topsSystemIncludeIds); +} + } // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/includecollector.h b/src/tools/clangpchmanagerbackend/source/includecollector.h index 30dd89d4704..2d54916cd04 100644 --- a/src/tools/clangpchmanagerbackend/source/includecollector.h +++ b/src/tools/clangpchmanagerbackend/source/includecollector.h @@ -42,11 +42,13 @@ public: FilePathIds takeIncludeIds(); FilePathIds takeTopIncludeIds(); + FilePathIds takeTopsSystemIncludeIds(); private: Utils::PathStringVector m_excludedIncludes; FilePathIds m_includeIds; FilePathIds m_topIncludeIds; + FilePathIds m_topsSystemIncludeIds; Utils::SmallStringVector m_directories; const FilePathCachingInterface &m_filePathCache; }; diff --git a/src/tools/clangpchmanagerbackend/source/pchcreator.cpp b/src/tools/clangpchmanagerbackend/source/pchcreator.cpp index e02f563efee..dda93d434d3 100644 --- a/src/tools/clangpchmanagerbackend/source/pchcreator.cpp +++ b/src/tools/clangpchmanagerbackend/source/pchcreator.cpp @@ -236,7 +236,7 @@ Utils::PathStringVector PchCreator::generateProjectPartSourcePaths( return includeAndSources; } -std::pair PchCreator::generateProjectPartPchIncludes( +PchCreatorIncludes PchCreator::generateProjectPartPchIncludes( const V2::ProjectPartContainer &projectPart) const { Utils::SmallString jointedFileContent = generateProjectPartSourcesContent(projectPart); @@ -261,7 +261,7 @@ std::pair PchCreator::generateProjectPartPchIncludes( jointFile->remove(); - return {collector.takeIncludeIds(), collector.takeTopIncludeIds()}; + return {collector.takeIncludeIds(), collector.takeTopIncludeIds(), collector.takeTopsSystemIncludeIds()}; } Utils::SmallString PchCreator::generateProjectPathPchHeaderFilePath( @@ -312,10 +312,8 @@ Utils::SmallStringVector PchCreator::generateProjectPartClangCompilerArguments( IdPaths PchCreator::generateProjectPartPch(const V2::ProjectPartContainer &projectPart) { long long lastModified = QDateTime::currentSecsSinceEpoch(); - FilePathIds allExternalIncludes; - FilePathIds topExternalIncludes; - std::tie(allExternalIncludes, topExternalIncludes) = generateProjectPartPchIncludes(projectPart); - auto content = generatePchIncludeFileContent(topExternalIncludes); + auto includes = generateProjectPartPchIncludes(projectPart); + auto content = generatePchIncludeFileContent(includes.topIncludeIds); auto pchIncludeFilePath = generateProjectPathPchHeaderFilePath(projectPart); auto pchFilePath = generateProjectPartPchFilePath(projectPart); generateFileWithContent(pchIncludeFilePath, content); @@ -329,7 +327,7 @@ IdPaths PchCreator::generateProjectPartPch(const V2::ProjectPartContainer &proje m_projectPartPch.lastModified = lastModified; } - return {projectPart.projectPartId.clone(), std::move(allExternalIncludes)}; + return {projectPart.projectPartId.clone(), std::move(includes.includeIds)}; } void PchCreator::generatePch(const V2::ProjectPartContainer &projectPart) diff --git a/src/tools/clangpchmanagerbackend/source/pchcreator.h b/src/tools/clangpchmanagerbackend/source/pchcreator.h index b3e0dcde565..7f95b074cbb 100644 --- a/src/tools/clangpchmanagerbackend/source/pchcreator.h +++ b/src/tools/clangpchmanagerbackend/source/pchcreator.h @@ -46,6 +46,14 @@ class GeneratedFiles; class PchManagerClientInterface; class ClangPathWatcherInterface; +class PchCreatorIncludes +{ +public: + FilePathIds includeIds; + FilePathIds topIncludeIds; + FilePathIds topSystemIncludeIds; +}; + class PchCreator final : public PchCreatorInterface { public: @@ -87,7 +95,7 @@ public: const V2::ProjectPartContainer &projectPart) const; Utils::PathStringVector generateProjectPartSourcePaths( const V2::ProjectPartContainer &projectPart) const; - std::pair generateProjectPartPchIncludes( + PchCreatorIncludes generateProjectPartPchIncludes( const V2::ProjectPartContainer &projectPart) const; Utils::SmallString generateProjectPathPchHeaderFilePath( const V2::ProjectPartContainer &projectPart) const; diff --git a/tests/unit/unittest/data/includecollector/external/external1.h b/tests/unit/unittest/data/includecollector/external/external1.h new file mode 100644 index 00000000000..6bc9da6c80d --- /dev/null +++ b/tests/unit/unittest/data/includecollector/external/external1.h @@ -0,0 +1,3 @@ +#pragma once + +#include "indirect_external.h" diff --git a/tests/unit/unittest/data/includecollector_external2.h b/tests/unit/unittest/data/includecollector/external/external2.h similarity index 100% rename from tests/unit/unittest/data/includecollector_external2.h rename to tests/unit/unittest/data/includecollector/external/external2.h diff --git a/tests/unit/unittest/data/includecollector_external3.h b/tests/unit/unittest/data/includecollector/external/external3.h similarity index 100% rename from tests/unit/unittest/data/includecollector_external3.h rename to tests/unit/unittest/data/includecollector/external/external3.h diff --git a/tests/unit/unittest/data/includecollector/external/indirect_external.h b/tests/unit/unittest/data/includecollector/external/indirect_external.h new file mode 100644 index 00000000000..33e9663b635 --- /dev/null +++ b/tests/unit/unittest/data/includecollector/external/indirect_external.h @@ -0,0 +1,3 @@ +#pragma once + +#include "indirect_external2.h" diff --git a/tests/unit/unittest/data/includecollector_false.h b/tests/unit/unittest/data/includecollector/external/indirect_external2.h similarity index 100% rename from tests/unit/unittest/data/includecollector_false.h rename to tests/unit/unittest/data/includecollector/external/indirect_external2.h diff --git a/tests/unit/unittest/data/includecollector_header1.h b/tests/unit/unittest/data/includecollector/project/false.h similarity index 100% rename from tests/unit/unittest/data/includecollector_header1.h rename to tests/unit/unittest/data/includecollector/project/false.h diff --git a/tests/unit/unittest/data/includecollector/project/faulty.cpp b/tests/unit/unittest/data/includecollector/project/faulty.cpp new file mode 100644 index 00000000000..e6697eb5d96 --- /dev/null +++ b/tests/unit/unittest/data/includecollector/project/faulty.cpp @@ -0,0 +1 @@ +#include "faulty.h" diff --git a/tests/unit/unittest/data/includecollector_faulty.h b/tests/unit/unittest/data/includecollector/project/faulty.h similarity index 100% rename from tests/unit/unittest/data/includecollector_faulty.h rename to tests/unit/unittest/data/includecollector/project/faulty.h diff --git a/tests/unit/unittest/data/includecollector_indirect_external2.h b/tests/unit/unittest/data/includecollector/project/header1.h similarity index 100% rename from tests/unit/unittest/data/includecollector_indirect_external2.h rename to tests/unit/unittest/data/includecollector/project/header1.h diff --git a/tests/unit/unittest/data/includecollector/project/header2.h b/tests/unit/unittest/data/includecollector/project/header2.h new file mode 100644 index 00000000000..851c723be56 --- /dev/null +++ b/tests/unit/unittest/data/includecollector/project/header2.h @@ -0,0 +1,3 @@ +#pragma once + +#include "external3.h" diff --git a/tests/unit/unittest/data/includecollector/project/if.cpp b/tests/unit/unittest/data/includecollector/project/if.cpp new file mode 100644 index 00000000000..f148f0bd9c8 --- /dev/null +++ b/tests/unit/unittest/data/includecollector/project/if.cpp @@ -0,0 +1,7 @@ +#if 0 +#include "false.h" +#endif + +#if 1 +#include "true.h" +#endif diff --git a/tests/unit/unittest/data/includecollector/project/main.cpp b/tests/unit/unittest/data/includecollector/project/main.cpp new file mode 100644 index 00000000000..caa808606ce --- /dev/null +++ b/tests/unit/unittest/data/includecollector/project/main.cpp @@ -0,0 +1,4 @@ +#include "header1.h" +#include "header2.h" +#include "external1.h" +#include "../external/external2.h" diff --git a/tests/unit/unittest/data/includecollector/project/main2.cpp b/tests/unit/unittest/data/includecollector/project/main2.cpp new file mode 100644 index 00000000000..fb7d23d9723 --- /dev/null +++ b/tests/unit/unittest/data/includecollector/project/main2.cpp @@ -0,0 +1,5 @@ +#include "header1.h" +#include "header2.h" +#include "external1.h" +#include "../external/external2.h" +#include "generated_file.h" diff --git a/tests/unit/unittest/data/includecollector/project/main3.cpp b/tests/unit/unittest/data/includecollector/project/main3.cpp new file mode 100644 index 00000000000..7f206d44f72 --- /dev/null +++ b/tests/unit/unittest/data/includecollector/project/main3.cpp @@ -0,0 +1,6 @@ +#include +#include +#include +#include +#include + diff --git a/tests/unit/unittest/data/includecollector_missingfile.cpp b/tests/unit/unittest/data/includecollector/project/missingfile.cpp similarity index 75% rename from tests/unit/unittest/data/includecollector_missingfile.cpp rename to tests/unit/unittest/data/includecollector/project/missingfile.cpp index 890b38c5276..6f3a7ea58cc 100644 --- a/tests/unit/unittest/data/includecollector_missingfile.cpp +++ b/tests/unit/unittest/data/includecollector/project/missingfile.cpp @@ -3,4 +3,4 @@ #include #include -#include "includecollector_external1.h" +#include "external1.h" diff --git a/tests/unit/unittest/data/includecollector_true.h b/tests/unit/unittest/data/includecollector/project/true.h similarity index 100% rename from tests/unit/unittest/data/includecollector_true.h rename to tests/unit/unittest/data/includecollector/project/true.h diff --git a/tests/unit/unittest/data/includecollector/system/indirect_system.h b/tests/unit/unittest/data/includecollector/system/indirect_system.h new file mode 100644 index 00000000000..e0fa22c9d9e --- /dev/null +++ b/tests/unit/unittest/data/includecollector/system/indirect_system.h @@ -0,0 +1,3 @@ +#pragma once + +#include "indirect_system2.h" diff --git a/tests/unit/unittest/data/includecollector/system/indirect_system2.h b/tests/unit/unittest/data/includecollector/system/indirect_system2.h new file mode 100644 index 00000000000..3f59c932d39 --- /dev/null +++ b/tests/unit/unittest/data/includecollector/system/indirect_system2.h @@ -0,0 +1,2 @@ +#pragma once + diff --git a/tests/unit/unittest/data/includecollector/system/system1.h b/tests/unit/unittest/data/includecollector/system/system1.h new file mode 100644 index 00000000000..98e09cd083a --- /dev/null +++ b/tests/unit/unittest/data/includecollector/system/system1.h @@ -0,0 +1,3 @@ +#pragma once + +#include "indirect_system.h" diff --git a/tests/unit/unittest/data/includecollector/system/system2.h b/tests/unit/unittest/data/includecollector/system/system2.h new file mode 100644 index 00000000000..6f70f09beec --- /dev/null +++ b/tests/unit/unittest/data/includecollector/system/system2.h @@ -0,0 +1 @@ +#pragma once diff --git a/tests/unit/unittest/data/includecollector/system/system3.h b/tests/unit/unittest/data/includecollector/system/system3.h new file mode 100644 index 00000000000..6f70f09beec --- /dev/null +++ b/tests/unit/unittest/data/includecollector/system/system3.h @@ -0,0 +1 @@ +#pragma once diff --git a/tests/unit/unittest/data/includecollector_external1.h b/tests/unit/unittest/data/includecollector_external1.h deleted file mode 100644 index 79f1ee616f2..00000000000 --- a/tests/unit/unittest/data/includecollector_external1.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#include "includecollector_indirect_external.h" diff --git a/tests/unit/unittest/data/includecollector_faulty.cpp b/tests/unit/unittest/data/includecollector_faulty.cpp deleted file mode 100644 index a25ff9062c0..00000000000 --- a/tests/unit/unittest/data/includecollector_faulty.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "includecollector_faulty.h" diff --git a/tests/unit/unittest/data/includecollector_header2.h b/tests/unit/unittest/data/includecollector_header2.h deleted file mode 100644 index 7bcf32a89ba..00000000000 --- a/tests/unit/unittest/data/includecollector_header2.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#include "includecollector_external3.h" diff --git a/tests/unit/unittest/data/includecollector_if.cpp b/tests/unit/unittest/data/includecollector_if.cpp deleted file mode 100644 index fab79180e26..00000000000 --- a/tests/unit/unittest/data/includecollector_if.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#if 0 -#include "includecollector_false.h" -#endif - -#if 1 -#include "includecollector_true.h" -#endif diff --git a/tests/unit/unittest/data/includecollector_indirect_external.h b/tests/unit/unittest/data/includecollector_indirect_external.h deleted file mode 100644 index bfd11c5d74c..00000000000 --- a/tests/unit/unittest/data/includecollector_indirect_external.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#include "includecollector_indirect_external2.h" diff --git a/tests/unit/unittest/data/includecollector_main.cpp b/tests/unit/unittest/data/includecollector_main.cpp deleted file mode 100644 index 068bf9546bc..00000000000 --- a/tests/unit/unittest/data/includecollector_main.cpp +++ /dev/null @@ -1,4 +0,0 @@ -#include "includecollector_header1.h" -#include "includecollector_header2.h" -#include "includecollector_external1.h" -#include "../data/includecollector_external2.h" diff --git a/tests/unit/unittest/data/includecollector_main2.cpp b/tests/unit/unittest/data/includecollector_main2.cpp deleted file mode 100644 index 243493ae3b2..00000000000 --- a/tests/unit/unittest/data/includecollector_main2.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "includecollector_header1.h" -#include "includecollector_header2.h" -#include "includecollector_external1.h" -#include "../data/includecollector_external2.h" -#include "includecollector_generated_file.h" diff --git a/tests/unit/unittest/data/includecollector_main3.cpp b/tests/unit/unittest/data/includecollector_main3.cpp deleted file mode 100644 index 9cfae8e5778..00000000000 --- a/tests/unit/unittest/data/includecollector_main3.cpp +++ /dev/null @@ -1,4 +0,0 @@ -#include -#include -#include -#include diff --git a/tests/unit/unittest/gtest-creator-printing.cpp b/tests/unit/unittest/gtest-creator-printing.cpp index 0113fdb8208..5d8507c8de9 100644 --- a/tests/unit/unittest/gtest-creator-printing.cpp +++ b/tests/unit/unittest/gtest-creator-printing.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -1000,6 +1001,11 @@ std::ostream &operator<<(std::ostream &out, const SymbolIndexerTask &task) return out << "(" << task.filePathId << ", " << task.projectPartId << ")"; } +std::ostream &operator<<(std::ostream &out, const PchCreatorIncludes &includes) +{ + return out << "(" << includes.includeIds << ", " << includes.topIncludeIds << ", " << includes.topSystemIncludeIds << ")"; +} + void PrintTo(const FilePath &filePath, ::std::ostream *os) { *os << filePath; diff --git a/tests/unit/unittest/gtest-creator-printing.h b/tests/unit/unittest/gtest-creator-printing.h index 4d733e36dce..4f3f6457b0c 100644 --- a/tests/unit/unittest/gtest-creator-printing.h +++ b/tests/unit/unittest/gtest-creator-printing.h @@ -169,6 +169,7 @@ class RemoveGeneratedFilesMessage; class SuspendResumeJobsEntry; class ReferencesResult; class SymbolIndexerTask; +class PchCreatorIncludes; std::ostream &operator<<(std::ostream &out, const SourceLocationEntry &entry); std::ostream &operator<<(std::ostream &out, const IdPaths &idPaths); @@ -248,6 +249,7 @@ std::ostream &operator<<(std::ostream &out, const RemoveGeneratedFilesMessage &m std::ostream &operator<<(std::ostream &os, const SuspendResumeJobsEntry &entry); std::ostream &operator<<(std::ostream &os, const ReferencesResult &value); std::ostream &operator<<(std::ostream &out, const SymbolIndexerTask &task); +std::ostream &operator<<(std::ostream &out, const PchCreatorIncludes &includes); void PrintTo(const FilePath &filePath, ::std::ostream *os); void PrintTo(const FilePathView &filePathView, ::std::ostream *os); diff --git a/tests/unit/unittest/pchcreator-test.cpp b/tests/unit/unittest/pchcreator-test.cpp index cd35d7fcae4..29056203e31 100644 --- a/tests/unit/unittest/pchcreator-test.cpp +++ b/tests/unit/unittest/pchcreator-test.cpp @@ -74,27 +74,27 @@ protected: protected: Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; ClangBackEnd::RefactoringDatabaseInitializer databaseInitializer{database}; - FilePath main1Path = TESTDATA_DIR "/includecollector_main3.cpp"; - FilePath main2Path = TESTDATA_DIR "/includecollector_main2.cpp"; - FilePath header1Path = TESTDATA_DIR "/includecollector_header1.h"; - FilePath header2Path = TESTDATA_DIR "/includecollector_header2.h"; - Utils::SmallStringView generatedFileName = "includecollector_generated_file.h"; - FilePath generatedFilePath = TESTDATA_DIR "/includecollector_generated_file.h"; + FilePath main1Path = TESTDATA_DIR "/includecollector/project/main3.cpp"; + FilePath main2Path = TESTDATA_DIR "/includecollector/project/main2.cpp"; + FilePath header1Path = TESTDATA_DIR "/includecollector/project/header1.h"; + FilePath header2Path = TESTDATA_DIR "/includecollector/project/header2.h"; + Utils::SmallStringView generatedFileName = "includecollector/project/generated_file.h"; + FilePath generatedFilePath = TESTDATA_DIR "/includecollector/project/generated_file.h"; TestEnvironment environment; FileContainer generatedFile{{TESTDATA_DIR, generatedFileName}, "#pragma once", {}}; NiceMock mockPchManagerClient; NiceMock mockClangPathWatcher; ClangBackEnd::PchCreator creator{environment, database, mockPchManagerClient, mockClangPathWatcher}; ProjectPartContainer projectPart1{"project1", - {"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"}, + {"-I", TESTDATA_DIR, "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-isystem", TESTDATA_DIR "/includecollector/system", "-Wno-pragma-once-outside-header"}, {{"DEFINE", "1"}}, - {"/includes"}, + {TESTDATA_DIR "/includecollector/external", TESTDATA_DIR "/includecollector/project"}, {id(header1Path)}, {id(main1Path)}}; ProjectPartContainer projectPart2{"project2", - {"-I", TESTDATA_DIR, "-x", "c++-header", "-Wno-pragma-once-outside-header"}, + {"-I", TESTDATA_DIR, "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-x", "c++-header", "-Wno-pragma-once-outside-header"}, {{"DEFINE", "1"}}, - {"/includes"}, + {TESTDATA_DIR "/includecollector/external", TESTDATA_DIR "/includecollector/project"}, {id(header2Path)}, {id(main2Path)}}; }; @@ -112,7 +112,7 @@ TEST_F(PchCreator, CreateProjectPartCommandLine) { auto commandLine = creator.generateProjectPartCommandLine(projectPart1); - ASSERT_THAT(commandLine, ElementsAre(environment.clangCompilerPath(), "-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header")); + ASSERT_THAT(commandLine, ElementsAre(environment.clangCompilerPath(), "-I", TESTDATA_DIR, "-I", TESTDATA_DIR "/includecollector/external", "-I", TESTDATA_DIR "/includecollector/project", "-isystem", TESTDATA_DIR "/includecollector/system", "-Wno-pragma-once-outside-header")); } TEST_F(PchCreator, CreateProjectPartHeaders) @@ -131,39 +131,41 @@ TEST_F(PchCreator, CreateProjectPartSources) TEST_F(PchCreatorSlowTest, CreateProjectPartPchIncludes) { - using IncludePair = decltype(creator.generateProjectPartPchIncludes(projectPart1)); + using ClangBackEnd::PchCreatorIncludes; auto includeIds = creator.generateProjectPartPchIncludes(projectPart1); ASSERT_THAT(includeIds, AllOf( - Field(&IncludePair::first, - AllOf(Contains(id(TESTDATA_DIR "/includecollector_external1.h")), - Contains(id(TESTDATA_DIR "/includecollector_external2.h")), - Contains(id(TESTDATA_DIR "/includecollector_header2.h")))), - Field(&IncludePair::second, - AllOf(Contains(id(TESTDATA_DIR "/includecollector_external1.h")), - Contains(id(TESTDATA_DIR "/includecollector_external2.h")))))); + Field(&PchCreatorIncludes::includeIds, + AllOf(Contains(id(TESTDATA_DIR "/includecollector/external/external1.h")), + Contains(id(TESTDATA_DIR "/includecollector/external/external2.h")), + Contains(id(TESTDATA_DIR "/includecollector/project/header2.h")), + Contains(id(TESTDATA_DIR "/includecollector/system/system1.h")))), + Field(&PchCreatorIncludes::topSystemIncludeIds, + AllOf(Contains(id(TESTDATA_DIR "/includecollector/system/system1.h")), + Not(Contains(id(TESTDATA_DIR "/includecollector/system/indirect_system.h"))))), + Field(&PchCreatorIncludes::topIncludeIds, + AllOf(Contains(id(TESTDATA_DIR "/includecollector/external/external1.h")), + Contains(id(TESTDATA_DIR "/includecollector/external/external2.h")))))); } TEST_F(PchCreatorSlowTest, CreateProjectPartPchFileContent) { - FilePathIds topExternalIncludes; - std::tie(std::ignore, topExternalIncludes) = creator.generateProjectPartPchIncludes(projectPart1); + auto includes = creator.generateProjectPartPchIncludes(projectPart1); - auto content = creator.generatePchIncludeFileContent(topExternalIncludes); + auto content = creator.generatePchIncludeFileContent(includes.topIncludeIds); ASSERT_THAT(std::string(content), - AllOf(HasSubstr("#include \"" TESTDATA_DIR "/includecollector_header2.h\"\n"), - HasSubstr("#include \"" TESTDATA_DIR "/includecollector_external1.h\"\n"), - HasSubstr("#include \"" TESTDATA_DIR "/includecollector_external2.h\"\n"))); + AllOf(HasSubstr("#include \"" TESTDATA_DIR "/includecollector/project/header2.h\"\n"), + HasSubstr("#include \"" TESTDATA_DIR "/includecollector/external/external1.h\"\n"), + HasSubstr("#include \"" TESTDATA_DIR "/includecollector/external/external2.h\"\n"))); } TEST_F(PchCreatorSlowTest, CreateProjectPartPchIncludeFile) { - FilePathIds topExternalIncludes; - std::tie(std::ignore, topExternalIncludes) = creator.generateProjectPartPchIncludes(projectPart1); - auto content = creator.generatePchIncludeFileContent(topExternalIncludes); + auto includes = creator.generateProjectPartPchIncludes(projectPart1); + auto content = creator.generatePchIncludeFileContent(includes.topIncludeIds); auto pchIncludeFilePath = creator.generateProjectPathPchHeaderFilePath(projectPart1); auto file = creator.generateFileWithContent(pchIncludeFilePath, content); file->open(QIODevice::ReadOnly); @@ -171,9 +173,9 @@ TEST_F(PchCreatorSlowTest, CreateProjectPartPchIncludeFile) auto fileContent = file->readAll(); ASSERT_THAT(fileContent.toStdString(), - AllOf(HasSubstr("#include \"" TESTDATA_DIR "/includecollector_header2.h\"\n"), - HasSubstr("#include \"" TESTDATA_DIR "/includecollector_external1.h\"\n"), - HasSubstr("#include \"" TESTDATA_DIR "/includecollector_external2.h\"\n"))); + AllOf(HasSubstr("#include \"" TESTDATA_DIR "/includecollector/project/header2.h\"\n"), + HasSubstr("#include \"" TESTDATA_DIR "/includecollector/external/external1.h\"\n"), + HasSubstr("#include \"" TESTDATA_DIR "/includecollector/external/external2.h\"\n"))); } TEST_F(PchCreator, CreateProjectPartPchCompilerArguments) @@ -233,9 +235,9 @@ TEST_F(PchCreatorVerySlowTest, IdPathsForCreatePchsForProjectParts) ASSERT_THAT(creator.takeProjectIncludes(), AllOf(Field(&IdPaths::id, "project1"), - Field(&IdPaths::filePathIds, AllOf(Contains(id(TESTDATA_DIR "/includecollector_header2.h")), - Contains(id(TESTDATA_DIR "/includecollector_external1.h")), - Contains(id(TESTDATA_DIR "/includecollector_external2.h")))))); + Field(&IdPaths::filePathIds, AllOf(Contains(id(TESTDATA_DIR "/includecollector/project/header2.h")), + Contains(id(TESTDATA_DIR "/includecollector/external/external1.h")), + Contains(id(TESTDATA_DIR "/includecollector/external/external2.h")))))); } TEST_F(PchCreatorVerySlowTest, ProjectPartPchForCreatesPchForProjectPart) @@ -274,7 +276,7 @@ TEST_F(PchCreatorVerySlowTest, FaultyProjectPartPchForCreatesNoPchForProjectPart {{"DEFINE", "1"}}, {"/includes"}, {}, - {id(TESTDATA_DIR "/includecollector_faulty.cpp")}}; + {id(TESTDATA_DIR "/includecollector/project/faulty.cpp")}}; creator.generatePch(faultyProjectPart); @@ -288,14 +290,14 @@ TEST_F(PchCreator, CreateProjectPartSourcesContent) { auto content = creator.generateProjectPartSourcesContent(projectPart1); - ASSERT_THAT(content, Eq("#include \"" TESTDATA_DIR "/includecollector_main3.cpp\"\n")); + ASSERT_THAT(content, Eq("#include \"" TESTDATA_DIR "/includecollector/project/main3.cpp\"\n")); } TEST_F(PchCreator, Call) { auto content = creator.generateProjectPartSourcesContent(projectPart1); - ASSERT_THAT(content, Eq("#include \"" TESTDATA_DIR "/includecollector_main3.cpp\"\n")); + ASSERT_THAT(content, Eq("#include \"" TESTDATA_DIR "/includecollector/project/main3.cpp\"\n")); }