forked from qt-creator/qt-creator
Utils: Add a way to provide fall-back entries in an environment
These are used if a (presumably fully-expanded) environment does not have a value for a certain key. Currently this works only for fully-known environments, but this can at least be delayed until the environment is needed, not when it is set up. Change-Id: I9baaa2d23002ddd574101741a91d5f872e6b0314 Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -494,6 +494,12 @@ void Environment::set(const QString &key, const QString &value, bool enabled)
|
||||
std::tuple<QString, QString, bool>{key, value, enabled}});
|
||||
}
|
||||
|
||||
void Environment::setFallback(const QString &key, const QString &value)
|
||||
{
|
||||
addItem(Item{std::in_place_index_t<SetFallbackValue>(),
|
||||
std::tuple<QString, QString>{key, value}});
|
||||
}
|
||||
|
||||
void Environment::unset(const QString &key)
|
||||
{
|
||||
addItem(Item{std::in_place_index_t<UnsetValue>(), key});
|
||||
@@ -536,19 +542,33 @@ const NameValueDictionary &Environment::resolved() const
|
||||
if (m_dict.size() != 0)
|
||||
return m_dict;
|
||||
|
||||
m_fullDict = false;
|
||||
for (const Item &item : m_changeItems) {
|
||||
switch (item.index()) {
|
||||
case SetSystemEnvironment:
|
||||
m_dict = Environment::systemEnvironment().toDictionary();
|
||||
m_fullDict = true;
|
||||
break;
|
||||
case SetFixedDictionary:
|
||||
m_dict = std::get<SetFixedDictionary>(item);
|
||||
m_fullDict = true;
|
||||
break;
|
||||
case SetValue: {
|
||||
auto [key, value, enabled] = std::get<SetValue>(item);
|
||||
m_dict.set(key, value, enabled);
|
||||
break;
|
||||
}
|
||||
case SetFallbackValue: {
|
||||
auto [key, value] = std::get<SetFallbackValue>(item);
|
||||
if (m_fullDict) {
|
||||
if (m_dict.value(key).isEmpty())
|
||||
m_dict.set(key, value, true);
|
||||
} else {
|
||||
QTC_ASSERT(false, qDebug() << "operating on partial dictionary");
|
||||
m_dict.set(key, value, true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case UnsetValue:
|
||||
m_dict.unset(std::get<UnsetValue>(item));
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user