CMakePM: Do not flush CMake parameters model on parsing complete

The flush there was as a "hack" for the case:

1. failed initial configuration (CMAKE_GENERATOR as Ninja2)
2. successful configuration

The current configuration would get current items with unexpanded
values e.g.: QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable}

But flush also removed the expanded values of the selected
initial parameters from CMakeBuildSystem::updateInitialCMakeExpandableVars

This is useful when CMAKE_CXX_COMPILER changes or
CMAKE_PROJECT_INCLUDE_BEFORE gets a new path to the new Qt Creator.

Change-Id: I480ce141d043d8ba6001fa47a54b066762b6a128
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Cristian Adam
2022-01-27 12:36:21 +01:00
parent 0923d8676e
commit ff66f501f2
2 changed files with 55 additions and 37 deletions

View File

@@ -272,46 +272,61 @@ void ConfigModel::setInitialParametersConfiguration(const CMakeConfig &config)
void ConfigModel::setConfiguration(const QList<ConfigModel::InternalDataItem> &config)
{
QList<InternalDataItem> tmp = config;
auto newIt = tmp.constBegin();
auto newEndIt = tmp.constEnd();
auto oldIt = m_configuration.constBegin();
auto oldEndIt = m_configuration.constEnd();
auto mergeLists = [](const QList<InternalDataItem> &oldList,
const QList<InternalDataItem> &newList) -> QList<InternalDataItem> {
auto newIt = newList.constBegin();
auto newEndIt = newList.constEnd();
auto oldIt = oldList.constBegin();
auto oldEndIt = oldList.constEnd();
QList<InternalDataItem> result;
while (newIt != newEndIt && oldIt != oldEndIt) {
if (oldIt->isUnset) {
++oldIt;
} else if (newIt->isHidden || newIt->isUnset) {
++newIt;
} else if (newIt->key < oldIt->key) {
// Add new entry:
result << *newIt;
++newIt;
} else if (newIt->key > oldIt->key) {
// Keep old user settings, but skip other entries:
if (oldIt->isUserChanged || oldIt->isUserNew)
result << InternalDataItem(*oldIt);
++oldIt;
} else {
// merge old/new entry:
InternalDataItem item(*newIt);
item.newValue = (newIt->value != oldIt->newValue) ? oldIt->newValue : QString();
item.isUserChanged = !item.newValue.isEmpty() && (item.newValue != item.value);
result << item;
++newIt;
++oldIt;
QList<InternalDataItem> result;
while (newIt != newEndIt && oldIt != oldEndIt) {
if (oldIt->isUnset) {
++oldIt;
} else if (newIt->isHidden || newIt->isUnset) {
++newIt;
} else if (newIt->key < oldIt->key) {
// Add new entry:
result << *newIt;
++newIt;
} else if (newIt->key > oldIt->key) {
// Keep old user settings, but skip other entries:
if (oldIt->isUserChanged || oldIt->isUserNew)
result << InternalDataItem(*oldIt);
++oldIt;
} else {
// merge old/new entry:
InternalDataItem item(*newIt);
item.newValue = (newIt->value != oldIt->newValue) ? oldIt->newValue : QString();
item.isUserChanged = !item.newValue.isEmpty() && (item.newValue != item.value);
result << item;
++newIt;
++oldIt;
}
}
}
// Add remaining new entries:
for (; newIt != newEndIt; ++newIt) {
if (newIt->isHidden)
continue;
result << InternalDataItem(*newIt);
}
// Add remaining new entries:
for (; newIt != newEndIt; ++newIt) {
if (newIt->isHidden)
continue;
result << InternalDataItem(*newIt);
}
m_configuration = result;
return result;
};
auto isInitial = [](const InternalDataItem &i) { return i.isInitial; };
QList<InternalDataItem> initialOld;
QList<InternalDataItem> currentOld;
std::tie(initialOld, currentOld) = Utils::partition(m_configuration, isInitial);
QList<InternalDataItem> initialNew;
QList<InternalDataItem> currentNew;
std::tie(initialNew, currentNew) = Utils::partition(config, isInitial);
m_configuration = mergeLists(initialOld, initialNew);
m_configuration.append(mergeLists(currentOld, currentNew));
generateTree();
}