diff options
author | hjk <hjk@qt.io> | 2023-01-26 16:26:39 +0100 |
---|---|---|
committer | hjk <hjk@qt.io> | 2023-01-27 11:24:36 +0000 |
commit | 5f359a1dfffba7bd85ac80c39aff6897d9b39fc3 (patch) | |
tree | 0326a9c005b864e8d749d0625e3b3002d8797cd0 | |
parent | bc87abec329eb15659367385999a8b94ac79b90a (diff) | |
download | qt-creator-5f359a1dfffba7bd85ac80c39aff6897d9b39fc3.tar.gz |
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>
-rw-r--r-- | src/libs/utils/aspects.cpp | 5 | ||||
-rw-r--r-- | src/libs/utils/aspects.h | 1 | ||||
-rw-r--r-- | src/libs/utils/environment.cpp | 8 | ||||
-rw-r--r-- | src/libs/utils/environment.h | 6 | ||||
-rw-r--r-- | src/libs/utils/pathchooser.cpp | 5 | ||||
-rw-r--r-- | src/libs/utils/pathchooser.h | 1 | ||||
-rw-r--r-- | src/plugins/projectexplorer/buildconfiguration.cpp | 4 | ||||
-rw-r--r-- | src/plugins/projectexplorer/customexecutablerunconfiguration.cpp | 4 | ||||
-rw-r--r-- | src/plugins/projectexplorer/runconfigurationaspects.cpp | 9 | ||||
-rw-r--r-- | src/plugins/projectexplorer/runconfigurationaspects.h | 1 |
10 files changed, 31 insertions, 13 deletions
diff --git a/src/libs/utils/aspects.cpp b/src/libs/utils/aspects.cpp index 957bf6db9e..4296a3d1f0 100644 --- a/src/libs/utils/aspects.cpp +++ b/src/libs/utils/aspects.cpp @@ -974,6 +974,11 @@ void StringAspect::setEnvironmentChange(const EnvironmentChange &change) d->m_pathChooserDisplay->setEnvironmentChange(change); } +void StringAspect::setEnvironment(const Environment &env) +{ + setEnvironmentChange(EnvironmentChange::fromDictionary(env.toDictionary())); +} + void StringAspect::setBaseFileName(const FilePath &baseFileName) { d->m_baseFileName = baseFileName; diff --git a/src/libs/utils/aspects.h b/src/libs/utils/aspects.h index 30d51c2c8a..5a99515e67 100644 --- a/src/libs/utils/aspects.h +++ b/src/libs/utils/aspects.h @@ -356,6 +356,7 @@ public: void setHistoryCompleter(const QString &historyCompleterKey); void setExpectedKind(const PathChooser::Kind expectedKind); void setEnvironmentChange(const EnvironmentChange &change); + void setEnvironment(const Environment &env); void setBaseFileName(const FilePath &baseFileName); void setUndoRedoEnabled(bool readOnly); void setAcceptRichText(bool acceptRichText); diff --git a/src/libs/utils/environment.cpp b/src/libs/utils/environment.cpp index a020e6518d..2102179303 100644 --- a/src/libs/utils/environment.cpp +++ b/src/libs/utils/environment.cpp @@ -417,10 +417,10 @@ void EnvironmentChange::addAppendToPath(const FilePaths &values) 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; - 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; } @@ -431,8 +431,8 @@ void EnvironmentChange::applyToEnvironment(Environment &env) const case SetSystemEnvironment: env = Environment::systemEnvironment(); break; - case SetFixedEnvironment: - env = std::get<SetFixedEnvironment>(item); + case SetFixedDictionary: + env = Environment(std::get<SetFixedDictionary>(item)); break; case SetValue: { const QPair<QString, QString> data = std::get<SetValue>(item); diff --git a/src/libs/utils/environment.h b/src/libs/utils/environment.h index 06f3177f1f..e9cf20a1bd 100644 --- a/src/libs/utils/environment.h +++ b/src/libs/utils/environment.h @@ -111,7 +111,7 @@ public: enum Type { SetSystemEnvironment, - SetFixedEnvironment, + SetFixedDictionary, SetValue, UnsetValue, PrependToPath, @@ -120,14 +120,14 @@ public: using Item = std::variant< std::monostate, // SetSystemEnvironment dummy - Environment, // SetFixedEnvironment + NameValueDictionary, // SetFixedDictionary QPair<QString, QString>, // SetValue QString, // UnsetValue FilePath, // PrependToPath FilePath // AppendToPath >; - static EnvironmentChange fromFixedEnvironment(const Environment &fixedEnv); + static EnvironmentChange fromDictionary(const NameValueDictionary &dict); void applyToEnvironment(Environment &) const; diff --git a/src/libs/utils/pathchooser.cpp b/src/libs/utils/pathchooser.cpp index 05825220af..6f6a217321 100644 --- a/src/libs/utils/pathchooser.cpp +++ b/src/libs/utils/pathchooser.cpp @@ -324,6 +324,11 @@ void PathChooser::setBaseDirectory(const FilePath &base) triggerChanged(); } +void PathChooser::setEnvironment(const Environment &env) +{ + setEnvironmentChange(EnvironmentChange::fromDictionary(env.toDictionary())); +} + FilePath PathChooser::baseDirectory() const { return d->m_baseDirectory; diff --git a/src/libs/utils/pathchooser.h b/src/libs/utils/pathchooser.h index 2a3ee05610..92b5973b2d 100644 --- a/src/libs/utils/pathchooser.h +++ b/src/libs/utils/pathchooser.h @@ -76,6 +76,7 @@ public: FilePath baseDirectory() const; void setBaseDirectory(const FilePath &base); + void setEnvironment(const Environment &env); void setEnvironmentChange(const EnvironmentChange &change); /** Returns the suggested label title when used in a form layout. */ diff --git a/src/plugins/projectexplorer/buildconfiguration.cpp b/src/plugins/projectexplorer/buildconfiguration.cpp index 21d0c24ff3..ff14b7ab07 100644 --- a/src/plugins/projectexplorer/buildconfiguration.cpp +++ b/src/plugins/projectexplorer/buildconfiguration.cpp @@ -188,12 +188,12 @@ BuildConfiguration::BuildConfiguration(Target *target, Utils::Id id) d->m_buildDirectoryAspect = addAspect<BuildDirectoryAspect>(this); 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(); }); connect(d->m_buildDirectoryAspect, &StringAspect::changed, this, &BuildConfiguration::emitBuildDirectoryChanged); connect(this, &BuildConfiguration::environmentChanged, this, [this] { - d->m_buildDirectoryAspect->setEnvironmentChange(EnvironmentChange::fromFixedEnvironment(environment())); + d->m_buildDirectoryAspect->setEnvironment(environment()); emit this->target()->buildEnvironmentChanged(this); }); diff --git a/src/plugins/projectexplorer/customexecutablerunconfiguration.cpp b/src/plugins/projectexplorer/customexecutablerunconfiguration.cpp index 6f333c9b11..9d25bb7dfe 100644 --- a/src/plugins/projectexplorer/customexecutablerunconfiguration.cpp +++ b/src/plugins/projectexplorer/customexecutablerunconfiguration.cpp @@ -31,14 +31,14 @@ CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Target *targe exeAspect->setDisplayStyle(StringAspect::PathChooserDisplay); exeAspect->setHistoryCompleter("Qt.CustomExecutable.History"); exeAspect->setExpectedKind(PathChooser::ExistingCommand); - exeAspect->setEnvironmentChange(EnvironmentChange::fromFixedEnvironment(envAspect->environment())); + exeAspect->setEnvironment(envAspect->environment()); addAspect<ArgumentsAspect>(macroExpander()); addAspect<WorkingDirectoryAspect>(macroExpander(), envAspect); addAspect<TerminalAspect>(); connect(envAspect, &EnvironmentAspect::environmentChanged, this, [exeAspect, envAspect] { - exeAspect->setEnvironmentChange(EnvironmentChange::fromFixedEnvironment(envAspect->environment())); + exeAspect->setEnvironment(envAspect->environment()); }); setDefaultDisplayName(defaultDisplayName()); diff --git a/src/plugins/projectexplorer/runconfigurationaspects.cpp b/src/plugins/projectexplorer/runconfigurationaspects.cpp index c8f3836e46..9ba24c0467 100644 --- a/src/plugins/projectexplorer/runconfigurationaspects.cpp +++ b/src/plugins/projectexplorer/runconfigurationaspects.cpp @@ -187,9 +187,9 @@ void WorkingDirectoryAspect::addToLayout(LayoutBuilder &builder) if (m_envAspect) { 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()}); @@ -580,6 +580,11 @@ void ExecutableAspect::setEnvironmentChange(const EnvironmentChange &change) m_alternativeExecutable->setEnvironmentChange(change); } +void ExecutableAspect::setEnvironment(const Environment &env) +{ + setEnvironmentChange(EnvironmentChange::fromDictionary(env.toDictionary())); +} + /*! Sets the display \a style for aspect. diff --git a/src/plugins/projectexplorer/runconfigurationaspects.h b/src/plugins/projectexplorer/runconfigurationaspects.h index 0290b837af..9e948bc6ec 100644 --- a/src/plugins/projectexplorer/runconfigurationaspects.h +++ b/src/plugins/projectexplorer/runconfigurationaspects.h @@ -169,6 +169,7 @@ public: void setHistoryCompleter(const QString &historyCompleterKey); void setExpectedKind(const Utils::PathChooser::Kind expectedKind); void setEnvironmentChange(const Utils::EnvironmentChange &change); + void setEnvironment(const Utils::Environment &env); void setDisplayStyle(Utils::StringAspect::DisplayStyle style); struct Data : BaseAspect::Data |