From 6e419d642a2c1e9d6f5cc334bdd58305fd01b3e5 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Wed, 7 Mar 2018 10:35:08 +0100 Subject: RunConfigurationFactories: Fix crash opening non-qmake based projects Make sure the Qnx RCs only get triggered for qmake-based projects and defend against broken set-ups using QTC_ASSERT. Task-number: QTCREATORBUG-19755 Change-Id: If64b73de49b0199308f767151d68909dc8b1bc53 Reviewed-by: hjk --- src/plugins/cmakeprojectmanager/cmakerunconfiguration.cpp | 3 ++- src/plugins/ios/iosrunfactories.cpp | 3 ++- src/plugins/qbsprojectmanager/qbsrunconfiguration.cpp | 2 +- src/plugins/qmakeandroidsupport/qmakeandroidrunfactories.cpp | 3 ++- src/plugins/qmakeprojectmanager/desktopqmakerunconfiguration.cpp | 6 ++++-- src/plugins/qnx/qnxrunconfigurationfactory.cpp | 9 +++++++-- src/plugins/winrt/winrtrunfactories.cpp | 3 ++- 7 files changed, 20 insertions(+), 9 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/cmakeprojectmanager/cmakerunconfiguration.cpp b/src/plugins/cmakeprojectmanager/cmakerunconfiguration.cpp index e59daaa0fe..6b68d47868 100644 --- a/src/plugins/cmakeprojectmanager/cmakerunconfiguration.cpp +++ b/src/plugins/cmakeprojectmanager/cmakerunconfiguration.cpp @@ -241,7 +241,8 @@ CMakeRunConfigurationFactory::CMakeRunConfigurationFactory(QObject *parent) : QList CMakeRunConfigurationFactory::availableBuildTargets(Target *parent, CreationMode) const { - CMakeProject *project = static_cast(parent->project()); + CMakeProject *project = qobject_cast(parent->project()); + QTC_ASSERT(project, return {}); const QStringList titles = project->buildTargetTitles(true); return Utils::transform(titles, [project](const QString &title) { BuildTargetInfo bti; diff --git a/src/plugins/ios/iosrunfactories.cpp b/src/plugins/ios/iosrunfactories.cpp index dccf82e952..854cf45c75 100644 --- a/src/plugins/ios/iosrunfactories.cpp +++ b/src/plugins/ios/iosrunfactories.cpp @@ -62,7 +62,8 @@ bool IosRunConfigurationFactory::canCreateHelper(Target *parent, const QString & QList IosRunConfigurationFactory::availableBuildTargets(Target *parent, CreationMode mode) const { - auto project = static_cast(parent->project()); + auto project = qobject_cast(parent->project()); + QTC_ASSERT(project, return {}); return project->buildTargets(mode, {ProjectType::ApplicationTemplate, ProjectType::SharedLibraryTemplate, ProjectType::AuxTemplate}); diff --git a/src/plugins/qbsprojectmanager/qbsrunconfiguration.cpp b/src/plugins/qbsprojectmanager/qbsrunconfiguration.cpp index e2324f39f9..ca0ed33f0c 100644 --- a/src/plugins/qbsprojectmanager/qbsrunconfiguration.cpp +++ b/src/plugins/qbsprojectmanager/qbsrunconfiguration.cpp @@ -388,7 +388,7 @@ QList QbsRunConfigurationFactory::availableBuildTargets(Target { QList products; - QbsProject *project = static_cast(parent->project()); + QbsProject *project = qobject_cast(parent->project()); if (!project || !project->qbsProject().isValid()) return {}; diff --git a/src/plugins/qmakeandroidsupport/qmakeandroidrunfactories.cpp b/src/plugins/qmakeandroidsupport/qmakeandroidrunfactories.cpp index e5c62c52dc..dfb0084c61 100644 --- a/src/plugins/qmakeandroidsupport/qmakeandroidrunfactories.cpp +++ b/src/plugins/qmakeandroidsupport/qmakeandroidrunfactories.cpp @@ -59,7 +59,8 @@ QmakeAndroidRunConfigurationFactory::QmakeAndroidRunConfigurationFactory(QObject QList QmakeAndroidRunConfigurationFactory::availableBuildTargets(Target *parent, CreationMode mode) const { - auto project = static_cast(parent->project()); + auto project = qobject_cast(parent->project()); + QTC_ASSERT(project, return {}); return project->buildTargets(mode, {ProjectType::ApplicationTemplate, ProjectType::SharedLibraryTemplate}); } diff --git a/src/plugins/qmakeprojectmanager/desktopqmakerunconfiguration.cpp b/src/plugins/qmakeprojectmanager/desktopqmakerunconfiguration.cpp index 549db31d2f..6ead3531d9 100644 --- a/src/plugins/qmakeprojectmanager/desktopqmakerunconfiguration.cpp +++ b/src/plugins/qmakeprojectmanager/desktopqmakerunconfiguration.cpp @@ -439,14 +439,16 @@ DesktopQmakeRunConfigurationFactory::DesktopQmakeRunConfigurationFactory(QObject bool DesktopQmakeRunConfigurationFactory::canCreateHelper(Target *parent, const QString &buildTarget) const { - QmakeProject *project = static_cast(parent->project()); + QmakeProject *project = qobject_cast(parent->project()); + QTC_ASSERT(project, return {}); return project->hasApplicationProFile(Utils::FileName::fromString(buildTarget)); } QList DesktopQmakeRunConfigurationFactory::availableBuildTargets(Target *parent, CreationMode mode) const { - QmakeProject *project = static_cast(parent->project()); + QmakeProject *project = qobject_cast(parent->project()); + QTC_ASSERT(project, return {}); return project->buildTargets(mode); } diff --git a/src/plugins/qnx/qnxrunconfigurationfactory.cpp b/src/plugins/qnx/qnxrunconfigurationfactory.cpp index 05112b36bb..5e2e2c8e46 100644 --- a/src/plugins/qnx/qnxrunconfigurationfactory.cpp +++ b/src/plugins/qnx/qnxrunconfigurationfactory.cpp @@ -32,6 +32,7 @@ #include #include #include +#include using namespace ProjectExplorer; @@ -41,14 +42,17 @@ namespace Internal { QnxRunConfigurationFactory::QnxRunConfigurationFactory(QObject *parent) : ProjectExplorer::IRunConfigurationFactory(parent) { - registerRunConfiguration(Constants::QNX_QNX_RUNCONFIGURATION_PREFIX); - setSupportedTargetDeviceTypes({Constants::QNX_QNX_OS_TYPE}); + registerRunConfiguration(Qnx::Constants::QNX_QNX_RUNCONFIGURATION_PREFIX); + setSupportedTargetDeviceTypes({Qnx::Constants::QNX_QNX_OS_TYPE}); + addSupportedProjectType(QmakeProjectManager::Constants::QMAKEPROJECT_ID); } QList QnxRunConfigurationFactory::availableBuildTargets(Target *parent, CreationMode mode) const { auto project = qobject_cast(parent->project()); + QTC_ASSERT(project, return {}); + const QList buildTargets = project->buildTargets(mode); return Utils::transform(buildTargets, [](BuildTargetInfo bti) { bti.displayName = tr("%1 on QNX Device").arg(QFileInfo(bti.targetName).completeBaseName()); @@ -60,6 +64,7 @@ bool QnxRunConfigurationFactory::canCreateHelper(ProjectExplorer::Target *parent const QString &buildTarget) const { auto project = qobject_cast(parent->project()); + QTC_ASSERT(project, return false); return project->hasApplicationProFile(Utils::FileName::fromString(buildTarget)); } diff --git a/src/plugins/winrt/winrtrunfactories.cpp b/src/plugins/winrt/winrtrunfactories.cpp index 55e098db0c..f8bc558cfa 100644 --- a/src/plugins/winrt/winrtrunfactories.cpp +++ b/src/plugins/winrt/winrtrunfactories.cpp @@ -53,7 +53,8 @@ WinRtRunConfigurationFactory::WinRtRunConfigurationFactory() QList WinRtRunConfigurationFactory::availableBuildTargets(Target *parent, CreationMode mode) const { - QmakeProject *project = static_cast(parent->project()); + QmakeProject *project = qobject_cast(parent->project()); + QTC_ASSERT(project, return {}); const QList buildTargets = project->buildTargets(mode); return Utils::transform(buildTargets, [](BuildTargetInfo bti) { bti.displayName = tr("Run App Package"); -- cgit v1.2.1