McuSupport: Display errors when configuring Qt for MCUs SDK

Fixes: QTCREATORBUG-25258
Change-Id: I6f445bddb51f3bc1850793966f049c4b7ce7889f
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: Erik Verbruggen <erik.verbruggen@me.com>
This commit is contained in:
Christiaan Janssen
2020-12-04 16:32:34 +01:00
committed by christiaan.janssen
parent ef5b4b8db5
commit 5b7a3fba27
5 changed files with 151 additions and 29 deletions

View File

@@ -31,6 +31,7 @@
#include <cmakeprojectmanager/cmaketoolmanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/helpmanager.h>
#include <coreplugin/messagemanager.h>
#include <cmakeprojectmanager/cmakekitinformation.h>
#include <debugger/debuggeritem.h>
#include <debugger/debuggeritemmanager.h>
@@ -105,10 +106,14 @@ McuPackage::McuPackage(const QString &label, const QString &defaultPath,
m_automaticKitCreation = automaticKitCreationFromSettings(QSettings::UserScope);
}
QString McuPackage::basePath() const
{
return m_fileChooser != nullptr ? m_fileChooser->filePath().toString() : m_path;
}
QString McuPackage::path() const
{
QString basePath = m_fileChooser != nullptr ? m_fileChooser->filePath().toString() : m_path;
return QFileInfo(basePath + m_relativePathModifier).absoluteFilePath();
return QFileInfo(basePath() + m_relativePathModifier).absoluteFilePath();
}
QString McuPackage::label() const
@@ -159,8 +164,12 @@ QWidget *McuPackage::widget()
m_fileChooser->setPath(m_path);
QObject::connect(this, &McuPackage::statusChanged, this, [this] {
updateStatusUi();
});
QObject::connect(m_fileChooser, &PathChooser::pathChanged, this, [this] {
updateStatus();
updatePath();
emit changed();
});
@@ -228,35 +237,58 @@ void McuPackage::setAutomaticKitCreationEnabled(const bool enabled)
m_automaticKitCreation = enabled;
}
void McuPackage::updatePath()
{
m_path = m_fileChooser->rawPath();
m_fileChooser->lineEdit()->button(FancyLineEdit::Right)->setEnabled(m_path != m_defaultPath);
updateStatus();
}
void McuPackage::updateStatus()
{
m_path = m_fileChooser->rawPath();
const bool validPath = m_fileChooser->isValid();
const FilePath detectionPath = FilePath::fromString(
m_fileChooser->filePath().toString() + "/" + m_detectionPath);
const QString displayDetectionPath = FilePath::fromString(m_detectionPath).toUserOutput();
bool validPath = !m_path.isEmpty() && FilePath::fromString(m_path).exists();
const FilePath detectionPath = FilePath::fromString(basePath() + "/" + m_detectionPath);
const bool validPackage = m_detectionPath.isEmpty() || detectionPath.exists();
m_status = validPath ? (validPackage ? ValidPackage : ValidPathInvalidPackage) : InvalidPath;
m_status = validPath ? (validPackage ? ValidPackage : ValidPathInvalidPackage) :
m_path.isEmpty() ? EmptyPath : InvalidPath;
emit statusChanged();
}
void McuPackage::updateStatusUi()
{
m_infoLabel->setType(m_status == ValidPackage ? InfoLabel::Ok : InfoLabel::NotOk);
m_infoLabel->setText(statusText());
}
QString statusText;
QString McuPackage::statusText() const
{
const QString displayPackagePath = FilePath::fromString(m_path).toUserOutput();
const QString displayDetectionPath = FilePath::fromString(m_detectionPath).toUserOutput();
QString response;
switch (m_status) {
case ValidPackage:
statusText = m_detectionPath.isEmpty()
? tr("Path exists.")
: tr("Path is valid, \"%1\" was found.").arg(displayDetectionPath);
response = m_detectionPath.isEmpty()
? tr("Path %1 exists.").arg(displayPackagePath)
: tr("Path %1 is valid, %2 was found.")
.arg(displayPackagePath, displayDetectionPath);
break;
case ValidPathInvalidPackage:
statusText = tr("Path exists, but does not contain \"%1\".").arg(displayDetectionPath);
response = tr("Path %1 exists, but does not contain %2.")
.arg(displayPackagePath, displayDetectionPath);
break;
case InvalidPath:
statusText = tr("Path does not exist.");
response = tr("Path %1 does not exist.").arg(displayPackagePath);
break;
case EmptyPath:
response = m_detectionPath.isEmpty()
? tr("Path is empty.")
: tr("Path is empty, %1 not found.")
.arg(displayDetectionPath);
break;
}
m_infoLabel->setText(statusText);
m_fileChooser->lineEdit()->button(FancyLineEdit::Right)->setEnabled(m_path != m_defaultPath);
return response;
}
McuToolChainPackage::McuToolChainPackage(const QString &label,
@@ -453,6 +485,7 @@ McuTarget::Platform McuTarget::platform() const
bool McuTarget::isValid() const
{
return !Utils::anyOf(packages(), [](McuPackage *package) {
package->updateStatus();
return package->status() != McuPackage::ValidPackage;
});
}
@@ -544,8 +577,9 @@ const QVersionNumber &McuSupportOptions::minimalQulVersion()
void McuSupportOptions::setQulDir(const FilePath &dir)
{
deletePackagesAndTargets();
Sdk::targetsAndPackages(dir, &packages, &mcuTargets);
//packages.append(qtForMCUsSdkPackage);
qtForMCUsSdkPackage->updateStatus();
if (qtForMCUsSdkPackage->status() == McuPackage::Status::ValidPackage)
Sdk::targetsAndPackages(dir, &packages, &mcuTargets);
for (auto package : packages)
connect(package, &McuPackage::changed, this, &McuSupportOptions::changed);
@@ -772,27 +806,70 @@ Kit *McuSupportOptions::newKit(const McuTarget *mcuTarget, const McuPackage *qtF
return KitManager::registerKit(init);
}
void printMessage(const QString &message, bool important)
{
const QString displayMessage = QCoreApplication::translate("QtForMCUs", "Qt for MCUs: %1").arg(message);
if (important)
Core::MessageManager::writeFlashing(displayMessage);
else
Core::MessageManager::writeSilently(displayMessage);
}
void McuSupportOptions::createAutomaticKits()
{
if (qulDirFromSettings().isEmpty())
return;
auto qtForMCUsPackage = Sdk::createQtForMCUsPackage();
const auto createKits = [qtForMCUsPackage]() {
if (qtForMCUsPackage->automaticKitCreationEnabled()) {
qtForMCUsPackage->updateStatus();
if (qtForMCUsPackage->status() != McuPackage::ValidPackage) {
switch (qtForMCUsPackage->status()) {
case McuPackage::ValidPathInvalidPackage: {
const QString displayPath = FilePath::fromString(qtForMCUsPackage->detectionPath())
.toUserOutput();
printMessage(tr("Path %1 exists, but does not contain %2.")
.arg(qtForMCUsPackage->path(), displayPath),
true);
break;
}
case McuPackage::InvalidPath: {
printMessage(tr("Path %1 does not exist. Add the path in Tools > Options > Devices > MCU.")
.arg(qtForMCUsPackage->path()),
true);
break;
}
case McuPackage::EmptyPath: {
printMessage(tr("Missing %1. Add the path in Tools > Options > Devices > MCU.")
.arg(qtForMCUsPackage->detectionPath()),
true);
return;
}
default: break;
}
return;
}
if (CMakeProjectManager::CMakeToolManager::cmakeTools().isEmpty()) {
printMessage(tr("No CMake tool was detected. Add a CMake tool in Tools > Options > Kits > CMake."),
true);
return;
}
auto dir = FilePath::fromUserInput(qtForMCUsPackage->path());
QVector<McuPackage*> packages;
QVector<McuTarget*> mcuTargets;
Sdk::targetsAndPackages(dir, &packages, &mcuTargets);
for (auto target: qAsConst(mcuTargets))
if (existingKits(target).isEmpty())
if (target->isValid() && existingKits(target).isEmpty())
newKit(target, qtForMCUsPackage);
qDeleteAll(packages);
qDeleteAll(mcuTargets);
}
};
createKits();
delete qtForMCUsPackage;
}