From 4136b6e7959281659f284d1ac010131d4cb85436 Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 25 May 2023 09:23:04 +0200 Subject: [PATCH] Meson: Compactify MesonRunConfiguration setup Change-Id: I10a600b601301283dbdc960d9e07e5587b52c031 Reviewed-by: Reviewed-by: Alessandro Portale --- .../mesonrunconfiguration.cpp | 93 +++++++++---------- .../mesonrunconfiguration.h | 15 +-- 2 files changed, 47 insertions(+), 61 deletions(-) diff --git a/src/plugins/mesonprojectmanager/mesonrunconfiguration.cpp b/src/plugins/mesonprojectmanager/mesonrunconfiguration.cpp index 4af312fda9c..74919a49696 100644 --- a/src/plugins/mesonprojectmanager/mesonrunconfiguration.cpp +++ b/src/plugins/mesonprojectmanager/mesonrunconfiguration.cpp @@ -6,67 +6,65 @@ #include "mesonpluginconstants.h" #include -#include -#include #include #include #include -#include #include using namespace ProjectExplorer; +using namespace Utils; -namespace MesonProjectManager { -namespace Internal { +namespace MesonProjectManager::Internal { -MesonRunConfiguration::MesonRunConfiguration(Target *target, Utils::Id id) - : RunConfiguration{target, id} +class MesonRunConfiguration final : public RunConfiguration { - auto envAspect = addAspect(); - envAspect->setSupportForBuildEnvironment(target); +public: + MesonRunConfiguration(Target *target, Id id) + : RunConfiguration(target, id) + { + auto envAspect = addAspect(); + envAspect->setSupportForBuildEnvironment(target); - addAspect(target, ExecutableAspect::RunDevice); - addAspect(macroExpander()); - addAspect(macroExpander(), envAspect); - addAspect(); + addAspect(target, ExecutableAspect::RunDevice); + addAspect(macroExpander()); + addAspect(macroExpander(), envAspect); + addAspect(); - auto libAspect = addAspect(); - connect(libAspect, &UseLibraryPathsAspect::changed, - envAspect, &EnvironmentAspect::environmentChanged); - - if (Utils::HostOsInfo::isMacHost()) { - auto dyldAspect = addAspect(); - connect(dyldAspect, &UseLibraryPathsAspect::changed, + auto libAspect = addAspect(); + connect(libAspect, &UseLibraryPathsAspect::changed, envAspect, &EnvironmentAspect::environmentChanged); - envAspect->addModifier([dyldAspect](Utils::Environment &env) { - if (dyldAspect->value()) - env.set(QLatin1String("DYLD_IMAGE_SUFFIX"), QLatin1String("_debug")); + + if (HostOsInfo::isMacHost()) { + auto dyldAspect = addAspect(); + connect(dyldAspect, &UseLibraryPathsAspect::changed, + envAspect, &EnvironmentAspect::environmentChanged); + envAspect->addModifier([dyldAspect](Utils::Environment &env) { + if (dyldAspect->value()) + env.set(QLatin1String("DYLD_IMAGE_SUFFIX"), QLatin1String("_debug")); + }); + } + + envAspect->addModifier([this, libAspect](Environment &env) { + BuildTargetInfo bti = buildTargetInfo(); + if (bti.runEnvModifier) + bti.runEnvModifier(env, libAspect->value()); }); + + setUpdater([this] { + if (!activeBuildSystem()) + return; + + BuildTargetInfo bti = buildTargetInfo(); + aspect()->setUseTerminalHint(bti.usesTerminal); + aspect()->setExecutable(bti.targetFilePath); + aspect()->setDefaultWorkingDirectory(bti.workingDirectory); + emit aspect()->environmentChanged(); + }); + + connect(target, &Target::buildSystemUpdated, this, &RunConfiguration::update); } - - envAspect->addModifier([this, libAspect](Utils::Environment &env) { - BuildTargetInfo bti = buildTargetInfo(); - if (bti.runEnvModifier) - bti.runEnvModifier(env, libAspect->value()); - }); - - setUpdater([this] { updateTargetInformation(); }); - - connect(target, &Target::buildSystemUpdated, this, &RunConfiguration::update); -} - -void MesonRunConfiguration::updateTargetInformation() -{ - if (!activeBuildSystem()) - return; - - BuildTargetInfo bti = buildTargetInfo(); - aspect()->setUseTerminalHint(bti.usesTerminal); - aspect()->setExecutable(bti.targetFilePath); - aspect()->setDefaultWorkingDirectory(bti.workingDirectory); - emit aspect()->environmentChanged(); -} +}; MesonRunConfigurationFactory::MesonRunConfigurationFactory() { @@ -75,5 +73,4 @@ MesonRunConfigurationFactory::MesonRunConfigurationFactory() addSupportedTargetDeviceType(ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE); } -} // namespace Internal -} // namespace MesonProjectManager +} // MesonProjectManager::Internal diff --git a/src/plugins/mesonprojectmanager/mesonrunconfiguration.h b/src/plugins/mesonprojectmanager/mesonrunconfiguration.h index 8a23dcbec4a..8c1f7580975 100644 --- a/src/plugins/mesonprojectmanager/mesonrunconfiguration.h +++ b/src/plugins/mesonprojectmanager/mesonrunconfiguration.h @@ -5,17 +5,7 @@ #include -namespace MesonProjectManager { -namespace Internal { - -class MesonRunConfiguration final : public ProjectExplorer::RunConfiguration -{ -public: - MesonRunConfiguration(ProjectExplorer::Target *target, Utils::Id id); - -private: - void updateTargetInformation(); -}; +namespace MesonProjectManager::Internal { class MesonRunConfigurationFactory final : public ProjectExplorer::RunConfigurationFactory { @@ -23,5 +13,4 @@ public: MesonRunConfigurationFactory(); }; -} // namespace Internal -} // namespace MesonProjectManager +} // MesonProjectManager::Internal