diff options
author | Marco Bubke <marco.bubke@qt.io> | 2018-08-07 19:01:01 +0200 |
---|---|---|
committer | Marco Bubke <marco.bubke@qt.io> | 2018-08-14 12:47:03 +0000 |
commit | 4195fce68f06a1b0ed86cd1f36cddab160f3bf29 (patch) | |
tree | 087e3ce65d82c184097beea14d6bf0d72bab0122 | |
parent | f6b228842c7d605d59f08e31bcdc090524d53ccf (diff) | |
download | qt-creator-4195fce68f06a1b0ed86cd1f36cddab160f3bf29.tar.gz |
ClangRefactoring: Integrate generated files
This is an intermediate step to handle the indexing of the project parts
completely. The generated files are now independently handled from the
project parts. We still not handle the case the a file is indexed but the
generated file is not provided. This will be done in a different patch.
All provided data is now sorted too to improve merging.
Change-Id: I09712b99217a881ec0a233d09aea8659fb787324
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
-rw-r--r-- | src/libs/clangsupport/filecontainerv2.h | 4 | ||||
-rw-r--r-- | src/libs/clangsupport/filepath.h | 7 | ||||
-rw-r--r-- | src/libs/clangsupport/generatedfiles.cpp | 14 | ||||
-rw-r--r-- | src/libs/clangsupport/generatedfiles.h | 7 | ||||
-rw-r--r-- | src/plugins/clangpchmanager/projectupdater.cpp | 58 | ||||
-rw-r--r-- | src/plugins/clangpchmanager/projectupdater.h | 17 | ||||
-rw-r--r-- | src/plugins/clangpchmanager/qtcreatorprojectupdater.cpp | 2 | ||||
-rw-r--r-- | src/plugins/clangpchmanager/qtcreatorprojectupdater.h | 23 | ||||
-rw-r--r-- | src/tools/clangrefactoringbackend/source/refactoringserver.cpp | 7 | ||||
-rw-r--r-- | src/tools/clangrefactoringbackend/source/refactoringserver.h | 3 | ||||
-rw-r--r-- | tests/unit/unittest/gtest-creator-printing.cpp | 16 | ||||
-rw-r--r-- | tests/unit/unittest/gtest-creator-printing.h | 6 | ||||
-rw-r--r-- | tests/unit/unittest/projectupdater-test.cpp | 97 |
13 files changed, 212 insertions, 49 deletions
diff --git a/src/libs/clangsupport/filecontainerv2.h b/src/libs/clangsupport/filecontainerv2.h index be6e30093b..aa7248fb5e 100644 --- a/src/libs/clangsupport/filecontainerv2.h +++ b/src/libs/clangsupport/filecontainerv2.h @@ -77,8 +77,8 @@ public: friend bool operator<(const FileContainer &first, const FileContainer &second) { - return std::tie(first.documentRevision, first.filePath, first.unsavedFileContent, first.commandLineArguments) - < std::tie(second.documentRevision, second.filePath, second.unsavedFileContent, second.commandLineArguments); + return std::tie(first.filePath, first.documentRevision, first.unsavedFileContent, first.commandLineArguments) + < std::tie(second.filePath, second.documentRevision, second.unsavedFileContent, second.commandLineArguments); } FileContainer clone() const diff --git a/src/libs/clangsupport/filepath.h b/src/libs/clangsupport/filepath.h index 50f6f44323..9ff019de76 100644 --- a/src/libs/clangsupport/filepath.h +++ b/src/libs/clangsupport/filepath.h @@ -133,7 +133,9 @@ public: friend bool operator==(const FilePath &first, const FilePath &second) { - return first.toStringView() == second.toStringView(); + return first.slashIndex() == second.slashIndex() + && first.name() == second.name() + && first.directory() == second.directory(); } friend bool operator==(const FilePath &first, const FilePathView &second) @@ -148,7 +150,8 @@ public: friend bool operator<(const FilePath &first, const FilePath &second) { - return first.toStringView() < second.toStringView(); + return std::make_tuple(first.slashIndex(), first.name(), first.directory()) + < std::make_tuple(second.slashIndex(), second.name(), second.directory()); } FilePath clone() const diff --git a/src/libs/clangsupport/generatedfiles.cpp b/src/libs/clangsupport/generatedfiles.cpp index 233fd40eea..554d84d2f4 100644 --- a/src/libs/clangsupport/generatedfiles.cpp +++ b/src/libs/clangsupport/generatedfiles.cpp @@ -26,8 +26,8 @@ #include "generatedfiles.h" namespace ClangBackEnd { - -void GeneratedFiles::update(V2::FileContainers &&fileContainers) +template<class Type> +void GeneratedFiles::updateInternal(Type &&fileContainers) { V2::FileContainers unionFileContainers; unionFileContainers.reserve(m_fileContainers.size() + fileContainers.size()); @@ -46,6 +46,16 @@ void GeneratedFiles::update(V2::FileContainers &&fileContainers) m_fileContainers = std::move(unionFileContainers); } +void GeneratedFiles::update(V2::FileContainers &&fileContainers) +{ + updateInternal(std::move(fileContainers)); +} + +void GeneratedFiles::update(const V2::FileContainers &fileContainers) +{ + updateInternal(fileContainers); +} + class Compare { public: bool operator()(const FilePath &first, const FilePath &second) diff --git a/src/libs/clangsupport/generatedfiles.h b/src/libs/clangsupport/generatedfiles.h index e78409b009..1838e7dab4 100644 --- a/src/libs/clangsupport/generatedfiles.h +++ b/src/libs/clangsupport/generatedfiles.h @@ -29,14 +29,19 @@ namespace ClangBackEnd { -class GeneratedFiles +class CLANGSUPPORT_EXPORT GeneratedFiles { public: void update(V2::FileContainers &&fileContainers); + void update(const V2::FileContainers &fileContainers); void remove(const FilePaths &filePaths); const V2::FileContainers &fileContainers() const; private: + template<class Type> + void updateInternal(Type &&fileContainers); + +private: V2::FileContainers m_fileContainers; }; diff --git a/src/plugins/clangpchmanager/projectupdater.cpp b/src/plugins/clangpchmanager/projectupdater.cpp index 10fd98771f..66c63d1387 100644 --- a/src/plugins/clangpchmanager/projectupdater.cpp +++ b/src/plugins/clangpchmanager/projectupdater.cpp @@ -29,6 +29,7 @@ #include <filepathid.h> #include <pchmanagerserverinterface.h> +#include <removegeneratedfilesmessage.h> #include <removeprojectpartsmessage.h> #include <updategeneratedfilesmessage.h> #include <updateprojectpartsmessage.h> @@ -63,14 +64,8 @@ ProjectUpdater::ProjectUpdater(ClangBackEnd::ProjectManagementServerInterface &s { } -void ProjectUpdater::updateProjectParts(const std::vector<CppTools::ProjectPart *> &projectParts, - ClangBackEnd::V2::FileContainers &&generatedFiles) +void ProjectUpdater::updateProjectParts(const std::vector<CppTools::ProjectPart *> &projectParts) { - m_excludedPaths = createExcludedPaths(generatedFiles); - - m_server.updateGeneratedFiles( // TODO move to an other code path - ClangBackEnd::UpdateGeneratedFilesMessage{std::move(generatedFiles)}); - m_server.updateProjectParts( ClangBackEnd::UpdateProjectPartsMessage{toProjectPartContainers(projectParts)}); } @@ -82,9 +77,41 @@ void ProjectUpdater::removeProjectParts(const QStringList &projectPartIds) m_server.removeProjectParts(std::move(message)); } -void ProjectUpdater::setExcludedPaths(Utils::PathStringVector &&excludedPaths) +void ProjectUpdater::updateGeneratedFiles(ClangBackEnd::V2::FileContainers &&generatedFiles) +{ + std::sort(generatedFiles.begin(), generatedFiles.end()); + + m_generatedFiles.update(generatedFiles); + + m_excludedPaths = createExcludedPaths(m_generatedFiles.fileContainers()); + + m_server.updateGeneratedFiles( + ClangBackEnd::UpdateGeneratedFilesMessage{std::move(generatedFiles)}); +} + +void ProjectUpdater::removeGeneratedFiles(ClangBackEnd::FilePaths &&filePaths) +{ + m_generatedFiles.remove(filePaths); + + m_excludedPaths = createExcludedPaths(m_generatedFiles.fileContainers()); + + m_server.removeGeneratedFiles( + ClangBackEnd::RemoveGeneratedFilesMessage{std::move(filePaths)}); +} + +void ProjectUpdater::setExcludedPaths(ClangBackEnd::FilePaths &&excludedPaths) +{ + m_excludedPaths = std::move(excludedPaths); +} + +const ClangBackEnd::FilePaths &ProjectUpdater::excludedPaths() const { - m_excludedPaths = excludedPaths; + return m_excludedPaths; +} + +const ClangBackEnd::GeneratedFiles &ProjectUpdater::generatedFiles() const +{ + return m_generatedFiles; } void ProjectUpdater::addToHeaderAndSources(HeaderAndSources &headerAndSources, @@ -113,6 +140,9 @@ HeaderAndSources ProjectUpdater::headerAndSourcesFromProjectPart( for (const CppTools::ProjectFile &projectFile : projectPart->files) addToHeaderAndSources(headerAndSources, projectFile); + std::sort(headerAndSources.sources.begin(), headerAndSources.sources.end()); + std::sort(headerAndSources.headers.begin(), headerAndSources.headers.end()); + return headerAndSources; } @@ -145,6 +175,8 @@ Utils::SmallStringVector ProjectUpdater::createIncludeSearchPaths( includePaths.emplace_back(projectPartHeaderPath.path); } + std::sort(includePaths.begin(), includePaths.end()); + return includePaths; } @@ -177,17 +209,19 @@ std::vector<ClangBackEnd::V2::ProjectPartContainer> ProjectUpdater::toProjectPar std::back_inserter(projectPartContainers), std::bind(&ProjectUpdater::toProjectPartContainer, this, _1)); + std::sort(projectPartContainers.begin(), projectPartContainers.end()); + return projectPartContainers; } -Utils::PathStringVector ProjectUpdater::createExcludedPaths( +ClangBackEnd::FilePaths ProjectUpdater::createExcludedPaths( const ClangBackEnd::V2::FileContainers &generatedFiles) { - Utils::PathStringVector excludedPaths; + ClangBackEnd::FilePaths excludedPaths; excludedPaths.reserve(generatedFiles.size()); auto convertToPath = [] (const ClangBackEnd::V2::FileContainer &fileContainer) { - return fileContainer.filePath.path(); + return fileContainer.filePath; }; std::transform(generatedFiles.begin(), diff --git a/src/plugins/clangpchmanager/projectupdater.h b/src/plugins/clangpchmanager/projectupdater.h index e4066cd0d1..c0040863a9 100644 --- a/src/plugins/clangpchmanager/projectupdater.h +++ b/src/plugins/clangpchmanager/projectupdater.h @@ -30,6 +30,7 @@ #include <compilermacro.h> #include <filecontainerv2.h> #include <filepathcachinginterface.h> +#include <generatedfiles.h> namespace ProjectExplorer { class Macro; @@ -66,12 +67,17 @@ public: ProjectUpdater(ClangBackEnd::ProjectManagementServerInterface &server, ClangBackEnd::FilePathCachingInterface &filePathCache); - void updateProjectParts(const std::vector<CppTools::ProjectPart *> &projectParts, - ClangBackEnd::V2::FileContainers &&generatedFiles); + void updateProjectParts(const std::vector<CppTools::ProjectPart *> &projectParts); void removeProjectParts(const QStringList &projectPartIds); + void updateGeneratedFiles(ClangBackEnd::V2::FileContainers &&generatedFiles); + void removeGeneratedFiles(ClangBackEnd::FilePaths &&filePaths); + unittest_public: - void setExcludedPaths(Utils::PathStringVector &&excludedPaths); + void setExcludedPaths(ClangBackEnd::FilePaths &&excludedPaths); + const ClangBackEnd::FilePaths &excludedPaths() const; + + const ClangBackEnd::GeneratedFiles &generatedFiles() const; HeaderAndSources headerAndSourcesFromProjectPart(CppTools::ProjectPart *projectPart) const; ClangBackEnd::V2::ProjectPartContainer toProjectPartContainer( @@ -85,11 +91,12 @@ unittest_public: const ProjectExplorer::Macros &projectMacros); static Utils::SmallStringVector createIncludeSearchPaths( const CppTools::ProjectPartHeaderPaths &projectPartHeaderPaths); - static Utils::PathStringVector createExcludedPaths( + static ClangBackEnd::FilePaths createExcludedPaths( const ClangBackEnd::V2::FileContainers &generatedFiles); private: - Utils::PathStringVector m_excludedPaths; + ClangBackEnd::GeneratedFiles m_generatedFiles; + ClangBackEnd::FilePaths m_excludedPaths; ClangBackEnd::ProjectManagementServerInterface &m_server; ClangBackEnd::FilePathCachingInterface &m_filePathCache; }; diff --git a/src/plugins/clangpchmanager/qtcreatorprojectupdater.cpp b/src/plugins/clangpchmanager/qtcreatorprojectupdater.cpp index 53b37ee2b5..5331e2ef05 100644 --- a/src/plugins/clangpchmanager/qtcreatorprojectupdater.cpp +++ b/src/plugins/clangpchmanager/qtcreatorprojectupdater.cpp @@ -55,6 +55,8 @@ std::vector<ClangBackEnd::V2::FileContainer> createGeneratedFiles() std::back_inserter(generatedFiles), toFileContainer); + std::sort(generatedFiles.begin(), generatedFiles.end()); + return generatedFiles; } diff --git a/src/plugins/clangpchmanager/qtcreatorprojectupdater.h b/src/plugins/clangpchmanager/qtcreatorprojectupdater.h index 387e4573ad..9be66f1444 100644 --- a/src/plugins/clangpchmanager/qtcreatorprojectupdater.h +++ b/src/plugins/clangpchmanager/qtcreatorprojectupdater.h @@ -71,8 +71,7 @@ public: void projectPartsUpdated(ProjectExplorer::Project *project) { - ProjectUpdaterType::updateProjectParts(Internal::createProjectParts(project), - Internal::createGeneratedFiles()); + ProjectUpdaterType::updateProjectParts(Internal::createProjectParts(project)); } void projectPartsRemoved(const QStringList &projectPartIds) @@ -80,15 +79,35 @@ public: ProjectUpdaterType::removeProjectParts(projectPartIds); } + void abstractEditorUpdated(const QString &filePath, const QByteArray &contents) + { + ProjectUpdaterType::updateGeneratedFiles({{ClangBackEnd::FilePath{filePath}, contents}}); + } + + void abstractEditorRemoved(const QString &filePath) + { + ProjectUpdaterType::removeGeneratedFiles({ClangBackEnd::FilePath{filePath}}); + } + private: void connectToCppModelManager() { + ProjectUpdaterType::updateGeneratedFiles(Internal::createGeneratedFiles()); + QObject::connect(Internal::cppModelManager(), &CppTools::CppModelManager::projectPartsUpdated, [&] (ProjectExplorer::Project *project) { projectPartsUpdated(project); }); QObject::connect(Internal::cppModelManager(), &CppTools::CppModelManager::projectPartsRemoved, [&] (const QStringList &projectPartIds) { projectPartsRemoved(projectPartIds); }); + QObject::connect(Internal::cppModelManager(), + &CppTools::CppModelManager::abstractEditorSupportContentsUpdated, + [&] (const QString &filePath, const QByteArray &contents) { + abstractEditorUpdated(filePath, contents); + }); + QObject::connect(Internal::cppModelManager(), + &CppTools::CppModelManager::abstractEditorSupportRemoved, + [&] (const QString &filePath) { abstractEditorRemoved(filePath); }); } }; diff --git a/src/tools/clangrefactoringbackend/source/refactoringserver.cpp b/src/tools/clangrefactoringbackend/source/refactoringserver.cpp index 35da59d77a..799901a520 100644 --- a/src/tools/clangrefactoringbackend/source/refactoringserver.cpp +++ b/src/tools/clangrefactoringbackend/source/refactoringserver.cpp @@ -97,12 +97,13 @@ void RefactoringServer::requestSourceRangesForQueryMessage(RequestSourceRangesFo void RefactoringServer::updateProjectParts(UpdateProjectPartsMessage &&message) { - m_symbolIndexing.updateProjectParts(message.takeProjectsParts(), m_generatedFiles); + m_symbolIndexing.updateProjectParts(message.takeProjectsParts(), + m_generatedFiles.fileContainers()); } void RefactoringServer::updateGeneratedFiles(UpdateGeneratedFilesMessage &&message) { - m_generatedFiles = message.takeGeneratedFiles(); + m_generatedFiles.update(message.takeGeneratedFiles()); } void RefactoringServer::removeProjectParts(RemoveProjectPartsMessage &&) @@ -112,7 +113,7 @@ void RefactoringServer::removeProjectParts(RemoveProjectPartsMessage &&) void RefactoringServer::removeGeneratedFiles(RemoveGeneratedFilesMessage &&message) { - // TODO + m_generatedFiles.remove(message.generatedFiles); } void RefactoringServer::cancel() diff --git a/src/tools/clangrefactoringbackend/source/refactoringserver.h b/src/tools/clangrefactoringbackend/source/refactoringserver.h index f46aac9577..ce18aaf548 100644 --- a/src/tools/clangrefactoringbackend/source/refactoringserver.h +++ b/src/tools/clangrefactoringbackend/source/refactoringserver.h @@ -31,6 +31,7 @@ #include <ipcclientprovider.h> #include <filepathcachinginterface.h> +#include <generatedfiles.h> #include <utils/smallstring.h> @@ -84,7 +85,7 @@ private: private: ClangQueryGatherer m_gatherer; - V2::FileContainers m_generatedFiles; + GeneratedFiles m_generatedFiles; QTimer m_pollTimer; SymbolIndexingInterface &m_symbolIndexing; FilePathCachingInterface &m_filePathCache; diff --git a/tests/unit/unittest/gtest-creator-printing.cpp b/tests/unit/unittest/gtest-creator-printing.cpp index 73184a17af..28cbf6b788 100644 --- a/tests/unit/unittest/gtest-creator-printing.cpp +++ b/tests/unit/unittest/gtest-creator-printing.cpp @@ -143,6 +143,11 @@ std::ostream &operator<<(std::ostream &out, const LineColumn &lineColumn) return out << "(" << lineColumn.line << ", " << lineColumn.column << ")"; } +void PrintTo(Utils::SmallStringView text, ::std::ostream *os) +{ + *os << text; +} + void PrintTo(const Utils::SmallString &text, ::std::ostream *os) { *os << text; @@ -981,6 +986,16 @@ std::ostream &operator<<(std::ostream &out, SymbolTags symbolTags) return out; } +std::ostream &operator<<(std::ostream &out, const UpdateGeneratedFilesMessage &message) +{ + return out << "(" << message.generatedFiles << ")"; +} + +std::ostream &operator<<(std::ostream &out, const RemoveGeneratedFilesMessage &message) +{ + return out << "(" << message.generatedFiles << ")"; +} + void PrintTo(const FilePath &filePath, ::std::ostream *os) { *os << filePath; @@ -1020,6 +1035,7 @@ std::ostream &operator<<(std::ostream &out, const ProjectPartContainer &containe << container.projectPartId << ", " << container.arguments << ", " << container.headerPathIds << ", " + << container.sourcePathIds << ", " << container.compilerMacros << ", " << container.includeSearchPaths << ")"; diff --git a/tests/unit/unittest/gtest-creator-printing.h b/tests/unit/unittest/gtest-creator-printing.h index a7c200daad..91c1e7fd37 100644 --- a/tests/unit/unittest/gtest-creator-printing.h +++ b/tests/unit/unittest/gtest-creator-printing.h @@ -67,6 +67,7 @@ std::ostream &operator<<(std::ostream &out, const Macro ¯o); namespace Utils { class LineColumn; +class SmallStringView; std::ostream &operator<<(std::ostream &out, const LineColumn &lineColumn); @@ -85,6 +86,7 @@ void PrintTo(const Utils::optional<Type> &optional, ::std::ostream *os) *os << optional; } +void PrintTo(Utils::SmallStringView text, ::std::ostream *os); void PrintTo(const Utils::SmallString &text, ::std::ostream *os); void PrintTo(const Utils::PathString &text, ::std::ostream *os); @@ -165,6 +167,8 @@ class SymbolEntry; enum class SymbolKind : uchar; enum class SymbolTag : uchar; using SymbolTags = Utils::SizedArray<SymbolTag, 7>; +class UpdateGeneratedFilesMessage; +class RemoveGeneratedFilesMessage; std::ostream &operator<<(std::ostream &out, const SourceLocationEntry &entry); std::ostream &operator<<(std::ostream &out, const IdPaths &idPaths); @@ -242,6 +246,8 @@ std::ostream &operator<<(std::ostream &out, const SymbolEntry &symbolEntry); std::ostream &operator<<(std::ostream &out, SymbolKind symbolKind); std::ostream &operator<<(std::ostream &out, SymbolTag symbolTag); std::ostream &operator<<(std::ostream &out, SymbolTags symbolTags); +std::ostream &operator<<(std::ostream &out, const UpdateGeneratedFilesMessage &message); +std::ostream &operator<<(std::ostream &out, const RemoveGeneratedFilesMessage &message); void PrintTo(const FilePath &filePath, ::std::ostream *os); void PrintTo(const FilePathView &filePathView, ::std::ostream *os); diff --git a/tests/unit/unittest/projectupdater-test.cpp b/tests/unit/unittest/projectupdater-test.cpp index 4e43d6b577..0dd63c2558 100644 --- a/tests/unit/unittest/projectupdater-test.cpp +++ b/tests/unit/unittest/projectupdater-test.cpp @@ -83,11 +83,19 @@ protected: projectPart.files.push_back(source1ProjectFile); projectPart.files.push_back(source2ProjectFile); projectPart.displayName = QString(projectPartId); - projectPart.projectMacros.push_back({"DEFINE", "1"}); + projectPart.projectMacros = {{"FOO", "2"}, {"BAR", "1"}}; + projectPart2.files.push_back(header2ProjectFile); + projectPart2.files.push_back(header1ProjectFile); + projectPart2.files.push_back(source2ProjectFile); + projectPart2.files.push_back(source1ProjectFile); + projectPart2.displayName = QString(projectPartId2); + projectPart2.projectMacros = {{"BAR", "1"}, {"FOO", "2"}}; Utils::SmallStringVector arguments{ClangPchManager::ProjectUpdater::compilerArguments( &projectPart)}; + Utils::SmallStringVector arguments2{ClangPchManager::ProjectUpdater::compilerArguments( + &projectPart2)}; expectedContainer = {projectPartId.clone(), arguments.clone(), @@ -95,6 +103,12 @@ protected: {}, {filePathId(headerPaths[1])}, {filePathIds(sourcePaths)}}; + expectedContainer2 = {projectPartId2.clone(), + arguments2.clone(), + Utils::clone(compilerMacros), + {}, + {filePathId(headerPaths[1])}, + {filePathIds(sourcePaths)}}; } protected: @@ -110,34 +124,73 @@ protected: Utils::SmallString projectPartId2{"project2"}; Utils::PathStringVector headerPaths = {"/path/to/header1.h", "/path/to/header2.h"}; Utils::PathStringVector sourcePaths = {"/path/to/source1.cpp", "/path/to/source2.cpp"}; - ClangBackEnd::CompilerMacros compilerMacros = {{"DEFINE", "1"}}; + ClangBackEnd::CompilerMacros compilerMacros = {{"BAR", "1"}, {"FOO", "2"}}; CppTools::ProjectFile header1ProjectFile{QString(headerPaths[0]), CppTools::ProjectFile::CXXHeader}; CppTools::ProjectFile header2ProjectFile{QString(headerPaths[1]), CppTools::ProjectFile::CXXHeader}; CppTools::ProjectFile source1ProjectFile{QString(sourcePaths[0]), CppTools::ProjectFile::CXXSource}; CppTools::ProjectFile source2ProjectFile{QString(sourcePaths[1]), CppTools::ProjectFile::CXXSource}; CppTools::ProjectPart projectPart; + CppTools::ProjectPart projectPart2; ProjectPartContainer expectedContainer; + ProjectPartContainer expectedContainer2; FileContainer generatedFile{{"/path/to", "header1.h"}, "content", {}}; + FileContainer generatedFile2{{"/path/to2", "header1.h"}, "content", {}}; + FileContainer generatedFile3{{"/path/to", "header2.h"}, "content", {}}; }; TEST_F(ProjectUpdater, CallUpdateProjectParts) { - std::vector<CppTools::ProjectPart*> projectParts = {&projectPart, &projectPart}; - ClangBackEnd::UpdateProjectPartsMessage message{{expectedContainer.clone(), expectedContainer.clone()}}; + std::vector<CppTools::ProjectPart*> projectParts = {&projectPart2, &projectPart}; + ClangBackEnd::UpdateProjectPartsMessage message{{expectedContainer.clone(), expectedContainer2.clone()}}; + updater.updateGeneratedFiles({generatedFile}); EXPECT_CALL(mockPchManagerServer, updateProjectParts(message)); - updater.updateProjectParts(projectParts, {generatedFile}); + updater.updateProjectParts(projectParts); } -TEST_F(ProjectUpdater, CallUpdateGeneratedFiles) +TEST_F(ProjectUpdater, CallUpdateGeneratedFilesWithSortedEntries) { - std::vector<CppTools::ProjectPart*> projectParts = {&projectPart, &projectPart}; - ClangBackEnd::UpdateGeneratedFilesMessage message{{generatedFile}}; + ClangBackEnd::UpdateGeneratedFilesMessage message{{generatedFile, generatedFile3, generatedFile2}}; EXPECT_CALL(mockPchManagerServer, updateGeneratedFiles(message)); - updater.updateProjectParts(projectParts, {generatedFile}); + updater.updateGeneratedFiles({generatedFile2, generatedFile3, generatedFile}); +} + +TEST_F(ProjectUpdater, GeneratedFilesAddedAreSorted) +{ + updater.updateGeneratedFiles({generatedFile2, generatedFile3, generatedFile}); + + ASSERT_THAT(updater.generatedFiles().fileContainers(), + ElementsAre(generatedFile, generatedFile3, generatedFile2)); +} + +TEST_F(ProjectUpdater, GeneratedFilesAddedToExcludePaths) +{ + updater.updateGeneratedFiles({generatedFile2, generatedFile3, generatedFile}); + + ASSERT_THAT(updater.excludedPaths(), ElementsAre(generatedFile.filePath, + generatedFile3.filePath, + generatedFile2.filePath)); +} + +TEST_F(ProjectUpdater, CallRemoveGeneratedFiles) +{ + ClangBackEnd::RemoveGeneratedFilesMessage message{{{"/path/to/header1.h"}}}; + + EXPECT_CALL(mockPchManagerServer, removeGeneratedFiles(message)); + + updater.removeGeneratedFiles({{"/path/to/header1.h"}}); +} + +TEST_F(ProjectUpdater, GeneratedFilesRemovedFromExcludePaths) +{ + updater.updateGeneratedFiles({generatedFile}); + + updater.removeGeneratedFiles({generatedFile.filePath}); + + ASSERT_THAT(updater.excludedPaths(), IsEmpty()); } TEST_F(ProjectUpdater, CallRemoveProjectParts) @@ -153,6 +206,7 @@ TEST_F(ProjectUpdater, CallPrecompiledHeaderRemovedInPchManagerProjectUpdater) { ClangPchManager::PchManagerProjectUpdater pchUpdater{mockPchManagerServer, pchManagerClient, filePathCache}; ClangBackEnd::RemoveProjectPartsMessage message{{projectPartId, projectPartId2}}; + EXPECT_CALL(mockPrecompiledHeaderStorage, deletePrecompiledHeader(_)).Times(AnyNumber()); EXPECT_CALL(mockPchManagerNotifier, precompiledHeaderRemoved(projectPartId.toQString())); EXPECT_CALL(mockPchManagerNotifier, precompiledHeaderRemoved(projectPartId2.toQString())); @@ -176,29 +230,34 @@ TEST_F(ProjectUpdater, ConvertProjectPartToProjectPartContainersHaveSameSizeLike ASSERT_THAT(containers, SizeIs(2)); } -TEST_F(ProjectUpdater, CreateExcludedPaths) +TEST_F(ProjectUpdater, CreateSortedExcludedPaths) { - auto excludedPaths = updater.createExcludedPaths({generatedFile}); + auto excludedPaths = updater.createExcludedPaths({generatedFile2, generatedFile3, generatedFile}); - ASSERT_THAT(excludedPaths, ElementsAre("/path/to/header1.h")); + ASSERT_THAT(excludedPaths, ElementsAre(ClangBackEnd::FilePath{"/path/to/header1.h"}, + ClangBackEnd::FilePath{"/path/to/header2.h"}, + ClangBackEnd::FilePath{"/path/to2/header1.h"})); } -TEST_F(ProjectUpdater, CreateCompilerMacros) +TEST_F(ProjectUpdater, CreateSortedCompilerMacros) { - auto paths = updater.createCompilerMacros({{"DEFINE", "1"}}); + auto paths = updater.createCompilerMacros({{"DEFINE", "1"}, {"FOO", "2"}, {"BAR", "1"}}); - ASSERT_THAT(paths, ElementsAre(CompilerMacro{"DEFINE", "1"})); + ASSERT_THAT(paths, ElementsAre(CompilerMacro{"BAR", "1"}, + CompilerMacro{"FOO", "2"}, + CompilerMacro{"DEFINE", "1"})); } -TEST_F(ProjectUpdater, CreateIncludeSearchPaths) +TEST_F(ProjectUpdater, CreateSortedIncludeSearchPaths) { - ProjectPartHeaderPath includePath{"/to/path", ProjectPartHeaderPath::IncludePath}; + ProjectPartHeaderPath includePath{"/to/path1", ProjectPartHeaderPath::IncludePath}; + ProjectPartHeaderPath includePath2{"/to/path2", ProjectPartHeaderPath::IncludePath}; ProjectPartHeaderPath invalidPath; ProjectPartHeaderPath frameworkPath{"/framework/path", ProjectPartHeaderPath::FrameworkPath}; - auto paths = updater.createIncludeSearchPaths({includePath, invalidPath, frameworkPath}); + auto paths = updater.createIncludeSearchPaths({frameworkPath, includePath2, includePath, invalidPath}); - ASSERT_THAT(paths, ElementsAre(includePath.path, frameworkPath.path)); + ASSERT_THAT(paths, ElementsAre(includePath.path, includePath2.path, frameworkPath.path)); } } |