forked from qt-creator/qt-creator
CMakePM: Presets: Add ability to register a Debugger via "vendor" field
This adds "Debugger" as a dependency for the CMake Project Manager.
The "vendor" field of a configurePreset can look like:
```
"vendor": {
"qt.io/QtCreator/1.0": {
"debugger": "C:/Qt/Tools/mingw1120_64/bin/gdb.exe"
}
}
}
```
or with all the DebugItem details as:
```
"vendor": {
"qt.io/QtCreator/1.0": {
"debugger": {
"DisplayName": "GNU gdb 11.2.0 for MinGW 11.2.0 64-bit",
"Abis": ["x86-windows-msys-pe-64bit"],
"Binary": "C:/Qt/Tools/mingw1120_64/bin/gdb.exe",
"EngineType": 1,
"Version": "11.2.0"
}
}
}
```
Fixes: QTCREATORBUG-30836
Change-Id: Ia89ff29ce5fad713ee8617477ec798bd86f2f811
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -12,6 +12,9 @@
|
||||
#include "presetsmacros.h"
|
||||
|
||||
#include <coreplugin/messagemanager.h>
|
||||
#include <debugger/debuggeritem.h>
|
||||
#include <debugger/debuggeritemmanager.h>
|
||||
#include <debugger/debuggerkitaspect.h>
|
||||
|
||||
#include <projectexplorer/buildinfo.h>
|
||||
#include <projectexplorer/kitaspects.h>
|
||||
@@ -30,7 +33,9 @@
|
||||
|
||||
#include <QApplication>
|
||||
#include <QLoggingCategory>
|
||||
#include <QUuid>
|
||||
|
||||
using namespace Debugger;
|
||||
using namespace ProjectExplorer;
|
||||
using namespace QtSupport;
|
||||
using namespace Utils;
|
||||
@@ -60,6 +65,7 @@ struct DirectoryData
|
||||
FilePath sysroot;
|
||||
QtProjectImporter::QtVersionData qt;
|
||||
QVector<ToolchainDescription> toolchains;
|
||||
QVariant debugger;
|
||||
};
|
||||
|
||||
static FilePaths scanDirectory(const FilePath &path, const QString &prefix)
|
||||
@@ -205,6 +211,48 @@ FilePaths CMakeProjectImporter::presetCandidates()
|
||||
return candidates;
|
||||
}
|
||||
|
||||
static QVariant findOrRegisterDebugger(
|
||||
Environment &env, const std::optional<QVariantMap> &vendor, const QString &presetName)
|
||||
{
|
||||
const QString debuggerKey("debugger");
|
||||
if (!vendor || !vendor.value().contains(debuggerKey))
|
||||
return {};
|
||||
|
||||
const QVariant debuggerVariant = vendor.value().value(debuggerKey);
|
||||
FilePath debuggerPath = FilePath::fromUserInput(debuggerVariant.toString());
|
||||
if (!debuggerPath.isEmpty()) {
|
||||
if (debuggerPath.isRelativePath())
|
||||
debuggerPath = env.searchInPath(debuggerPath.fileName());
|
||||
|
||||
const QString mainName = Tr::tr("CMake Preset (%1) %2 Debugger");
|
||||
DebuggerItem debugger;
|
||||
debugger.setCommand(debuggerPath);
|
||||
debugger.setUnexpandedDisplayName(
|
||||
mainName.arg(presetName).arg(debuggerPath.completeBaseName()));
|
||||
debugger.setAutoDetected(false);
|
||||
QString errorMessage;
|
||||
debugger.reinitializeFromFile(&errorMessage, &env);
|
||||
if (!errorMessage.isEmpty())
|
||||
qCWarning(cmInputLog()) << "Error reinitializing debugger" << debuggerPath.toString()
|
||||
<< "Error:" << errorMessage;
|
||||
|
||||
return DebuggerItemManager::registerDebugger(debugger);
|
||||
} else {
|
||||
auto debuggerMap = debuggerVariant.toMap();
|
||||
if (debuggerMap.isEmpty())
|
||||
return {};
|
||||
|
||||
// Manually create an Id, otrhewise the Kit will not have a debugger set
|
||||
if (!debuggerMap.contains("Id"))
|
||||
debuggerMap.insert("Id", QUuid::createUuid().toString());
|
||||
|
||||
auto store = storeFromMap(debuggerMap);
|
||||
DebuggerItem debugger(store);
|
||||
|
||||
return DebuggerItemManager::registerDebugger(debugger);
|
||||
}
|
||||
}
|
||||
|
||||
Target *CMakeProjectImporter::preferredTarget(const QList<Target *> &possibleTargets)
|
||||
{
|
||||
for (Kit *kit : m_project->oldPresetKits()) {
|
||||
@@ -835,6 +883,8 @@ QList<void *> CMakeProjectImporter::examineDirectory(const FilePath &importPath,
|
||||
|
||||
data->hasQmlDebugging = CMakeBuildConfiguration::hasQmlDebugging(config);
|
||||
|
||||
data->debugger = findOrRegisterDebugger(env, configurePreset.vendor, configurePreset.name);
|
||||
|
||||
QByteArrayList buildConfigurationTypes = {cache.valueOf("CMAKE_BUILD_TYPE")};
|
||||
if (buildConfigurationTypes.front().isEmpty()) {
|
||||
buildConfigurationTypes.clear();
|
||||
@@ -1055,6 +1105,9 @@ Kit *CMakeProjectImporter::createKit(void *directoryData) const
|
||||
if (!data->cmakePreset.isEmpty())
|
||||
ensureBuildDirectory(*data, k);
|
||||
|
||||
if (data->debugger.isValid())
|
||||
DebuggerKitAspect::setDebugger(k, data->debugger);
|
||||
|
||||
qCInfo(cmInputLog) << "Temporary Kit created.";
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user