forked from qt-creator/qt-creator
Clang: Save compilation database to the build directory
For example CMake puts compile_commands.json into the build directory and it makes sense because it uses some target-specific command line options. Change-Id: I92a5b391f35e3f75bbcf41b8efff448f197895bb Reviewed-by: Marco Bubke <marco.bubke@qt.io> Reviewed-by: Alessandro Portale <alessandro.portale@qt.io> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -68,13 +68,12 @@ void ClangCodeModelPlugin::generateCompilationDB() {
|
|||||||
using namespace CppTools;
|
using namespace CppTools;
|
||||||
|
|
||||||
ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject();
|
ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject();
|
||||||
if (!project)
|
if (!project || !project->activeTarget())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_generatorWatcher.setFuture(QtConcurrent::run(
|
m_generatorWatcher.setFuture(
|
||||||
&Utils::generateCompilationDB,
|
QtConcurrent::run(&Utils::generateCompilationDB,
|
||||||
project->projectDirectory(),
|
CppModelManager::instance()->projectInfo(project)));
|
||||||
CppModelManager::instance()->projectInfo(project)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isDBGenerationEnabled(ProjectExplorer::Project *project)
|
static bool isDBGenerationEnabled(ProjectExplorer::Project *project)
|
||||||
|
@@ -313,9 +313,9 @@ static ::Utils::FileName compilerPath(const CppTools::ProjectPart &projectPart)
|
|||||||
return toolchain->compilerCommand();
|
return toolchain->compilerCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
static ::Utils::FileName buildDirectory(const CppTools::ProjectPart &projectPart)
|
static ::Utils::FileName buildDirectory(const ProjectExplorer::Project &project)
|
||||||
{
|
{
|
||||||
ProjectExplorer::Target *target = projectPart.project->activeTarget();
|
ProjectExplorer::Target *target = project.activeTarget();
|
||||||
if (!target)
|
if (!target)
|
||||||
return ::Utils::FileName();
|
return ::Utils::FileName();
|
||||||
|
|
||||||
@@ -386,17 +386,21 @@ static QJsonObject createFileObject(const ::Utils::FileName &buildDir,
|
|||||||
return fileObject;
|
return fileObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
void generateCompilationDB(::Utils::FileName projectDir, CppTools::ProjectInfo projectInfo)
|
void generateCompilationDB(CppTools::ProjectInfo projectInfo)
|
||||||
{
|
{
|
||||||
QFile compileCommandsFile(projectDir.toString() + "/compile_commands.json");
|
const ::Utils::FileName buildDir = buildDirectory(*projectInfo.project());
|
||||||
|
QTC_ASSERT(!buildDir.isEmpty(), return;);
|
||||||
|
|
||||||
|
QDir dir(buildDir.toString());
|
||||||
|
if (!dir.exists())
|
||||||
|
dir.mkpath(dir.path());
|
||||||
|
QFile compileCommandsFile(buildDir.toString() + "/compile_commands.json");
|
||||||
const bool fileOpened = compileCommandsFile.open(QIODevice::WriteOnly | QIODevice::Truncate);
|
const bool fileOpened = compileCommandsFile.open(QIODevice::WriteOnly | QIODevice::Truncate);
|
||||||
if (!fileOpened)
|
if (!fileOpened)
|
||||||
return;
|
return;
|
||||||
compileCommandsFile.write("[");
|
compileCommandsFile.write("[");
|
||||||
|
|
||||||
for (ProjectPart::Ptr projectPart : projectInfo.projectParts()) {
|
for (ProjectPart::Ptr projectPart : projectInfo.projectParts()) {
|
||||||
const ::Utils::FileName buildDir = buildDirectory(*projectPart);
|
|
||||||
const QStringList args = projectPartArguments(*projectPart);
|
const QStringList args = projectPartArguments(*projectPart);
|
||||||
for (const ProjectFile &projFile : projectPart->files) {
|
for (const ProjectFile &projFile : projectPart->files) {
|
||||||
const QJsonObject json = createFileObject(buildDir, args, *projectPart, projFile);
|
const QJsonObject json = createFileObject(buildDir, args, *projectPart, projFile);
|
||||||
|
@@ -70,7 +70,7 @@ QString diagnosticCategoryPrefixRemoved(const QString &text);
|
|||||||
|
|
||||||
::Utils::CodeModelIcon::Type iconTypeForToken(const ClangBackEnd::TokenInfoContainer &token);
|
::Utils::CodeModelIcon::Type iconTypeForToken(const ClangBackEnd::TokenInfoContainer &token);
|
||||||
|
|
||||||
void generateCompilationDB(::Utils::FileName projectDir, CppTools::ProjectInfo projectInfo);
|
void generateCompilationDB(CppTools::ProjectInfo projectInfo);
|
||||||
|
|
||||||
class DiagnosticTextInfo
|
class DiagnosticTextInfo
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user