Utils: Start Environment/EnvironmentChange consolidation

The plan is now to keep 'Environment' as the concept name, but
have what is currently 'EnvironmentChange' as implementation,
as keeping a full env vs env change(set) distiction gets messy.

First step is to cut the direct dependency of EnvironmentChange
from a (current) Environment that causes circularity when moving
the implementation.

Change-Id: Id8b512b311071611b750b27af59549ce7c2ce8e6
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2023-01-26 16:26:39 +01:00
parent bc87abec32
commit 5f359a1dff
10 changed files with 31 additions and 13 deletions

View File

@@ -974,6 +974,11 @@ void StringAspect::setEnvironmentChange(const EnvironmentChange &change)
d->m_pathChooserDisplay->setEnvironmentChange(change); d->m_pathChooserDisplay->setEnvironmentChange(change);
} }
void StringAspect::setEnvironment(const Environment &env)
{
setEnvironmentChange(EnvironmentChange::fromDictionary(env.toDictionary()));
}
void StringAspect::setBaseFileName(const FilePath &baseFileName) void StringAspect::setBaseFileName(const FilePath &baseFileName)
{ {
d->m_baseFileName = baseFileName; d->m_baseFileName = baseFileName;

View File

@@ -356,6 +356,7 @@ public:
void setHistoryCompleter(const QString &historyCompleterKey); void setHistoryCompleter(const QString &historyCompleterKey);
void setExpectedKind(const PathChooser::Kind expectedKind); void setExpectedKind(const PathChooser::Kind expectedKind);
void setEnvironmentChange(const EnvironmentChange &change); void setEnvironmentChange(const EnvironmentChange &change);
void setEnvironment(const Environment &env);
void setBaseFileName(const FilePath &baseFileName); void setBaseFileName(const FilePath &baseFileName);
void setUndoRedoEnabled(bool readOnly); void setUndoRedoEnabled(bool readOnly);
void setAcceptRichText(bool acceptRichText); void setAcceptRichText(bool acceptRichText);

View File

@@ -417,10 +417,10 @@ void EnvironmentChange::addAppendToPath(const FilePaths &values)
m_changeItems.append(Item{std::in_place_index_t<AppendToPath>(), value}); m_changeItems.append(Item{std::in_place_index_t<AppendToPath>(), value});
} }
EnvironmentChange EnvironmentChange::fromFixedEnvironment(const Environment &fixedEnv) EnvironmentChange EnvironmentChange::fromDictionary(const NameValueDictionary &dict)
{ {
EnvironmentChange change; EnvironmentChange change;
change.m_changeItems.append(Item{std::in_place_index_t<SetFixedEnvironment>(), fixedEnv}); change.m_changeItems.append(Item{std::in_place_index_t<SetFixedDictionary>(), dict});
return change; return change;
} }
@@ -431,8 +431,8 @@ void EnvironmentChange::applyToEnvironment(Environment &env) const
case SetSystemEnvironment: case SetSystemEnvironment:
env = Environment::systemEnvironment(); env = Environment::systemEnvironment();
break; break;
case SetFixedEnvironment: case SetFixedDictionary:
env = std::get<SetFixedEnvironment>(item); env = Environment(std::get<SetFixedDictionary>(item));
break; break;
case SetValue: { case SetValue: {
const QPair<QString, QString> data = std::get<SetValue>(item); const QPair<QString, QString> data = std::get<SetValue>(item);

View File

@@ -111,7 +111,7 @@ public:
enum Type { enum Type {
SetSystemEnvironment, SetSystemEnvironment,
SetFixedEnvironment, SetFixedDictionary,
SetValue, SetValue,
UnsetValue, UnsetValue,
PrependToPath, PrependToPath,
@@ -120,14 +120,14 @@ public:
using Item = std::variant< using Item = std::variant<
std::monostate, // SetSystemEnvironment dummy std::monostate, // SetSystemEnvironment dummy
Environment, // SetFixedEnvironment NameValueDictionary, // SetFixedDictionary
QPair<QString, QString>, // SetValue QPair<QString, QString>, // SetValue
QString, // UnsetValue QString, // UnsetValue
FilePath, // PrependToPath FilePath, // PrependToPath
FilePath // AppendToPath FilePath // AppendToPath
>; >;
static EnvironmentChange fromFixedEnvironment(const Environment &fixedEnv); static EnvironmentChange fromDictionary(const NameValueDictionary &dict);
void applyToEnvironment(Environment &) const; void applyToEnvironment(Environment &) const;

View File

@@ -324,6 +324,11 @@ void PathChooser::setBaseDirectory(const FilePath &base)
triggerChanged(); triggerChanged();
} }
void PathChooser::setEnvironment(const Environment &env)
{
setEnvironmentChange(EnvironmentChange::fromDictionary(env.toDictionary()));
}
FilePath PathChooser::baseDirectory() const FilePath PathChooser::baseDirectory() const
{ {
return d->m_baseDirectory; return d->m_baseDirectory;

View File

@@ -76,6 +76,7 @@ public:
FilePath baseDirectory() const; FilePath baseDirectory() const;
void setBaseDirectory(const FilePath &base); void setBaseDirectory(const FilePath &base);
void setEnvironment(const Environment &env);
void setEnvironmentChange(const EnvironmentChange &change); void setEnvironmentChange(const EnvironmentChange &change);
/** Returns the suggested label title when used in a form layout. */ /** Returns the suggested label title when used in a form layout. */

View File

@@ -188,12 +188,12 @@ BuildConfiguration::BuildConfiguration(Target *target, Utils::Id id)
d->m_buildDirectoryAspect = addAspect<BuildDirectoryAspect>(this); d->m_buildDirectoryAspect = addAspect<BuildDirectoryAspect>(this);
d->m_buildDirectoryAspect->setBaseFileName(target->project()->projectDirectory()); d->m_buildDirectoryAspect->setBaseFileName(target->project()->projectDirectory());
d->m_buildDirectoryAspect->setEnvironmentChange(EnvironmentChange::fromFixedEnvironment(environment())); d->m_buildDirectoryAspect->setEnvironment(environment());
d->m_buildDirectoryAspect->setMacroExpanderProvider([this] { return macroExpander(); }); d->m_buildDirectoryAspect->setMacroExpanderProvider([this] { return macroExpander(); });
connect(d->m_buildDirectoryAspect, &StringAspect::changed, connect(d->m_buildDirectoryAspect, &StringAspect::changed,
this, &BuildConfiguration::emitBuildDirectoryChanged); this, &BuildConfiguration::emitBuildDirectoryChanged);
connect(this, &BuildConfiguration::environmentChanged, this, [this] { connect(this, &BuildConfiguration::environmentChanged, this, [this] {
d->m_buildDirectoryAspect->setEnvironmentChange(EnvironmentChange::fromFixedEnvironment(environment())); d->m_buildDirectoryAspect->setEnvironment(environment());
emit this->target()->buildEnvironmentChanged(this); emit this->target()->buildEnvironmentChanged(this);
}); });

View File

@@ -31,14 +31,14 @@ CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Target *targe
exeAspect->setDisplayStyle(StringAspect::PathChooserDisplay); exeAspect->setDisplayStyle(StringAspect::PathChooserDisplay);
exeAspect->setHistoryCompleter("Qt.CustomExecutable.History"); exeAspect->setHistoryCompleter("Qt.CustomExecutable.History");
exeAspect->setExpectedKind(PathChooser::ExistingCommand); exeAspect->setExpectedKind(PathChooser::ExistingCommand);
exeAspect->setEnvironmentChange(EnvironmentChange::fromFixedEnvironment(envAspect->environment())); exeAspect->setEnvironment(envAspect->environment());
addAspect<ArgumentsAspect>(macroExpander()); addAspect<ArgumentsAspect>(macroExpander());
addAspect<WorkingDirectoryAspect>(macroExpander(), envAspect); addAspect<WorkingDirectoryAspect>(macroExpander(), envAspect);
addAspect<TerminalAspect>(); addAspect<TerminalAspect>();
connect(envAspect, &EnvironmentAspect::environmentChanged, this, [exeAspect, envAspect] { connect(envAspect, &EnvironmentAspect::environmentChanged, this, [exeAspect, envAspect] {
exeAspect->setEnvironmentChange(EnvironmentChange::fromFixedEnvironment(envAspect->environment())); exeAspect->setEnvironment(envAspect->environment());
}); });
setDefaultDisplayName(defaultDisplayName()); setDefaultDisplayName(defaultDisplayName());

View File

@@ -187,9 +187,9 @@ void WorkingDirectoryAspect::addToLayout(LayoutBuilder &builder)
if (m_envAspect) { if (m_envAspect) {
connect(m_envAspect, &EnvironmentAspect::environmentChanged, m_chooser.data(), [this] { connect(m_envAspect, &EnvironmentAspect::environmentChanged, m_chooser.data(), [this] {
m_chooser->setEnvironmentChange(EnvironmentChange::fromFixedEnvironment(m_envAspect->environment())); m_chooser->setEnvironment(m_envAspect->environment());
}); });
m_chooser->setEnvironmentChange(EnvironmentChange::fromFixedEnvironment(m_envAspect->environment())); m_chooser->setEnvironment(m_envAspect->environment());
} }
builder.addItems({Tr::tr("Working directory:"), m_chooser.data(), m_resetButton.data()}); builder.addItems({Tr::tr("Working directory:"), m_chooser.data(), m_resetButton.data()});
@@ -580,6 +580,11 @@ void ExecutableAspect::setEnvironmentChange(const EnvironmentChange &change)
m_alternativeExecutable->setEnvironmentChange(change); m_alternativeExecutable->setEnvironmentChange(change);
} }
void ExecutableAspect::setEnvironment(const Environment &env)
{
setEnvironmentChange(EnvironmentChange::fromDictionary(env.toDictionary()));
}
/*! /*!
Sets the display \a style for aspect. Sets the display \a style for aspect.

View File

@@ -169,6 +169,7 @@ public:
void setHistoryCompleter(const QString &historyCompleterKey); void setHistoryCompleter(const QString &historyCompleterKey);
void setExpectedKind(const Utils::PathChooser::Kind expectedKind); void setExpectedKind(const Utils::PathChooser::Kind expectedKind);
void setEnvironmentChange(const Utils::EnvironmentChange &change); void setEnvironmentChange(const Utils::EnvironmentChange &change);
void setEnvironment(const Utils::Environment &env);
void setDisplayStyle(Utils::StringAspect::DisplayStyle style); void setDisplayStyle(Utils::StringAspect::DisplayStyle style);
struct Data : BaseAspect::Data struct Data : BaseAspect::Data