From b860d465797a6e42ac9eee9e2aa80645af1d2714 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Wed, 1 Feb 2017 13:43:28 +0100 Subject: [PATCH] Clang: Handle generated files We don't handled generated files so we got internal parse errors. Change-Id: If75e202f93fe3f71f43e3b1d15c0fb77e20c2248 Reviewed-by: Tim Jenssen --- src/libs/clangbackendipc/filecontainerv2.h | 11 ++- src/libs/clangbackendipc/filepath.h | 11 +++ .../clangbackendipc/projectpartcontainerv2.h | 12 +-- .../updatepchprojectpartsmessage.h | 26 +++++- .../clangpchmanager/projectupdater.cpp | 92 ++++++++++++++----- src/plugins/clangpchmanager/projectupdater.h | 24 ++++- .../qtcreatorprojectupdater.cpp | 34 ++++++- .../source/collectincludestoolaction.h | 38 +++++++- .../source/includecollector.cpp | 41 +++++---- .../source/includecollector.h | 7 +- .../source/pchcreator.cpp | 92 +++++++++++++++---- .../source/pchcreator.h | 15 ++- .../source/pchcreatorinterface.h | 2 + .../source/pchmanagerserver.cpp | 2 + .../source/clangtool.cpp | 18 +++- .../source/clangtool.h | 6 +- .../unittest/data/includecollector_main2.cpp | 1 + tests/unit/unittest/includecollector-test.cpp | 5 +- tests/unit/unittest/mockpchcreator.h | 12 ++- tests/unit/unittest/pchcreator-test.cpp | 27 ++++-- .../pchmanagerclientserverinprocess-test.cpp | 4 +- tests/unit/unittest/pchmanagerserver-test.cpp | 21 +++-- tests/unit/unittest/projectupdater-test.cpp | 25 +++-- 23 files changed, 402 insertions(+), 124 deletions(-) diff --git a/src/libs/clangbackendipc/filecontainerv2.h b/src/libs/clangbackendipc/filecontainerv2.h index fa014a48244..6c9135cdf91 100644 --- a/src/libs/clangbackendipc/filecontainerv2.h +++ b/src/libs/clangbackendipc/filecontainerv2.h @@ -28,6 +28,8 @@ #include "clangbackendipc_global.h" #include "filepath.h" +#include + namespace ClangBackEnd { namespace V2 { @@ -104,6 +106,12 @@ public: && first.commandLineArguments_ == second.commandLineArguments_; } + 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_); + } + FileContainer clone() const { return FileContainer(filePath_.clone(), @@ -119,9 +127,10 @@ private: quint32 documentRevision_ = 0; }; +using FileContainers = std::vector; + CMBIPC_EXPORT QDebug operator<<(QDebug debug, const FileContainer &container); void PrintTo(const FileContainer &container, ::std::ostream* os); - } // namespace V2 } // namespace ClangBackEnd diff --git a/src/libs/clangbackendipc/filepath.h b/src/libs/clangbackendipc/filepath.h index 3a7f8b3c368..5d4e5a7f476 100644 --- a/src/libs/clangbackendipc/filepath.h +++ b/src/libs/clangbackendipc/filepath.h @@ -77,6 +77,11 @@ public: return std::move(name_); } + Utils::PathString path() const + { + return {directory_, "/", name_}; + } + friend QDataStream &operator<<(QDataStream &out, const FilePath &filePath) { out << filePath.directory_; @@ -106,6 +111,12 @@ public: && first.directory_ == second.directory_; } + friend bool operator<(const FilePath &first, const FilePath &second) + { + return std::tie(first.name_, first.directory_) + < std::tie(second.name_, second.directory_); + } + FilePath clone() const { return FilePath(directory_.clone(), name_.clone()); diff --git a/src/libs/clangbackendipc/projectpartcontainerv2.h b/src/libs/clangbackendipc/projectpartcontainerv2.h index db5781daacf..9c6b32f4c9b 100644 --- a/src/libs/clangbackendipc/projectpartcontainerv2.h +++ b/src/libs/clangbackendipc/projectpartcontainerv2.h @@ -38,8 +38,8 @@ public: ProjectPartContainer() = default; ProjectPartContainer(Utils::SmallString &&projectPartId, Utils::SmallStringVector &&arguments, - Utils::SmallStringVector &&headerPaths, - Utils::SmallStringVector &&sourcePaths) + Utils::PathStringVector &&headerPaths, + Utils::PathStringVector &&sourcePaths) : projectPartId_(std::move(projectPartId)), arguments_(std::move(arguments)), headerPaths_(std::move(headerPaths)), @@ -57,12 +57,12 @@ public: return arguments_; } - const Utils::SmallStringVector &sourcePaths() const + const Utils::PathStringVector &sourcePaths() const { return sourcePaths_; } - const Utils::SmallStringVector &headerPaths() const + const Utils::PathStringVector &headerPaths() const { return headerPaths_; } @@ -112,8 +112,8 @@ public: private: Utils::SmallString projectPartId_; Utils::SmallStringVector arguments_; - Utils::SmallStringVector headerPaths_; - Utils::SmallStringVector sourcePaths_; + Utils::PathStringVector headerPaths_; + Utils::PathStringVector sourcePaths_; }; using ProjectPartContainers = std::vector; diff --git a/src/libs/clangbackendipc/updatepchprojectpartsmessage.h b/src/libs/clangbackendipc/updatepchprojectpartsmessage.h index dc5534c0b3b..c308e3e4dff 100644 --- a/src/libs/clangbackendipc/updatepchprojectpartsmessage.h +++ b/src/libs/clangbackendipc/updatepchprojectpartsmessage.h @@ -25,6 +25,7 @@ #pragma once +#include "filecontainerv2.h" #include "projectpartcontainerv2.h" namespace ClangBackEnd { @@ -33,8 +34,10 @@ class UpdatePchProjectPartsMessage { public: UpdatePchProjectPartsMessage() = default; - UpdatePchProjectPartsMessage(V2::ProjectPartContainers &&projectsParts) - : projectsParts_(std::move(projectsParts)) + UpdatePchProjectPartsMessage(V2::ProjectPartContainers &&projectsParts, + V2::FileContainers &&generatedFiles) + : projectsParts_(std::move(projectsParts)), + generatedFiles_(std::move(generatedFiles)) {} const V2::ProjectPartContainers &projectsParts() const @@ -47,9 +50,20 @@ public: return std::move(projectsParts_); } + const V2::FileContainers &generatedFiles() const + { + return generatedFiles_; + } + + V2::FileContainers takeGeneratedFiles() + { + return std::move(generatedFiles_); + } + friend QDataStream &operator<<(QDataStream &out, const UpdatePchProjectPartsMessage &message) { out << message.projectsParts_; + out << message.generatedFiles_; return out; } @@ -57,6 +71,7 @@ public: friend QDataStream &operator>>(QDataStream &in, UpdatePchProjectPartsMessage &message) { in >> message.projectsParts_; + in >> message.generatedFiles_; return in; } @@ -64,16 +79,19 @@ public: friend bool operator==(const UpdatePchProjectPartsMessage &first, const UpdatePchProjectPartsMessage &second) { - return first.projectsParts_ == second.projectsParts_; + return first.projectsParts_ == second.projectsParts_ + && first.generatedFiles_ == second.generatedFiles_; } UpdatePchProjectPartsMessage clone() const { - return UpdatePchProjectPartsMessage(Utils::clone(projectsParts_)); + return UpdatePchProjectPartsMessage(Utils::clone(projectsParts_), + Utils::clone(generatedFiles_)); } private: V2::ProjectPartContainers projectsParts_; + V2::FileContainers generatedFiles_; }; CMBIPC_EXPORT QDebug operator<<(QDebug debug, const UpdatePchProjectPartsMessage &message); diff --git a/src/plugins/clangpchmanager/projectupdater.cpp b/src/plugins/clangpchmanager/projectupdater.cpp index 9e26fa72170..c6f3fd80960 100644 --- a/src/plugins/clangpchmanager/projectupdater.cpp +++ b/src/plugins/clangpchmanager/projectupdater.cpp @@ -34,8 +34,24 @@ #include #include +#include +#include + namespace ClangPchManager { +class HeaderAndSources +{ +public: + void reserve(std::size_t size) + { + headers.reserve(size); + sources.reserve(size); + } + + Utils::PathStringVector headers; + Utils::PathStringVector sources; +}; + ProjectUpdater::ProjectUpdater(ClangBackEnd::PchManagerServerInterface &server, PchManagerClient &client) : m_server(server), @@ -43,9 +59,13 @@ ProjectUpdater::ProjectUpdater(ClangBackEnd::PchManagerServerInterface &server, { } -void ProjectUpdater::updateProjectParts(const std::vector &projectParts) +void ProjectUpdater::updateProjectParts(const std::vector &projectParts, + ClangBackEnd::V2::FileContainers &&generatedFiles) { - ClangBackEnd::UpdatePchProjectPartsMessage message{toProjectPartContainers(projectParts)}; + m_excludedPaths = createExcludedPaths(generatedFiles); + + ClangBackEnd::UpdatePchProjectPartsMessage message{toProjectPartContainers(projectParts), + std::move(generatedFiles)}; m_server.updatePchProjectParts(std::move(message)); } @@ -60,37 +80,39 @@ void ProjectUpdater::removeProjectParts(const QStringList &projectPartIds) m_client.precompiledHeaderRemoved(projectPartiId); } -namespace { -class HeaderAndSources +void ProjectUpdater::setExcludedPaths(Utils::PathStringVector &&excludedPaths) { -public: - void reserve(std::size_t size) - { - headers.reserve(size); - sources.reserve(size); + m_excludedPaths = excludedPaths; +} + +void ProjectUpdater::addToHeaderAndSources(HeaderAndSources &headerAndSources, + const CppTools::ProjectFile &projectFile) const +{ + Utils::PathString path = projectFile.path; + bool exclude = std::binary_search(m_excludedPaths.begin(), m_excludedPaths.end(), path); + + if (!exclude) { + if (projectFile.isSource()) + headerAndSources.sources.push_back(path); + else if (projectFile.isHeader()) + headerAndSources.headers.push_back(path); } +} - Utils::SmallStringVector headers; - Utils::SmallStringVector sources; -}; - -HeaderAndSources headerAndSourcesFromProjectPart(CppTools::ProjectPart *projectPart) +HeaderAndSources ProjectUpdater::headerAndSourcesFromProjectPart( + CppTools::ProjectPart *projectPart) const { HeaderAndSources headerAndSources; headerAndSources.reserve(std::size_t(projectPart->files.size()) * 3 / 2); - for (const CppTools::ProjectFile &projectFile : projectPart->files) { - if (projectFile.isSource()) - headerAndSources.sources.push_back(projectFile.path); - else if (projectFile.isHeader()) - headerAndSources.headers.push_back(projectFile.path); - } + for (const CppTools::ProjectFile &projectFile : projectPart->files) + addToHeaderAndSources(headerAndSources, projectFile); return headerAndSources; } -} -ClangBackEnd::V2::ProjectPartContainer ProjectUpdater::toProjectPartContainer(CppTools::ProjectPart *projectPart) +ClangBackEnd::V2::ProjectPartContainer ProjectUpdater::toProjectPartContainer( + CppTools::ProjectPart *projectPart) const { using CppTools::ClangCompilerOptionsBuilder; @@ -110,17 +132,39 @@ ClangBackEnd::V2::ProjectPartContainer ProjectUpdater::toProjectPartContainer(Cp } std::vector ProjectUpdater::toProjectPartContainers( - std::vector projectParts) + std::vector projectParts) const { + using namespace std::placeholders; + std::vector projectPartContainers; projectPartContainers.reserve(projectParts.size()); std::transform(projectParts.begin(), projectParts.end(), std::back_inserter(projectPartContainers), - ProjectUpdater::toProjectPartContainer); + std::bind(&ProjectUpdater::toProjectPartContainer, this, _1)); return projectPartContainers; } +Utils::PathStringVector ProjectUpdater::createExcludedPaths( + const ClangBackEnd::V2::FileContainers &generatedFiles) +{ + Utils::PathStringVector excludedPaths; + excludedPaths.reserve(generatedFiles.size()); + + auto convertToPath = [] (const ClangBackEnd::V2::FileContainer &fileContainer) { + return fileContainer.filePath().path(); + }; + + std::transform(generatedFiles.begin(), + generatedFiles.end(), + std::back_inserter(excludedPaths), + convertToPath); + + std::sort(excludedPaths.begin(), excludedPaths.end()); + + return excludedPaths; +} + } // namespace ClangPchManager diff --git a/src/plugins/clangpchmanager/projectupdater.h b/src/plugins/clangpchmanager/projectupdater.h index 880920d1b7a..b50dc8af65f 100644 --- a/src/plugins/clangpchmanager/projectupdater.h +++ b/src/plugins/clangpchmanager/projectupdater.h @@ -27,8 +27,11 @@ #include +#include + namespace CppTools { class ProjectPart; +class ProjectFile; } namespace ClangBackEnd { @@ -45,6 +48,7 @@ QT_FORWARD_DECLARE_CLASS(QStringList) namespace ClangPchManager { +class HeaderAndSources; class PchManagerClient; class ProjectUpdater @@ -53,16 +57,26 @@ public: ProjectUpdater(ClangBackEnd::PchManagerServerInterface &server, PchManagerClient &client); - void updateProjectParts(const std::vector &projectParts); + void updateProjectParts(const std::vector &projectParts, + ClangBackEnd::V2::FileContainers &&generatedFiles); void removeProjectParts(const QStringList &projectPartIds); unittest_public: - static ClangBackEnd::V2::ProjectPartContainer toProjectPartContainer( - CppTools::ProjectPart *projectPart); - static std::vector toProjectPartContainers( - std::vector projectParts); + void setExcludedPaths(Utils::PathStringVector &&excludedPaths); + + HeaderAndSources headerAndSourcesFromProjectPart(CppTools::ProjectPart *projectPart) const; + ClangBackEnd::V2::ProjectPartContainer toProjectPartContainer( + CppTools::ProjectPart *projectPart) const; + std::vector toProjectPartContainers( + std::vector projectParts) const; + void addToHeaderAndSources(HeaderAndSources &headerAndSources, + const CppTools::ProjectFile &projectFile) const; + + static Utils::PathStringVector createExcludedPaths( + const ClangBackEnd::V2::FileContainers &generatedFiles); private: + Utils::PathStringVector m_excludedPaths; ClangBackEnd::PchManagerServerInterface &m_server; PchManagerClient &m_client; }; diff --git a/src/plugins/clangpchmanager/qtcreatorprojectupdater.cpp b/src/plugins/clangpchmanager/qtcreatorprojectupdater.cpp index 48a6a287fc8..6ac93c747a7 100644 --- a/src/plugins/clangpchmanager/qtcreatorprojectupdater.cpp +++ b/src/plugins/clangpchmanager/qtcreatorprojectupdater.cpp @@ -25,6 +25,7 @@ #include "qtcreatorprojectupdater.h" +#include #include #include @@ -43,7 +44,29 @@ QtCreatorProjectUpdater::QtCreatorProjectUpdater(ClangBackEnd::PchManagerServerI connectToCppModelManager(); } -void QtCreatorProjectUpdater::projectPartsUpdated(ProjectExplorer::Project *project) +namespace { + +std::vector createGeneratedFiles() +{ + auto abstractEditors = CppTools::CppModelManager::instance()->abstractEditorSupports(); + std::vector generatedFiles; + generatedFiles.reserve(std::size_t(abstractEditors.size())); + + auto toFileContainer = [] (const CppTools::AbstractEditorSupport *abstractEditor) { + return ClangBackEnd::V2::FileContainer(ClangBackEnd::FilePath(abstractEditor->fileName()), + Utils::SmallString::fromQByteArray(abstractEditor->contents()), + {}); + }; + + std::transform(abstractEditors.begin(), + abstractEditors.end(), + std::back_inserter(generatedFiles), + toFileContainer); + + return generatedFiles; +} + +std::vector createProjectParts(ProjectExplorer::Project *project) { const CppTools::ProjectInfo projectInfo = cppModelManager()->projectInfo(project); @@ -61,7 +84,14 @@ void QtCreatorProjectUpdater::projectPartsUpdated(ProjectExplorer::Project *proj std::back_inserter(projectParts), convertToRawPointer); - updateProjectParts(projectParts); + return projectParts; +} + +} + +void QtCreatorProjectUpdater::projectPartsUpdated(ProjectExplorer::Project *project) +{ + updateProjectParts(createProjectParts(project), createGeneratedFiles()); } void QtCreatorProjectUpdater::projectPartsRemoved(const QStringList &projectPartIds) diff --git a/src/tools/clangpchmanagerbackend/source/collectincludestoolaction.h b/src/tools/clangpchmanagerbackend/source/collectincludestoolaction.h index f8b9f28a83c..7b81228b09a 100644 --- a/src/tools/clangpchmanagerbackend/source/collectincludestoolaction.h +++ b/src/tools/clangpchmanagerbackend/source/collectincludestoolaction.h @@ -38,12 +38,26 @@ class CollectIncludesToolAction final : public clang::tooling::FrontendActionFac public: CollectIncludesToolAction(std::vector &includeIds, StringCache &filePathCache, - const std::vector &excludedIncludeUIDs) + const Utils::PathStringVector &excludedIncludes) : m_includeIds(includeIds), m_filePathCache(filePathCache), - m_excludedIncludeUIDs(excludedIncludeUIDs) + m_excludedIncludes(excludedIncludes) {} + bool runInvocation(clang::CompilerInvocation *invocation, + clang::FileManager *fileManager, + std::shared_ptr pchContainerOperations, + clang::DiagnosticConsumer *diagnosticConsumer) override + { + if (m_excludedIncludeUIDs.empty()) + m_excludedIncludeUIDs = generateExcludedIncludeFileUIDs(*fileManager); + + return clang::tooling::FrontendActionFactory::runInvocation(invocation, + fileManager, + pchContainerOperations, + diagnosticConsumer); + } + clang::FrontendAction *create() { return new CollectIncludesAction(m_includeIds, @@ -52,11 +66,29 @@ public: m_alreadyIncludedFileUIDs); } + std::vector generateExcludedIncludeFileUIDs(clang::FileManager &fileManager) const + { + std::vector fileUIDs; + fileUIDs.reserve(m_excludedIncludes.size()); + + for (const Utils::PathString &filePath : m_excludedIncludes) { + const clang::FileEntry *file = fileManager.getFile({filePath.data(), filePath.size()}); + + if (file) + fileUIDs.push_back(file->getUID()); + } + + std::sort(fileUIDs.begin(), fileUIDs.end()); + + return fileUIDs; + } + private: std::vector m_alreadyIncludedFileUIDs; + std::vector m_excludedIncludeUIDs; std::vector &m_includeIds; StringCache &m_filePathCache; - const std::vector &m_excludedIncludeUIDs; + const Utils::PathStringVector &m_excludedIncludes; }; } // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/includecollector.cpp b/src/tools/clangpchmanagerbackend/source/includecollector.cpp index c90f345cc2a..cf9dd759336 100644 --- a/src/tools/clangpchmanagerbackend/source/includecollector.cpp +++ b/src/tools/clangpchmanagerbackend/source/includecollector.cpp @@ -29,6 +29,8 @@ #include +#include + namespace ClangBackEnd { IncludeCollector::IncludeCollector(StringCache &filePathCache) @@ -40,17 +42,31 @@ void IncludeCollector::collectIncludes() { clang::tooling::ClangTool tool = createTool(); - auto excludedIncludeFileUIDs = generateExcludedIncludeFileUIDs(tool.getFiles()); - auto action = std::unique_ptr( - new CollectIncludesToolAction(m_includeIds, m_filePathCache, excludedIncludeFileUIDs)); + new CollectIncludesToolAction(m_includeIds, + m_filePathCache, + m_excludedIncludes)); tool.run(action.get()); } -void IncludeCollector::setExcludedIncludes(Utils::SmallStringVector &&excludedIncludes) +void IncludeCollector::setExcludedIncludes(Utils::PathStringVector &&excludedIncludes) { - this->m_excludedIncludes = std::move(excludedIncludes); +#ifdef _WIN32 + m_excludedIncludes.clear(); + m_excludedIncludes.reserve(excludedIncludes.size()); + std::transform(std::make_move_iterator(excludedIncludes.begin()), + std::make_move_iterator(excludedIncludes.end()), + std::back_inserter(m_excludedIncludes), + [] (Utils::PathString &&path) { + path.replace("/", "\\"); + return std::move(path); + }); + + +#else + m_excludedIncludes = std::move(excludedIncludes); +#endif } std::vector IncludeCollector::takeIncludeIds() @@ -60,21 +76,6 @@ std::vector IncludeCollector::takeIncludeIds() return std::move(m_includeIds); } -std::vector IncludeCollector::generateExcludedIncludeFileUIDs(clang::FileManager &fileManager) const -{ - std::vector fileUIDs; - fileUIDs.reserve(m_excludedIncludes.size()); - for (const Utils::SmallString &filePath : m_excludedIncludes) { - const clang::FileEntry *file = fileManager.getFile({filePath.data(), filePath.size()}); - - if (file) - fileUIDs.push_back(file->getUID()); - } - - std::sort(fileUIDs.begin(), fileUIDs.end()); - - return fileUIDs; -} } // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/includecollector.h b/src/tools/clangpchmanagerbackend/source/includecollector.h index 15914c22a2b..09575abd424 100644 --- a/src/tools/clangpchmanagerbackend/source/includecollector.h +++ b/src/tools/clangpchmanagerbackend/source/includecollector.h @@ -38,15 +38,12 @@ public: void collectIncludes(); - void setExcludedIncludes(Utils::SmallStringVector &&excludedIncludes); + void setExcludedIncludes(Utils::PathStringVector &&excludedIncludes); std::vector takeIncludeIds(); private: - std::vector generateExcludedIncludeFileUIDs(clang::FileManager &fileManager) const; - -private: - Utils::SmallStringVector m_excludedIncludes; + Utils::PathStringVector m_excludedIncludes; std::vector m_includeIds; Utils::SmallStringVector m_directories; StringCache &m_filePathCache; diff --git a/src/tools/clangpchmanagerbackend/source/pchcreator.cpp b/src/tools/clangpchmanagerbackend/source/pchcreator.cpp index 0b2d1c67ae8..84883aba53a 100644 --- a/src/tools/clangpchmanagerbackend/source/pchcreator.cpp +++ b/src/tools/clangpchmanagerbackend/source/pchcreator.cpp @@ -45,14 +45,21 @@ PchCreator::PchCreator(Environment &environment, StringCache PchCreator::PchCreator(V2::ProjectPartContainers &&projectsParts, Environment &environment, StringCache &filePathCache, - PchGeneratorInterface *pchGenerator) + PchGeneratorInterface *pchGenerator, + V2::FileContainers &&generatedFiles) : m_projectParts(std::move(projectsParts)), + m_generatedFiles(std::move(generatedFiles)), m_environment(environment), m_filePathCache(filePathCache), m_pchGenerator(pchGenerator) { } +void PchCreator::setGeneratedFiles(V2::FileContainers &&generatedFiles) +{ + m_generatedFiles = generatedFiles; +} + namespace { template @@ -92,12 +99,13 @@ std::size_t globalCount(const V2::ProjectPartContainers &projectsParts, sizeFunction); } -template -void generateGlobal(Utils::SmallStringVector &entries, +template +void generateGlobal(Container &entries, const V2::ProjectPartContainers &projectsParts, GetterFunction getterFunction) { - entries.reserve(entries.size() + globalCount(projectsParts, getterFunction)); + entries.reserve(entries.capacity() + globalCount(projectsParts, getterFunction)); for (const V2::ProjectPartContainer &projectPart : projectsParts) { const auto &projectPartPaths = getterFunction(projectPart); @@ -106,41 +114,66 @@ void generateGlobal(Utils::SmallStringVector &entries, }; } -template -Utils::SmallStringVector generateGlobal( +template +Utils::PathStringVector generateGlobal( const V2::ProjectPartContainers &projectsParts, - GetterFunction getterFunction) + GetterFunction getterFunction, + std::size_t prereserve = 0) { - Utils::SmallStringVector entries; + Container entries; + entries.reserve(prereserve); generateGlobal(entries, projectsParts, getterFunction); return entries; } + +Utils::PathStringVector generatedFilePaths(const V2::FileContainers &generaredFiles) +{ + Utils::PathStringVector generaredFilePaths; + generaredFilePaths.reserve(generaredFiles.size()); + + for (const V2::FileContainer &generatedFile : generaredFiles) + generaredFilePaths.push_back(generatedFile.filePath().path()); + + return generaredFilePaths; } -Utils::SmallStringVector PchCreator::generateGlobalHeaderPaths() const +} + +Utils::PathStringVector PchCreator::generateGlobalHeaderPaths() const { auto includeFunction = [] (const V2::ProjectPartContainer &projectPart) - -> const Utils::SmallStringVector & { + -> const Utils::PathStringVector & { return projectPart.headerPaths(); }; - return generateGlobal(m_projectParts, includeFunction); + Utils::PathStringVector headerPaths = generateGlobal(m_projectParts, + includeFunction, + m_generatedFiles.size()); + + Utils::PathStringVector generatedPath = generatedFilePaths(m_generatedFiles); + + headerPaths.insert(headerPaths.end(), + std::make_move_iterator(generatedPath.begin()), + std::make_move_iterator(generatedPath.end())); + + return headerPaths; } -Utils::SmallStringVector PchCreator::generateGlobalSourcePaths() const +Utils::PathStringVector PchCreator::generateGlobalSourcePaths() const { auto sourceFunction = [] (const V2::ProjectPartContainer &projectPart) - -> const Utils::SmallStringVector & { + -> const Utils::PathStringVector & { return projectPart.sourcePaths(); }; - return generateGlobal(m_projectParts, sourceFunction); + return generateGlobal(m_projectParts, sourceFunction); } -Utils::SmallStringVector PchCreator::generateGlobalHeaderAndSourcePaths() const +Utils::PathStringVector PchCreator::generateGlobalHeaderAndSourcePaths() const { const auto &sourcePaths = generateGlobalSourcePaths(); auto includePaths = generateGlobalHeaderPaths(); @@ -213,6 +246,8 @@ std::vector PchCreator::generateGlobalPchIncludeIds() const collector.addFiles(generateGlobalHeaderAndSourcePaths(), generateGlobalCommandLine()); + collector.addUnsavedFiles(m_generatedFiles); + collector.collectIncludes(); return collector.takeIncludeIds(); @@ -357,10 +392,29 @@ Utils::SmallString PchCreator::generateProjectPartPchFilePathWithoutExtension( return Utils::SmallString::fromQByteArray(fileName); } -Utils::SmallStringVector PchCreator::generateProjectPartHeaderAndSourcePaths( +Utils::PathStringVector PchCreator::generateProjectPartHeaders( + const V2::ProjectPartContainer &projectPart) const +{ + Utils::PathStringVector headerPaths; + headerPaths.reserve(projectPart.headerPaths().size() + m_generatedFiles.size()); + + std::copy(projectPart.headerPaths().begin(), + projectPart.headerPaths().end(), + std::back_inserter(headerPaths)); + + Utils::PathStringVector generatedPath = generatedFilePaths(m_generatedFiles); + + std::copy(std::make_move_iterator(generatedPath.begin()), + std::make_move_iterator(generatedPath.end()), + std::back_inserter(headerPaths)); + + return headerPaths; +} + +Utils::PathStringVector PchCreator::generateProjectPartHeaderAndSourcePaths( const V2::ProjectPartContainer &projectPart) { - Utils::SmallStringVector includeAndSources; + Utils::PathStringVector includeAndSources; includeAndSources.reserve(projectPart.headerPaths().size() + projectPart.sourcePaths().size()); append(includeAndSources, projectPart.headerPaths()); @@ -374,11 +428,13 @@ std::vector PchCreator::generateProjectPartPchIncludes( { IncludeCollector collector(m_filePathCache); - collector.setExcludedIncludes(projectPart.headerPaths().clone()); + collector.setExcludedIncludes(generateProjectPartHeaders(projectPart)); collector.addFiles(generateProjectPartHeaderAndSourcePaths(projectPart), generateProjectPartCommandLine(projectPart)); + collector.addUnsavedFiles(m_generatedFiles); + collector.collectIncludes(); return collector.takeIncludeIds(); diff --git a/src/tools/clangpchmanagerbackend/source/pchcreator.h b/src/tools/clangpchmanagerbackend/source/pchcreator.h index 7affe82f6c6..70fddd29646 100644 --- a/src/tools/clangpchmanagerbackend/source/pchcreator.h +++ b/src/tools/clangpchmanagerbackend/source/pchcreator.h @@ -52,17 +52,19 @@ public: PchCreator(V2::ProjectPartContainers &&projectsParts, Environment &environment, StringCache &filePathCache, - PchGeneratorInterface *pchGenerator); + PchGeneratorInterface *pchGenerator, + V2::FileContainers &&generatedFiles); void generatePchs(V2::ProjectPartContainers &&projectsParts) override; + void setGeneratedFiles(V2::FileContainers &&generatedFiles) override; std::vector takeProjectsIncludes() override; void setGenerator(PchGeneratorInterface *pchGenerator); unitttest_public: - Utils::SmallStringVector generateGlobalHeaderPaths() const; - Utils::SmallStringVector generateGlobalSourcePaths() const; - Utils::SmallStringVector generateGlobalHeaderAndSourcePaths() const; + Utils::PathStringVector generateGlobalHeaderPaths() const; + Utils::PathStringVector generateGlobalSourcePaths() const; + Utils::PathStringVector generateGlobalHeaderAndSourcePaths() const; Utils::SmallStringVector generateGlobalArguments() const; Utils::SmallStringVector generateGlobalCommandLine() const; Utils::SmallStringVector generateGlobalPchCompilerArguments() const; @@ -89,7 +91,9 @@ unitttest_public: const V2::ProjectPartContainer &projectPart) const; Utils::SmallString generateProjectPartPchFilePathWithoutExtension( const V2::ProjectPartContainer &projectPart) const; - static Utils::SmallStringVector generateProjectPartHeaderAndSourcePaths( + Utils::PathStringVector generateProjectPartHeaders( + const V2::ProjectPartContainer &projectPart) const; + static Utils::PathStringVector generateProjectPartHeaderAndSourcePaths( const V2::ProjectPartContainer &projectPart); std::vector generateProjectPartPchIncludes( const V2::ProjectPartContainer &projectPart) const; @@ -115,6 +119,7 @@ private: private: V2::ProjectPartContainers m_projectParts; + V2::FileContainers m_generatedFiles; std::vector m_projectPartPchs; std::vector m_projectsIncludeIds; Environment &m_environment; diff --git a/src/tools/clangpchmanagerbackend/source/pchcreatorinterface.h b/src/tools/clangpchmanagerbackend/source/pchcreatorinterface.h index f2e6f0f6a2a..f7ca1c6bf88 100644 --- a/src/tools/clangpchmanagerbackend/source/pchcreatorinterface.h +++ b/src/tools/clangpchmanagerbackend/source/pchcreatorinterface.h @@ -28,6 +28,7 @@ #include "idpaths.h" #include "projectpartpch.h" +#include #include namespace ClangBackEnd { @@ -38,6 +39,7 @@ public: virtual ~PchCreatorInterface(); virtual void generatePchs(V2::ProjectPartContainers &&projectsParts) = 0; + virtual void setGeneratedFiles(V2::FileContainers &&generatedFiles) = 0; virtual std::vector takeProjectsIncludes() = 0; }; diff --git a/src/tools/clangpchmanagerbackend/source/pchmanagerserver.cpp b/src/tools/clangpchmanagerbackend/source/pchmanagerserver.cpp index 271412bf36d..2d443dd7149 100644 --- a/src/tools/clangpchmanagerbackend/source/pchmanagerserver.cpp +++ b/src/tools/clangpchmanagerbackend/source/pchmanagerserver.cpp @@ -56,6 +56,8 @@ void PchManagerServer::end() void PchManagerServer::updatePchProjectParts(UpdatePchProjectPartsMessage &&message) { + m_pchCreator.setGeneratedFiles(message.takeGeneratedFiles()); + m_pchCreator.generatePchs(m_projectParts.update(message.takeProjectsParts())); m_fileSystemWatcher.updateIdPaths(m_pchCreator.takeProjectsIncludes()); diff --git a/src/tools/clangrefactoringbackend/source/clangtool.cpp b/src/tools/clangrefactoringbackend/source/clangtool.cpp index 1e7520de2d7..dd4b6c57a3f 100644 --- a/src/tools/clangrefactoringbackend/source/clangtool.cpp +++ b/src/tools/clangrefactoringbackend/source/clangtool.cpp @@ -58,10 +58,11 @@ void ClangTool::addFile(std::string &&directory, sourceFilePaths.push_back(fileContent.filePath); } -void ClangTool::addFiles(const Utils::SmallStringVector &filePaths, +template +void ClangTool::addFiles(const Container &filePaths, const Utils::SmallStringVector &arguments) { - for (const Utils::SmallString &filePath : filePaths) { + for (const typename Container::value_type &filePath : filePaths) { auto found = std::find(filePath.rbegin(), filePath.rend(), '/'); auto fileNameBegin = found.base(); @@ -76,6 +77,13 @@ void ClangTool::addFiles(const Utils::SmallStringVector &filePaths, } } +template +void ClangTool::addFiles(const Utils::SmallStringVector &filePaths, + const Utils::SmallStringVector &arguments); +template +void ClangTool::addFiles(const Utils::PathStringVector &filePaths, + const Utils::SmallStringVector &arguments); + namespace { Utils::SmallString toNativeFilePath(const FilePath &filePath) { @@ -87,13 +95,13 @@ Utils::SmallString toNativeFilePath(const FilePath &filePath) } } -void ClangTool::addUnsavedFiles(std::vector &&unsavedFiles) +void ClangTool::addUnsavedFiles(const V2::FileContainers &unsavedFiles) { unsavedFileContents.reserve(unsavedFileContents.size() + unsavedFiles.size()); - auto convertToUnsavedFileContent = [] (V2::FileContainer &unsavedFile) { + auto convertToUnsavedFileContent = [] (const V2::FileContainer &unsavedFile) { return UnsavedFileContent{toNativeFilePath(unsavedFile.filePath()), - unsavedFile.takeUnsavedFileContent()}; + unsavedFile.unsavedFileContent().clone()}; }; std::transform(unsavedFiles.begin(), diff --git a/src/tools/clangrefactoringbackend/source/clangtool.h b/src/tools/clangrefactoringbackend/source/clangtool.h index e75d020e600..c7ee2a83e02 100644 --- a/src/tools/clangrefactoringbackend/source/clangtool.h +++ b/src/tools/clangrefactoringbackend/source/clangtool.h @@ -94,10 +94,12 @@ public: std::string &&fileName, std::string &&content, std::vector &&commandLine); - void addFiles(const Utils::SmallStringVector &filePaths, + + template + void addFiles(const Container &filePaths, const Utils::SmallStringVector &arguments); - void addUnsavedFiles(std::vector &&unsavedFiles); + void addUnsavedFiles(const V2::FileContainers &unsavedFiles); clang::tooling::ClangTool createTool() const; diff --git a/tests/unit/unittest/data/includecollector_main2.cpp b/tests/unit/unittest/data/includecollector_main2.cpp index 068bf9546bc..243493ae3b2 100644 --- a/tests/unit/unittest/data/includecollector_main2.cpp +++ b/tests/unit/unittest/data/includecollector_main2.cpp @@ -2,3 +2,4 @@ #include "includecollector_header2.h" #include "includecollector_external1.h" #include "../data/includecollector_external2.h" +#include "includecollector_generated_file.h" diff --git a/tests/unit/unittest/includecollector-test.cpp b/tests/unit/unittest/includecollector-test.cpp index 16e07a6e3ba..50c0529e781 100644 --- a/tests/unit/unittest/includecollector-test.cpp +++ b/tests/unit/unittest/includecollector-test.cpp @@ -86,8 +86,11 @@ void IncludeCollector::SetUp() collector.addFile(TESTDATA_DIR, "includecollector_main.cpp", "", {"cc", "includecollector_main.cpp"}); collector.addFile(TESTDATA_DIR, "includecollector_main2.cpp", "", {"cc", "includecollector_main2.cpp"}); + collector.addUnsavedFiles({{{TESTDATA_DIR, "includecollector_generated_file.h"}, "#pragma once", {}}}); + collector.setExcludedIncludes({TESTDATA_DIR "/includecollector_header1.h", - TESTDATA_DIR "/includecollector_header2.h"}); + TESTDATA_DIR "/includecollector_header2.h", + TESTDATA_DIR "/includecollector_generated_file.h"}); } uint IncludeCollector::id(const Utils::SmallString &path) diff --git a/tests/unit/unittest/mockpchcreator.h b/tests/unit/unittest/mockpchcreator.h index 761c10b3164..dfc3a60051f 100644 --- a/tests/unit/unittest/mockpchcreator.h +++ b/tests/unit/unittest/mockpchcreator.h @@ -27,6 +27,7 @@ #include "googletest.h" +#include #include #include #include @@ -35,12 +36,19 @@ class MockPchCreator : public ClangBackEnd::PchCreatorInterface { public: MOCK_METHOD1(generatePchs, - void(const std::vector &projectParts)); + void(const ClangBackEnd::V2::ProjectPartContainers &projectParts)); + MOCK_METHOD1(setGeneratedFiles, + void(const ClangBackEnd::V2::FileContainers &generatedFiles)); MOCK_METHOD0(takeProjectsIncludes, std::vector()); - void generatePchs(std::vector &&projectParts) + void generatePchs(std::vector &&projectParts) override { generatePchs(projectParts); } + + void setGeneratedFiles(ClangBackEnd::V2::FileContainers &&generatedFiles) override + { + setGeneratedFiles(generatedFiles); + } }; diff --git a/tests/unit/unittest/pchcreator-test.cpp b/tests/unit/unittest/pchcreator-test.cpp index bf44fbdbb92..31a4c95acfe 100644 --- a/tests/unit/unittest/pchcreator-test.cpp +++ b/tests/unit/unittest/pchcreator-test.cpp @@ -40,6 +40,8 @@ namespace { using ClangBackEnd::IdPaths; using ClangBackEnd::ProjectPartPch; using ClangBackEnd::V2::ProjectPartContainer; +using ClangBackEnd::V2::FileContainer; +using Utils::PathString; using Utils::SmallString; using testing::_; @@ -60,10 +62,12 @@ protected: protected: ClangBackEnd::StringCache filePathCache; - SmallString main1Path = TESTDATA_DIR "/includecollector_main3.cpp"; - SmallString main2Path = TESTDATA_DIR "/includecollector_main2.cpp"; - SmallString header1Path = TESTDATA_DIR "/includecollector_header1.h"; - SmallString header2Path = TESTDATA_DIR "/includecollector_header2.h"; + PathString main1Path = TESTDATA_DIR "/includecollector_main3.cpp"; + PathString main2Path = TESTDATA_DIR "/includecollector_main2.cpp"; + PathString header1Path = TESTDATA_DIR "/includecollector_header1.h"; + PathString header2Path = TESTDATA_DIR "/includecollector_header2.h"; + SmallString generatedFileName = "includecollector_generated_file.h"; + PathString generatedFilePath = TESTDATA_DIR "/includecollector_generated_file.h"; ProjectPartContainer projectPart1{"project1", {"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"}, {header1Path.clone()}, @@ -73,12 +77,14 @@ protected: {header2Path.clone()}, {main2Path.clone()}}; TestEnvironment environment; + FileContainer generatedFile{{TESTDATA_DIR, generatedFileName.clone()}, "#pragma once", {}}; NiceMock mockPchGeneratorNotifier; ClangBackEnd::PchGenerator generator{environment, &mockPchGeneratorNotifier}; ClangBackEnd::PchCreator creator{{projectPart1.clone(),projectPart2.clone()}, environment, filePathCache, - &generator}; + &generator, + {generatedFile}}; }; using PchCreatorSlowTest = PchCreator; @@ -89,7 +95,7 @@ TEST_F(PchCreator, CreateGlobalHeaderPaths) auto filePaths = creator.generateGlobalHeaderPaths(); ASSERT_THAT(filePaths, - UnorderedElementsAre(header1Path, header2Path)); + UnorderedElementsAre(header1Path, header2Path, generatedFilePath)); } TEST_F(PchCreator, CreateGlobalSourcePaths) @@ -105,7 +111,7 @@ TEST_F(PchCreator, CreateGlobalHeaderAndSourcePaths) auto filePaths = creator.generateGlobalHeaderAndSourcePaths(); ASSERT_THAT(filePaths, - UnorderedElementsAre(main1Path, main2Path, header1Path, header2Path)); + UnorderedElementsAre(main1Path, main2Path, header1Path, header2Path, generatedFilePath)); } TEST_F(PchCreator, CreateGlobalArguments) @@ -180,6 +186,13 @@ TEST_F(PchCreator, CreateProjectPartCommandLine) ASSERT_THAT(commandLine, ElementsAre(environment.clangCompilerPath(), "-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header")); } +TEST_F(PchCreator, CreateProjectPartHeaders) +{ + auto includeIds = creator.generateProjectPartHeaders(projectPart1); + + ASSERT_THAT(includeIds, UnorderedElementsAre(header1Path, generatedFilePath)); +} + TEST_F(PchCreator, CreateProjectPartHeaderAndSources) { auto includeIds = creator.generateProjectPartHeaderAndSourcePaths(projectPart1); diff --git a/tests/unit/unittest/pchmanagerclientserverinprocess-test.cpp b/tests/unit/unittest/pchmanagerclientserverinprocess-test.cpp index 6ae9ff8fa32..ed2ced23111 100644 --- a/tests/unit/unittest/pchmanagerclientserverinprocess-test.cpp +++ b/tests/unit/unittest/pchmanagerclientserverinprocess-test.cpp @@ -42,6 +42,7 @@ #include using ClangBackEnd::UpdatePchProjectPartsMessage; +using ClangBackEnd::V2::FileContainer; using ClangBackEnd::V2::ProjectPartContainer; using ClangBackEnd::RemovePchProjectPartsMessage; using ClangBackEnd::PrecompiledHeadersUpdatedMessage; @@ -95,7 +96,8 @@ TEST_F(PchManagerClientServerInProcess, SendUpdatePchProjectPartsMessage) {"-x", "c++-header", "-Wno-pragma-once-outside-header"}, {TESTDATA_DIR "/includecollector_header.h"}, {TESTDATA_DIR "/includecollector_main.cpp"}}; - UpdatePchProjectPartsMessage message{{projectPart2}}; + FileContainer fileContainer{{"/path/to/", "file"}, "content", {}}; + UpdatePchProjectPartsMessage message{{projectPart2}, {fileContainer}}; EXPECT_CALL(mockPchManagerServer, updatePchProjectParts(message)); diff --git a/tests/unit/unittest/pchmanagerserver-test.cpp b/tests/unit/unittest/pchmanagerserver-test.cpp index b1f6ca8ab02..f90347e4881 100644 --- a/tests/unit/unittest/pchmanagerserver-test.cpp +++ b/tests/unit/unittest/pchmanagerserver-test.cpp @@ -45,7 +45,9 @@ using testing::Return; using testing::_; using testing::IsEmpty; +using Utils::PathString; using Utils::SmallString; +using ClangBackEnd::V2::FileContainer; using ClangBackEnd::V2::ProjectPartContainer; using ClangBackEnd::TaskFinishStatus; @@ -62,10 +64,10 @@ protected: NiceMock mockPchManagerClient; SmallString projectPartId1 = "project1"; SmallString projectPartId2 = "project2"; - SmallString main1Path = TESTDATA_DIR "/includecollector_main3.cpp"; - SmallString main2Path = TESTDATA_DIR "/includecollector_main2.cpp"; - SmallString header1Path = TESTDATA_DIR "/includecollector_header1.h"; - SmallString header2Path = TESTDATA_DIR "/includecollector_header2.h"; + PathString main1Path = TESTDATA_DIR "/includecollector_main3.cpp"; + PathString main2Path = TESTDATA_DIR "/includecollector_main2.cpp"; + PathString header1Path = TESTDATA_DIR "/includecollector_header1.h"; + PathString header2Path = TESTDATA_DIR "/includecollector_header2.h"; std::vector idPaths = {{projectPartId1, {1, 2}}}; ProjectPartContainer projectPart1{projectPartId1.clone(), {"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"}, @@ -75,8 +77,10 @@ protected: {"-x", "c++-header", "-Wno-pragma-once-outside-header"}, {header2Path.clone()}, {main2Path.clone()}}; - std::vector projectParts{projectPart1, projectPart2}; - ClangBackEnd::UpdatePchProjectPartsMessage updatePchProjectPartsMessage{Utils::clone(projectParts)}; + std::vector projectParts{projectPart1, projectPart2}; + FileContainer generatedFile{{"/path/to/", "file"}, "content", {}}; + ClangBackEnd::UpdatePchProjectPartsMessage updatePchProjectPartsMessage{Utils::clone(projectParts), + {generatedFile}}; ClangBackEnd::ProjectPartPch projectPartPch1{projectPart1.projectPartId().clone(), "/path1/to/pch"}; ClangBackEnd::ProjectPartPch projectPartPch2{projectPart2.projectPartId().clone(), "/path2/to/pch"}; std::vector projectPartPchs{projectPartPch1, projectPartPch2}; @@ -103,7 +107,10 @@ TEST_F(PchManagerServer, DoNotCallPrecompiledHeadersForUnsuccessfullyFinishedTas TEST_F(PchManagerServer, CallBuildInPchCreator) { - EXPECT_CALL(mockPchCreator, generatePchs(updatePchProjectPartsMessage.projectsParts())); + auto &&callSetGeneratedFiles = EXPECT_CALL(mockPchCreator, + setGeneratedFiles(updatePchProjectPartsMessage.generatedFiles())); + EXPECT_CALL(mockPchCreator, generatePchs(updatePchProjectPartsMessage.projectsParts())) + .After(callSetGeneratedFiles); server.updatePchProjectParts(updatePchProjectPartsMessage.clone()); } diff --git a/tests/unit/unittest/projectupdater-test.cpp b/tests/unit/unittest/projectupdater-test.cpp index 7a5e45e21a9..25725a9597c 100644 --- a/tests/unit/unittest/projectupdater-test.cpp +++ b/tests/unit/unittest/projectupdater-test.cpp @@ -42,10 +42,12 @@ namespace { using testing::_; +using testing::ElementsAre; using testing::SizeIs; using testing::NiceMock; using testing::AnyNumber; +using ClangBackEnd::V2::FileContainer; using ClangBackEnd::V2::ProjectPartContainer; using CppTools::ClangCompilerOptionsBuilder; @@ -61,24 +63,26 @@ protected: ClangPchManager::ProjectUpdater updater{mockPchManagerServer, pchManagerClient}; Utils::SmallString projectPartId{"project1"}; Utils::SmallString projectPartId2{"project2"}; - Utils::SmallStringVector headerPaths = {"/path/to/header1.h", "/path/to/header2.h"}; - Utils::SmallStringVector sourcePaths = {"/path/to/source1.h", "/path/to/source2.h"}; + Utils::PathStringVector headerPaths = {"/path/to/header1.h", "/path/to/header2.h"}; + Utils::PathStringVector sourcePaths = {"/path/to/source1.cpp", "/path/to/source2.cpp"}; CppTools::ProjectFile header1ProjectFile{headerPaths[0], CppTools::ProjectFile::CXXHeader}; CppTools::ProjectFile header2ProjectFile{headerPaths[1], CppTools::ProjectFile::CXXHeader}; CppTools::ProjectFile source1ProjectFile{sourcePaths[0], CppTools::ProjectFile::CXXSource}; CppTools::ProjectFile source2ProjectFile{sourcePaths[1], CppTools::ProjectFile::CXXSource}; CppTools::ProjectPart projectPart; ProjectPartContainer expectedContainer; + FileContainer generatedFile{{"/path/to", "header1.h"}, "content", {}}; }; TEST_F(ProjectUpdater, CallUpdatePchProjectParts) { std::vector projectParts = {&projectPart, &projectPart}; - ClangBackEnd::UpdatePchProjectPartsMessage message{{expectedContainer.clone(), expectedContainer.clone()}}; + ClangBackEnd::UpdatePchProjectPartsMessage message{{expectedContainer.clone(), expectedContainer.clone()}, + {generatedFile}}; EXPECT_CALL(mockPchManagerServer, updatePchProjectParts(message)); - updater.updateProjectParts(projectParts); + updater.updateProjectParts(projectParts, {generatedFile}); } TEST_F(ProjectUpdater, CallRemovePchProjectParts) @@ -103,6 +107,8 @@ TEST_F(ProjectUpdater, CallPrecompiledHeaderRemoved) TEST_F(ProjectUpdater, ConvertProjectPartToProjectPartContainer) { + updater.setExcludedPaths({"/path/to/header1.h"}); + auto container = updater.toProjectPartContainer(&projectPart); ASSERT_THAT(container, expectedContainer); @@ -115,6 +121,13 @@ TEST_F(ProjectUpdater, ConvertProjectPartToProjectPartContainersHaveSameSizeLike ASSERT_THAT(containers, SizeIs(2)); } +TEST_F(ProjectUpdater, CreateExcludedPaths) +{ + auto excludedPaths = updater.createExcludedPaths({generatedFile}); + + ASSERT_THAT(excludedPaths, ElementsAre("/path/to/header1.h")); +} + void ProjectUpdater::SetUp() { projectPart.files.push_back(header1ProjectFile); @@ -133,8 +146,8 @@ void ProjectUpdater::SetUp() expectedContainer = {projectPartId.clone(), arguments.clone(), - headerPaths.clone(), - sourcePaths.clone()}; + {headerPaths[1]}, + sourcePaths.clone()}; } }