forked from qt-creator/qt-creator
McuSupport: Add toolchain information for desktop kits
To be able to check the validity of a desktop toolchain used in an mcusupport kit with qt platform. Task-number: QTCREATORBUG-26750 Change-Id: Ifc518257844c8994150f3d86eb5512701c38c2b7 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Piotr Mućko <piotr.mucko@qt.io> Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -43,6 +43,7 @@
|
||||
#include <debugger/debuggerkitinformation.h>
|
||||
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/toolchain.h>
|
||||
|
||||
#include <qtsupport/qtkitinformation.h>
|
||||
#include <qtsupport/qtversionmanager.h>
|
||||
@@ -250,14 +251,27 @@ public:
|
||||
auto configMap = cMakeConfigToMap(CMakeConfigurationKitAspect::configuration(k));
|
||||
|
||||
// CMake ToolChain file for ghs handles CMAKE_*_COMPILER autonomously
|
||||
if (mcuTarget->toolChainPackage()->toolchainType() != McuToolChainPackage::ToolChainType::GHS
|
||||
&& mcuTarget->toolChainPackage()->toolchainType()
|
||||
!= McuToolChainPackage::ToolChainType::GHSArm) {
|
||||
const QList autonomousCompilerDetectionToolchains{
|
||||
McuToolChainPackage::ToolChainType::GHS,
|
||||
McuToolChainPackage::ToolChainType::GHSArm,
|
||||
};
|
||||
if (!autonomousCompilerDetectionToolchains.contains(
|
||||
mcuTarget->toolChainPackage()->toolchainType())) {
|
||||
configMap.insert("CMAKE_CXX_COMPILER", "%{Compiler:Executable:Cxx}");
|
||||
configMap.insert("CMAKE_C_COMPILER", "%{Compiler:Executable:C}");
|
||||
}
|
||||
|
||||
if (!mcuTarget->toolChainPackage()->isDesktopToolchain()) {
|
||||
auto toolchainPackage = mcuTarget->toolChainPackage();
|
||||
if (toolchainPackage->isDesktopToolchain()) {
|
||||
auto cToolchain = toolchainPackage->toolChain(ProjectExplorer::Constants::C_LANGUAGE_ID);
|
||||
auto cxxToolchain = toolchainPackage->toolChain(
|
||||
ProjectExplorer::Constants::CXX_LANGUAGE_ID);
|
||||
|
||||
configMap.insert("CMAKE_CXX_COMPILER",
|
||||
cxxToolchain->compilerCommand().toString().toLatin1());
|
||||
configMap.insert("CMAKE_C_COMPILER",
|
||||
cToolchain->compilerCommand().toString().toLatin1());
|
||||
} else {
|
||||
const FilePath cMakeToolchainFile = mcuTarget->toolChainFilePackage()->path();
|
||||
|
||||
configMap.insert(Legacy::Constants::TOOLCHAIN_FILE_CMAKE_VARIABLE,
|
||||
@@ -348,8 +362,7 @@ Kit *newKit(const McuTarget *mcuTarget, const McuPackagePtr &qtForMCUsSdk)
|
||||
QString generateKitNameFromTarget(const McuTarget *mcuTarget)
|
||||
{
|
||||
McuToolChainPackagePtr tcPkg = mcuTarget->toolChainPackage();
|
||||
const QString compilerName = tcPkg && !tcPkg->isDesktopToolchain()
|
||||
? QString::fromLatin1(" (%1)").arg(
|
||||
const QString compilerName = tcPkg ? QString::fromLatin1(" (%1)").arg(
|
||||
tcPkg->toolChainName().toUpper())
|
||||
: "";
|
||||
const QString colorDepth = mcuTarget->colorDepth() != McuTarget::UnspecifiedColorDepth
|
||||
|
||||
@@ -317,7 +317,7 @@ bool McuToolChainPackage::isDesktopToolchain() const
|
||||
return m_type == ToolChainType::MSVC || m_type == ToolChainType::GCC;
|
||||
}
|
||||
|
||||
static ToolChain *msvcToolChain(Id language)
|
||||
ToolChain *McuToolChainPackage::msvcToolChain(Id language)
|
||||
{
|
||||
ToolChain *toolChain = ToolChainManager::toolChain([language](const ToolChain *t) {
|
||||
const Abi abi = t->targetAbi();
|
||||
@@ -330,7 +330,7 @@ static ToolChain *msvcToolChain(Id language)
|
||||
return toolChain;
|
||||
}
|
||||
|
||||
static ToolChain *gccToolChain(Id language)
|
||||
ToolChain *McuToolChainPackage::gccToolChain(Id language)
|
||||
{
|
||||
ToolChain *toolChain = ToolChainManager::toolChain([language](const ToolChain *t) {
|
||||
const Abi abi = t->targetAbi();
|
||||
@@ -430,6 +430,10 @@ ToolChain *McuToolChainPackage::toolChain(Id language) const
|
||||
QString McuToolChainPackage::toolChainName() const
|
||||
{
|
||||
switch (m_type) {
|
||||
case ToolChainType::MSVC:
|
||||
return QLatin1String("msvc");
|
||||
case ToolChainType::GCC:
|
||||
return QLatin1String("gcc");
|
||||
case ToolChainType::ArmGcc:
|
||||
return QLatin1String("armgcc");
|
||||
case ToolChainType::IAR:
|
||||
|
||||
@@ -140,6 +140,9 @@ public:
|
||||
QString toolChainName() const;
|
||||
QVariant debuggerId() const;
|
||||
|
||||
static ProjectExplorer::ToolChain *msvcToolChain(Utils::Id language);
|
||||
static ProjectExplorer::ToolChain *gccToolChain(Utils::Id language);
|
||||
|
||||
private:
|
||||
const ToolChainType m_type;
|
||||
};
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
|
||||
#include <baremetal/baremetalconstants.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/toolchain.h>
|
||||
#include <projectexplorer/toolchainmanager.h>
|
||||
#include <utils/algorithm.h>
|
||||
@@ -55,6 +56,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Utils;
|
||||
|
||||
namespace McuSupport::Internal {
|
||||
@@ -204,31 +206,54 @@ McuToolChainPackagePtr createUnsupportedToolChainPackage(const SettingsHandler::
|
||||
McuToolChainPackagePtr createMsvcToolChainPackage(const SettingsHandler::Ptr &settingsHandler,
|
||||
const QStringList &versions)
|
||||
{
|
||||
ToolChain *toolChain = McuToolChainPackage::msvcToolChain(
|
||||
ProjectExplorer::Constants::CXX_LANGUAGE_ID);
|
||||
|
||||
const FilePath detectionPath = FilePath("cl").withExecutableSuffix();
|
||||
const FilePath defaultPath = toolChain ? toolChain->compilerCommand().parentDir() : FilePath();
|
||||
|
||||
const auto versionDetector
|
||||
= new McuPackageExecutableVersionDetector(detectionPath,
|
||||
{"--version"},
|
||||
"\\b(\\d+\\.\\d+)\\.\\d+\\b");
|
||||
|
||||
return McuToolChainPackagePtr{new McuToolChainPackage(settingsHandler,
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
McuPackage::tr("MSVC Binary directory"),
|
||||
defaultPath,
|
||||
detectionPath,
|
||||
"MsvcToolchain",
|
||||
McuToolChainPackage::ToolChainType::MSVC,
|
||||
versions,
|
||||
{},
|
||||
{},
|
||||
nullptr)};
|
||||
versionDetector)};
|
||||
}
|
||||
|
||||
McuToolChainPackagePtr createGccToolChainPackage(const SettingsHandler::Ptr &settingsHandler,
|
||||
const QStringList &versions)
|
||||
{
|
||||
ToolChain *toolChain = McuToolChainPackage::gccToolChain(
|
||||
ProjectExplorer::Constants::CXX_LANGUAGE_ID);
|
||||
|
||||
const FilePath detectionPath = FilePath("bin/g++").withExecutableSuffix();
|
||||
const FilePath defaultPath = toolChain ? toolChain->compilerCommand().parentDir().parentDir()
|
||||
: FilePath();
|
||||
|
||||
const auto versionDetector
|
||||
= new McuPackageExecutableVersionDetector(detectionPath,
|
||||
{"--version"},
|
||||
"\\b(\\d+\\.\\d+\\.\\d+)\\b");
|
||||
|
||||
return McuToolChainPackagePtr{new McuToolChainPackage(settingsHandler,
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
McuPackage::tr("GCC Toolchain"),
|
||||
defaultPath,
|
||||
detectionPath,
|
||||
"GnuToolchain",
|
||||
McuToolChainPackage::ToolChainType::GCC,
|
||||
versions,
|
||||
Constants::TOOLCHAIN_DIR_CMAKE_VARIABLE,
|
||||
{},
|
||||
{},
|
||||
nullptr)};
|
||||
versionDetector)};
|
||||
}
|
||||
|
||||
McuToolChainPackagePtr createArmGccToolchainPackage(const SettingsHandler::Ptr &settingsHandler,
|
||||
@@ -250,7 +275,7 @@ McuToolChainPackagePtr createArmGccToolchainPackage(const SettingsHandler::Ptr &
|
||||
}
|
||||
}
|
||||
|
||||
const Utils::FilePath detectionPath = FilePath("bin/arm-none-eabi-g++").withExecutableSuffix();
|
||||
const FilePath detectionPath = FilePath("bin/arm-none-eabi-g++").withExecutableSuffix();
|
||||
const auto versionDetector = new McuPackageExecutableVersionDetector(detectionPath,
|
||||
{"--version"},
|
||||
R"(\b(\d+\.\d+\.\d+)\b)");
|
||||
@@ -511,8 +536,8 @@ static McuAbstractTargetFactory::Ptr createFactory(bool isLegacy,
|
||||
|
||||
const FilePath toolchainFilePrefix = qtMcuSdkPath
|
||||
/ Legacy::Constants::QUL_TOOLCHAIN_CMAKE_DIR;
|
||||
static const QHash<QString, McuPackagePtr> toolchainFiles = {
|
||||
{{"armgcc"},
|
||||
static const QHash<QString, McuPackagePtr> toolchainFiles
|
||||
= {{{"armgcc"},
|
||||
McuPackagePtr{new McuPackage{settingsHandler,
|
||||
{},
|
||||
toolchainFilePrefix / "armgcc.cmake",
|
||||
@@ -544,7 +569,8 @@ static McuAbstractTargetFactory::Ptr createFactory(bool isLegacy,
|
||||
{},
|
||||
{},
|
||||
Legacy::Constants::TOOLCHAIN_FILE_CMAKE_VARIABLE,
|
||||
{}}}},
|
||||
{}}}}
|
||||
|
||||
};
|
||||
|
||||
// Note: the vendor name (the key of the hash) is case-sensitive. It has to match the "platformVendor" key in the
|
||||
@@ -595,12 +621,12 @@ McuSdkRepository targetsFromDescriptions(const QList<McuTargetDescription> &desc
|
||||
return McuSdkRepository{mcuTargets, mcuPackages};
|
||||
}
|
||||
|
||||
Utils::FilePath kitsPath(const Utils::FilePath &qtMcuSdkPath)
|
||||
FilePath kitsPath(const FilePath &qtMcuSdkPath)
|
||||
{
|
||||
return qtMcuSdkPath / "kits/";
|
||||
}
|
||||
|
||||
static QFileInfoList targetDescriptionFiles(const Utils::FilePath &dir)
|
||||
static QFileInfoList targetDescriptionFiles(const FilePath &dir)
|
||||
{
|
||||
const QDir kitsDir(kitsPath(dir).toString(), "*.json");
|
||||
return kitsDir.entryInfoList();
|
||||
@@ -721,7 +747,7 @@ static const QString legacySupportVersionFor(const QString &sdkVersion)
|
||||
return QString();
|
||||
}
|
||||
|
||||
bool checkDeprecatedSdkError(const Utils::FilePath &qulDir, QString &message)
|
||||
bool checkDeprecatedSdkError(const FilePath &qulDir, QString &message)
|
||||
{
|
||||
const McuPackagePathVersionDetector versionDetector(R"((?<=\bQtMCUs.)(\d+\.\d+))");
|
||||
const QString sdkDetectedVersion = versionDetector.parseVersion(qulDir);
|
||||
@@ -740,7 +766,7 @@ bool checkDeprecatedSdkError(const Utils::FilePath &qulDir, QString &message)
|
||||
return false;
|
||||
}
|
||||
|
||||
McuSdkRepository targetsAndPackages(const Utils::FilePath &qtForMCUSdkPath,
|
||||
McuSdkRepository targetsAndPackages(const FilePath &qtForMCUSdkPath,
|
||||
const SettingsHandler::Ptr &settingsHandler)
|
||||
{
|
||||
QList<McuTargetDescription> descriptions;
|
||||
@@ -752,7 +778,7 @@ McuSdkRepository targetsAndPackages(const Utils::FilePath &qtForMCUSdkPath,
|
||||
if (!file.open(QFile::ReadOnly))
|
||||
continue;
|
||||
const McuTargetDescription desc = parseDescriptionJson(file.readAll());
|
||||
const auto pth = Utils::FilePath::fromString(fileInfo.filePath());
|
||||
const auto pth = FilePath::fromString(fileInfo.filePath());
|
||||
bool ok = false;
|
||||
const int compatVersion = desc.compatVersion.toInt(&ok);
|
||||
if (!desc.compatVersion.isEmpty() && ok && compatVersion > MAX_COMPATIBILITY_VERSION) {
|
||||
|
||||
@@ -57,7 +57,7 @@ QPair<Targets, Packages> McuTargetFactory::createTargets(const McuTargetDescript
|
||||
for (int colorDepth : desc.platform.colorDepths) {
|
||||
Packages required3rdPartyPkgs;
|
||||
// Desktop toolchains don't need any additional settings
|
||||
if (toolchainPackage && !toolchainPackage->isDesktopToolchain()
|
||||
if (toolchainPackage
|
||||
&& toolchainPackage->toolchainType()
|
||||
!= McuToolChainPackage::ToolChainType::Unsupported) {
|
||||
required3rdPartyPkgs.insert(toolchainPackage);
|
||||
|
||||
@@ -55,6 +55,10 @@ FilePath SettingsHandler::getPath(const QString &settingsKey,
|
||||
QSettings::Scope scope,
|
||||
const Utils::FilePath &defaultPath) const
|
||||
{
|
||||
//Use the default value for empty keys
|
||||
if (settingsKey.isEmpty())
|
||||
return defaultPath;
|
||||
|
||||
return packagePathFromSettings(settingsKey, *Core::ICore::settings(scope), defaultPath);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user