forked from qt-creator/qt-creator
Compilation database: Add information to message pane
We must tell users where we generated the file, and also inform them about errors. Change-Id: I6383655e2f731f41b9121b2a6a31bba551d1c1de Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -36,6 +36,7 @@
|
|||||||
|
|
||||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||||
#include <coreplugin/actionmanager/actionmanager.h>
|
#include <coreplugin/actionmanager/actionmanager.h>
|
||||||
|
#include <coreplugin/messagemanager.h>
|
||||||
#include <coreplugin/progressmanager/progressmanager.h>
|
#include <coreplugin/progressmanager/progressmanager.h>
|
||||||
|
|
||||||
#include <cpptools/cppmodelmanager.h>
|
#include <cpptools/cppmodelmanager.h>
|
||||||
@@ -72,8 +73,9 @@ void ClangCodeModelPlugin::generateCompilationDB() {
|
|||||||
if (!project || !project->activeTarget())
|
if (!project || !project->activeTarget())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QFuture<void> task = QtConcurrent::run(&Utils::generateCompilationDB,
|
QFuture<Utils::GenerateCompilationDbResult> task
|
||||||
CppModelManager::instance()->projectInfo(project));
|
= QtConcurrent::run(&Utils::generateCompilationDB,
|
||||||
|
CppModelManager::instance()->projectInfo(project));
|
||||||
Core::ProgressManager::addTask(task, tr("Generating Compilation DB"), "generate compilation db");
|
Core::ProgressManager::addTask(task, tr("Generating Compilation DB"), "generate compilation db");
|
||||||
m_generatorWatcher.setFuture(task);
|
m_generatorWatcher.setFuture(task);
|
||||||
}
|
}
|
||||||
@@ -135,7 +137,17 @@ void ClangCodeModelPlugin::createCompilationDBButton()
|
|||||||
command->setDescription(m_generateCompilationDBAction->text());
|
command->setDescription(m_generateCompilationDBAction->text());
|
||||||
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_BUILD);
|
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_BUILD);
|
||||||
|
|
||||||
connect(&m_generatorWatcher, &QFutureWatcher<void>::finished, this, [this] () {
|
connect(&m_generatorWatcher, &QFutureWatcher<Utils::GenerateCompilationDbResult>::finished,
|
||||||
|
this, [this] () {
|
||||||
|
const Utils::GenerateCompilationDbResult result = m_generatorWatcher.result();
|
||||||
|
QString message;
|
||||||
|
if (result.error.isEmpty()) {
|
||||||
|
message = tr("Clang compilation database generated at \"%1\".")
|
||||||
|
.arg(QDir::toNativeSeparators(result.filePath));
|
||||||
|
} else {
|
||||||
|
message = tr("Generating clang compilation database failed: %1").arg(result.error);
|
||||||
|
}
|
||||||
|
Core::MessageManager::write(message, Core::MessageManager::Flash);
|
||||||
m_generateCompilationDBAction->setEnabled(
|
m_generateCompilationDBAction->setEnabled(
|
||||||
isDBGenerationEnabled(ProjectExplorer::SessionManager::startupProject()));
|
isDBGenerationEnabled(ProjectExplorer::SessionManager::startupProject()));
|
||||||
});
|
});
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "clangmodelmanagersupport.h"
|
#include "clangmodelmanagersupport.h"
|
||||||
|
#include "clangutils.h"
|
||||||
|
|
||||||
#include <extensionsystem/iplugin.h>
|
#include <extensionsystem/iplugin.h>
|
||||||
|
|
||||||
@@ -54,8 +55,8 @@ private:
|
|||||||
void createCompilationDBButton();
|
void createCompilationDBButton();
|
||||||
|
|
||||||
ClangModelManagerSupportProvider m_modelManagerSupportProvider;
|
ClangModelManagerSupportProvider m_modelManagerSupportProvider;
|
||||||
Utils::ParameterAction *m_generateCompilationDBAction = nullptr;
|
::Utils::ParameterAction *m_generateCompilationDBAction = nullptr;
|
||||||
QFutureWatcher<void> m_generatorWatcher;
|
QFutureWatcher<Utils::GenerateCompilationDbResult> m_generatorWatcher;
|
||||||
#ifdef WITH_TESTS
|
#ifdef WITH_TESTS
|
||||||
QList<QObject *> createTestObjects() const override;
|
QList<QObject *> createTestObjects() const override;
|
||||||
#endif
|
#endif
|
||||||
|
@@ -386,18 +386,22 @@ static QJsonObject createFileObject(const ::Utils::FileName &buildDir,
|
|||||||
return fileObject;
|
return fileObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
void generateCompilationDB(CppTools::ProjectInfo projectInfo)
|
GenerateCompilationDbResult generateCompilationDB(CppTools::ProjectInfo projectInfo)
|
||||||
{
|
{
|
||||||
const ::Utils::FileName buildDir = buildDirectory(*projectInfo.project());
|
const ::Utils::FileName buildDir = buildDirectory(*projectInfo.project());
|
||||||
QTC_ASSERT(!buildDir.isEmpty(), return;);
|
QTC_ASSERT(!buildDir.isEmpty(), return GenerateCompilationDbResult(QString(),
|
||||||
|
QCoreApplication::translate("ClangUtils", "Could not retrieve build directory.")));
|
||||||
|
|
||||||
QDir dir(buildDir.toString());
|
QDir dir(buildDir.toString());
|
||||||
if (!dir.exists())
|
if (!dir.exists())
|
||||||
dir.mkpath(dir.path());
|
dir.mkpath(dir.path());
|
||||||
QFile compileCommandsFile(buildDir.toString() + "/compile_commands.json");
|
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 GenerateCompilationDbResult(QString(),
|
||||||
|
QCoreApplication::translate("ClangUtils", "Could not create \"%1\": %2")
|
||||||
|
.arg(compileCommandsFile.fileName(), compileCommandsFile.errorString()));
|
||||||
|
}
|
||||||
compileCommandsFile.write("[");
|
compileCommandsFile.write("[");
|
||||||
|
|
||||||
for (ProjectPart::Ptr projectPart : projectInfo.projectParts()) {
|
for (ProjectPart::Ptr projectPart : projectInfo.projectParts()) {
|
||||||
@@ -412,6 +416,7 @@ void generateCompilationDB(CppTools::ProjectInfo projectInfo)
|
|||||||
|
|
||||||
compileCommandsFile.write("\n]");
|
compileCommandsFile.write("\n]");
|
||||||
compileCommandsFile.close();
|
compileCommandsFile.close();
|
||||||
|
return GenerateCompilationDbResult(compileCommandsFile.fileName(), QString());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString currentCppEditorDocumentFilePath()
|
QString currentCppEditorDocumentFilePath()
|
||||||
|
@@ -70,7 +70,19 @@ QString diagnosticCategoryPrefixRemoved(const QString &text);
|
|||||||
|
|
||||||
::Utils::CodeModelIcon::Type iconTypeForToken(const ClangBackEnd::TokenInfoContainer &token);
|
::Utils::CodeModelIcon::Type iconTypeForToken(const ClangBackEnd::TokenInfoContainer &token);
|
||||||
|
|
||||||
void generateCompilationDB(CppTools::ProjectInfo projectInfo);
|
class GenerateCompilationDbResult
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GenerateCompilationDbResult() = default;
|
||||||
|
GenerateCompilationDbResult(const QString &filePath, const QString &error)
|
||||||
|
: filePath(filePath), error(error)
|
||||||
|
{}
|
||||||
|
|
||||||
|
QString filePath;
|
||||||
|
QString error;
|
||||||
|
};
|
||||||
|
|
||||||
|
GenerateCompilationDbResult generateCompilationDB(CppTools::ProjectInfo projectInfo);
|
||||||
|
|
||||||
class DiagnosticTextInfo
|
class DiagnosticTextInfo
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user