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

@@ -365,7 +365,6 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc)
} }
connect(bc->buildSystem(), &BuildSystem::parsingFinished, this, [this, stretcher] { connect(bc->buildSystem(), &BuildSystem::parsingFinished, this, [this, stretcher] {
m_configModel->flush();
m_configModel->setConfiguration(m_buildConfiguration->configurationFromCMake()); m_configModel->setConfiguration(m_buildConfiguration->configurationFromCMake());
m_configModel->setInitialParametersConfiguration( m_configModel->setInitialParametersConfiguration(
m_buildConfiguration->initialCMakeConfiguration()); m_buildConfiguration->initialCMakeConfiguration());
@@ -1622,6 +1621,8 @@ void InitialCMakeArgumentsAspect::setAllValues(const QString &values, QStringLis
arg.replace("-T", "-DCMAKE_GENERATOR_TOOLSET:STRING="); arg.replace("-T", "-DCMAKE_GENERATOR_TOOLSET:STRING=");
} }
m_cmakeConfiguration = CMakeConfig::fromArguments(arguments, additionalArguments); m_cmakeConfiguration = CMakeConfig::fromArguments(arguments, additionalArguments);
for (CMakeConfigItem &ci : m_cmakeConfiguration)
ci.isInitial = true;
// Display the unknown arguments in "Additional CMake parameters" // Display the unknown arguments in "Additional CMake parameters"
const QString additionalArgumentsValue = ProcessArgs::joinArgs(additionalArguments); const QString additionalArgumentsValue = ProcessArgs::joinArgs(additionalArguments);
@@ -1631,6 +1632,8 @@ void InitialCMakeArgumentsAspect::setAllValues(const QString &values, QStringLis
void InitialCMakeArgumentsAspect::setCMakeConfiguration(const CMakeConfig &config) void InitialCMakeArgumentsAspect::setCMakeConfiguration(const CMakeConfig &config)
{ {
m_cmakeConfiguration = config; m_cmakeConfiguration = config;
for (CMakeConfigItem &ci : m_cmakeConfiguration)
ci.isInitial = true;
} }
void InitialCMakeArgumentsAspect::fromMap(const QVariantMap &map) void InitialCMakeArgumentsAspect::fromMap(const QVariantMap &map)

View File

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