forked from qt-creator/qt-creator
Utils: Start collecting environment changes instead of full environments
We have a couple of cases where classes need to modify environments but have only the ability to provide complete environments without actually knowing the full context. Starting with systemEnvironment usually works so far, but breaks down in cases of e.g. containerized builds. This patch here introduces the ability to collect changes to environments, and postpones creating a full environment until the context is clear. As introductory example use BaseQtVersion::qmakeRunEnvironment Change-Id: Id23c0aa80fc95b0a8a01f8e3a87adc9b1a57002a Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -401,4 +401,35 @@ optional<EnvironmentProvider> EnvironmentProvider::provider(const QByteArray &id
|
||||
return nullopt;
|
||||
}
|
||||
|
||||
void EnvironmentChange::addSetValue(const QString &key, const QString &value)
|
||||
{
|
||||
m_changeItems.append([key, value](Environment &env) { env.set(key, value); });
|
||||
}
|
||||
|
||||
void EnvironmentChange::addUnsetValue(const QString &key)
|
||||
{
|
||||
m_changeItems.append([key](Environment &env) { env.unset(key); });
|
||||
}
|
||||
|
||||
void EnvironmentChange::addPrependToPath(const QString &value)
|
||||
{
|
||||
m_changeItems.append([value](Environment &env) { env.prependOrSetPath(value); });
|
||||
}
|
||||
|
||||
void EnvironmentChange::addAppendToPath(const QString &value)
|
||||
{
|
||||
m_changeItems.append([value](Environment &env) { env.appendOrSetPath(value); });
|
||||
}
|
||||
|
||||
void EnvironmentChange::addModify(const NameValueItems &items)
|
||||
{
|
||||
m_changeItems.append([items](Environment &env) { env.modify(items); });
|
||||
}
|
||||
|
||||
void EnvironmentChange::applyToEnvironment(Environment &env) const
|
||||
{
|
||||
for (const Item &item : m_changeItems)
|
||||
item(env);
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
|
||||
Reference in New Issue
Block a user