forked from qt-creator/qt-creator
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:
@@ -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;
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -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. */
|
||||
|
@@ -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);
|
||||
});
|
||||
|
||||
|
@@ -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());
|
||||
|
@@ -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.
|
||||
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user