CMakeProjectManager: Make backup of CMake configuration before starting CMake

CMake's fileapi functionality will save the project structure in json
files in the .cmake/api/v1/reply directory.

When issuing a cmake command with -D variables CMake will update its
CMakeCache.txt file even if cmake will fail.

This commit will rename .cmake/api/v1/reply as .cmake/api/v1/reply.prev
and make a copy of CMakeCache.txt before starting CMake, and if
something fails, replace the existing files with the previous values.

Also make sure the changed values are not dissappearing when the
old .cmake/api/v1/reply gets parsed.

Fixes: QTCREATORBUG-24593
Change-Id: I82141786fea7068699e0f761a8978ba1f3203e47
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Cristian Adam
2021-02-04 16:22:40 +01:00
parent 2fb9d08082
commit fc411cd0d1
7 changed files with 83 additions and 26 deletions

View File

@@ -470,8 +470,7 @@ void CMakeBuildSettingsWidget::updateButtonState()
m_resetButton->setEnabled(m_configModel->hasChanges() && !isParsing);
m_reconfigureButton->setEnabled((!configChanges.isEmpty() || m_configModel->hasCMakeChanges())
&& !isParsing);
m_buildConfiguration->setExtraCMakeArguments(
Utils::transform(configChanges, [](const CMakeConfigItem &i) { return i.toArgument(); }));
m_buildConfiguration->setConfigurationChanges(configChanges);
}
void CMakeBuildSettingsWidget::updateAdvancedCheckBox()
@@ -943,9 +942,14 @@ CMakeConfig CMakeBuildConfiguration::configurationFromCMake() const
return m_configurationFromCMake;
}
QStringList CMakeBuildConfiguration::extraCMakeArguments() const
CMakeConfig CMakeBuildConfiguration::configurationChanges() const
{
return m_extraCMakeArguments;
return m_configurationChanges;
}
QStringList CMakeBuildConfiguration::configurationChangesArguments() const
{
return Utils::transform(m_configurationChanges, [](const CMakeConfigItem &i) { return i.toArgument(); });
}
QStringList CMakeBuildConfiguration::initialCMakeArguments() const
@@ -953,21 +957,22 @@ QStringList CMakeBuildConfiguration::initialCMakeArguments() const
return aspect<InitialCMakeArgumentsAspect>()->value().split('\n', Qt::SkipEmptyParts);
}
void CMakeBuildConfiguration::setExtraCMakeArguments(const QStringList &args)
{
if (m_extraCMakeArguments == args)
return;
qCDebug(cmakeBuildConfigurationLog)
<< "Extra Args changed from" << m_extraCMakeArguments << "to" << args << "...";
m_extraCMakeArguments = args;
}
void CMakeBuildConfiguration::setConfigurationFromCMake(const CMakeConfig &config)
{
m_configurationFromCMake = config;
}
void CMakeBuildConfiguration::setConfigurationChanges(const CMakeConfig &config)
{
qCDebug(cmakeBuildConfigurationLog)
<< "Configuration changes before:" << configurationChangesArguments();
m_configurationChanges = config;
qCDebug(cmakeBuildConfigurationLog)
<< "Configuration changes after:" << configurationChangesArguments();
}
// FIXME: Run clean steps when a setting starting with "ANDROID_BUILD_ABI_" is changed.
// FIXME: Warn when kit settings are overridden by a project.