forked from qt-creator/qt-creator
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:
@@ -28,6 +28,8 @@
|
||||
#include "clangbackendipc_global.h"
|
||||
#include "filepath.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
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<FileContainer>;
|
||||
|
||||
CMBIPC_EXPORT QDebug operator<<(QDebug debug, const FileContainer &container);
|
||||
void PrintTo(const FileContainer &container, ::std::ostream* os);
|
||||
|
||||
|
||||
} // namespace V2
|
||||
} // namespace ClangBackEnd
|
||||
|
@@ -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());
|
||||
|
@@ -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<ProjectPartContainer>;
|
||||
|
@@ -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);
|
||||
|
@@ -34,8 +34,24 @@
|
||||
#include <cpptools/clangcompileroptionsbuilder.h>
|
||||
#include <cpptools/projectpart.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
|
||||
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<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));
|
||||
}
|
||||
@@ -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<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;
|
||||
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
|
||||
|
@@ -27,8 +27,11 @@
|
||||
|
||||
#include <clangpchmanager_global.h>
|
||||
|
||||
#include <filecontainerv2.h>
|
||||
|
||||
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<CppTools::ProjectPart *> &projectParts);
|
||||
void updateProjectParts(const std::vector<CppTools::ProjectPart *> &projectParts,
|
||||
ClangBackEnd::V2::FileContainers &&generatedFiles);
|
||||
void removeProjectParts(const QStringList &projectPartIds);
|
||||
|
||||
unittest_public:
|
||||
static ClangBackEnd::V2::ProjectPartContainer toProjectPartContainer(
|
||||
CppTools::ProjectPart *projectPart);
|
||||
static std::vector<ClangBackEnd::V2::ProjectPartContainer> toProjectPartContainers(
|
||||
std::vector<CppTools::ProjectPart *> projectParts);
|
||||
void setExcludedPaths(Utils::PathStringVector &&excludedPaths);
|
||||
|
||||
HeaderAndSources headerAndSourcesFromProjectPart(CppTools::ProjectPart *projectPart) const;
|
||||
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:
|
||||
Utils::PathStringVector m_excludedPaths;
|
||||
ClangBackEnd::PchManagerServerInterface &m_server;
|
||||
PchManagerClient &m_client;
|
||||
};
|
||||
|
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "qtcreatorprojectupdater.h"
|
||||
|
||||
#include <cpptools/abstracteditorsupport.h>
|
||||
#include <cpptools/cppmodelmanager.h>
|
||||
|
||||
#include <projectexplorer/project.h>
|
||||
@@ -43,7 +44,29 @@ QtCreatorProjectUpdater::QtCreatorProjectUpdater(ClangBackEnd::PchManagerServerI
|
||||
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);
|
||||
|
||||
@@ -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)
|
||||
|
@@ -38,12 +38,26 @@ class CollectIncludesToolAction final : public clang::tooling::FrontendActionFac
|
||||
public:
|
||||
CollectIncludesToolAction(std::vector<uint> &includeIds,
|
||||
StringCache<Utils::SmallString> &filePathCache,
|
||||
const std::vector<uint> &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<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()
|
||||
{
|
||||
return new CollectIncludesAction(m_includeIds,
|
||||
@@ -52,11 +66,29 @@ public:
|
||||
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:
|
||||
std::vector<uint> m_alreadyIncludedFileUIDs;
|
||||
std::vector<uint> m_excludedIncludeUIDs;
|
||||
std::vector<uint> &m_includeIds;
|
||||
StringCache<Utils::SmallString> &m_filePathCache;
|
||||
const std::vector<uint> &m_excludedIncludeUIDs;
|
||||
const Utils::PathStringVector &m_excludedIncludes;
|
||||
};
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
|
@@ -29,6 +29,8 @@
|
||||
|
||||
#include <utils/smallstring.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
IncludeCollector::IncludeCollector(StringCache<Utils::SmallString> &filePathCache)
|
||||
@@ -40,17 +42,31 @@ void IncludeCollector::collectIncludes()
|
||||
{
|
||||
clang::tooling::ClangTool tool = createTool();
|
||||
|
||||
auto excludedIncludeFileUIDs = generateExcludedIncludeFileUIDs(tool.getFiles());
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
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()
|
||||
@@ -60,21 +76,6 @@ std::vector<uint> IncludeCollector::takeIncludeIds()
|
||||
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
|
||||
|
@@ -38,15 +38,12 @@ public:
|
||||
|
||||
void collectIncludes();
|
||||
|
||||
void setExcludedIncludes(Utils::SmallStringVector &&excludedIncludes);
|
||||
void setExcludedIncludes(Utils::PathStringVector &&excludedIncludes);
|
||||
|
||||
std::vector<uint> takeIncludeIds();
|
||||
|
||||
private:
|
||||
std::vector<uint> generateExcludedIncludeFileUIDs(clang::FileManager &fileManager) const;
|
||||
|
||||
private:
|
||||
Utils::SmallStringVector m_excludedIncludes;
|
||||
Utils::PathStringVector m_excludedIncludes;
|
||||
std::vector<uint> m_includeIds;
|
||||
Utils::SmallStringVector m_directories;
|
||||
StringCache<Utils::SmallString> &m_filePathCache;
|
||||
|
@@ -45,14 +45,21 @@ PchCreator::PchCreator(Environment &environment, StringCache<Utils::SmallString>
|
||||
PchCreator::PchCreator(V2::ProjectPartContainers &&projectsParts,
|
||||
Environment &environment,
|
||||
StringCache<Utils::SmallString> &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 <typename Source,
|
||||
typename Target>
|
||||
@@ -92,12 +99,13 @@ std::size_t globalCount(const V2::ProjectPartContainers &projectsParts,
|
||||
sizeFunction);
|
||||
}
|
||||
|
||||
template <typename GetterFunction>
|
||||
void generateGlobal(Utils::SmallStringVector &entries,
|
||||
template <typename Container,
|
||||
typename GetterFunction>
|
||||
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 <typename GetterFunction>
|
||||
Utils::SmallStringVector generateGlobal(
|
||||
template <typename Container,
|
||||
typename GetterFunction>
|
||||
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<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)
|
||||
-> const Utils::SmallStringVector & {
|
||||
-> const Utils::PathStringVector & {
|
||||
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();
|
||||
auto includePaths = generateGlobalHeaderPaths();
|
||||
@@ -213,6 +246,8 @@ std::vector<uint> 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<uint> 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();
|
||||
|
@@ -52,17 +52,19 @@ public:
|
||||
PchCreator(V2::ProjectPartContainers &&projectsParts,
|
||||
Environment &environment,
|
||||
StringCache<Utils::SmallString> &filePathCache,
|
||||
PchGeneratorInterface *pchGenerator);
|
||||
PchGeneratorInterface *pchGenerator,
|
||||
V2::FileContainers &&generatedFiles);
|
||||
|
||||
void generatePchs(V2::ProjectPartContainers &&projectsParts) override;
|
||||
void setGeneratedFiles(V2::FileContainers &&generatedFiles) override;
|
||||
std::vector<IdPaths> 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<uint> generateProjectPartPchIncludes(
|
||||
const V2::ProjectPartContainer &projectPart) const;
|
||||
@@ -115,6 +119,7 @@ private:
|
||||
|
||||
private:
|
||||
V2::ProjectPartContainers m_projectParts;
|
||||
V2::FileContainers m_generatedFiles;
|
||||
std::vector<ProjectPartPch> m_projectPartPchs;
|
||||
std::vector<IdPaths> m_projectsIncludeIds;
|
||||
Environment &m_environment;
|
||||
|
@@ -28,6 +28,7 @@
|
||||
#include "idpaths.h"
|
||||
#include "projectpartpch.h"
|
||||
|
||||
#include <filecontainerv2.h>
|
||||
#include <projectpartcontainerv2.h>
|
||||
|
||||
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<IdPaths> takeProjectsIncludes() = 0;
|
||||
};
|
||||
|
||||
|
@@ -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());
|
||||
|
@@ -58,10 +58,11 @@ void ClangTool::addFile(std::string &&directory,
|
||||
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)
|
||||
{
|
||||
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<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 {
|
||||
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());
|
||||
|
||||
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(),
|
||||
|
@@ -94,10 +94,12 @@ public:
|
||||
std::string &&fileName,
|
||||
std::string &&content,
|
||||
std::vector<std::string> &&commandLine);
|
||||
void addFiles(const Utils::SmallStringVector &filePaths,
|
||||
|
||||
template <typename Container>
|
||||
void addFiles(const Container &filePaths,
|
||||
const Utils::SmallStringVector &arguments);
|
||||
|
||||
void addUnsavedFiles(std::vector<V2::FileContainer> &&unsavedFiles);
|
||||
void addUnsavedFiles(const V2::FileContainers &unsavedFiles);
|
||||
|
||||
clang::tooling::ClangTool createTool() const;
|
||||
|
||||
|
@@ -2,3 +2,4 @@
|
||||
#include "includecollector_header2.h"
|
||||
#include "includecollector_external1.h"
|
||||
#include "../data/includecollector_external2.h"
|
||||
#include "includecollector_generated_file.h"
|
||||
|
@@ -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)
|
||||
|
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "googletest.h"
|
||||
|
||||
#include <filecontainerv2.h>
|
||||
#include <pchcreatorinterface.h>
|
||||
#include <projectpartpch.h>
|
||||
#include <projectpartcontainerv2.h>
|
||||
@@ -35,12 +36,19 @@ class MockPchCreator : public ClangBackEnd::PchCreatorInterface
|
||||
{
|
||||
public:
|
||||
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,
|
||||
std::vector<ClangBackEnd::IdPaths>());
|
||||
|
||||
void generatePchs(std::vector<ClangBackEnd::V2::ProjectPartContainer> &&projectParts)
|
||||
void generatePchs(std::vector<ClangBackEnd::V2::ProjectPartContainer> &&projectParts) override
|
||||
{
|
||||
generatePchs(projectParts);
|
||||
}
|
||||
|
||||
void setGeneratedFiles(ClangBackEnd::V2::FileContainers &&generatedFiles) override
|
||||
{
|
||||
setGeneratedFiles(generatedFiles);
|
||||
}
|
||||
};
|
||||
|
@@ -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<Utils::SmallString> 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> mockPchGeneratorNotifier;
|
||||
ClangBackEnd::PchGenerator<FakeProcess> 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);
|
||||
|
@@ -42,6 +42,7 @@
|
||||
#include <vector>
|
||||
|
||||
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));
|
||||
|
||||
|
@@ -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> 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<ClangBackEnd::IdPaths> 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<ClangBackEnd::V2::ProjectPartContainer> projectParts{projectPart1, projectPart2};
|
||||
ClangBackEnd::UpdatePchProjectPartsMessage updatePchProjectPartsMessage{Utils::clone(projectParts)};
|
||||
std::vector<ProjectPartContainer> 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<ClangBackEnd::ProjectPartPch> 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());
|
||||
}
|
||||
|
@@ -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<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));
|
||||
|
||||
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,7 +146,7 @@ void ProjectUpdater::SetUp()
|
||||
|
||||
expectedContainer = {projectPartId.clone(),
|
||||
arguments.clone(),
|
||||
headerPaths.clone(),
|
||||
{headerPaths[1]},
|
||||
sourcePaths.clone()};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user