Meson: Compactify MesonRunConfiguration setup

Change-Id: I10a600b601301283dbdc960d9e07e5587b52c031
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
hjk
2023-05-25 09:23:04 +02:00
parent 6ab66690af
commit 4136b6e795
2 changed files with 47 additions and 61 deletions

View File

@@ -6,67 +6,65 @@
#include "mesonpluginconstants.h" #include "mesonpluginconstants.h"
#include <projectexplorer/buildsystem.h> #include <projectexplorer/buildsystem.h>
#include <projectexplorer/desktoprunconfiguration.h>
#include <projectexplorer/environmentaspect.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/runconfigurationaspects.h> #include <projectexplorer/runconfigurationaspects.h>
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
#include <utils/environment.h>
#include <utils/hostosinfo.h> #include <utils/hostosinfo.h>
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Utils;
namespace MesonProjectManager { namespace MesonProjectManager::Internal {
namespace Internal {
MesonRunConfiguration::MesonRunConfiguration(Target *target, Utils::Id id) class MesonRunConfiguration final : public RunConfiguration
: RunConfiguration{target, id}
{ {
auto envAspect = addAspect<EnvironmentAspect>(); public:
envAspect->setSupportForBuildEnvironment(target); MesonRunConfiguration(Target *target, Id id)
: RunConfiguration(target, id)
{
auto envAspect = addAspect<EnvironmentAspect>();
envAspect->setSupportForBuildEnvironment(target);
addAspect<ExecutableAspect>(target, ExecutableAspect::RunDevice); addAspect<ExecutableAspect>(target, ExecutableAspect::RunDevice);
addAspect<ArgumentsAspect>(macroExpander()); addAspect<ArgumentsAspect>(macroExpander());
addAspect<WorkingDirectoryAspect>(macroExpander(), envAspect); addAspect<WorkingDirectoryAspect>(macroExpander(), envAspect);
addAspect<TerminalAspect>(); addAspect<TerminalAspect>();
auto libAspect = addAspect<UseLibraryPathsAspect>(); auto libAspect = addAspect<UseLibraryPathsAspect>();
connect(libAspect, &UseLibraryPathsAspect::changed, connect(libAspect, &UseLibraryPathsAspect::changed,
envAspect, &EnvironmentAspect::environmentChanged);
if (Utils::HostOsInfo::isMacHost()) {
auto dyldAspect = addAspect<UseDyldSuffixAspect>();
connect(dyldAspect, &UseLibraryPathsAspect::changed,
envAspect, &EnvironmentAspect::environmentChanged); envAspect, &EnvironmentAspect::environmentChanged);
envAspect->addModifier([dyldAspect](Utils::Environment &env) {
if (dyldAspect->value()) if (HostOsInfo::isMacHost()) {
env.set(QLatin1String("DYLD_IMAGE_SUFFIX"), QLatin1String("_debug")); auto dyldAspect = addAspect<UseDyldSuffixAspect>();
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<TerminalAspect>()->setUseTerminalHint(bti.usesTerminal);
aspect<ExecutableAspect>()->setExecutable(bti.targetFilePath);
aspect<WorkingDirectoryAspect>()->setDefaultWorkingDirectory(bti.workingDirectory);
emit aspect<EnvironmentAspect>()->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<TerminalAspect>()->setUseTerminalHint(bti.usesTerminal);
aspect<ExecutableAspect>()->setExecutable(bti.targetFilePath);
aspect<WorkingDirectoryAspect>()->setDefaultWorkingDirectory(bti.workingDirectory);
emit aspect<EnvironmentAspect>()->environmentChanged();
}
MesonRunConfigurationFactory::MesonRunConfigurationFactory() MesonRunConfigurationFactory::MesonRunConfigurationFactory()
{ {
@@ -75,5 +73,4 @@ MesonRunConfigurationFactory::MesonRunConfigurationFactory()
addSupportedTargetDeviceType(ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE); addSupportedTargetDeviceType(ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE);
} }
} // namespace Internal } // MesonProjectManager::Internal
} // namespace MesonProjectManager

View File

@@ -5,17 +5,7 @@
#include <projectexplorer/runconfiguration.h> #include <projectexplorer/runconfiguration.h>
namespace MesonProjectManager { namespace MesonProjectManager::Internal {
namespace Internal {
class MesonRunConfiguration final : public ProjectExplorer::RunConfiguration
{
public:
MesonRunConfiguration(ProjectExplorer::Target *target, Utils::Id id);
private:
void updateTargetInformation();
};
class MesonRunConfigurationFactory final : public ProjectExplorer::RunConfigurationFactory class MesonRunConfigurationFactory final : public ProjectExplorer::RunConfigurationFactory
{ {
@@ -23,5 +13,4 @@ public:
MesonRunConfigurationFactory(); MesonRunConfigurationFactory();
}; };
} // namespace Internal } // MesonProjectManager::Internal
} // namespace MesonProjectManager