forked from qt-creator/qt-creator
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:
@@ -107,10 +107,8 @@ void BaseStringListAspect::setLabel(const QString &label)
|
||||
AndroidRunConfiguration::AndroidRunConfiguration(Target *target, Core::Id id)
|
||||
: RunConfiguration(target, id)
|
||||
{
|
||||
enum BaseEnvironmentBase { CleanEnvironmentBase };
|
||||
auto envAspect = addAspect<EnvironmentAspect>();
|
||||
envAspect->addSupportedBaseEnvironment(CleanEnvironmentBase, tr("Clean Environment"));
|
||||
envAspect->setBaseEnvironmentGetter([] { return Utils::Environment(); });
|
||||
envAspect->addSupportedBaseEnvironment(tr("Clean Environment"), {});
|
||||
|
||||
addAspect<ArgumentsAspect>();
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include <projectexplorer/target.h>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Utils;
|
||||
|
||||
namespace CMakeProjectManager {
|
||||
namespace Internal {
|
||||
@@ -43,17 +44,18 @@ namespace Internal {
|
||||
CMakeRunConfiguration::CMakeRunConfiguration(Target *target, Core::Id id)
|
||||
: RunConfiguration(target, id)
|
||||
{
|
||||
// Workaround for QTCREATORBUG-19354:
|
||||
auto cmakeRunEnvironmentModifier = [target](Utils::Environment &env) {
|
||||
if (!Utils::HostOsInfo::isWindowsHost())
|
||||
return;
|
||||
auto envAspect = addAspect<LocalEnvironmentAspect>(target);
|
||||
|
||||
// Workaround for QTCREATORBUG-19354:
|
||||
if (HostOsInfo::isWindowsHost()) {
|
||||
envAspect->addModifier([target](Environment &env) {
|
||||
const Kit *k = target->kit();
|
||||
const QtSupport::BaseQtVersion *qt = QtSupport::QtKitAspect::qtVersion(k);
|
||||
if (qt)
|
||||
env.prependOrSetPath(qt->qmakeProperty("QT_INSTALL_BINS"));
|
||||
};
|
||||
auto envAspect = addAspect<LocalEnvironmentAspect>(target, cmakeRunEnvironmentModifier);
|
||||
if (const QtSupport::BaseQtVersion *qt = QtSupport::QtKitAspect::qtVersion(k)) {
|
||||
const QString installBinPath = qt->qmakeProperty("QT_INSTALL_BINS");
|
||||
env.prependOrSetPath(installBinPath);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
addAspect<ExecutableAspect>();
|
||||
addAspect<ArgumentsAspect>();
|
||||
|
||||
@@ -44,8 +44,7 @@ namespace Nim {
|
||||
NimRunConfiguration::NimRunConfiguration(Target *target, Core::Id id)
|
||||
: RunConfiguration(target, id)
|
||||
{
|
||||
auto envAspect = addAspect<LocalEnvironmentAspect>
|
||||
(target, LocalEnvironmentAspect::BaseEnvironmentModifier());
|
||||
auto envAspect = addAspect<LocalEnvironmentAspect>(target);
|
||||
|
||||
addAspect<ExecutableAspect>();
|
||||
addAspect<ArgumentsAspect>();
|
||||
|
||||
@@ -184,8 +184,7 @@ CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Target *targe
|
||||
CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Target *target, Core::Id id)
|
||||
: RunConfiguration(target, id)
|
||||
{
|
||||
auto envAspect = addAspect<LocalEnvironmentAspect>
|
||||
(target, LocalEnvironmentAspect::BaseEnvironmentModifier());
|
||||
auto envAspect = addAspect<LocalEnvironmentAspect>(target);
|
||||
|
||||
auto exeAspect = addAspect<ExecutableAspect>();
|
||||
exeAspect->setSettingsKey("ProjectExplorer.CustomExecutableRunConfiguration.Executable");
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
static const char BASE_KEY[] = "PE.EnvironmentAspect.Base";
|
||||
static const char CHANGES_KEY[] = "PE.EnvironmentAspect.Changes";
|
||||
|
||||
@@ -53,9 +55,7 @@ int EnvironmentAspect::baseEnvironmentBase() const
|
||||
|
||||
void EnvironmentAspect::setBaseEnvironmentBase(int base)
|
||||
{
|
||||
QTC_ASSERT(base >= 0, return);
|
||||
QTC_ASSERT(possibleBaseEnvironments().contains(base), return);
|
||||
|
||||
QTC_ASSERT(base >= 0 && base < m_baseEnvironments.size(), return);
|
||||
if (m_base != base) {
|
||||
m_base = base;
|
||||
emit baseEnvironmentChanged();
|
||||
@@ -64,64 +64,81 @@ void EnvironmentAspect::setBaseEnvironmentBase(int base)
|
||||
|
||||
void EnvironmentAspect::setUserEnvironmentChanges(const QList<Utils::EnvironmentItem> &diff)
|
||||
{
|
||||
if (m_changes != diff) {
|
||||
m_changes = diff;
|
||||
emit userEnvironmentChangesChanged(m_changes);
|
||||
if (m_userChanges != diff) {
|
||||
m_userChanges = diff;
|
||||
emit userEnvironmentChangesChanged(m_userChanges);
|
||||
emit environmentChanged();
|
||||
}
|
||||
}
|
||||
|
||||
Utils::Environment EnvironmentAspect::environment() const
|
||||
{
|
||||
Utils::Environment env = baseEnvironment();
|
||||
env.modify(m_changes);
|
||||
QTC_ASSERT(m_base >= 0 && m_base < m_baseEnvironments.size(), return Environment());
|
||||
Environment env = m_baseEnvironments.at(m_base).unmodifiedBaseEnvironment();
|
||||
for (const EnvironmentModifier &modifier : m_modifiers)
|
||||
modifier(env);
|
||||
env.modify(m_userChanges);
|
||||
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)
|
||||
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;
|
||||
setBaseEnvironmentBase(base);
|
||||
BaseEnvironment baseEnv;
|
||||
baseEnv.displayName = displayName;
|
||||
baseEnv.getter = getter;
|
||||
m_baseEnvironments.append(baseEnv);
|
||||
setBaseEnvironmentBase(m_baseEnvironments.size() - 1);
|
||||
}
|
||||
|
||||
void EnvironmentAspect::fromMap(const QVariantMap &map)
|
||||
{
|
||||
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
|
||||
{
|
||||
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());
|
||||
return m_baseEnvironmentGetter();
|
||||
QTC_ASSERT(m_base >= 0 && m_base < m_baseEnvironments.size(), return Environment());
|
||||
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
|
||||
|
||||
@@ -43,24 +43,28 @@ class PROJECTEXPLORER_EXPORT EnvironmentAspect : public ProjectConfigurationAspe
|
||||
public:
|
||||
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.
|
||||
Utils::Environment environment() const;
|
||||
|
||||
QList<int> possibleBaseEnvironments() const;
|
||||
QString baseEnvironmentDisplayName(int base) const;
|
||||
|
||||
int baseEnvironmentBase() const;
|
||||
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 addSupportedBaseEnvironment(int base, const QString &displayName);
|
||||
void addPreferredBaseEnvironment(int base, const QString &displayName);
|
||||
void addSupportedBaseEnvironment(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:
|
||||
void baseEnvironmentChanged();
|
||||
@@ -72,10 +76,18 @@ protected:
|
||||
void toMap(QVariantMap &map) const override;
|
||||
|
||||
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;
|
||||
std::function<Utils::Environment()> m_baseEnvironmentGetter;
|
||||
QList<Utils::EnvironmentItem> m_changes;
|
||||
QMap<int, QString> m_displayNames;
|
||||
QList<Utils::EnvironmentItem> m_userChanges;
|
||||
QList<EnvironmentModifier> m_modifiers;
|
||||
QList<BaseEnvironment> m_baseEnvironments;
|
||||
};
|
||||
|
||||
} // namespace ProjectExplorer
|
||||
|
||||
@@ -56,20 +56,13 @@ EnvironmentAspectWidget::EnvironmentAspectWidget(EnvironmentAspect *aspect, QWid
|
||||
baseLayout->setMargin(0);
|
||||
auto label = new QLabel(tr("Base environment for this run configuration:"), this);
|
||||
baseLayout->addWidget(label);
|
||||
|
||||
m_baseEnvironmentComboBox = new QComboBox;
|
||||
QList<int> bases = m_aspect->possibleBaseEnvironments();
|
||||
int currentBase = m_aspect->baseEnvironmentBase();
|
||||
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;
|
||||
}
|
||||
}
|
||||
for (const QString &displayName : m_aspect->displayNames())
|
||||
m_baseEnvironmentComboBox->addItem(displayName);
|
||||
if (m_baseEnvironmentComboBox->count() == 1)
|
||||
m_baseEnvironmentComboBox->setEnabled(false);
|
||||
m_baseEnvironmentComboBox->setCurrentIndex(m_aspect->baseEnvironmentBase());
|
||||
|
||||
connect(m_baseEnvironmentComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
||||
this, &EnvironmentAspectWidget::baseEnvironmentSelected);
|
||||
@@ -80,8 +73,8 @@ EnvironmentAspectWidget::EnvironmentAspectWidget(EnvironmentAspect *aspect, QWid
|
||||
baseLayout->addWidget(additionalWidget);
|
||||
|
||||
m_environmentWidget = new EnvironmentWidget(this, baseEnvironmentWidget);
|
||||
m_environmentWidget->setBaseEnvironment(m_aspect->baseEnvironment());
|
||||
m_environmentWidget->setBaseEnvironmentText(baseDisplayName);
|
||||
m_environmentWidget->setBaseEnvironment(m_aspect->currentUnmodifiedBaseEnvironment());
|
||||
m_environmentWidget->setBaseEnvironmentText(m_aspect->currentDisplayName());
|
||||
m_environmentWidget->setUserChanges(m_aspect->userEnvironmentChanges());
|
||||
m_environmentWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
topLayout->addWidget(m_environmentWidget);
|
||||
@@ -110,10 +103,9 @@ QWidget *EnvironmentAspectWidget::additionalWidget() const
|
||||
void EnvironmentAspectWidget::baseEnvironmentSelected(int idx)
|
||||
{
|
||||
m_ignoreChange = true;
|
||||
int base = m_baseEnvironmentComboBox->itemData(idx).toInt();
|
||||
m_aspect->setBaseEnvironmentBase(base);
|
||||
m_environmentWidget->setBaseEnvironment(m_aspect->baseEnvironment());
|
||||
m_environmentWidget->setBaseEnvironmentText(m_aspect->baseEnvironmentDisplayName(base));
|
||||
m_aspect->setBaseEnvironmentBase(idx);
|
||||
m_environmentWidget->setBaseEnvironment(m_aspect->currentUnmodifiedBaseEnvironment());
|
||||
m_environmentWidget->setBaseEnvironmentText(m_aspect->currentDisplayName());
|
||||
m_ignoreChange = false;
|
||||
}
|
||||
|
||||
@@ -127,8 +119,8 @@ void EnvironmentAspectWidget::changeBaseEnvironment()
|
||||
if (m_baseEnvironmentComboBox->itemData(i).toInt() == base)
|
||||
m_baseEnvironmentComboBox->setCurrentIndex(i);
|
||||
}
|
||||
m_environmentWidget->setBaseEnvironmentText(m_aspect->baseEnvironmentDisplayName(base));
|
||||
m_environmentWidget->setBaseEnvironment(m_aspect->baseEnvironment());
|
||||
m_environmentWidget->setBaseEnvironmentText(m_aspect->currentDisplayName());
|
||||
m_environmentWidget->setBaseEnvironment(m_aspect->currentUnmodifiedBaseEnvironment());
|
||||
}
|
||||
|
||||
void EnvironmentAspectWidget::userChangesEdited()
|
||||
@@ -149,7 +141,7 @@ void EnvironmentAspectWidget::environmentChanged()
|
||||
{
|
||||
if (m_ignoreChange)
|
||||
return;
|
||||
m_environmentWidget->setBaseEnvironment(m_aspect->baseEnvironment());
|
||||
m_environmentWidget->setBaseEnvironment(m_aspect->currentUnmodifiedBaseEnvironment());
|
||||
}
|
||||
|
||||
} // namespace ProjectExplorer
|
||||
|
||||
@@ -32,50 +32,37 @@
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
namespace ProjectExplorer {
|
||||
|
||||
enum BaseEnvironmentBase {
|
||||
CleanEnvironmentBase = 0,
|
||||
SystemEnvironmentBase,
|
||||
BuildEnvironmentBase
|
||||
};
|
||||
|
||||
LocalEnvironmentAspect::LocalEnvironmentAspect(Target *target,
|
||||
const BaseEnvironmentModifier &modifier)
|
||||
LocalEnvironmentAspect::LocalEnvironmentAspect(Target *target)
|
||||
{
|
||||
addPreferredBaseEnvironment(BuildEnvironmentBase, tr("Build Environment"));
|
||||
addSupportedBaseEnvironment(SystemEnvironmentBase, tr("System Environment"));
|
||||
addSupportedBaseEnvironment(CleanEnvironmentBase, tr("Clean Environment"));
|
||||
addSupportedBaseEnvironment(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,
|
||||
this, &LocalEnvironmentAspect::buildEnvironmentHasChanged);
|
||||
connect(target, &Target::activeBuildConfigurationChanged,
|
||||
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()
|
||||
{
|
||||
if (baseEnvironmentBase() == static_cast<int>(BuildEnvironmentBase))
|
||||
emit environmentChanged();
|
||||
}
|
||||
|
||||
|
||||
@@ -34,8 +34,7 @@ class PROJECTEXPLORER_EXPORT LocalEnvironmentAspect : public EnvironmentAspect
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
using BaseEnvironmentModifier = std::function<void(Utils::Environment &)>;
|
||||
LocalEnvironmentAspect(Target *parent, const BaseEnvironmentModifier &modifier);
|
||||
explicit LocalEnvironmentAspect(Target *parent);
|
||||
|
||||
void buildEnvironmentHasChanged();
|
||||
};
|
||||
|
||||
@@ -270,7 +270,7 @@ PythonRunConfiguration::PythonRunConfiguration(Target *target, Core::Id id)
|
||||
scriptAspect->setLabelText(tr("Script:"));
|
||||
scriptAspect->setDisplayStyle(BaseStringAspect::LabelDisplay);
|
||||
|
||||
addAspect<LocalEnvironmentAspect>(target, LocalEnvironmentAspect::BaseEnvironmentModifier());
|
||||
addAspect<LocalEnvironmentAspect>(target);
|
||||
addAspect<ArgumentsAspect>();
|
||||
addAspect<TerminalAspect>();
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -61,8 +61,11 @@ namespace Internal {
|
||||
DesktopQmakeRunConfiguration::DesktopQmakeRunConfiguration(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) {
|
||||
BuildTargetInfo bti = buildTargetInfo();
|
||||
if (bti.runEnvModifier)
|
||||
bti.runEnvModifier(env, aspect<UseLibraryPathsAspect>()->value());
|
||||
});
|
||||
|
||||
addAspect<ExecutableAspect>();
|
||||
@@ -80,6 +83,10 @@ DesktopQmakeRunConfiguration::DesktopQmakeRunConfiguration(Target *target, Core:
|
||||
auto dyldAspect = addAspect<UseDyldSuffixAspect>();
|
||||
connect(dyldAspect, &UseLibraryPathsAspect::changed,
|
||||
envAspect, &EnvironmentAspect::environmentChanged);
|
||||
envAspect->addModifier([dyldAspect](Environment &env) {
|
||||
if (dyldAspect->value())
|
||||
env.set(QLatin1String("DYLD_IMAGE_SUFFIX"), QLatin1String("_debug"));
|
||||
});
|
||||
}
|
||||
|
||||
connect(target->project(), &Project::parsingFinished,
|
||||
@@ -118,18 +125,6 @@ void DesktopQmakeRunConfiguration::doAdditionalSetup(const RunConfigurationCreat
|
||||
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
|
||||
{
|
||||
return FileName::fromString(buildKey());
|
||||
|
||||
@@ -39,8 +39,6 @@ class DesktopQmakeRunConfiguration : public ProjectExplorer::RunConfiguration
|
||||
public:
|
||||
DesktopQmakeRunConfiguration(ProjectExplorer::Target *target, Core::Id id);
|
||||
|
||||
void addToBaseEnvironment(Utils::Environment &env) const;
|
||||
|
||||
private:
|
||||
void updateTargetInformation();
|
||||
bool fromMap(const QVariantMap &map) final;
|
||||
|
||||
@@ -278,27 +278,24 @@ void MainQmlFileAspect::changeCurrentFile(IEditor *editor)
|
||||
QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id)
|
||||
: RunConfiguration(target, id)
|
||||
{
|
||||
enum BaseEnvironmentBase {
|
||||
SystemEnvironmentBase = 0,
|
||||
CleanEnvironmentBase
|
||||
};
|
||||
|
||||
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()))
|
||||
env.modify(project->environment());
|
||||
|
||||
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->setLabelText(tr("QML Viewer:"));
|
||||
|
||||
@@ -41,39 +41,20 @@ static bool displayAlreadySet(const QList<Utils::EnvironmentItem> &changes)
|
||||
});
|
||||
}
|
||||
|
||||
enum BaseEnvironmentBase {
|
||||
CleanBaseEnvironment = 0,
|
||||
RemoteBaseEnvironment = 1
|
||||
};
|
||||
|
||||
|
||||
RemoteLinuxEnvironmentAspect::RemoteLinuxEnvironmentAspect(ProjectExplorer::Target *target)
|
||||
{
|
||||
addSupportedBaseEnvironment(CleanBaseEnvironment, tr("Clean Environment"));
|
||||
addPreferredBaseEnvironment(RemoteBaseEnvironment, tr("System Environment"));
|
||||
addSupportedBaseEnvironment(tr("Clean Environment"), {});
|
||||
addPreferredBaseEnvironment(tr("System Environment"), [this] { return m_remoteEnvironment; });
|
||||
|
||||
setConfigWidgetCreator([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)
|
||||
{
|
||||
if (env != m_remoteEnvironment) {
|
||||
m_remoteEnvironment = env;
|
||||
if (baseEnvironmentBase() == static_cast<int>(RemoteBaseEnvironment))
|
||||
emit environmentChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,6 @@ class REMOTELINUX_EXPORT RemoteLinuxEnvironmentAspect : public ProjectExplorer::
|
||||
public:
|
||||
RemoteLinuxEnvironmentAspect(ProjectExplorer::Target *target);
|
||||
|
||||
Utils::Environment remoteEnvironment() const;
|
||||
void setRemoteEnvironment(const Utils::Environment &env);
|
||||
|
||||
QString userEnvironmentChangesAsString() const;
|
||||
|
||||
Reference in New Issue
Block a user