forked from qt-creator/qt-creator
CMakePM: Add default kit configuration hashing
This adds a QTC_KIT_DEFAULT_CONFIG_HASH variable containing the hash of all the default Qt Creator CMake kit variables: * CMAKE_C_COMPILER * CMAKE_CXX_COMPILER * QT_QMAKE_EXECUTABLE * CMAKE_PREFIX_PATH This way when a CMake preset changes any of these CMake variables a new Kit will be created. Otherwise a previous kit containing different values will be used. Fixes: QTCREATORBUG-28609 Change-Id: I77b67e9c8fa15dc3ff2f22c5b63d4ca1c7670fdc Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -39,6 +39,7 @@
|
||||
#include <utils/variablechooser.h>
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QCryptographicHash>
|
||||
#include <QDialog>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QGridLayout>
|
||||
@@ -875,6 +876,7 @@ const char CMAKE_CXX_TOOLCHAIN_KEY[] = "CMAKE_CXX_COMPILER";
|
||||
const char CMAKE_QMAKE_KEY[] = "QT_QMAKE_EXECUTABLE";
|
||||
const char CMAKE_PREFIX_PATH_KEY[] = "CMAKE_PREFIX_PATH";
|
||||
const char QTC_CMAKE_PRESET_KEY[] = "QTC_CMAKE_PRESET";
|
||||
const char QTC_KIT_DEFAULT_CONFIG_HASH[] = "QTC_KIT_DEFAULT_CONFIG_HASH";
|
||||
|
||||
class CMakeConfigurationKitAspectWidget final : public KitAspectWidget
|
||||
{
|
||||
@@ -1135,6 +1137,43 @@ CMakeConfigItem CMakeConfigurationKitAspect::cmakePresetConfigItem(const Project
|
||||
});
|
||||
}
|
||||
|
||||
void CMakeConfigurationKitAspect::setKitDefaultConfigHash(ProjectExplorer::Kit *k)
|
||||
{
|
||||
const CMakeConfig defaultConfigExpanded
|
||||
= Utils::transform(defaultConfiguration(k).toList(), [k](const CMakeConfigItem &item) {
|
||||
CMakeConfigItem expanded(item);
|
||||
expanded.value = item.expandedValue(k).toUtf8();
|
||||
return expanded;
|
||||
});
|
||||
const QByteArray kitHash = computeDefaultConfigHash(defaultConfigExpanded);
|
||||
|
||||
CMakeConfig config = configuration(k);
|
||||
config.append(CMakeConfigItem(QTC_KIT_DEFAULT_CONFIG_HASH, CMakeConfigItem::INTERNAL, kitHash));
|
||||
|
||||
setConfiguration(k, config);
|
||||
}
|
||||
|
||||
CMakeConfigItem CMakeConfigurationKitAspect::kitDefaultConfigHashItem(const ProjectExplorer::Kit *k)
|
||||
{
|
||||
const CMakeConfig config = configuration(k);
|
||||
return Utils::findOrDefault(config, [](const CMakeConfigItem &item) {
|
||||
return item.key == QTC_KIT_DEFAULT_CONFIG_HASH;
|
||||
});
|
||||
}
|
||||
|
||||
QByteArray CMakeConfigurationKitAspect::computeDefaultConfigHash(const CMakeConfig &config)
|
||||
{
|
||||
const CMakeConfig defaultConfig = defaultConfiguration(nullptr);
|
||||
const QByteArray configValues = std::accumulate(defaultConfig.begin(),
|
||||
defaultConfig.end(),
|
||||
QByteArray(),
|
||||
[config](QByteArray &sum,
|
||||
const CMakeConfigItem &item) {
|
||||
return sum += config.valueOf(item.key);
|
||||
});
|
||||
return QCryptographicHash::hash(configValues, QCryptographicHash::Md5).toHex();
|
||||
}
|
||||
|
||||
QVariant CMakeConfigurationKitAspect::defaultValue(const Kit *k) const
|
||||
{
|
||||
// FIXME: Convert preload scripts
|
||||
|
||||
Reference in New Issue
Block a user