diff options
author | Cristian Adam <cristian.adam@qt.io> | 2021-02-04 16:22:40 +0100 |
---|---|---|
committer | Cristian Adam <cristian.adam@qt.io> | 2021-02-18 13:21:11 +0000 |
commit | fc411cd0d1806435a9c89e8a10cdfed012663fd9 (patch) | |
tree | c3846def813a90fd67444a3f14cc4c9e321c3e02 /src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp | |
parent | 2fb9d080829cf766bf7fb0cf5b69b85fc35fc2bd (diff) | |
download | qt-creator-fc411cd0d1806435a9c89e8a10cdfed012663fd9.tar.gz |
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>
Diffstat (limited to 'src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp')
-rw-r--r-- | src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp b/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp index 636f0c47f5..abd515f1a0 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp @@ -676,6 +676,24 @@ void CMakeBuildSystem::updateFallbackProjectData() qCDebug(cmakeBuildSystemLog) << "All fallback CMake project data up to date."; } +void CMakeBuildSystem::updateCMakeConfiguration(QString &errorMessage) +{ + CMakeConfig cmakeConfig = m_reader.takeParsedConfiguration(errorMessage); + for (auto &ci : cmakeConfig) + ci.inCMakeCache = true; + if (!errorMessage.isEmpty()) { + const CMakeConfig changes = cmakeBuildConfiguration()->configurationChanges(); + for (const auto &ci : changes) { + const bool haveConfigItem = Utils::contains(cmakeConfig, [ci](const CMakeConfigItem& i) { + return i.key == ci.key; + }); + if (!haveConfigItem) + cmakeConfig.append(ci); + } + } + cmakeBuildConfiguration()->setConfigurationFromCMake(cmakeConfig); +} + void CMakeBuildSystem::handleParsingSucceeded() { if (!cmakeBuildConfiguration()->isActive()) { @@ -699,10 +717,7 @@ void CMakeBuildSystem::handleParsingSucceeded() } { - CMakeConfig cmakeConfig = m_reader.takeParsedConfiguration(errorMessage); - for (auto &ci : cmakeConfig) - ci.inCMakeCache = true; - cmakeBuildConfiguration()->setConfigurationFromCMake(cmakeConfig); + updateCMakeConfiguration(errorMessage); checkAndReportError(errorMessage); } @@ -722,10 +737,7 @@ void CMakeBuildSystem::handleParsingFailed(const QString &msg) cmakeBuildConfiguration()->setError(msg); QString errorMessage; - CMakeConfig cmakeConfig = m_reader.takeParsedConfiguration(errorMessage); - for (auto &ci : cmakeConfig) - ci.inCMakeCache = true; - cmakeBuildConfiguration()->setConfigurationFromCMake(cmakeConfig); + updateCMakeConfiguration(errorMessage); // ignore errorMessage here, we already got one. m_ctestPath.clear(); |