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

@@ -107,10 +107,8 @@ void BaseStringListAspect::setLabel(const QString &label)
AndroidRunConfiguration::AndroidRunConfiguration(Target *target, Core::Id id) AndroidRunConfiguration::AndroidRunConfiguration(Target *target, Core::Id id)
: RunConfiguration(target, id) : RunConfiguration(target, id)
{ {
enum BaseEnvironmentBase { CleanEnvironmentBase };
auto envAspect = addAspect<EnvironmentAspect>(); auto envAspect = addAspect<EnvironmentAspect>();
envAspect->addSupportedBaseEnvironment(CleanEnvironmentBase, tr("Clean Environment")); envAspect->addSupportedBaseEnvironment(tr("Clean Environment"), {});
envAspect->setBaseEnvironmentGetter([] { return Utils::Environment(); });
addAspect<ArgumentsAspect>(); addAspect<ArgumentsAspect>();

View File

@@ -36,6 +36,7 @@
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Utils;
namespace CMakeProjectManager { namespace CMakeProjectManager {
namespace Internal { namespace Internal {
@@ -43,17 +44,18 @@ namespace Internal {
CMakeRunConfiguration::CMakeRunConfiguration(Target *target, Core::Id id) CMakeRunConfiguration::CMakeRunConfiguration(Target *target, Core::Id id)
: RunConfiguration(target, id) : RunConfiguration(target, id)
{ {
// Workaround for QTCREATORBUG-19354: auto envAspect = addAspect<LocalEnvironmentAspect>(target);
auto cmakeRunEnvironmentModifier = [target](Utils::Environment &env) {
if (!Utils::HostOsInfo::isWindowsHost())
return;
const Kit *k = target->kit(); // Workaround for QTCREATORBUG-19354:
const QtSupport::BaseQtVersion *qt = QtSupport::QtKitAspect::qtVersion(k); if (HostOsInfo::isWindowsHost()) {
if (qt) envAspect->addModifier([target](Environment &env) {
env.prependOrSetPath(qt->qmakeProperty("QT_INSTALL_BINS")); const Kit *k = target->kit();
}; if (const QtSupport::BaseQtVersion *qt = QtSupport::QtKitAspect::qtVersion(k)) {
auto envAspect = addAspect<LocalEnvironmentAspect>(target, cmakeRunEnvironmentModifier); const QString installBinPath = qt->qmakeProperty("QT_INSTALL_BINS");
env.prependOrSetPath(installBinPath);
}
});
}
addAspect<ExecutableAspect>(); addAspect<ExecutableAspect>();
addAspect<ArgumentsAspect>(); addAspect<ArgumentsAspect>();

View File

@@ -44,8 +44,7 @@ namespace Nim {
NimRunConfiguration::NimRunConfiguration(Target *target, Core::Id id) NimRunConfiguration::NimRunConfiguration(Target *target, Core::Id id)
: RunConfiguration(target, id) : RunConfiguration(target, id)
{ {
auto envAspect = addAspect<LocalEnvironmentAspect> auto envAspect = addAspect<LocalEnvironmentAspect>(target);
(target, LocalEnvironmentAspect::BaseEnvironmentModifier());
addAspect<ExecutableAspect>(); addAspect<ExecutableAspect>();
addAspect<ArgumentsAspect>(); addAspect<ArgumentsAspect>();

View File

@@ -184,8 +184,7 @@ CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Target *targe
CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Target *target, Core::Id id) CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Target *target, Core::Id id)
: RunConfiguration(target, id) : RunConfiguration(target, id)
{ {
auto envAspect = addAspect<LocalEnvironmentAspect> auto envAspect = addAspect<LocalEnvironmentAspect>(target);
(target, LocalEnvironmentAspect::BaseEnvironmentModifier());
auto exeAspect = addAspect<ExecutableAspect>(); auto exeAspect = addAspect<ExecutableAspect>();
exeAspect->setSettingsKey("ProjectExplorer.CustomExecutableRunConfiguration.Executable"); exeAspect->setSettingsKey("ProjectExplorer.CustomExecutableRunConfiguration.Executable");

View File

@@ -30,6 +30,8 @@
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
using namespace Utils;
static const char BASE_KEY[] = "PE.EnvironmentAspect.Base"; static const char BASE_KEY[] = "PE.EnvironmentAspect.Base";
static const char CHANGES_KEY[] = "PE.EnvironmentAspect.Changes"; static const char CHANGES_KEY[] = "PE.EnvironmentAspect.Changes";
@@ -53,9 +55,7 @@ int EnvironmentAspect::baseEnvironmentBase() const
void EnvironmentAspect::setBaseEnvironmentBase(int base) void EnvironmentAspect::setBaseEnvironmentBase(int base)
{ {
QTC_ASSERT(base >= 0, return); QTC_ASSERT(base >= 0 && base < m_baseEnvironments.size(), return);
QTC_ASSERT(possibleBaseEnvironments().contains(base), return);
if (m_base != base) { if (m_base != base) {
m_base = base; m_base = base;
emit baseEnvironmentChanged(); emit baseEnvironmentChanged();
@@ -64,64 +64,81 @@ void EnvironmentAspect::setBaseEnvironmentBase(int base)
void EnvironmentAspect::setUserEnvironmentChanges(const QList<Utils::EnvironmentItem> &diff) void EnvironmentAspect::setUserEnvironmentChanges(const QList<Utils::EnvironmentItem> &diff)
{ {
if (m_changes != diff) { if (m_userChanges != diff) {
m_changes = diff; m_userChanges = diff;
emit userEnvironmentChangesChanged(m_changes); emit userEnvironmentChangesChanged(m_userChanges);
emit environmentChanged(); emit environmentChanged();
} }
} }
Utils::Environment EnvironmentAspect::environment() const Utils::Environment EnvironmentAspect::environment() const
{ {
Utils::Environment env = baseEnvironment(); QTC_ASSERT(m_base >= 0 && m_base < m_baseEnvironments.size(), return Environment());
env.modify(m_changes); Environment env = m_baseEnvironments.at(m_base).unmodifiedBaseEnvironment();
for (const EnvironmentModifier &modifier : m_modifiers)
modifier(env);
env.modify(m_userChanges);
return env; return env;
} }
QList<int> EnvironmentAspect::possibleBaseEnvironments() const const QStringList EnvironmentAspect::displayNames() const
{ {
return m_displayNames.keys(); return Utils::transform(m_baseEnvironments, &BaseEnvironment::displayName);
} }
QString EnvironmentAspect::baseEnvironmentDisplayName(int base) const void EnvironmentAspect::addModifier(const EnvironmentAspect::EnvironmentModifier &modifier)
{ {
return m_displayNames[base]; m_modifiers.append(modifier);
} }
void EnvironmentAspect::addSupportedBaseEnvironment(int base, const QString &displayName) void EnvironmentAspect::addSupportedBaseEnvironment(const QString &displayName,
const std::function<Environment()> &getter)
{ {
m_displayNames[base] = displayName; BaseEnvironment baseEnv;
baseEnv.displayName = displayName;
baseEnv.getter = getter;
m_baseEnvironments.append(baseEnv);
if (m_base == -1) if (m_base == -1)
setBaseEnvironmentBase(base); setBaseEnvironmentBase(m_baseEnvironments.size() - 1);
} }
void EnvironmentAspect::addPreferredBaseEnvironment(int base, const QString &displayName) void EnvironmentAspect::addPreferredBaseEnvironment(const QString &displayName,
const std::function<Environment()> &getter)
{ {
m_displayNames[base] = displayName; BaseEnvironment baseEnv;
setBaseEnvironmentBase(base); baseEnv.displayName = displayName;
baseEnv.getter = getter;
m_baseEnvironments.append(baseEnv);
setBaseEnvironmentBase(m_baseEnvironments.size() - 1);
} }
void EnvironmentAspect::fromMap(const QVariantMap &map) void EnvironmentAspect::fromMap(const QVariantMap &map)
{ {
m_base = map.value(QLatin1String(BASE_KEY), -1).toInt(); m_base = map.value(QLatin1String(BASE_KEY), -1).toInt();
m_changes = Utils::EnvironmentItem::fromStringList(map.value(QLatin1String(CHANGES_KEY)).toStringList()); m_userChanges = Utils::EnvironmentItem::fromStringList(map.value(QLatin1String(CHANGES_KEY)).toStringList());
} }
void EnvironmentAspect::toMap(QVariantMap &data) const void EnvironmentAspect::toMap(QVariantMap &data) const
{ {
data.insert(QLatin1String(BASE_KEY), m_base); data.insert(QLatin1String(BASE_KEY), m_base);
data.insert(QLatin1String(CHANGES_KEY), Utils::EnvironmentItem::toStringList(m_changes)); data.insert(QLatin1String(CHANGES_KEY), Utils::EnvironmentItem::toStringList(m_userChanges));
} }
Utils::Environment EnvironmentAspect::baseEnvironment() const Environment EnvironmentAspect::currentUnmodifiedBaseEnvironment() const
{ {
QTC_ASSERT(m_baseEnvironmentGetter, return Utils::Environment()); QTC_ASSERT(m_base >= 0 && m_base < m_baseEnvironments.size(), return Environment());
return m_baseEnvironmentGetter(); return m_baseEnvironments.at(m_base).unmodifiedBaseEnvironment();
} }
void EnvironmentAspect::setBaseEnvironmentGetter(const std::function<Utils::Environment ()> &getter) QString EnvironmentAspect::currentDisplayName() const
{ {
m_baseEnvironmentGetter = getter; QTC_ASSERT(m_base >= 0 && m_base < m_baseEnvironments.size(), return {});
return m_baseEnvironments[m_base].displayName;
}
Environment EnvironmentAspect::BaseEnvironment::unmodifiedBaseEnvironment() const
{
return getter ? getter() : Environment();
} }
} // namespace ProjectExplorer } // namespace ProjectExplorer

View File

@@ -43,24 +43,28 @@ class PROJECTEXPLORER_EXPORT EnvironmentAspect : public ProjectConfigurationAspe
public: public:
EnvironmentAspect(); EnvironmentAspect();
// The environment the user chose as base for his modifications.
Utils::Environment baseEnvironment() const;
void setBaseEnvironmentGetter(const std::function<Utils::Environment ()> &getter);
// The environment including the user's modifications. // The environment including the user's modifications.
Utils::Environment environment() const; Utils::Environment environment() const;
QList<int> possibleBaseEnvironments() const;
QString baseEnvironmentDisplayName(int base) const;
int baseEnvironmentBase() const; int baseEnvironmentBase() const;
void setBaseEnvironmentBase(int base); void setBaseEnvironmentBase(int base);
QList<Utils::EnvironmentItem> userEnvironmentChanges() const { return m_changes; } QList<Utils::EnvironmentItem> userEnvironmentChanges() const { return m_userChanges; }
void setUserEnvironmentChanges(const QList<Utils::EnvironmentItem> &diff); void setUserEnvironmentChanges(const QList<Utils::EnvironmentItem> &diff);
void addSupportedBaseEnvironment(int base, const QString &displayName); void addSupportedBaseEnvironment(const QString &displayName,
void addPreferredBaseEnvironment(int base, const QString &displayName); const std::function<Utils::Environment()> &getter);
void addPreferredBaseEnvironment(const QString &displayName,
const std::function<Utils::Environment()> &getter);
// The environment the user chose as base for his modifications.
Utils::Environment currentUnmodifiedBaseEnvironment() const;
QString currentDisplayName() const;
const QStringList displayNames() const;
using EnvironmentModifier = std::function<void(Utils::Environment &)>;
void addModifier(const EnvironmentModifier &);
signals: signals:
void baseEnvironmentChanged(); void baseEnvironmentChanged();
@@ -72,10 +76,18 @@ protected:
void toMap(QVariantMap &map) const override; void toMap(QVariantMap &map) const override;
private: private:
// One possible choice in the Environment aspect.
struct BaseEnvironment {
Utils::Environment unmodifiedBaseEnvironment() const;
std::function<Utils::Environment()> getter;
QString displayName;
};
int m_base = -1; int m_base = -1;
std::function<Utils::Environment()> m_baseEnvironmentGetter; QList<Utils::EnvironmentItem> m_userChanges;
QList<Utils::EnvironmentItem> m_changes; QList<EnvironmentModifier> m_modifiers;
QMap<int, QString> m_displayNames; QList<BaseEnvironment> m_baseEnvironments;
}; };
} // namespace ProjectExplorer } // namespace ProjectExplorer

View File

@@ -56,20 +56,13 @@ EnvironmentAspectWidget::EnvironmentAspectWidget(EnvironmentAspect *aspect, QWid
baseLayout->setMargin(0); baseLayout->setMargin(0);
auto label = new QLabel(tr("Base environment for this run configuration:"), this); auto label = new QLabel(tr("Base environment for this run configuration:"), this);
baseLayout->addWidget(label); baseLayout->addWidget(label);
m_baseEnvironmentComboBox = new QComboBox; m_baseEnvironmentComboBox = new QComboBox;
QList<int> bases = m_aspect->possibleBaseEnvironments(); for (const QString &displayName : m_aspect->displayNames())
int currentBase = m_aspect->baseEnvironmentBase(); m_baseEnvironmentComboBox->addItem(displayName);
QString baseDisplayName;
foreach (int i, bases) {
const QString displayName = m_aspect->baseEnvironmentDisplayName(i);
m_baseEnvironmentComboBox->addItem(displayName, i);
if (i == currentBase) {
m_baseEnvironmentComboBox->setCurrentIndex(m_baseEnvironmentComboBox->count() - 1);
baseDisplayName = displayName;
}
}
if (m_baseEnvironmentComboBox->count() == 1) if (m_baseEnvironmentComboBox->count() == 1)
m_baseEnvironmentComboBox->setEnabled(false); m_baseEnvironmentComboBox->setEnabled(false);
m_baseEnvironmentComboBox->setCurrentIndex(m_aspect->baseEnvironmentBase());
connect(m_baseEnvironmentComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), connect(m_baseEnvironmentComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &EnvironmentAspectWidget::baseEnvironmentSelected); this, &EnvironmentAspectWidget::baseEnvironmentSelected);
@@ -80,8 +73,8 @@ EnvironmentAspectWidget::EnvironmentAspectWidget(EnvironmentAspect *aspect, QWid
baseLayout->addWidget(additionalWidget); baseLayout->addWidget(additionalWidget);
m_environmentWidget = new EnvironmentWidget(this, baseEnvironmentWidget); m_environmentWidget = new EnvironmentWidget(this, baseEnvironmentWidget);
m_environmentWidget->setBaseEnvironment(m_aspect->baseEnvironment()); m_environmentWidget->setBaseEnvironment(m_aspect->currentUnmodifiedBaseEnvironment());
m_environmentWidget->setBaseEnvironmentText(baseDisplayName); m_environmentWidget->setBaseEnvironmentText(m_aspect->currentDisplayName());
m_environmentWidget->setUserChanges(m_aspect->userEnvironmentChanges()); m_environmentWidget->setUserChanges(m_aspect->userEnvironmentChanges());
m_environmentWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); m_environmentWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
topLayout->addWidget(m_environmentWidget); topLayout->addWidget(m_environmentWidget);
@@ -110,10 +103,9 @@ QWidget *EnvironmentAspectWidget::additionalWidget() const
void EnvironmentAspectWidget::baseEnvironmentSelected(int idx) void EnvironmentAspectWidget::baseEnvironmentSelected(int idx)
{ {
m_ignoreChange = true; m_ignoreChange = true;
int base = m_baseEnvironmentComboBox->itemData(idx).toInt(); m_aspect->setBaseEnvironmentBase(idx);
m_aspect->setBaseEnvironmentBase(base); m_environmentWidget->setBaseEnvironment(m_aspect->currentUnmodifiedBaseEnvironment());
m_environmentWidget->setBaseEnvironment(m_aspect->baseEnvironment()); m_environmentWidget->setBaseEnvironmentText(m_aspect->currentDisplayName());
m_environmentWidget->setBaseEnvironmentText(m_aspect->baseEnvironmentDisplayName(base));
m_ignoreChange = false; m_ignoreChange = false;
} }
@@ -127,8 +119,8 @@ void EnvironmentAspectWidget::changeBaseEnvironment()
if (m_baseEnvironmentComboBox->itemData(i).toInt() == base) if (m_baseEnvironmentComboBox->itemData(i).toInt() == base)
m_baseEnvironmentComboBox->setCurrentIndex(i); m_baseEnvironmentComboBox->setCurrentIndex(i);
} }
m_environmentWidget->setBaseEnvironmentText(m_aspect->baseEnvironmentDisplayName(base)); m_environmentWidget->setBaseEnvironmentText(m_aspect->currentDisplayName());
m_environmentWidget->setBaseEnvironment(m_aspect->baseEnvironment()); m_environmentWidget->setBaseEnvironment(m_aspect->currentUnmodifiedBaseEnvironment());
} }
void EnvironmentAspectWidget::userChangesEdited() void EnvironmentAspectWidget::userChangesEdited()
@@ -149,7 +141,7 @@ void EnvironmentAspectWidget::environmentChanged()
{ {
if (m_ignoreChange) if (m_ignoreChange)
return; return;
m_environmentWidget->setBaseEnvironment(m_aspect->baseEnvironment()); m_environmentWidget->setBaseEnvironment(m_aspect->currentUnmodifiedBaseEnvironment());
} }
} // namespace ProjectExplorer } // namespace ProjectExplorer

View File

@@ -32,51 +32,38 @@
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
using namespace Utils;
namespace ProjectExplorer { namespace ProjectExplorer {
enum BaseEnvironmentBase { LocalEnvironmentAspect::LocalEnvironmentAspect(Target *target)
CleanEnvironmentBase = 0,
SystemEnvironmentBase,
BuildEnvironmentBase
};
LocalEnvironmentAspect::LocalEnvironmentAspect(Target *target,
const BaseEnvironmentModifier &modifier)
{ {
addPreferredBaseEnvironment(BuildEnvironmentBase, tr("Build Environment")); addSupportedBaseEnvironment(tr("Clean Environment"), {});
addSupportedBaseEnvironment(SystemEnvironmentBase, tr("System Environment"));
addSupportedBaseEnvironment(CleanEnvironmentBase, tr("Clean Environment")); addSupportedBaseEnvironment(tr("System Environment"), [] {
return Environment::systemEnvironment();
});
addPreferredBaseEnvironment(tr("Build Environment"), [target] {
Environment env;
if (BuildConfiguration *bc = target->activeBuildConfiguration()) {
env = bc->environment();
} else { // Fallback for targets without buildconfigurations:
env = Environment::systemEnvironment();
target->kit()->addToEnvironment(env);
}
return env;
});
target->subscribeSignal(&BuildConfiguration::environmentChanged, target->subscribeSignal(&BuildConfiguration::environmentChanged,
this, &LocalEnvironmentAspect::buildEnvironmentHasChanged); this, &LocalEnvironmentAspect::buildEnvironmentHasChanged);
connect(target, &Target::activeBuildConfigurationChanged, connect(target, &Target::activeBuildConfigurationChanged,
this, &LocalEnvironmentAspect::buildEnvironmentHasChanged); this, &LocalEnvironmentAspect::buildEnvironmentHasChanged);
setBaseEnvironmentGetter([this, target, modifier] {
int base = baseEnvironmentBase();
Utils::Environment env;
if (base == static_cast<int>(BuildEnvironmentBase)) {
if (BuildConfiguration *bc = target->activeBuildConfiguration()) {
env = bc->environment();
} else { // Fallback for targets without buildconfigurations:
env = Utils::Environment::systemEnvironment();
target->kit()->addToEnvironment(env);
}
} else if (base == static_cast<int>(SystemEnvironmentBase)) {
env = Utils::Environment::systemEnvironment();
}
if (modifier)
modifier(env);
return env;
});
} }
void LocalEnvironmentAspect::buildEnvironmentHasChanged() void LocalEnvironmentAspect::buildEnvironmentHasChanged()
{ {
if (baseEnvironmentBase() == static_cast<int>(BuildEnvironmentBase)) emit environmentChanged();
emit environmentChanged();
} }
} // namespace ProjectExplorer } // namespace ProjectExplorer

View File

@@ -34,8 +34,7 @@ class PROJECTEXPLORER_EXPORT LocalEnvironmentAspect : public EnvironmentAspect
Q_OBJECT Q_OBJECT
public: public:
using BaseEnvironmentModifier = std::function<void(Utils::Environment &)>; explicit LocalEnvironmentAspect(Target *parent);
LocalEnvironmentAspect(Target *parent, const BaseEnvironmentModifier &modifier);
void buildEnvironmentHasChanged(); void buildEnvironmentHasChanged();
}; };

View File

@@ -270,7 +270,7 @@ PythonRunConfiguration::PythonRunConfiguration(Target *target, Core::Id id)
scriptAspect->setLabelText(tr("Script:")); scriptAspect->setLabelText(tr("Script:"));
scriptAspect->setDisplayStyle(BaseStringAspect::LabelDisplay); scriptAspect->setDisplayStyle(BaseStringAspect::LabelDisplay);
addAspect<LocalEnvironmentAspect>(target, LocalEnvironmentAspect::BaseEnvironmentModifier()); addAspect<LocalEnvironmentAspect>(target);
addAspect<ArgumentsAspect>(); addAspect<ArgumentsAspect>();
addAspect<TerminalAspect>(); addAspect<TerminalAspect>();

View File

@@ -52,8 +52,21 @@ namespace Internal {
QbsRunConfiguration::QbsRunConfiguration(Target *target, Core::Id id) QbsRunConfiguration::QbsRunConfiguration(Target *target, Core::Id id)
: RunConfiguration(target, id) : RunConfiguration(target, id)
{ {
auto envAspect = addAspect<LocalEnvironmentAspect>(target, auto envAspect = addAspect<LocalEnvironmentAspect>(target);
[this](Environment &env) { addToBaseEnvironment(env); }); 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<ExecutableAspect>();
addAspect<ArgumentsAspect>(); addAspect<ArgumentsAspect>();
@@ -69,6 +82,10 @@ QbsRunConfiguration::QbsRunConfiguration(Target *target, Core::Id id)
auto dyldAspect = addAspect<UseDyldSuffixAspect>(); auto dyldAspect = addAspect<UseDyldSuffixAspect>();
connect(dyldAspect, &UseDyldSuffixAspect::changed, connect(dyldAspect, &UseDyldSuffixAspect::changed,
envAspect, &EnvironmentAspect::environmentChanged); envAspect, &EnvironmentAspect::environmentChanged);
envAspect->addModifier([dyldAspect](Environment &env) {
if (dyldAspect->value())
env.set("DYLD_IMAGE_SUFFIX", "_debug");
});
} }
connect(project(), &Project::parsingFinished, this, connect(project(), &Project::parsingFinished, this,
@@ -108,26 +125,6 @@ void QbsRunConfiguration::doAdditionalSetup(const RunConfigurationCreationInfo &
updateTargetInformation(); 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 Utils::FileName QbsRunConfiguration::executableToRun(const BuildTargetInfo &targetInfo) const
{ {
const FileName appInBuildDir = targetInfo.targetFilePath; const FileName appInBuildDir = targetInfo.targetFilePath;

View File

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

View File

@@ -61,9 +61,12 @@ namespace Internal {
DesktopQmakeRunConfiguration::DesktopQmakeRunConfiguration(Target *target, Core::Id id) DesktopQmakeRunConfiguration::DesktopQmakeRunConfiguration(Target *target, Core::Id id)
: RunConfiguration(target, id) : RunConfiguration(target, id)
{ {
auto envAspect = addAspect<LocalEnvironmentAspect>(target, [this](Environment &env) { auto envAspect = addAspect<LocalEnvironmentAspect>(target);
addToBaseEnvironment(env); envAspect->addModifier([this](Environment &env) {
}); BuildTargetInfo bti = buildTargetInfo();
if (bti.runEnvModifier)
bti.runEnvModifier(env, aspect<UseLibraryPathsAspect>()->value());
});
addAspect<ExecutableAspect>(); addAspect<ExecutableAspect>();
addAspect<ArgumentsAspect>(); addAspect<ArgumentsAspect>();
@@ -80,6 +83,10 @@ DesktopQmakeRunConfiguration::DesktopQmakeRunConfiguration(Target *target, Core:
auto dyldAspect = addAspect<UseDyldSuffixAspect>(); auto dyldAspect = addAspect<UseDyldSuffixAspect>();
connect(dyldAspect, &UseLibraryPathsAspect::changed, connect(dyldAspect, &UseLibraryPathsAspect::changed,
envAspect, &EnvironmentAspect::environmentChanged); envAspect, &EnvironmentAspect::environmentChanged);
envAspect->addModifier([dyldAspect](Environment &env) {
if (dyldAspect->value())
env.set(QLatin1String("DYLD_IMAGE_SUFFIX"), QLatin1String("_debug"));
});
} }
connect(target->project(), &Project::parsingFinished, connect(target->project(), &Project::parsingFinished,
@@ -118,18 +125,6 @@ void DesktopQmakeRunConfiguration::doAdditionalSetup(const RunConfigurationCreat
updateTargetInformation(); updateTargetInformation();
} }
void DesktopQmakeRunConfiguration::addToBaseEnvironment(Environment &env) const
{
BuildTargetInfo bti = buildTargetInfo();
if (bti.runEnvModifier)
bti.runEnvModifier(env, aspect<UseLibraryPathsAspect>()->value());
if (auto dyldAspect = aspect<UseDyldSuffixAspect>()) {
if (dyldAspect->value())
env.set(QLatin1String("DYLD_IMAGE_SUFFIX"), QLatin1String("_debug"));
}
}
FileName DesktopQmakeRunConfiguration::proFilePath() const FileName DesktopQmakeRunConfiguration::proFilePath() const
{ {
return FileName::fromString(buildKey()); return FileName::fromString(buildKey());

View File

@@ -39,8 +39,6 @@ class DesktopQmakeRunConfiguration : public ProjectExplorer::RunConfiguration
public: public:
DesktopQmakeRunConfiguration(ProjectExplorer::Target *target, Core::Id id); DesktopQmakeRunConfiguration(ProjectExplorer::Target *target, Core::Id id);
void addToBaseEnvironment(Utils::Environment &env) const;
private: private:
void updateTargetInformation(); void updateTargetInformation();
bool fromMap(const QVariantMap &map) final; bool fromMap(const QVariantMap &map) final;

View File

@@ -278,27 +278,24 @@ void MainQmlFileAspect::changeCurrentFile(IEditor *editor)
QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id) QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id)
: RunConfiguration(target, id) : RunConfiguration(target, id)
{ {
enum BaseEnvironmentBase {
SystemEnvironmentBase = 0,
CleanEnvironmentBase
};
auto envAspect = addAspect<EnvironmentAspect>(); auto envAspect = addAspect<EnvironmentAspect>();
const Id deviceTypeId = DeviceTypeKitAspect::deviceTypeId(target->kit());
if (deviceTypeId == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE)
envAspect->addPreferredBaseEnvironment(SystemEnvironmentBase, tr("System Environment"));
envAspect->addSupportedBaseEnvironment(CleanEnvironmentBase, tr("Clean Environment"));
envAspect->setBaseEnvironmentGetter([envAspect, target]() -> Utils::Environment {
Environment env = envAspect->baseEnvironmentBase() == SystemEnvironmentBase
? Environment::systemEnvironment()
: Environment();
auto envModifier = [&](Environment env) {
if (auto project = qobject_cast<const QmlProject *>(target->project())) if (auto project = qobject_cast<const QmlProject *>(target->project()))
env.modify(project->environment()); env.modify(project->environment());
return env; return env;
}); };
const Id deviceTypeId = DeviceTypeKitAspect::deviceTypeId(target->kit());
if (deviceTypeId == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) {
envAspect->addPreferredBaseEnvironment(tr("System Environment"), [&] {
return envModifier(Environment::systemEnvironment());
});
}
envAspect->addSupportedBaseEnvironment(tr("Clean Environment"), [&] {
return envModifier(Environment());
});
m_qmlViewerAspect = addAspect<BaseStringAspect>(); m_qmlViewerAspect = addAspect<BaseStringAspect>();
m_qmlViewerAspect->setLabelText(tr("QML Viewer:")); m_qmlViewerAspect->setLabelText(tr("QML Viewer:"));

View File

@@ -41,40 +41,21 @@ static bool displayAlreadySet(const QList<Utils::EnvironmentItem> &changes)
}); });
} }
enum BaseEnvironmentBase {
CleanBaseEnvironment = 0,
RemoteBaseEnvironment = 1
};
RemoteLinuxEnvironmentAspect::RemoteLinuxEnvironmentAspect(ProjectExplorer::Target *target) RemoteLinuxEnvironmentAspect::RemoteLinuxEnvironmentAspect(ProjectExplorer::Target *target)
{ {
addSupportedBaseEnvironment(CleanBaseEnvironment, tr("Clean Environment")); addSupportedBaseEnvironment(tr("Clean Environment"), {});
addPreferredBaseEnvironment(RemoteBaseEnvironment, tr("System Environment")); addPreferredBaseEnvironment(tr("System Environment"), [this] { return m_remoteEnvironment; });
setConfigWidgetCreator([this, target] { setConfigWidgetCreator([this, target] {
return new RemoteLinuxEnvironmentAspectWidget(this, target); return new RemoteLinuxEnvironmentAspectWidget(this, target);
}); });
setBaseEnvironmentGetter([this] {
Utils::Environment env;
if (baseEnvironmentBase() == static_cast<int>(RemoteBaseEnvironment))
env = m_remoteEnvironment;
return env;
});
}
Utils::Environment RemoteLinuxEnvironmentAspect::remoteEnvironment() const
{
return m_remoteEnvironment;
} }
void RemoteLinuxEnvironmentAspect::setRemoteEnvironment(const Utils::Environment &env) void RemoteLinuxEnvironmentAspect::setRemoteEnvironment(const Utils::Environment &env)
{ {
if (env != m_remoteEnvironment) { if (env != m_remoteEnvironment) {
m_remoteEnvironment = env; m_remoteEnvironment = env;
if (baseEnvironmentBase() == static_cast<int>(RemoteBaseEnvironment)) emit environmentChanged();
emit environmentChanged();
} }
} }

View File

@@ -38,7 +38,6 @@ class REMOTELINUX_EXPORT RemoteLinuxEnvironmentAspect : public ProjectExplorer::
public: public:
RemoteLinuxEnvironmentAspect(ProjectExplorer::Target *target); RemoteLinuxEnvironmentAspect(ProjectExplorer::Target *target);
Utils::Environment remoteEnvironment() const;
void setRemoteEnvironment(const Utils::Environment &env); void setRemoteEnvironment(const Utils::Environment &env);
QString userEnvironmentChangesAsString() const; QString userEnvironmentChangesAsString() const;