forked from qt-creator/qt-creator
Clang: Fix compile commands generation for large projects
...such as Qt Creator. Avoid storing the entire JSON in-memory. Instead, write as you go. Change-Id: Ie298af546b25d80813a75d8dc09f3244488b8658 Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
committed by
Orgad Shaneh
parent
63eae7932f
commit
57af3f1f3d
@@ -347,7 +347,8 @@ void generateCompilationDB(::Utils::FileName projectDir, CppTools::ProjectInfo p
|
||||
{
|
||||
QFile compileCommandsFile(projectDir.toString() + "/compile_commands.json");
|
||||
|
||||
QJsonArray array;
|
||||
compileCommandsFile.open(QIODevice::WriteOnly | QIODevice::Truncate);
|
||||
compileCommandsFile.write("[");
|
||||
for (ProjectPart::Ptr projectPart : projectInfo.projectParts()) {
|
||||
const ::Utils::FileName buildDir = buildDirectory(*projectPart);
|
||||
|
||||
@@ -357,12 +358,15 @@ void generateCompilationDB(::Utils::FileName projectDir, CppTools::ProjectInfo p
|
||||
optionsBuilder.build(CppTools::ProjectFile::Unclassified,
|
||||
CppTools::CompilerOptionsBuilder::PchUsage::None);
|
||||
|
||||
for (const ProjectFile &projFile : projectPart->files)
|
||||
array.push_back(createFileObject(optionsBuilder, projFile, buildDir));
|
||||
for (const ProjectFile &projFile : projectPart->files) {
|
||||
const QJsonObject json = createFileObject(optionsBuilder, projFile, buildDir);
|
||||
if (compileCommandsFile.size() > 1)
|
||||
compileCommandsFile.write(",");
|
||||
compileCommandsFile.write('\n' + QJsonDocument(json).toJson().trimmed());
|
||||
}
|
||||
}
|
||||
|
||||
compileCommandsFile.open(QIODevice::WriteOnly | QIODevice::Truncate);
|
||||
compileCommandsFile.write(QJsonDocument(array).toJson());
|
||||
compileCommandsFile.write("\n]");
|
||||
compileCommandsFile.close();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user