From 8ae505f30ea7d41f404112f563012acd2361de03 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Thu, 8 Mar 2018 17:46:20 +0100 Subject: [PATCH] QmlProject: Unify selection of supported kits Change-Id: Ic33e9688d823bd09664e5dc74fe5253cb5fcbc58 Reviewed-by: hjk Reviewed-by: Tobias Hunger --- .../cmakeprojectmanager/cmakeproject.cpp | 2 +- .../cmakeprojectmanager/cmakeproject.h | 2 +- src/plugins/nim/project/nimproject.cpp | 2 +- src/plugins/nim/project/nimproject.h | 2 +- src/plugins/projectexplorer/project.cpp | 2 +- src/plugins/projectexplorer/project.h | 2 +- .../qmakeprojectmanager/qmakeproject.cpp | 2 +- .../qmakeprojectmanager/qmakeproject.h | 2 +- src/plugins/qmlprojectmanager/qmlproject.cpp | 72 +++++++++---------- src/plugins/qmlprojectmanager/qmlproject.h | 2 +- 10 files changed, 44 insertions(+), 46 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp index 64cf50b6e4d..cd29127f6a7 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp @@ -376,7 +376,7 @@ bool CMakeProject::knowsAllBuildExecutables() const return false; } -bool CMakeProject::supportsKit(Kit *k, QString *errorMessage) const +bool CMakeProject::supportsKit(const Kit *k, QString *errorMessage) const { if (!CMakeKitInformation::cmakeTool(k)) { if (errorMessage) diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.h b/src/plugins/cmakeprojectmanager/cmakeproject.h index a747504740b..73b4c90f01a 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.h +++ b/src/plugins/cmakeprojectmanager/cmakeproject.h @@ -72,7 +72,7 @@ public: bool requiresTargetPanel() const final; bool knowsAllBuildExecutables() const final; - bool supportsKit(ProjectExplorer::Kit *k, QString *errorMessage = 0) const final; + bool supportsKit(const ProjectExplorer::Kit *k, QString *errorMessage = 0) const final; void runCMake(); void runCMakeAndScanProjectTree(); diff --git a/src/plugins/nim/project/nimproject.cpp b/src/plugins/nim/project/nimproject.cpp index 47bd87ee12b..82a412e41bd 100644 --- a/src/plugins/nim/project/nimproject.cpp +++ b/src/plugins/nim/project/nimproject.cpp @@ -159,7 +159,7 @@ void NimProject::updateProject() emitParsingFinished(true); } -bool NimProject::supportsKit(Kit *k, QString *errorMessage) const +bool NimProject::supportsKit(const Kit *k, QString *errorMessage) const { auto tc = dynamic_cast(ToolChainKitInformation::toolChain(k, Constants::C_NIMLANGUAGE_ID)); if (!tc) { diff --git a/src/plugins/nim/project/nimproject.h b/src/plugins/nim/project/nimproject.h index 50e03a3fa31..75a9fe1cffc 100644 --- a/src/plugins/nim/project/nimproject.h +++ b/src/plugins/nim/project/nimproject.h @@ -42,7 +42,7 @@ public: explicit NimProject(const Utils::FileName &fileName); bool needsConfiguration() const override; - bool supportsKit(ProjectExplorer::Kit *k, QString *errorMessage) const override; + bool supportsKit(const ProjectExplorer::Kit *k, QString *errorMessage) const override; Utils::FileNameList nimFiles() const; QVariantMap toMap() const override; diff --git a/src/plugins/projectexplorer/project.cpp b/src/plugins/projectexplorer/project.cpp index f2704e6119e..af299aa5d74 100644 --- a/src/plugins/projectexplorer/project.cpp +++ b/src/plugins/projectexplorer/project.cpp @@ -329,7 +329,7 @@ Target *Project::target(Kit *k) const return Utils::findOrDefault(d->m_targets, Utils::equal(&Target::kit, k)); } -bool Project::supportsKit(Kit *k, QString *errorMessage) const +bool Project::supportsKit(const Kit *k, QString *errorMessage) const { Q_UNUSED(k); Q_UNUSED(errorMessage); diff --git a/src/plugins/projectexplorer/project.h b/src/plugins/projectexplorer/project.h index 28b50551895..96056a991f3 100644 --- a/src/plugins/projectexplorer/project.h +++ b/src/plugins/projectexplorer/project.h @@ -123,7 +123,7 @@ public: Target *activeTarget() const; Target *target(Core::Id id) const; Target *target(Kit *k) const; - virtual bool supportsKit(Kit *k, QString *errorMessage = nullptr) const; + virtual bool supportsKit(const Kit *k, QString *errorMessage = nullptr) const; Target *createTarget(Kit *k); static bool copySteps(Target *sourceTarget, Target *newTarget); diff --git a/src/plugins/qmakeprojectmanager/qmakeproject.cpp b/src/plugins/qmakeprojectmanager/qmakeproject.cpp index 68fe0d4355c..7d10a31cd8d 100644 --- a/src/plugins/qmakeprojectmanager/qmakeproject.cpp +++ b/src/plugins/qmakeprojectmanager/qmakeproject.cpp @@ -588,7 +588,7 @@ void QmakeProject::buildFinished(bool success) m_qmakeVfs->invalidateContents(); } -bool QmakeProject::supportsKit(Kit *k, QString *errorMessage) const +bool QmakeProject::supportsKit(const Kit *k, QString *errorMessage) const { QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(k); if (!version && errorMessage) diff --git a/src/plugins/qmakeprojectmanager/qmakeproject.h b/src/plugins/qmakeprojectmanager/qmakeproject.h index 3e745193e83..580b750aade 100644 --- a/src/plugins/qmakeprojectmanager/qmakeproject.h +++ b/src/plugins/qmakeprojectmanager/qmakeproject.h @@ -61,7 +61,7 @@ public: QmakeProFile *rootProFile() const; - bool supportsKit(ProjectExplorer::Kit *k, QString *errorMesage) const final; + bool supportsKit(const ProjectExplorer::Kit *k, QString *errorMesage) const final; QmakeProFileNode *rootProjectNode() const final; diff --git a/src/plugins/qmlprojectmanager/qmlproject.cpp b/src/plugins/qmlprojectmanager/qmlproject.cpp index 26e5060b0fb..fb1b20bbfa6 100644 --- a/src/plugins/qmlprojectmanager/qmlproject.cpp +++ b/src/plugins/qmlprojectmanager/qmlproject.cpp @@ -277,20 +277,51 @@ void QmlProject::refreshTargetDirectory() updateDeploymentData(target); } -bool QmlProject::supportsKit(Kit *k, QString *errorMessage) const +bool QmlProject::supportsKit(const Kit *k, QString *errorMessage) const { + if (!k->isValid()) { + if (errorMessage) + *errorMessage = tr("Kit is not valid."); + return false; + } + + IDevice::ConstPtr dev = DeviceKitInformation::device(k); + if (dev.isNull()) { + if (errorMessage) + *errorMessage = tr("Kit has no device."); + return false; + } + QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(k); if (!version) { if (errorMessage) *errorMessage = tr("No Qt version set in kit."); return false; } - if (version->qtVersion() < QtSupport::QtVersionNumber(5, 0, 0)) { if (errorMessage) *errorMessage = tr("Qt version is too old."); return false; } + + if (dev->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) { + if (version->type() != QtSupport::Constants::DESKTOPQT) { + if (static_cast(version)->qmlsceneCommand().isEmpty()) { + if (errorMessage) + *errorMessage = tr("Qt version has no qmlscene command."); + return false; + } + } else { + // Non-desktop Qt on a desktop device? We don't support that. + if (errorMessage) + *errorMessage = tr("Non-desktop Qt is used with a Desktop device."); + return false; + } + } + + // If not a desktop device, don't check the Qt version for qmlscene. + // The device is responsible for providing it and we assume qmlscene can be found + // in $PATH if it's not explicitly given. return true; } @@ -305,43 +336,10 @@ Project::RestoreResult QmlProject::fromMap(const QVariantMap &map, QString *erro if (!activeTarget()) { // find a kit that matches prerequisites (prefer default one) - QList kits = KitManager::kits( - std::function([](const Kit *k) -> bool { - if (!k->isValid()) - return false; - - IDevice::ConstPtr dev = DeviceKitInformation::device(k); - if (dev.isNull()) - return false; - - QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(k); - if (!version || version->qtVersion() < QtSupport::QtVersionNumber(5, 0, 0)) - return false; - - if (dev->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) { - if (version->type() != QLatin1String(QtSupport::Constants::DESKTOPQT)) { - return !static_cast(version) - ->qmlsceneCommand().isEmpty(); - } else { - // Non-desktop Qt on a desktop device? We don't support that. - return false; - } - } - - // If not a desktop device, don't check the Qt version for qmlscene. - // The device is responsible for providing it and we assume qmlscene can be found - // in $PATH if it's not explicitly given. - return true; - - }) - ); + const QList kits = KitManager::kits([this](const Kit *k) { return supportsKit(k, nullptr); }); if (!kits.isEmpty()) { - Kit *kit = 0; - if (kits.contains(KitManager::defaultKit())) - kit = KitManager::defaultKit(); - else - kit = kits.first(); + Kit *kit = kits.contains(KitManager::defaultKit()) ? KitManager::defaultKit() : kits.first(); addTarget(createTarget(kit)); } } diff --git a/src/plugins/qmlprojectmanager/qmlproject.h b/src/plugins/qmlprojectmanager/qmlproject.h index 1728aad36fa..0a23f43a792 100644 --- a/src/plugins/qmlprojectmanager/qmlproject.h +++ b/src/plugins/qmlprojectmanager/qmlproject.h @@ -48,7 +48,7 @@ public: explicit QmlProject(const Utils::FileName &filename); ~QmlProject() override; - bool supportsKit(ProjectExplorer::Kit *k, QString *errorMessage) const override; + bool supportsKit(const ProjectExplorer::Kit *k, QString *errorMessage) const override; bool validProjectFile() const;