Clang: Handle generated files

We don't handled generated files so we got internal parse errors.

Change-Id: If75e202f93fe3f71f43e3b1d15c0fb77e20c2248
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2017-02-01 13:43:28 +01:00
parent 55400d5bec
commit b860d46579
23 changed files with 402 additions and 124 deletions

View File

@@ -28,6 +28,8 @@
#include "clangbackendipc_global.h" #include "clangbackendipc_global.h"
#include "filepath.h" #include "filepath.h"
#include <vector>
namespace ClangBackEnd { namespace ClangBackEnd {
namespace V2 { namespace V2 {
@@ -104,6 +106,12 @@ public:
&& first.commandLineArguments_ == second.commandLineArguments_; && 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 FileContainer clone() const
{ {
return FileContainer(filePath_.clone(), return FileContainer(filePath_.clone(),
@@ -119,9 +127,10 @@ private:
quint32 documentRevision_ = 0; quint32 documentRevision_ = 0;
}; };
using FileContainers = std::vector<FileContainer>;
CMBIPC_EXPORT QDebug operator<<(QDebug debug, const FileContainer &container); CMBIPC_EXPORT QDebug operator<<(QDebug debug, const FileContainer &container);
void PrintTo(const FileContainer &container, ::std::ostream* os); void PrintTo(const FileContainer &container, ::std::ostream* os);
} // namespace V2 } // namespace V2
} // namespace ClangBackEnd } // namespace ClangBackEnd

View File

@@ -77,6 +77,11 @@ public:
return std::move(name_); return std::move(name_);
} }
Utils::PathString path() const
{
return {directory_, "/", name_};
}
friend QDataStream &operator<<(QDataStream &out, const FilePath &filePath) friend QDataStream &operator<<(QDataStream &out, const FilePath &filePath)
{ {
out << filePath.directory_; out << filePath.directory_;
@@ -106,6 +111,12 @@ public:
&& first.directory_ == second.directory_; && 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 FilePath clone() const
{ {
return FilePath(directory_.clone(), name_.clone()); return FilePath(directory_.clone(), name_.clone());

View File

@@ -38,8 +38,8 @@ public:
ProjectPartContainer() = default; ProjectPartContainer() = default;
ProjectPartContainer(Utils::SmallString &&projectPartId, ProjectPartContainer(Utils::SmallString &&projectPartId,
Utils::SmallStringVector &&arguments, Utils::SmallStringVector &&arguments,
Utils::SmallStringVector &&headerPaths, Utils::PathStringVector &&headerPaths,
Utils::SmallStringVector &&sourcePaths) Utils::PathStringVector &&sourcePaths)
: projectPartId_(std::move(projectPartId)), : projectPartId_(std::move(projectPartId)),
arguments_(std::move(arguments)), arguments_(std::move(arguments)),
headerPaths_(std::move(headerPaths)), headerPaths_(std::move(headerPaths)),
@@ -57,12 +57,12 @@ public:
return arguments_; return arguments_;
} }
const Utils::SmallStringVector &sourcePaths() const const Utils::PathStringVector &sourcePaths() const
{ {
return sourcePaths_; return sourcePaths_;
} }
const Utils::SmallStringVector &headerPaths() const const Utils::PathStringVector &headerPaths() const
{ {
return headerPaths_; return headerPaths_;
} }
@@ -112,8 +112,8 @@ public:
private: private:
Utils::SmallString projectPartId_; Utils::SmallString projectPartId_;
Utils::SmallStringVector arguments_; Utils::SmallStringVector arguments_;
Utils::SmallStringVector headerPaths_; Utils::PathStringVector headerPaths_;
Utils::SmallStringVector sourcePaths_; Utils::PathStringVector sourcePaths_;
}; };
using ProjectPartContainers = std::vector<ProjectPartContainer>; using ProjectPartContainers = std::vector<ProjectPartContainer>;

View File

@@ -25,6 +25,7 @@
#pragma once #pragma once
#include "filecontainerv2.h"
#include "projectpartcontainerv2.h" #include "projectpartcontainerv2.h"
namespace ClangBackEnd { namespace ClangBackEnd {
@@ -33,8 +34,10 @@ class UpdatePchProjectPartsMessage
{ {
public: public:
UpdatePchProjectPartsMessage() = default; UpdatePchProjectPartsMessage() = default;
UpdatePchProjectPartsMessage(V2::ProjectPartContainers &&projectsParts) UpdatePchProjectPartsMessage(V2::ProjectPartContainers &&projectsParts,
: projectsParts_(std::move(projectsParts)) V2::FileContainers &&generatedFiles)
: projectsParts_(std::move(projectsParts)),
generatedFiles_(std::move(generatedFiles))
{} {}
const V2::ProjectPartContainers &projectsParts() const const V2::ProjectPartContainers &projectsParts() const
@@ -47,9 +50,20 @@ public:
return std::move(projectsParts_); 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) friend QDataStream &operator<<(QDataStream &out, const UpdatePchProjectPartsMessage &message)
{ {
out << message.projectsParts_; out << message.projectsParts_;
out << message.generatedFiles_;
return out; return out;
} }
@@ -57,6 +71,7 @@ public:
friend QDataStream &operator>>(QDataStream &in, UpdatePchProjectPartsMessage &message) friend QDataStream &operator>>(QDataStream &in, UpdatePchProjectPartsMessage &message)
{ {
in >> message.projectsParts_; in >> message.projectsParts_;
in >> message.generatedFiles_;
return in; return in;
} }
@@ -64,16 +79,19 @@ public:
friend bool operator==(const UpdatePchProjectPartsMessage &first, friend bool operator==(const UpdatePchProjectPartsMessage &first,
const UpdatePchProjectPartsMessage &second) const UpdatePchProjectPartsMessage &second)
{ {
return first.projectsParts_ == second.projectsParts_; return first.projectsParts_ == second.projectsParts_
&& first.generatedFiles_ == second.generatedFiles_;
} }
UpdatePchProjectPartsMessage clone() const UpdatePchProjectPartsMessage clone() const
{ {
return UpdatePchProjectPartsMessage(Utils::clone(projectsParts_)); return UpdatePchProjectPartsMessage(Utils::clone(projectsParts_),
Utils::clone(generatedFiles_));
} }
private: private:
V2::ProjectPartContainers projectsParts_; V2::ProjectPartContainers projectsParts_;
V2::FileContainers generatedFiles_;
}; };
CMBIPC_EXPORT QDebug operator<<(QDebug debug, const UpdatePchProjectPartsMessage &message); CMBIPC_EXPORT QDebug operator<<(QDebug debug, const UpdatePchProjectPartsMessage &message);

View File

@@ -34,8 +34,24 @@
#include <cpptools/clangcompileroptionsbuilder.h> #include <cpptools/clangcompileroptionsbuilder.h>
#include <cpptools/projectpart.h> #include <cpptools/projectpart.h>
#include <algorithm>
#include <functional>
namespace ClangPchManager { 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, ProjectUpdater::ProjectUpdater(ClangBackEnd::PchManagerServerInterface &server,
PchManagerClient &client) PchManagerClient &client)
: m_server(server), : m_server(server),
@@ -43,9 +59,13 @@ ProjectUpdater::ProjectUpdater(ClangBackEnd::PchManagerServerInterface &server,
{ {
} }
void ProjectUpdater::updateProjectParts(const std::vector<CppTools::ProjectPart *> &projectParts) void ProjectUpdater::updateProjectParts(const std::vector<CppTools::ProjectPart *> &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)); m_server.updatePchProjectParts(std::move(message));
} }
@@ -60,37 +80,39 @@ void ProjectUpdater::removeProjectParts(const QStringList &projectPartIds)
m_client.precompiledHeaderRemoved(projectPartiId); m_client.precompiledHeaderRemoved(projectPartiId);
} }
namespace { void ProjectUpdater::setExcludedPaths(Utils::PathStringVector &&excludedPaths)
class HeaderAndSources
{ {
public: m_excludedPaths = excludedPaths;
void reserve(std::size_t size) }
{
headers.reserve(size); void ProjectUpdater::addToHeaderAndSources(HeaderAndSources &headerAndSources,
sources.reserve(size); 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; HeaderAndSources ProjectUpdater::headerAndSourcesFromProjectPart(
Utils::SmallStringVector sources; CppTools::ProjectPart *projectPart) const
};
HeaderAndSources headerAndSourcesFromProjectPart(CppTools::ProjectPart *projectPart)
{ {
HeaderAndSources headerAndSources; HeaderAndSources headerAndSources;
headerAndSources.reserve(std::size_t(projectPart->files.size()) * 3 / 2); headerAndSources.reserve(std::size_t(projectPart->files.size()) * 3 / 2);
for (const CppTools::ProjectFile &projectFile : projectPart->files) { for (const CppTools::ProjectFile &projectFile : projectPart->files)
if (projectFile.isSource()) addToHeaderAndSources(headerAndSources, projectFile);
headerAndSources.sources.push_back(projectFile.path);
else if (projectFile.isHeader())
headerAndSources.headers.push_back(projectFile.path);
}
return headerAndSources; return headerAndSources;
} }
}
ClangBackEnd::V2::ProjectPartContainer ProjectUpdater::toProjectPartContainer(CppTools::ProjectPart *projectPart) ClangBackEnd::V2::ProjectPartContainer ProjectUpdater::toProjectPartContainer(
CppTools::ProjectPart *projectPart) const
{ {
using CppTools::ClangCompilerOptionsBuilder; using CppTools::ClangCompilerOptionsBuilder;
@@ -110,17 +132,39 @@ ClangBackEnd::V2::ProjectPartContainer ProjectUpdater::toProjectPartContainer(Cp
} }
std::vector<ClangBackEnd::V2::ProjectPartContainer> ProjectUpdater::toProjectPartContainers( std::vector<ClangBackEnd::V2::ProjectPartContainer> ProjectUpdater::toProjectPartContainers(
std::vector<CppTools::ProjectPart *> projectParts) std::vector<CppTools::ProjectPart *> projectParts) const
{ {
using namespace std::placeholders;
std::vector<ClangBackEnd::V2::ProjectPartContainer> projectPartContainers; std::vector<ClangBackEnd::V2::ProjectPartContainer> projectPartContainers;
projectPartContainers.reserve(projectParts.size()); projectPartContainers.reserve(projectParts.size());
std::transform(projectParts.begin(), std::transform(projectParts.begin(),
projectParts.end(), projectParts.end(),
std::back_inserter(projectPartContainers), std::back_inserter(projectPartContainers),
ProjectUpdater::toProjectPartContainer); std::bind(&ProjectUpdater::toProjectPartContainer, this, _1));
return projectPartContainers; 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 } // namespace ClangPchManager

View File

@@ -27,8 +27,11 @@
#include <clangpchmanager_global.h> #include <clangpchmanager_global.h>
#include <filecontainerv2.h>
namespace CppTools { namespace CppTools {
class ProjectPart; class ProjectPart;
class ProjectFile;
} }
namespace ClangBackEnd { namespace ClangBackEnd {
@@ -45,6 +48,7 @@ QT_FORWARD_DECLARE_CLASS(QStringList)
namespace ClangPchManager { namespace ClangPchManager {
class HeaderAndSources;
class PchManagerClient; class PchManagerClient;
class ProjectUpdater class ProjectUpdater
@@ -53,16 +57,26 @@ public:
ProjectUpdater(ClangBackEnd::PchManagerServerInterface &server, ProjectUpdater(ClangBackEnd::PchManagerServerInterface &server,
PchManagerClient &client); PchManagerClient &client);
void updateProjectParts(const std::vector<CppTools::ProjectPart *> &projectParts); void updateProjectParts(const std::vector<CppTools::ProjectPart *> &projectParts,
ClangBackEnd::V2::FileContainers &&generatedFiles);
void removeProjectParts(const QStringList &projectPartIds); void removeProjectParts(const QStringList &projectPartIds);
unittest_public: unittest_public:
static ClangBackEnd::V2::ProjectPartContainer toProjectPartContainer( void setExcludedPaths(Utils::PathStringVector &&excludedPaths);
CppTools::ProjectPart *projectPart);
static std::vector<ClangBackEnd::V2::ProjectPartContainer> toProjectPartContainers( HeaderAndSources headerAndSourcesFromProjectPart(CppTools::ProjectPart *projectPart) const;
std::vector<CppTools::ProjectPart *> projectParts); ClangBackEnd::V2::ProjectPartContainer toProjectPartContainer(
CppTools::ProjectPart *projectPart) const;
std::vector<ClangBackEnd::V2::ProjectPartContainer> toProjectPartContainers(
std::vector<CppTools::ProjectPart *> projectParts) const;
void addToHeaderAndSources(HeaderAndSources &headerAndSources,
const CppTools::ProjectFile &projectFile) const;
static Utils::PathStringVector createExcludedPaths(
const ClangBackEnd::V2::FileContainers &generatedFiles);
private: private:
Utils::PathStringVector m_excludedPaths;
ClangBackEnd::PchManagerServerInterface &m_server; ClangBackEnd::PchManagerServerInterface &m_server;
PchManagerClient &m_client; PchManagerClient &m_client;
}; };

View File

@@ -25,6 +25,7 @@
#include "qtcreatorprojectupdater.h" #include "qtcreatorprojectupdater.h"
#include <cpptools/abstracteditorsupport.h>
#include <cpptools/cppmodelmanager.h> #include <cpptools/cppmodelmanager.h>
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
@@ -43,7 +44,29 @@ QtCreatorProjectUpdater::QtCreatorProjectUpdater(ClangBackEnd::PchManagerServerI
connectToCppModelManager(); connectToCppModelManager();
} }
void QtCreatorProjectUpdater::projectPartsUpdated(ProjectExplorer::Project *project) namespace {
std::vector<ClangBackEnd::V2::FileContainer> createGeneratedFiles()
{
auto abstractEditors = CppTools::CppModelManager::instance()->abstractEditorSupports();
std::vector<ClangBackEnd::V2::FileContainer> 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<CppTools::ProjectPart*> createProjectParts(ProjectExplorer::Project *project)
{ {
const CppTools::ProjectInfo projectInfo = cppModelManager()->projectInfo(project); const CppTools::ProjectInfo projectInfo = cppModelManager()->projectInfo(project);
@@ -61,7 +84,14 @@ void QtCreatorProjectUpdater::projectPartsUpdated(ProjectExplorer::Project *proj
std::back_inserter(projectParts), std::back_inserter(projectParts),
convertToRawPointer); convertToRawPointer);
updateProjectParts(projectParts); return projectParts;
}
}
void QtCreatorProjectUpdater::projectPartsUpdated(ProjectExplorer::Project *project)
{
updateProjectParts(createProjectParts(project), createGeneratedFiles());
} }
void QtCreatorProjectUpdater::projectPartsRemoved(const QStringList &projectPartIds) void QtCreatorProjectUpdater::projectPartsRemoved(const QStringList &projectPartIds)

View File

@@ -38,12 +38,26 @@ class CollectIncludesToolAction final : public clang::tooling::FrontendActionFac
public: public:
CollectIncludesToolAction(std::vector<uint> &includeIds, CollectIncludesToolAction(std::vector<uint> &includeIds,
StringCache<Utils::SmallString> &filePathCache, StringCache<Utils::SmallString> &filePathCache,
const std::vector<uint> &excludedIncludeUIDs) const Utils::PathStringVector &excludedIncludes)
: m_includeIds(includeIds), : m_includeIds(includeIds),
m_filePathCache(filePathCache), m_filePathCache(filePathCache),
m_excludedIncludeUIDs(excludedIncludeUIDs) m_excludedIncludes(excludedIncludes)
{} {}
bool runInvocation(clang::CompilerInvocation *invocation,
clang::FileManager *fileManager,
std::shared_ptr<clang::PCHContainerOperations> 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() clang::FrontendAction *create()
{ {
return new CollectIncludesAction(m_includeIds, return new CollectIncludesAction(m_includeIds,
@@ -52,11 +66,29 @@ public:
m_alreadyIncludedFileUIDs); m_alreadyIncludedFileUIDs);
} }
std::vector<uint> generateExcludedIncludeFileUIDs(clang::FileManager &fileManager) const
{
std::vector<uint> 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: private:
std::vector<uint> m_alreadyIncludedFileUIDs; std::vector<uint> m_alreadyIncludedFileUIDs;
std::vector<uint> m_excludedIncludeUIDs;
std::vector<uint> &m_includeIds; std::vector<uint> &m_includeIds;
StringCache<Utils::SmallString> &m_filePathCache; StringCache<Utils::SmallString> &m_filePathCache;
const std::vector<uint> &m_excludedIncludeUIDs; const Utils::PathStringVector &m_excludedIncludes;
}; };
} // namespace ClangBackEnd } // namespace ClangBackEnd

View File

@@ -29,6 +29,8 @@
#include <utils/smallstring.h> #include <utils/smallstring.h>
#include <algorithm>
namespace ClangBackEnd { namespace ClangBackEnd {
IncludeCollector::IncludeCollector(StringCache<Utils::SmallString> &filePathCache) IncludeCollector::IncludeCollector(StringCache<Utils::SmallString> &filePathCache)
@@ -40,17 +42,31 @@ void IncludeCollector::collectIncludes()
{ {
clang::tooling::ClangTool tool = createTool(); clang::tooling::ClangTool tool = createTool();
auto excludedIncludeFileUIDs = generateExcludedIncludeFileUIDs(tool.getFiles());
auto action = std::unique_ptr<CollectIncludesToolAction>( auto action = std::unique_ptr<CollectIncludesToolAction>(
new CollectIncludesToolAction(m_includeIds, m_filePathCache, excludedIncludeFileUIDs)); new CollectIncludesToolAction(m_includeIds,
m_filePathCache,
m_excludedIncludes));
tool.run(action.get()); 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<uint> IncludeCollector::takeIncludeIds() std::vector<uint> IncludeCollector::takeIncludeIds()
@@ -60,21 +76,6 @@ std::vector<uint> IncludeCollector::takeIncludeIds()
return std::move(m_includeIds); return std::move(m_includeIds);
} }
std::vector<uint> IncludeCollector::generateExcludedIncludeFileUIDs(clang::FileManager &fileManager) const
{
std::vector<uint> 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 } // namespace ClangBackEnd

View File

@@ -38,15 +38,12 @@ public:
void collectIncludes(); void collectIncludes();
void setExcludedIncludes(Utils::SmallStringVector &&excludedIncludes); void setExcludedIncludes(Utils::PathStringVector &&excludedIncludes);
std::vector<uint> takeIncludeIds(); std::vector<uint> takeIncludeIds();
private: private:
std::vector<uint> generateExcludedIncludeFileUIDs(clang::FileManager &fileManager) const; Utils::PathStringVector m_excludedIncludes;
private:
Utils::SmallStringVector m_excludedIncludes;
std::vector<uint> m_includeIds; std::vector<uint> m_includeIds;
Utils::SmallStringVector m_directories; Utils::SmallStringVector m_directories;
StringCache<Utils::SmallString> &m_filePathCache; StringCache<Utils::SmallString> &m_filePathCache;

View File

@@ -45,14 +45,21 @@ PchCreator::PchCreator(Environment &environment, StringCache<Utils::SmallString>
PchCreator::PchCreator(V2::ProjectPartContainers &&projectsParts, PchCreator::PchCreator(V2::ProjectPartContainers &&projectsParts,
Environment &environment, Environment &environment,
StringCache<Utils::SmallString> &filePathCache, StringCache<Utils::SmallString> &filePathCache,
PchGeneratorInterface *pchGenerator) PchGeneratorInterface *pchGenerator,
V2::FileContainers &&generatedFiles)
: m_projectParts(std::move(projectsParts)), : m_projectParts(std::move(projectsParts)),
m_generatedFiles(std::move(generatedFiles)),
m_environment(environment), m_environment(environment),
m_filePathCache(filePathCache), m_filePathCache(filePathCache),
m_pchGenerator(pchGenerator) m_pchGenerator(pchGenerator)
{ {
} }
void PchCreator::setGeneratedFiles(V2::FileContainers &&generatedFiles)
{
m_generatedFiles = generatedFiles;
}
namespace { namespace {
template <typename Source, template <typename Source,
typename Target> typename Target>
@@ -92,12 +99,13 @@ std::size_t globalCount(const V2::ProjectPartContainers &projectsParts,
sizeFunction); sizeFunction);
} }
template <typename GetterFunction> template <typename Container,
void generateGlobal(Utils::SmallStringVector &entries, typename GetterFunction>
void generateGlobal(Container &entries,
const V2::ProjectPartContainers &projectsParts, const V2::ProjectPartContainers &projectsParts,
GetterFunction getterFunction) GetterFunction getterFunction)
{ {
entries.reserve(entries.size() + globalCount(projectsParts, getterFunction)); entries.reserve(entries.capacity() + globalCount(projectsParts, getterFunction));
for (const V2::ProjectPartContainer &projectPart : projectsParts) { for (const V2::ProjectPartContainer &projectPart : projectsParts) {
const auto &projectPartPaths = getterFunction(projectPart); const auto &projectPartPaths = getterFunction(projectPart);
@@ -106,41 +114,66 @@ void generateGlobal(Utils::SmallStringVector &entries,
}; };
} }
template <typename GetterFunction> template <typename Container,
Utils::SmallStringVector generateGlobal( typename GetterFunction>
Utils::PathStringVector generateGlobal(
const V2::ProjectPartContainers &projectsParts, 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); generateGlobal(entries, projectsParts, getterFunction);
return entries; 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) auto includeFunction = [] (const V2::ProjectPartContainer &projectPart)
-> const Utils::SmallStringVector & { -> const Utils::PathStringVector & {
return projectPart.headerPaths(); return projectPart.headerPaths();
}; };
return generateGlobal(m_projectParts, includeFunction); Utils::PathStringVector headerPaths = generateGlobal<Utils::PathStringVector>(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) auto sourceFunction = [] (const V2::ProjectPartContainer &projectPart)
-> const Utils::SmallStringVector & { -> const Utils::PathStringVector & {
return projectPart.sourcePaths(); return projectPart.sourcePaths();
}; };
return generateGlobal(m_projectParts, sourceFunction); return generateGlobal<Utils::PathStringVector>(m_projectParts, sourceFunction);
} }
Utils::SmallStringVector PchCreator::generateGlobalHeaderAndSourcePaths() const Utils::PathStringVector PchCreator::generateGlobalHeaderAndSourcePaths() const
{ {
const auto &sourcePaths = generateGlobalSourcePaths(); const auto &sourcePaths = generateGlobalSourcePaths();
auto includePaths = generateGlobalHeaderPaths(); auto includePaths = generateGlobalHeaderPaths();
@@ -213,6 +246,8 @@ std::vector<uint> PchCreator::generateGlobalPchIncludeIds() const
collector.addFiles(generateGlobalHeaderAndSourcePaths(), generateGlobalCommandLine()); collector.addFiles(generateGlobalHeaderAndSourcePaths(), generateGlobalCommandLine());
collector.addUnsavedFiles(m_generatedFiles);
collector.collectIncludes(); collector.collectIncludes();
return collector.takeIncludeIds(); return collector.takeIncludeIds();
@@ -357,10 +392,29 @@ Utils::SmallString PchCreator::generateProjectPartPchFilePathWithoutExtension(
return Utils::SmallString::fromQByteArray(fileName); 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) const V2::ProjectPartContainer &projectPart)
{ {
Utils::SmallStringVector includeAndSources; Utils::PathStringVector includeAndSources;
includeAndSources.reserve(projectPart.headerPaths().size() + projectPart.sourcePaths().size()); includeAndSources.reserve(projectPart.headerPaths().size() + projectPart.sourcePaths().size());
append(includeAndSources, projectPart.headerPaths()); append(includeAndSources, projectPart.headerPaths());
@@ -374,11 +428,13 @@ std::vector<uint> PchCreator::generateProjectPartPchIncludes(
{ {
IncludeCollector collector(m_filePathCache); IncludeCollector collector(m_filePathCache);
collector.setExcludedIncludes(projectPart.headerPaths().clone()); collector.setExcludedIncludes(generateProjectPartHeaders(projectPart));
collector.addFiles(generateProjectPartHeaderAndSourcePaths(projectPart), collector.addFiles(generateProjectPartHeaderAndSourcePaths(projectPart),
generateProjectPartCommandLine(projectPart)); generateProjectPartCommandLine(projectPart));
collector.addUnsavedFiles(m_generatedFiles);
collector.collectIncludes(); collector.collectIncludes();
return collector.takeIncludeIds(); return collector.takeIncludeIds();

View File

@@ -52,17 +52,19 @@ public:
PchCreator(V2::ProjectPartContainers &&projectsParts, PchCreator(V2::ProjectPartContainers &&projectsParts,
Environment &environment, Environment &environment,
StringCache<Utils::SmallString> &filePathCache, StringCache<Utils::SmallString> &filePathCache,
PchGeneratorInterface *pchGenerator); PchGeneratorInterface *pchGenerator,
V2::FileContainers &&generatedFiles);
void generatePchs(V2::ProjectPartContainers &&projectsParts) override; void generatePchs(V2::ProjectPartContainers &&projectsParts) override;
void setGeneratedFiles(V2::FileContainers &&generatedFiles) override;
std::vector<IdPaths> takeProjectsIncludes() override; std::vector<IdPaths> takeProjectsIncludes() override;
void setGenerator(PchGeneratorInterface *pchGenerator); void setGenerator(PchGeneratorInterface *pchGenerator);
unitttest_public: unitttest_public:
Utils::SmallStringVector generateGlobalHeaderPaths() const; Utils::PathStringVector generateGlobalHeaderPaths() const;
Utils::SmallStringVector generateGlobalSourcePaths() const; Utils::PathStringVector generateGlobalSourcePaths() const;
Utils::SmallStringVector generateGlobalHeaderAndSourcePaths() const; Utils::PathStringVector generateGlobalHeaderAndSourcePaths() const;
Utils::SmallStringVector generateGlobalArguments() const; Utils::SmallStringVector generateGlobalArguments() const;
Utils::SmallStringVector generateGlobalCommandLine() const; Utils::SmallStringVector generateGlobalCommandLine() const;
Utils::SmallStringVector generateGlobalPchCompilerArguments() const; Utils::SmallStringVector generateGlobalPchCompilerArguments() const;
@@ -89,7 +91,9 @@ unitttest_public:
const V2::ProjectPartContainer &projectPart) const; const V2::ProjectPartContainer &projectPart) const;
Utils::SmallString generateProjectPartPchFilePathWithoutExtension( Utils::SmallString generateProjectPartPchFilePathWithoutExtension(
const V2::ProjectPartContainer &projectPart) const; 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); const V2::ProjectPartContainer &projectPart);
std::vector<uint> generateProjectPartPchIncludes( std::vector<uint> generateProjectPartPchIncludes(
const V2::ProjectPartContainer &projectPart) const; const V2::ProjectPartContainer &projectPart) const;
@@ -115,6 +119,7 @@ private:
private: private:
V2::ProjectPartContainers m_projectParts; V2::ProjectPartContainers m_projectParts;
V2::FileContainers m_generatedFiles;
std::vector<ProjectPartPch> m_projectPartPchs; std::vector<ProjectPartPch> m_projectPartPchs;
std::vector<IdPaths> m_projectsIncludeIds; std::vector<IdPaths> m_projectsIncludeIds;
Environment &m_environment; Environment &m_environment;

View File

@@ -28,6 +28,7 @@
#include "idpaths.h" #include "idpaths.h"
#include "projectpartpch.h" #include "projectpartpch.h"
#include <filecontainerv2.h>
#include <projectpartcontainerv2.h> #include <projectpartcontainerv2.h>
namespace ClangBackEnd { namespace ClangBackEnd {
@@ -38,6 +39,7 @@ public:
virtual ~PchCreatorInterface(); virtual ~PchCreatorInterface();
virtual void generatePchs(V2::ProjectPartContainers &&projectsParts) = 0; virtual void generatePchs(V2::ProjectPartContainers &&projectsParts) = 0;
virtual void setGeneratedFiles(V2::FileContainers &&generatedFiles) = 0;
virtual std::vector<IdPaths> takeProjectsIncludes() = 0; virtual std::vector<IdPaths> takeProjectsIncludes() = 0;
}; };

View File

@@ -56,6 +56,8 @@ void PchManagerServer::end()
void PchManagerServer::updatePchProjectParts(UpdatePchProjectPartsMessage &&message) void PchManagerServer::updatePchProjectParts(UpdatePchProjectPartsMessage &&message)
{ {
m_pchCreator.setGeneratedFiles(message.takeGeneratedFiles());
m_pchCreator.generatePchs(m_projectParts.update(message.takeProjectsParts())); m_pchCreator.generatePchs(m_projectParts.update(message.takeProjectsParts()));
m_fileSystemWatcher.updateIdPaths(m_pchCreator.takeProjectsIncludes()); m_fileSystemWatcher.updateIdPaths(m_pchCreator.takeProjectsIncludes());

View File

@@ -58,10 +58,11 @@ void ClangTool::addFile(std::string &&directory,
sourceFilePaths.push_back(fileContent.filePath); sourceFilePaths.push_back(fileContent.filePath);
} }
void ClangTool::addFiles(const Utils::SmallStringVector &filePaths, template <typename Container>
void ClangTool::addFiles(const Container &filePaths,
const Utils::SmallStringVector &arguments) 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 found = std::find(filePath.rbegin(), filePath.rend(), '/');
auto fileNameBegin = found.base(); auto fileNameBegin = found.base();
@@ -76,6 +77,13 @@ void ClangTool::addFiles(const Utils::SmallStringVector &filePaths,
} }
} }
template
void ClangTool::addFiles<Utils::SmallStringVector>(const Utils::SmallStringVector &filePaths,
const Utils::SmallStringVector &arguments);
template
void ClangTool::addFiles<Utils::PathStringVector>(const Utils::PathStringVector &filePaths,
const Utils::SmallStringVector &arguments);
namespace { namespace {
Utils::SmallString toNativeFilePath(const FilePath &filePath) Utils::SmallString toNativeFilePath(const FilePath &filePath)
{ {
@@ -87,13 +95,13 @@ Utils::SmallString toNativeFilePath(const FilePath &filePath)
} }
} }
void ClangTool::addUnsavedFiles(std::vector<V2::FileContainer> &&unsavedFiles) void ClangTool::addUnsavedFiles(const V2::FileContainers &unsavedFiles)
{ {
unsavedFileContents.reserve(unsavedFileContents.size() + unsavedFiles.size()); unsavedFileContents.reserve(unsavedFileContents.size() + unsavedFiles.size());
auto convertToUnsavedFileContent = [] (V2::FileContainer &unsavedFile) { auto convertToUnsavedFileContent = [] (const V2::FileContainer &unsavedFile) {
return UnsavedFileContent{toNativeFilePath(unsavedFile.filePath()), return UnsavedFileContent{toNativeFilePath(unsavedFile.filePath()),
unsavedFile.takeUnsavedFileContent()}; unsavedFile.unsavedFileContent().clone()};
}; };
std::transform(unsavedFiles.begin(), std::transform(unsavedFiles.begin(),

View File

@@ -94,10 +94,12 @@ public:
std::string &&fileName, std::string &&fileName,
std::string &&content, std::string &&content,
std::vector<std::string> &&commandLine); std::vector<std::string> &&commandLine);
void addFiles(const Utils::SmallStringVector &filePaths,
template <typename Container>
void addFiles(const Container &filePaths,
const Utils::SmallStringVector &arguments); const Utils::SmallStringVector &arguments);
void addUnsavedFiles(std::vector<V2::FileContainer> &&unsavedFiles); void addUnsavedFiles(const V2::FileContainers &unsavedFiles);
clang::tooling::ClangTool createTool() const; clang::tooling::ClangTool createTool() const;

View File

@@ -2,3 +2,4 @@
#include "includecollector_header2.h" #include "includecollector_header2.h"
#include "includecollector_external1.h" #include "includecollector_external1.h"
#include "../data/includecollector_external2.h" #include "../data/includecollector_external2.h"
#include "includecollector_generated_file.h"

View File

@@ -86,8 +86,11 @@ void IncludeCollector::SetUp()
collector.addFile(TESTDATA_DIR, "includecollector_main.cpp", "", {"cc", "includecollector_main.cpp"}); collector.addFile(TESTDATA_DIR, "includecollector_main.cpp", "", {"cc", "includecollector_main.cpp"});
collector.addFile(TESTDATA_DIR, "includecollector_main2.cpp", "", {"cc", "includecollector_main2.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", 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) uint IncludeCollector::id(const Utils::SmallString &path)

View File

@@ -27,6 +27,7 @@
#include "googletest.h" #include "googletest.h"
#include <filecontainerv2.h>
#include <pchcreatorinterface.h> #include <pchcreatorinterface.h>
#include <projectpartpch.h> #include <projectpartpch.h>
#include <projectpartcontainerv2.h> #include <projectpartcontainerv2.h>
@@ -35,12 +36,19 @@ class MockPchCreator : public ClangBackEnd::PchCreatorInterface
{ {
public: public:
MOCK_METHOD1(generatePchs, MOCK_METHOD1(generatePchs,
void(const std::vector<ClangBackEnd::V2::ProjectPartContainer> &projectParts)); void(const ClangBackEnd::V2::ProjectPartContainers &projectParts));
MOCK_METHOD1(setGeneratedFiles,
void(const ClangBackEnd::V2::FileContainers &generatedFiles));
MOCK_METHOD0(takeProjectsIncludes, MOCK_METHOD0(takeProjectsIncludes,
std::vector<ClangBackEnd::IdPaths>()); std::vector<ClangBackEnd::IdPaths>());
void generatePchs(std::vector<ClangBackEnd::V2::ProjectPartContainer> &&projectParts) void generatePchs(std::vector<ClangBackEnd::V2::ProjectPartContainer> &&projectParts) override
{ {
generatePchs(projectParts); generatePchs(projectParts);
} }
void setGeneratedFiles(ClangBackEnd::V2::FileContainers &&generatedFiles) override
{
setGeneratedFiles(generatedFiles);
}
}; };

View File

@@ -40,6 +40,8 @@ namespace {
using ClangBackEnd::IdPaths; using ClangBackEnd::IdPaths;
using ClangBackEnd::ProjectPartPch; using ClangBackEnd::ProjectPartPch;
using ClangBackEnd::V2::ProjectPartContainer; using ClangBackEnd::V2::ProjectPartContainer;
using ClangBackEnd::V2::FileContainer;
using Utils::PathString;
using Utils::SmallString; using Utils::SmallString;
using testing::_; using testing::_;
@@ -60,10 +62,12 @@ protected:
protected: protected:
ClangBackEnd::StringCache<Utils::SmallString> filePathCache; ClangBackEnd::StringCache<Utils::SmallString> filePathCache;
SmallString main1Path = TESTDATA_DIR "/includecollector_main3.cpp"; PathString main1Path = TESTDATA_DIR "/includecollector_main3.cpp";
SmallString main2Path = TESTDATA_DIR "/includecollector_main2.cpp"; PathString main2Path = TESTDATA_DIR "/includecollector_main2.cpp";
SmallString header1Path = TESTDATA_DIR "/includecollector_header1.h"; PathString header1Path = TESTDATA_DIR "/includecollector_header1.h";
SmallString header2Path = TESTDATA_DIR "/includecollector_header2.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", ProjectPartContainer projectPart1{"project1",
{"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"}, {"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"},
{header1Path.clone()}, {header1Path.clone()},
@@ -73,12 +77,14 @@ protected:
{header2Path.clone()}, {header2Path.clone()},
{main2Path.clone()}}; {main2Path.clone()}};
TestEnvironment environment; TestEnvironment environment;
FileContainer generatedFile{{TESTDATA_DIR, generatedFileName.clone()}, "#pragma once", {}};
NiceMock<MockPchGeneratorNotifier> mockPchGeneratorNotifier; NiceMock<MockPchGeneratorNotifier> mockPchGeneratorNotifier;
ClangBackEnd::PchGenerator<FakeProcess> generator{environment, &mockPchGeneratorNotifier}; ClangBackEnd::PchGenerator<FakeProcess> generator{environment, &mockPchGeneratorNotifier};
ClangBackEnd::PchCreator creator{{projectPart1.clone(),projectPart2.clone()}, ClangBackEnd::PchCreator creator{{projectPart1.clone(),projectPart2.clone()},
environment, environment,
filePathCache, filePathCache,
&generator}; &generator,
{generatedFile}};
}; };
using PchCreatorSlowTest = PchCreator; using PchCreatorSlowTest = PchCreator;
@@ -89,7 +95,7 @@ TEST_F(PchCreator, CreateGlobalHeaderPaths)
auto filePaths = creator.generateGlobalHeaderPaths(); auto filePaths = creator.generateGlobalHeaderPaths();
ASSERT_THAT(filePaths, ASSERT_THAT(filePaths,
UnorderedElementsAre(header1Path, header2Path)); UnorderedElementsAre(header1Path, header2Path, generatedFilePath));
} }
TEST_F(PchCreator, CreateGlobalSourcePaths) TEST_F(PchCreator, CreateGlobalSourcePaths)
@@ -105,7 +111,7 @@ TEST_F(PchCreator, CreateGlobalHeaderAndSourcePaths)
auto filePaths = creator.generateGlobalHeaderAndSourcePaths(); auto filePaths = creator.generateGlobalHeaderAndSourcePaths();
ASSERT_THAT(filePaths, ASSERT_THAT(filePaths,
UnorderedElementsAre(main1Path, main2Path, header1Path, header2Path)); UnorderedElementsAre(main1Path, main2Path, header1Path, header2Path, generatedFilePath));
} }
TEST_F(PchCreator, CreateGlobalArguments) 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")); 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) TEST_F(PchCreator, CreateProjectPartHeaderAndSources)
{ {
auto includeIds = creator.generateProjectPartHeaderAndSourcePaths(projectPart1); auto includeIds = creator.generateProjectPartHeaderAndSourcePaths(projectPart1);

View File

@@ -42,6 +42,7 @@
#include <vector> #include <vector>
using ClangBackEnd::UpdatePchProjectPartsMessage; using ClangBackEnd::UpdatePchProjectPartsMessage;
using ClangBackEnd::V2::FileContainer;
using ClangBackEnd::V2::ProjectPartContainer; using ClangBackEnd::V2::ProjectPartContainer;
using ClangBackEnd::RemovePchProjectPartsMessage; using ClangBackEnd::RemovePchProjectPartsMessage;
using ClangBackEnd::PrecompiledHeadersUpdatedMessage; using ClangBackEnd::PrecompiledHeadersUpdatedMessage;
@@ -95,7 +96,8 @@ TEST_F(PchManagerClientServerInProcess, SendUpdatePchProjectPartsMessage)
{"-x", "c++-header", "-Wno-pragma-once-outside-header"}, {"-x", "c++-header", "-Wno-pragma-once-outside-header"},
{TESTDATA_DIR "/includecollector_header.h"}, {TESTDATA_DIR "/includecollector_header.h"},
{TESTDATA_DIR "/includecollector_main.cpp"}}; {TESTDATA_DIR "/includecollector_main.cpp"}};
UpdatePchProjectPartsMessage message{{projectPart2}}; FileContainer fileContainer{{"/path/to/", "file"}, "content", {}};
UpdatePchProjectPartsMessage message{{projectPart2}, {fileContainer}};
EXPECT_CALL(mockPchManagerServer, updatePchProjectParts(message)); EXPECT_CALL(mockPchManagerServer, updatePchProjectParts(message));

View File

@@ -45,7 +45,9 @@ using testing::Return;
using testing::_; using testing::_;
using testing::IsEmpty; using testing::IsEmpty;
using Utils::PathString;
using Utils::SmallString; using Utils::SmallString;
using ClangBackEnd::V2::FileContainer;
using ClangBackEnd::V2::ProjectPartContainer; using ClangBackEnd::V2::ProjectPartContainer;
using ClangBackEnd::TaskFinishStatus; using ClangBackEnd::TaskFinishStatus;
@@ -62,10 +64,10 @@ protected:
NiceMock<MockPchManagerClient> mockPchManagerClient; NiceMock<MockPchManagerClient> mockPchManagerClient;
SmallString projectPartId1 = "project1"; SmallString projectPartId1 = "project1";
SmallString projectPartId2 = "project2"; SmallString projectPartId2 = "project2";
SmallString main1Path = TESTDATA_DIR "/includecollector_main3.cpp"; PathString main1Path = TESTDATA_DIR "/includecollector_main3.cpp";
SmallString main2Path = TESTDATA_DIR "/includecollector_main2.cpp"; PathString main2Path = TESTDATA_DIR "/includecollector_main2.cpp";
SmallString header1Path = TESTDATA_DIR "/includecollector_header1.h"; PathString header1Path = TESTDATA_DIR "/includecollector_header1.h";
SmallString header2Path = TESTDATA_DIR "/includecollector_header2.h"; PathString header2Path = TESTDATA_DIR "/includecollector_header2.h";
std::vector<ClangBackEnd::IdPaths> idPaths = {{projectPartId1, {1, 2}}}; std::vector<ClangBackEnd::IdPaths> idPaths = {{projectPartId1, {1, 2}}};
ProjectPartContainer projectPart1{projectPartId1.clone(), ProjectPartContainer projectPart1{projectPartId1.clone(),
{"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"}, {"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"},
@@ -75,8 +77,10 @@ protected:
{"-x", "c++-header", "-Wno-pragma-once-outside-header"}, {"-x", "c++-header", "-Wno-pragma-once-outside-header"},
{header2Path.clone()}, {header2Path.clone()},
{main2Path.clone()}}; {main2Path.clone()}};
std::vector<ClangBackEnd::V2::ProjectPartContainer> projectParts{projectPart1, projectPart2}; std::vector<ProjectPartContainer> projectParts{projectPart1, projectPart2};
ClangBackEnd::UpdatePchProjectPartsMessage updatePchProjectPartsMessage{Utils::clone(projectParts)}; FileContainer generatedFile{{"/path/to/", "file"}, "content", {}};
ClangBackEnd::UpdatePchProjectPartsMessage updatePchProjectPartsMessage{Utils::clone(projectParts),
{generatedFile}};
ClangBackEnd::ProjectPartPch projectPartPch1{projectPart1.projectPartId().clone(), "/path1/to/pch"}; ClangBackEnd::ProjectPartPch projectPartPch1{projectPart1.projectPartId().clone(), "/path1/to/pch"};
ClangBackEnd::ProjectPartPch projectPartPch2{projectPart2.projectPartId().clone(), "/path2/to/pch"}; ClangBackEnd::ProjectPartPch projectPartPch2{projectPart2.projectPartId().clone(), "/path2/to/pch"};
std::vector<ClangBackEnd::ProjectPartPch> projectPartPchs{projectPartPch1, projectPartPch2}; std::vector<ClangBackEnd::ProjectPartPch> projectPartPchs{projectPartPch1, projectPartPch2};
@@ -103,7 +107,10 @@ TEST_F(PchManagerServer, DoNotCallPrecompiledHeadersForUnsuccessfullyFinishedTas
TEST_F(PchManagerServer, CallBuildInPchCreator) 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()); server.updatePchProjectParts(updatePchProjectPartsMessage.clone());
} }

View File

@@ -42,10 +42,12 @@
namespace { namespace {
using testing::_; using testing::_;
using testing::ElementsAre;
using testing::SizeIs; using testing::SizeIs;
using testing::NiceMock; using testing::NiceMock;
using testing::AnyNumber; using testing::AnyNumber;
using ClangBackEnd::V2::FileContainer;
using ClangBackEnd::V2::ProjectPartContainer; using ClangBackEnd::V2::ProjectPartContainer;
using CppTools::ClangCompilerOptionsBuilder; using CppTools::ClangCompilerOptionsBuilder;
@@ -61,24 +63,26 @@ protected:
ClangPchManager::ProjectUpdater updater{mockPchManagerServer, pchManagerClient}; ClangPchManager::ProjectUpdater updater{mockPchManagerServer, pchManagerClient};
Utils::SmallString projectPartId{"project1"}; Utils::SmallString projectPartId{"project1"};
Utils::SmallString projectPartId2{"project2"}; Utils::SmallString projectPartId2{"project2"};
Utils::SmallStringVector headerPaths = {"/path/to/header1.h", "/path/to/header2.h"}; Utils::PathStringVector headerPaths = {"/path/to/header1.h", "/path/to/header2.h"};
Utils::SmallStringVector sourcePaths = {"/path/to/source1.h", "/path/to/source2.h"}; Utils::PathStringVector sourcePaths = {"/path/to/source1.cpp", "/path/to/source2.cpp"};
CppTools::ProjectFile header1ProjectFile{headerPaths[0], CppTools::ProjectFile::CXXHeader}; CppTools::ProjectFile header1ProjectFile{headerPaths[0], CppTools::ProjectFile::CXXHeader};
CppTools::ProjectFile header2ProjectFile{headerPaths[1], CppTools::ProjectFile::CXXHeader}; CppTools::ProjectFile header2ProjectFile{headerPaths[1], CppTools::ProjectFile::CXXHeader};
CppTools::ProjectFile source1ProjectFile{sourcePaths[0], CppTools::ProjectFile::CXXSource}; CppTools::ProjectFile source1ProjectFile{sourcePaths[0], CppTools::ProjectFile::CXXSource};
CppTools::ProjectFile source2ProjectFile{sourcePaths[1], CppTools::ProjectFile::CXXSource}; CppTools::ProjectFile source2ProjectFile{sourcePaths[1], CppTools::ProjectFile::CXXSource};
CppTools::ProjectPart projectPart; CppTools::ProjectPart projectPart;
ProjectPartContainer expectedContainer; ProjectPartContainer expectedContainer;
FileContainer generatedFile{{"/path/to", "header1.h"}, "content", {}};
}; };
TEST_F(ProjectUpdater, CallUpdatePchProjectParts) TEST_F(ProjectUpdater, CallUpdatePchProjectParts)
{ {
std::vector<CppTools::ProjectPart*> projectParts = {&projectPart, &projectPart}; std::vector<CppTools::ProjectPart*> projectParts = {&projectPart, &projectPart};
ClangBackEnd::UpdatePchProjectPartsMessage message{{expectedContainer.clone(), expectedContainer.clone()}}; ClangBackEnd::UpdatePchProjectPartsMessage message{{expectedContainer.clone(), expectedContainer.clone()},
{generatedFile}};
EXPECT_CALL(mockPchManagerServer, updatePchProjectParts(message)); EXPECT_CALL(mockPchManagerServer, updatePchProjectParts(message));
updater.updateProjectParts(projectParts); updater.updateProjectParts(projectParts, {generatedFile});
} }
TEST_F(ProjectUpdater, CallRemovePchProjectParts) TEST_F(ProjectUpdater, CallRemovePchProjectParts)
@@ -103,6 +107,8 @@ TEST_F(ProjectUpdater, CallPrecompiledHeaderRemoved)
TEST_F(ProjectUpdater, ConvertProjectPartToProjectPartContainer) TEST_F(ProjectUpdater, ConvertProjectPartToProjectPartContainer)
{ {
updater.setExcludedPaths({"/path/to/header1.h"});
auto container = updater.toProjectPartContainer(&projectPart); auto container = updater.toProjectPartContainer(&projectPart);
ASSERT_THAT(container, expectedContainer); ASSERT_THAT(container, expectedContainer);
@@ -115,6 +121,13 @@ TEST_F(ProjectUpdater, ConvertProjectPartToProjectPartContainersHaveSameSizeLike
ASSERT_THAT(containers, SizeIs(2)); 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() void ProjectUpdater::SetUp()
{ {
projectPart.files.push_back(header1ProjectFile); projectPart.files.push_back(header1ProjectFile);
@@ -133,8 +146,8 @@ void ProjectUpdater::SetUp()
expectedContainer = {projectPartId.clone(), expectedContainer = {projectPartId.clone(),
arguments.clone(), arguments.clone(),
headerPaths.clone(), {headerPaths[1]},
sourcePaths.clone()}; sourcePaths.clone()};
} }
} }