ProjectExplorer: Split EnvironmentAspect

... at least logically a bit more into hunks responsible for
one of the possible choices of base environments.

This makes it possible to move code that modifies individual
cases closer to the only place that uses it.

Change-Id: I1c87bb869e04e44b92ff097b0bf25274f93808be
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2019-03-07 10:10:22 +01:00
parent 9606e240f7
commit 6faaea8d0c
17 changed files with 160 additions and 190 deletions

View File

@@ -52,8 +52,21 @@ namespace Internal {
QbsRunConfiguration::QbsRunConfiguration(Target *target, Core::Id id)
: RunConfiguration(target, id)
{
auto envAspect = addAspect<LocalEnvironmentAspect>(target,
[this](Environment &env) { addToBaseEnvironment(env); });
auto envAspect = addAspect<LocalEnvironmentAspect>(target);
envAspect->addModifier([this](Environment &env) {
bool usingLibraryPaths = aspect<UseLibraryPathsAspect>()->value();
const auto key = qMakePair(env.toStringList(), usingLibraryPaths);
const auto it = m_envCache.constFind(key);
if (it != m_envCache.constEnd()) {
env = it.value();
return;
}
BuildTargetInfo bti = buildTargetInfo();
if (bti.runEnvModifier)
bti.runEnvModifier(env, usingLibraryPaths);
m_envCache.insert(key, env);
});
addAspect<ExecutableAspect>();
addAspect<ArgumentsAspect>();
@@ -69,6 +82,10 @@ QbsRunConfiguration::QbsRunConfiguration(Target *target, Core::Id id)
auto dyldAspect = addAspect<UseDyldSuffixAspect>();
connect(dyldAspect, &UseDyldSuffixAspect::changed,
envAspect, &EnvironmentAspect::environmentChanged);
envAspect->addModifier([dyldAspect](Environment &env) {
if (dyldAspect->value())
env.set("DYLD_IMAGE_SUFFIX", "_debug");
});
}
connect(project(), &Project::parsingFinished, this,
@@ -108,26 +125,6 @@ void QbsRunConfiguration::doAdditionalSetup(const RunConfigurationCreationInfo &
updateTargetInformation();
}
void QbsRunConfiguration::addToBaseEnvironment(Utils::Environment &env) const
{
if (auto dyldAspect = aspect<UseDyldSuffixAspect>()) {
if (dyldAspect->value())
env.set("DYLD_IMAGE_SUFFIX", "_debug");
}
bool usingLibraryPaths = aspect<UseLibraryPathsAspect>()->value();
const auto key = qMakePair(env.toStringList(), usingLibraryPaths);
const auto it = m_envCache.constFind(key);
if (it != m_envCache.constEnd()) {
env = it.value();
return;
}
BuildTargetInfo bti = buildTargetInfo();
if (bti.runEnvModifier)
bti.runEnvModifier(env, usingLibraryPaths);
m_envCache.insert(key, env);
}
Utils::FileName QbsRunConfiguration::executableToRun(const BuildTargetInfo &targetInfo) const
{
const FileName appInBuildDir = targetInfo.targetFilePath;

View File

@@ -41,8 +41,6 @@ class QbsRunConfiguration : public ProjectExplorer::RunConfiguration
public:
QbsRunConfiguration(ProjectExplorer::Target *target, Core::Id id);
void addToBaseEnvironment(Utils::Environment &env) const;
private:
Utils::FileName executableToRun(const ProjectExplorer::BuildTargetInfo &targetInfo) const;
QVariantMap toMap() const final;