From c81efc39c8c900ced720aef17f2dde0d37e85a2a Mon Sep 17 00:00:00 2001 From: Dominik Holland Date: Fri, 12 Jan 2024 14:04:37 +0100 Subject: [PATCH] Create RunConfiguration specific DebugWorkerFactories Instead of relying on the DebuggerRunWorkerFactory to match for all RunConfiguration, every plugin needs to create a WorkerFactory for its own RunConfiguration. Similar to the SimpleTargetRunnerFactory there is now a SimpleDebugRunnerFactory which makes the setup easy. Change-Id: I25aaabcd70f7ac649baeab4eb4c7e88d53dac91e Reviewed-by: hjk --- src/plugins/debugger/debuggerconstants.h | 2 ++ src/plugins/debugger/debuggerruncontrol.cpp | 5 ++++- src/plugins/debugger/debuggerruncontrol.h | 14 ++++++++++++++ .../haskell/haskellrunconfiguration.cpp | 4 ++++ .../mesonprojectplugin.cpp | 4 ++++ src/plugins/nim/nimplugin.cpp | 5 +++++ .../desktoprunconfiguration.cpp | 10 +++------- .../projectexplorerconstants.h | 5 +++++ src/plugins/projectexplorer/runcontrol.cpp | 19 +++++++++++++++++++ src/plugins/projectexplorer/runcontrol.h | 3 +++ src/plugins/python/pythonplugin.cpp | 6 +++++- .../qmlprojectmanager/qmlprojectplugin.cpp | 4 ++++ 12 files changed, 72 insertions(+), 9 deletions(-) diff --git a/src/plugins/debugger/debuggerconstants.h b/src/plugins/debugger/debuggerconstants.h index d1f70644f6d..2011c3d7a3a 100644 --- a/src/plugins/debugger/debuggerconstants.h +++ b/src/plugins/debugger/debuggerconstants.h @@ -14,6 +14,8 @@ const char MODE_DEBUG[] = "Mode.Debug"; // Debug mode context const char C_DEBUGMODE[] = "Debugger.DebugMode"; +const char DEBUGGER_RUN_FACTORY[] = "RunWorkerFactory.DebuggerRunWorkerFactory"; + } // namespace Constants // Keep in sync with dumper.py diff --git a/src/plugins/debugger/debuggerruncontrol.cpp b/src/plugins/debugger/debuggerruncontrol.cpp index 5adcc2e4df2..a242fa5b3f2 100644 --- a/src/plugins/debugger/debuggerruncontrol.cpp +++ b/src/plugins/debugger/debuggerruncontrol.cpp @@ -1092,12 +1092,15 @@ void DebugServerRunner::setAttachPid(ProcessHandle pid) DebuggerRunWorkerFactory::DebuggerRunWorkerFactory() { setProduct(); + setId(Constants::DEBUGGER_RUN_FACTORY); addSupportedRunMode(ProjectExplorer::Constants::DEBUG_RUN_MODE); addSupportedRunMode(ProjectExplorer::Constants::DAP_CMAKE_DEBUG_RUN_MODE); addSupportedRunMode(ProjectExplorer::Constants::DAP_GDB_DEBUG_RUN_MODE); - addSupportedRunMode(ProjectExplorer::Constants::DAP_PY_DEBUG_RUN_MODE); addSupportedDeviceType(ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE); addSupportedDeviceType("DockerDeviceType"); + addSupportedRunConfig(ProjectExplorer::Constants::QMAKE_RUNCONFIG_ID); + addSupportedRunConfig(ProjectExplorer::Constants::QBS_RUNCONFIG_ID); + addSupportedRunConfig(ProjectExplorer::Constants::CMAKE_RUNCONFIG_ID); } } // Debugger diff --git a/src/plugins/debugger/debuggerruncontrol.h b/src/plugins/debugger/debuggerruncontrol.h index 49db615b09d..39fb7e9507f 100644 --- a/src/plugins/debugger/debuggerruncontrol.h +++ b/src/plugins/debugger/debuggerruncontrol.h @@ -8,6 +8,7 @@ #include "debuggerengine.h" #include "terminal.h" +#include #include #include @@ -160,6 +161,19 @@ public: DebuggerRunWorkerFactory(); }; +class SimpleDebugRunnerFactory final : public ProjectExplorer::RunWorkerFactory +{ +public: + explicit SimpleDebugRunnerFactory(const QList &runConfigs, const QList &extraRunModes = {}) + { + cloneProduct(Constants::DEBUGGER_RUN_FACTORY); + addSupportedRunMode(ProjectExplorer::Constants::DEBUG_RUN_MODE); + for (const Utils::Id &id : extraRunModes) + addSupportedRunMode(id); + setSupportedRunConfigs(runConfigs); + } +}; + extern DEBUGGER_EXPORT const char DebugServerRunnerWorkerId[]; extern DEBUGGER_EXPORT const char GdbServerPortGathererWorkerId[]; diff --git a/src/plugins/haskell/haskellrunconfiguration.cpp b/src/plugins/haskell/haskellrunconfiguration.cpp index 5c2162757b2..bdb5a70e161 100644 --- a/src/plugins/haskell/haskellrunconfiguration.cpp +++ b/src/plugins/haskell/haskellrunconfiguration.cpp @@ -7,6 +7,8 @@ #include "haskelltr.h" #include "haskellsettings.h" +#include + #include #include #include @@ -18,6 +20,7 @@ #include +using namespace Debugger; using namespace ProjectExplorer; using namespace Utils; @@ -92,6 +95,7 @@ void setupHaskellRunSupport() { static HaskellRunConfigurationFactory runConfigFactory; static SimpleTargetRunnerFactory runWorkerFactory{{Constants::C_HASKELL_RUNCONFIG_ID}}; + static SimpleDebugRunnerFactory debugWorkerFactory{{Constants::C_HASKELL_RUNCONFIG_ID}}; } } // Haskell::Internal diff --git a/src/plugins/mesonprojectmanager/mesonprojectplugin.cpp b/src/plugins/mesonprojectmanager/mesonprojectplugin.cpp index 3b3a9e6b862..a9a233fa9ee 100644 --- a/src/plugins/mesonprojectmanager/mesonprojectplugin.cpp +++ b/src/plugins/mesonprojectmanager/mesonprojectplugin.cpp @@ -10,6 +10,8 @@ #include "toolssettingsaccessor.h" #include "toolssettingspage.h" +#include + #include #include @@ -18,6 +20,7 @@ #include +using namespace Debugger; using namespace ProjectExplorer; using namespace Utils; @@ -34,6 +37,7 @@ public: MesonActionsManager m_actions; MachineFileManager m_machineFilesManager; SimpleTargetRunnerFactory m_mesonRunWorkerFactory{{m_runConfigurationFactory.runConfigurationId()}}; + SimpleDebugRunnerFactory m_mesonDebugRunWorkerFactory{{m_runConfigurationFactory.runConfigurationId()}}; }; class MesonProjectPlugin final : public ExtensionSystem::IPlugin diff --git a/src/plugins/nim/nimplugin.cpp b/src/plugins/nim/nimplugin.cpp index 8d4f389095d..eb1266b6637 100644 --- a/src/plugins/nim/nimplugin.cpp +++ b/src/plugins/nim/nimplugin.cpp @@ -21,6 +21,8 @@ #include +#include + #include #include #include @@ -32,6 +34,7 @@ #include #include +using namespace Debugger; using namespace Utils; using namespace ProjectExplorer; @@ -48,6 +51,8 @@ public: NimbleTestConfigurationFactory nimbleTestConfigFactory; SimpleTargetRunnerFactory nimRunWorkerFactory{{nimRunConfigFactory.runConfigurationId()}}; SimpleTargetRunnerFactory nimbleRunWorkerFactory{{nimbleRunConfigFactory.runConfigurationId()}}; + SimpleDebugRunnerFactory nimDebugWorkerFactory{{nimRunConfigFactory.runConfigurationId()}}; + SimpleDebugRunnerFactory nimbleDebugWorkerFactory{{nimbleRunConfigFactory.runConfigurationId()}}; SimpleTargetRunnerFactory nimbleTestWorkerFactory{{nimbleTestConfigFactory.runConfigurationId()}}; NimbleBuildStepFactory nimbleBuildStepFactory; NimbleTaskStepFactory nimbleTaskStepFactory; diff --git a/src/plugins/projectexplorer/desktoprunconfiguration.cpp b/src/plugins/projectexplorer/desktoprunconfiguration.cpp index afcfe3607c5..9c5b4df6e83 100644 --- a/src/plugins/projectexplorer/desktoprunconfiguration.cpp +++ b/src/plugins/projectexplorer/desktoprunconfiguration.cpp @@ -168,13 +168,9 @@ public: {} }; -const char QMAKE_RUNCONFIG_ID[] = "Qt4ProjectManager.Qt4RunConfiguration:"; -const char QBS_RUNCONFIG_ID[] = "Qbs.RunConfiguration:"; -const char CMAKE_RUNCONFIG_ID[] = "CMakeProjectManager.CMakeRunConfiguration."; - CMakeRunConfigurationFactory::CMakeRunConfigurationFactory() { - registerRunConfiguration(CMAKE_RUNCONFIG_ID); + registerRunConfiguration(ProjectExplorer::Constants::CMAKE_RUNCONFIG_ID); addSupportedProjectType(CMakeProjectManager::Constants::CMAKE_PROJECT_ID); addSupportedTargetDeviceType(ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE); addSupportedTargetDeviceType(Docker::Constants::DOCKER_DEVICE_TYPE); @@ -182,7 +178,7 @@ CMakeRunConfigurationFactory::CMakeRunConfigurationFactory() QbsRunConfigurationFactory::QbsRunConfigurationFactory() { - registerRunConfiguration(QBS_RUNCONFIG_ID); + registerRunConfiguration(ProjectExplorer::Constants::QBS_RUNCONFIG_ID); addSupportedProjectType(QbsProjectManager::Constants::PROJECT_ID); addSupportedTargetDeviceType(ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE); addSupportedTargetDeviceType(Docker::Constants::DOCKER_DEVICE_TYPE); @@ -190,7 +186,7 @@ QbsRunConfigurationFactory::QbsRunConfigurationFactory() DesktopQmakeRunConfigurationFactory::DesktopQmakeRunConfigurationFactory() { - registerRunConfiguration(QMAKE_RUNCONFIG_ID); + registerRunConfiguration(ProjectExplorer::Constants::QMAKE_RUNCONFIG_ID); addSupportedProjectType(QmakeProjectManager::Constants::QMAKEPROJECT_ID); addSupportedTargetDeviceType(ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE); addSupportedTargetDeviceType(Docker::Constants::DOCKER_DEVICE_TYPE); diff --git a/src/plugins/projectexplorer/projectexplorerconstants.h b/src/plugins/projectexplorer/projectexplorerconstants.h index dbf650b7c49..ead0c982221 100644 --- a/src/plugins/projectexplorer/projectexplorerconstants.h +++ b/src/plugins/projectexplorer/projectexplorerconstants.h @@ -176,6 +176,11 @@ const char QML_PREVIEW_RUNNER[]="RunConfiguration.QmlPreviewRunner"; const char PERFPROFILER_RUN_MODE[]="PerfProfiler.RunMode"; const char PERFPROFILER_RUNNER[]="PerfProfiler.Runner"; +// RunConfig +const char QMAKE_RUNCONFIG_ID[] = "Qt4ProjectManager.Qt4RunConfiguration:"; +const char QBS_RUNCONFIG_ID[] = "Qbs.RunConfiguration:"; +const char CMAKE_RUNCONFIG_ID[] = "CMakeProjectManager.CMakeRunConfiguration."; + // Navigation Widget const char PROJECTTREE_ID[] = "Projects"; diff --git a/src/plugins/projectexplorer/runcontrol.cpp b/src/plugins/projectexplorer/runcontrol.cpp index 17d87c8ab29..7077808d849 100644 --- a/src/plugins/projectexplorer/runcontrol.cpp +++ b/src/plugins/projectexplorer/runcontrol.cpp @@ -98,6 +98,25 @@ void RunWorkerFactory::addSupportedDeviceType(Id deviceType) m_supportedDeviceTypes.append(deviceType); } +void RunWorkerFactory::cloneProduct(Id exitstingStepId, Id overrideId) +{ + for (RunWorkerFactory *factory : g_runWorkerFactories) { + if (factory->m_id == exitstingStepId) { + m_producer = factory->m_producer; + // Other bits are intentionally not copied as they are unlikely to be + // useful in the cloner's context. The cloner can/has to finish the + // setup on its own. + break; + } + } + // Existence should be guaranteed by plugin dependencies. In case it fails, + // bark and keep the factory in a state where the invalid m_stepId keeps it + // inaction. + QTC_ASSERT(m_producer, return); + if (overrideId.isValid()) + m_id = overrideId; +} + bool RunWorkerFactory::canCreate(Id runMode, Id deviceType, const QString &runConfigId) const { if (!m_supportedRunModes.contains(runMode)) diff --git a/src/plugins/projectexplorer/runcontrol.h b/src/plugins/projectexplorer/runcontrol.h index b18291a3456..0700946f9a9 100644 --- a/src/plugins/projectexplorer/runcontrol.h +++ b/src/plugins/projectexplorer/runcontrol.h @@ -107,11 +107,13 @@ public: protected: template void setProduct() { setProducer([](RunControl *rc) { return new Worker(rc); }); } + void setId(Utils::Id id) { m_id = id; } void setProducer(const WorkerCreator &producer); void setSupportedRunConfigs(const QList &runConfigs); void addSupportedRunMode(Utils::Id runMode); void addSupportedRunConfig(Utils::Id runConfig); void addSupportedDeviceType(Utils::Id deviceType); + void cloneProduct(Utils::Id exitstingStepId, Utils::Id overrideId = Utils::Id()); private: friend class RunControl; @@ -122,6 +124,7 @@ private: QList m_supportedRunModes; QList m_supportedRunConfigurations; QList m_supportedDeviceTypes; + Utils::Id m_id; }; /** diff --git a/src/plugins/python/pythonplugin.cpp b/src/plugins/python/pythonplugin.cpp index 29964b83255..ed0c14c7b19 100644 --- a/src/plugins/python/pythonplugin.cpp +++ b/src/plugins/python/pythonplugin.cpp @@ -13,6 +13,8 @@ #include "pythontr.h" #include "pythonwizardpage.h" +#include + #include #include @@ -25,6 +27,7 @@ #include #include +using namespace Debugger; using namespace ProjectExplorer; using namespace Utils; @@ -45,6 +48,7 @@ public: PySideBuildStepFactory buildStepFactory; PythonBuildConfigurationFactory buildConfigFactory; SimpleTargetRunnerFactory runWorkerFactory{{runConfigFactory.runConfigurationId()}}; + SimpleDebugRunnerFactory debugRunWorkerFactory{{runConfigFactory.runConfigurationId()}, {ProjectExplorer::Constants::DAP_PY_DEBUG_RUN_MODE}}; PythonSettings settings; PythonWizardPageFactory pythonWizardPageFactory; }; @@ -84,7 +88,7 @@ private: { // Add MIME overlay icons (these icons displayed at Project dock panel) const QString imageFile = Utils::creatorTheme()->imageFile(Theme::IconOverlayPro, - ::Constants::FILEOVERLAY_PY); + ProjectExplorer::Constants::FILEOVERLAY_PY); FileIconProvider::registerIconOverlayForSuffix(imageFile, "py"); TaskHub::addCategory({PythonErrorTaskCategory, diff --git a/src/plugins/qmlprojectmanager/qmlprojectplugin.cpp b/src/plugins/qmlprojectmanager/qmlprojectplugin.cpp index abb366bd73d..7ccda14659a 100644 --- a/src/plugins/qmlprojectmanager/qmlprojectplugin.cpp +++ b/src/plugins/qmlprojectmanager/qmlprojectplugin.cpp @@ -21,6 +21,8 @@ #include #include +#include + #include #include @@ -55,6 +57,7 @@ #include using namespace Core; +using namespace Debugger; using namespace ProjectExplorer; using namespace Utils; @@ -97,6 +100,7 @@ class QmlProjectPluginPrivate public: QmlProjectRunConfigurationFactory runConfigFactory; SimpleTargetRunnerFactory runWorkerFactory{{runConfigFactory.runConfigurationId()}}; + SimpleDebugRunnerFactory debugRunWorkerFactory{{runConfigFactory.runConfigurationId()}}; QPointer lastMessageBox; QdsLandingPage *landingPage = nullptr; QdsLandingPageWidget *landingPageWidget = nullptr;