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:
Marco Bubke
2016-12-05 17:39:44 +01:00
parent e8960b9bd3
commit 3070a28422
3 changed files with 36 additions and 11 deletions

View File

@@ -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

View File

@@ -123,19 +123,43 @@ Utils::SmallStringVector createCommandLine(CppTools::ProjectPart *projectPart,
return commandLine; return commandLine;
} }
bool unsavedContentContains(const ClangBackEnd::FilePath &sourceFilePath,
const std::vector<ClangBackEnd::V2::FileContainer> &unsavedContent)
{
auto compare = [&] (const ClangBackEnd::V2::FileContainer &unsavedEntry) {
return unsavedEntry.filePath() == sourceFilePath;
};
auto found = std::find_if(unsavedContent.begin(), unsavedContent.end(), compare);
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),
"",
createCommandLine(projectPart.data(),
projectFile.path,
projectFile.kind));
}
}
std::vector<ClangBackEnd::V2::FileContainer> std::vector<ClangBackEnd::V2::FileContainer>
createSources(const std::vector<CppTools::ProjectPart::Ptr> &projectParts) createSources(const std::vector<CppTools::ProjectPart::Ptr> &projectParts,
const std::vector<ClangBackEnd::V2::FileContainer> &unsavedContent)
{ {
std::vector<ClangBackEnd::V2::FileContainer> sources; std::vector<ClangBackEnd::V2::FileContainer> sources;
for (const CppTools::ProjectPart::Ptr &projectPart : projectParts) { for (const CppTools::ProjectPart::Ptr &projectPart : projectParts) {
for (const CppTools::ProjectFile &projectFile : projectPart->files) { for (const CppTools::ProjectFile &projectFile : projectPart->files)
sources.emplace_back(ClangBackEnd::FilePath(projectFile.path), appendSource(sources, projectPart, projectFile, unsavedContent);
"",
createCommandLine(projectPart.data(),
projectFile.path,
projectFile.kind));
}
} }
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));
} }

View File

@@ -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};
} }