forked from qt-creator/qt-creator
Clang: Filter generated files
Generated files are not available, so clang will stop with an fatal error. Change-Id: I80754015a1daf48cbf2ce8e06526c75b05b2901c Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -102,8 +102,8 @@ public:
|
|||||||
|
|
||||||
friend bool operator==(const FilePath &first, const FilePath &second)
|
friend bool operator==(const FilePath &first, const FilePath &second)
|
||||||
{
|
{
|
||||||
return first.directory_ == second.directory_
|
return first.name_ == second.name_
|
||||||
&& first.name_ == second.name_;
|
&& first.directory_ == second.directory_;
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePath clone() const
|
FilePath clone() const
|
||||||
|
@@ -123,19 +123,43 @@ Utils::SmallStringVector createCommandLine(CppTools::ProjectPart *projectPart,
|
|||||||
return commandLine;
|
return commandLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<ClangBackEnd::V2::FileContainer>
|
bool unsavedContentContains(const ClangBackEnd::FilePath &sourceFilePath,
|
||||||
createSources(const std::vector<CppTools::ProjectPart::Ptr> &projectParts)
|
const std::vector<ClangBackEnd::V2::FileContainer> &unsavedContent)
|
||||||
{
|
{
|
||||||
std::vector<ClangBackEnd::V2::FileContainer> sources;
|
auto compare = [&] (const ClangBackEnd::V2::FileContainer &unsavedEntry) {
|
||||||
|
return unsavedEntry.filePath() == sourceFilePath;
|
||||||
|
};
|
||||||
|
|
||||||
for (const CppTools::ProjectPart::Ptr &projectPart : projectParts) {
|
auto found = std::find_if(unsavedContent.begin(), unsavedContent.end(), compare);
|
||||||
for (const CppTools::ProjectFile &projectFile : projectPart->files) {
|
|
||||||
|
return found != unsavedContent.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
void appendSource(std::vector<ClangBackEnd::V2::FileContainer> &sources,
|
||||||
|
const CppTools::ProjectPart::Ptr &projectPart,
|
||||||
|
const CppTools::ProjectFile &projectFile,
|
||||||
|
const std::vector<ClangBackEnd::V2::FileContainer> &unsavedContent)
|
||||||
|
{
|
||||||
|
ClangBackEnd::FilePath sourceFilePath(projectFile.path);
|
||||||
|
|
||||||
|
if (!unsavedContentContains(sourceFilePath, unsavedContent)) {
|
||||||
sources.emplace_back(ClangBackEnd::FilePath(projectFile.path),
|
sources.emplace_back(ClangBackEnd::FilePath(projectFile.path),
|
||||||
"",
|
"",
|
||||||
createCommandLine(projectPart.data(),
|
createCommandLine(projectPart.data(),
|
||||||
projectFile.path,
|
projectFile.path,
|
||||||
projectFile.kind));
|
projectFile.kind));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<ClangBackEnd::V2::FileContainer>
|
||||||
|
createSources(const std::vector<CppTools::ProjectPart::Ptr> &projectParts,
|
||||||
|
const std::vector<ClangBackEnd::V2::FileContainer> &unsavedContent)
|
||||||
|
{
|
||||||
|
std::vector<ClangBackEnd::V2::FileContainer> sources;
|
||||||
|
|
||||||
|
for (const CppTools::ProjectPart::Ptr &projectPart : projectParts) {
|
||||||
|
for (const CppTools::ProjectFile &projectFile : projectPart->files)
|
||||||
|
appendSource(sources, projectPart, projectFile, unsavedContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
return sources;
|
return sources;
|
||||||
@@ -147,7 +171,7 @@ ClangBackEnd::RequestSourceRangesAndDiagnosticsForQueryMessage ClangQueryProject
|
|||||||
{
|
{
|
||||||
return ClangBackEnd::RequestSourceRangesAndDiagnosticsForQueryMessage(
|
return ClangBackEnd::RequestSourceRangesAndDiagnosticsForQueryMessage(
|
||||||
Utils::SmallString(queryText),
|
Utils::SmallString(queryText),
|
||||||
createSources(projectParts),
|
createSources(projectParts, unsavedContent),
|
||||||
Utils::clone(unsavedContent));
|
Utils::clone(unsavedContent));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -166,6 +166,7 @@ std::vector<CppTools::ProjectPart::Ptr> createProjectParts()
|
|||||||
|
|
||||||
auto projectPart2 = CppTools::ProjectPart::Ptr(new CppTools::ProjectPart);
|
auto projectPart2 = CppTools::ProjectPart::Ptr(new CppTools::ProjectPart);
|
||||||
projectPart1->files.append({"/path/to/file2.cpp", CppTools::ProjectFile::CXXHeader});
|
projectPart1->files.append({"/path/to/file2.cpp", CppTools::ProjectFile::CXXHeader});
|
||||||
|
projectPart1->files.append({"/path/to/unsaved.cpp", CppTools::ProjectFile::CXXSource});
|
||||||
|
|
||||||
return {projectPart1, projectPart2};
|
return {projectPart1, projectPart2};
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user