From 842776fb6220f885d544bef76f44a5e7a3f649cf Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Thu, 29 Aug 2024 12:47:02 +0200 Subject: [PATCH] ProjectExplorer: Filter kit aspects by build device That is, do not offer toolchains, debuggers etc that do not match the kit's build device. Change-Id: I041ba9fd18ab553d9b2219116d87493e30f60aac Reviewed-by: Marcus Tillmanns --- .../cmakeprojectmanager/cmakekitaspect.cpp | 25 ++++-------- src/plugins/debugger/debuggerkitaspect.cpp | 20 +++------- src/plugins/projectexplorer/kitaspects.cpp | 38 ++++++------------- src/plugins/qtsupport/qtkitaspect.cpp | 21 +++------- 4 files changed, 29 insertions(+), 75 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakekitaspect.cpp b/src/plugins/cmakeprojectmanager/cmakekitaspect.cpp index a27f9e6505e..22248e9d5a4 100644 --- a/src/plugins/cmakeprojectmanager/cmakekitaspect.cpp +++ b/src/plugins/cmakeprojectmanager/cmakekitaspect.cpp @@ -163,29 +163,18 @@ private: IDeviceConstPtr device = BuildDeviceKitAspect::device(kit()); const FilePath rootPath = device->rootPath(); - const auto list = CMakeToolManager::cmakeTools(); + const QList toolsForBuildDevice + = Utils::filtered(CMakeToolManager::cmakeTools(), [rootPath](CMakeTool *item) { + return item->cmakeExecutable().isSameDevice(rootPath); + }); - m_comboBox->setEnabled(!list.isEmpty()); - - if (list.isEmpty()) { + m_comboBox->setEnabled(!toolsForBuildDevice.isEmpty()); + if (toolsForBuildDevice.isEmpty()) { m_comboBox->addItem(Tr::tr(""), Id().toSetting()); return; } - const QList same = Utils::filtered(list, [rootPath](CMakeTool *item) { - return item->cmakeExecutable().isSameDevice(rootPath); - }); - const QList other = Utils::filtered(list, [rootPath](CMakeTool *item) { - return !item->cmakeExecutable().isSameDevice(rootPath); - }); - - for (CMakeTool *item : same) - m_comboBox->addItem(item->displayName(), item->id().toSetting()); - - if (!same.isEmpty() && !other.isEmpty()) - m_comboBox->insertSeparator(m_comboBox->count()); - - for (CMakeTool *item : other) + for (CMakeTool *item : toolsForBuildDevice) m_comboBox->addItem(item->displayName(), item->id().toSetting()); CMakeTool *tool = CMakeKitAspect::cmakeTool(m_kit); diff --git a/src/plugins/debugger/debuggerkitaspect.cpp b/src/plugins/debugger/debuggerkitaspect.cpp index 3ba3b0be065..0e40ee60d19 100644 --- a/src/plugins/debugger/debuggerkitaspect.cpp +++ b/src/plugins/debugger/debuggerkitaspect.cpp @@ -86,22 +86,12 @@ private: IDeviceConstPtr device = BuildDeviceKitAspect::device(kit()); const Utils::FilePath path = device->rootPath(); - const QList list = DebuggerItemManager::debuggers(); - const QList same = Utils::filtered(list, [path](const DebuggerItem &item) { - return item.command().isSameDevice(path); - }); - const QList other = Utils::filtered(list, [path](const DebuggerItem &item) { - return !item.command().isSameDevice(path); - }); - - for (const DebuggerItem &item : same) - m_comboBox->addItem(item.displayName(), item.id()); - - if (!same.isEmpty() && !other.isEmpty()) - m_comboBox->insertSeparator(m_comboBox->count()); - - for (const DebuggerItem &item : other) + const QList debuggersForBuildDevice + = Utils::filtered(DebuggerItemManager::debuggers(), [path](const DebuggerItem &item) { + return item.command().isSameDevice(path); + }); + for (const DebuggerItem &item : debuggersForBuildDevice) m_comboBox->addItem(item.displayName(), item.id()); const DebuggerItem *item = DebuggerKitAspect::debugger(m_kit); diff --git a/src/plugins/projectexplorer/kitaspects.cpp b/src/plugins/projectexplorer/kitaspects.cpp index 1c3cb84c1b8..44b235f6c75 100644 --- a/src/plugins/projectexplorer/kitaspects.cpp +++ b/src/plugins/projectexplorer/kitaspects.cpp @@ -264,24 +264,13 @@ private: cb->clear(); cb->addItem(Tr::tr(""), QByteArray()); - const QList same = Utils::filtered(ltcList, [device](Toolchain *tc) { - return tc->compilerCommand().isSameDevice(device->rootPath()); - }); - const QList other = Utils::filtered(ltcList, [device](Toolchain *tc) { - return !tc->compilerCommand().isSameDevice(device->rootPath()); - }); - - const QList sameBundles - = ToolchainBundle::collectBundles(same, ToolchainBundle::AutoRegister::On); - const QList otherBundles - = ToolchainBundle::collectBundles(other, ToolchainBundle::AutoRegister::On); - for (const ToolchainBundle &b : sameBundles) - cb->addItem(b.displayName(), b.bundleId().toSetting()); - - if (!sameBundles.isEmpty() && !otherBundles.isEmpty()) - cb->insertSeparator(cb->count()); - - for (const ToolchainBundle &b : otherBundles) + const QList toolchainsForBuildDevice + = Utils::filtered(ltcList, [device](Toolchain *tc) { + return tc->compilerCommand().isSameDevice(device->rootPath()); + }); + const QList bundlesForBuildDevice = ToolchainBundle::collectBundles( + toolchainsForBuildDevice, ToolchainBundle::AutoRegister::On); + for (const ToolchainBundle &b : bundlesForBuildDevice) cb->addItem(b.displayName(), b.bundleId().toSetting()); cb->setEnabled(cb->count() > 1 && !m_isReadOnly); @@ -290,15 +279,12 @@ private: Toolchain * const currentTc = ToolchainKitAspect::toolchain(m_kit, lang); if (!currentTc) continue; - for (const QList &bundles : {sameBundles, otherBundles}) - for (const ToolchainBundle &b : bundles) { - if (b.bundleId() == currentTc->bundleId()) { - currentBundleId = b.bundleId(); - break; - } - if (currentBundleId.isValid()) - break; + for (const ToolchainBundle &b : bundlesForBuildDevice) { + if (b.bundleId() == currentTc->bundleId()) { + currentBundleId = b.bundleId(); + break; } + } if (currentBundleId.isValid()) break; } diff --git a/src/plugins/qtsupport/qtkitaspect.cpp b/src/plugins/qtsupport/qtkitaspect.cpp index 3eaaecb7988..d106a0071a4 100644 --- a/src/plugins/qtsupport/qtkitaspect.cpp +++ b/src/plugins/qtsupport/qtkitaspect.cpp @@ -77,24 +77,13 @@ private: IDeviceConstPtr device = BuildDeviceKitAspect::device(kit()); const FilePath deviceRoot = device->rootPath(); - const QtVersions versions = QtVersionManager::versions(); + const QList versionsForBuildDevice + = Utils::filtered(QtVersionManager::versions(), [device](QtVersion *qt) { + return qt->qmakeFilePath().isSameDevice(device->rootPath()); + }); - const QList same = Utils::filtered(versions, [device](QtVersion *qt) { - return qt->qmakeFilePath().isSameDevice(device->rootPath()); - }); - const QList other = Utils::filtered(versions, [device](QtVersion *qt) { - return !qt->qmakeFilePath().isSameDevice(device->rootPath()); - }); - - for (QtVersion *item : same) + for (QtVersion *item : versionsForBuildDevice) m_combo->addItem(item->displayName(), item->uniqueId()); - - if (!same.isEmpty() && !other.isEmpty()) - m_combo->insertSeparator(m_combo->count()); - - for (QtVersion *item : other) - m_combo->addItem(item->displayName(), item->uniqueId()); - m_combo->setCurrentIndex(findQtVersion(QtKitAspect::qtVersionId(m_kit))); }