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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user