forked from qt-creator/qt-creator
CMakePM: Fix duplicated CMake presets kits
QTC_KIT_DEFAULT_CONFIG_HASH was introduced in order to match the previous CMake presets kits. This would hash the Qt and the C/C++ compiler paths. Unfortunately on Linux CMake would pick "cc" and "c++" by default, whilst Qt Creator uses "gcc" and "g++". The compilers would match from the Qt Creator point of view, but the hash values would be different. On mac there is a similar issue with compiler launchers. This patchset fixes this by removing the hash and fixes also the issue of allowing broken CMake presets kits (without any compilers), which were the reason for introducing the hash key in the first place. Fixes: QTCREATORBUG-29075 Change-Id: Id8dc081febba7bc7023c98055afc6ebfcdc55542 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -1182,12 +1182,6 @@ static void addCMakeConfigurePresetToInitialArguments(QStringList &initialArgume
|
||||
initialArguments.removeIf(
|
||||
[presetArgument](const QString &item) { return item == presetArgument; });
|
||||
|
||||
// Remove the -DQTC_KIT_DEFAULT_CONFIG_HASH argument
|
||||
const QString presetHashArgument
|
||||
= CMakeConfigurationKitAspect::kitDefaultConfigHashItem(k).toArgument();
|
||||
initialArguments.removeIf(
|
||||
[presetHashArgument](const QString &item) { return item == presetHashArgument; });
|
||||
|
||||
PresetsDetails::ConfigurePreset configurePreset
|
||||
= Utils::findOrDefault(project->presetsData().configurePresets,
|
||||
[presetName](const PresetsDetails::ConfigurePreset &preset) {
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
#include <utils/variablechooser.h>
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QCryptographicHash>
|
||||
#include <QDialog>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QGridLayout>
|
||||
@@ -874,7 +873,6 @@ 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,51 +1133,6 @@ 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 CMakeTool *const tool = CMakeKitAspect::cmakeTool(k);
|
||||
const QByteArray kitHash = computeDefaultConfigHash(defaultConfigExpanded,
|
||||
tool ? tool->cmakeExecutable()
|
||||
: FilePath());
|
||||
|
||||
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 FilePath &cmakeBinary)
|
||||
{
|
||||
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(cmakeBinary.caseSensitivity() == Qt::CaseInsensitive
|
||||
? configValues.toLower()
|
||||
: configValues,
|
||||
QCryptographicHash::Md5)
|
||||
.toHex();
|
||||
}
|
||||
|
||||
QVariant CMakeConfigurationKitAspect::defaultValue(const Kit *k) const
|
||||
{
|
||||
// FIXME: Convert preload scripts
|
||||
|
||||
@@ -91,11 +91,6 @@ public:
|
||||
static void setCMakePreset(ProjectExplorer::Kit *k, const QString &presetName);
|
||||
static CMakeConfigItem cmakePresetConfigItem(const ProjectExplorer::Kit *k);
|
||||
|
||||
static void setKitDefaultConfigHash(ProjectExplorer::Kit *k);
|
||||
static CMakeConfigItem kitDefaultConfigHashItem(const ProjectExplorer::Kit *k);
|
||||
static QByteArray computeDefaultConfigHash(const CMakeConfig &config,
|
||||
const Utils::FilePath &cmakeBinary);
|
||||
|
||||
// KitAspect interface
|
||||
ProjectExplorer::Tasks validate(const ProjectExplorer::Kit *k) const final;
|
||||
void setup(ProjectExplorer::Kit *k) final;
|
||||
|
||||
@@ -46,7 +46,6 @@ struct DirectoryData
|
||||
|
||||
QString cmakePresetDisplayname;
|
||||
QString cmakePreset;
|
||||
QByteArray cmakePresetDefaultConfigHash;
|
||||
|
||||
// Kit Stuff
|
||||
FilePath cmakeBinary;
|
||||
@@ -731,9 +730,6 @@ QList<void *> CMakeProjectImporter::examineDirectory(const FilePath &importPath,
|
||||
// Update QT_QMAKE_EXECUTABLE and CMAKE_C|XX_COMPILER config values
|
||||
updateConfigWithDirectoryData(config, data);
|
||||
|
||||
data->cmakePresetDefaultConfigHash
|
||||
= CMakeConfigurationKitAspect::computeDefaultConfigHash(config, data->cmakeBinary);
|
||||
|
||||
QByteArrayList buildConfigurationTypes = {cache.valueOf("CMAKE_BUILD_TYPE")};
|
||||
if (buildConfigurationTypes.front().isEmpty()) {
|
||||
buildConfigurationTypes.clear();
|
||||
@@ -862,36 +858,50 @@ bool CMakeProjectImporter::matchKit(void *directoryData, const Kit *k) const
|
||||
if (data->qt.qt && QtSupport::QtKitAspect::qtVersionId(k) != data->qt.qt->uniqueId())
|
||||
return false;
|
||||
|
||||
const bool compilersMatch = [k, data] {
|
||||
const QList<Id> allLanguages = ToolChainManager::allLanguages();
|
||||
for (const ToolChainDescription &tcd : data->toolChains) {
|
||||
if (!Utils::contains(allLanguages,
|
||||
[&tcd](const Id &language) { return language == tcd.language; }))
|
||||
continue;
|
||||
ToolChain *tc = ToolChainKitAspect::toolChain(k, tcd.language);
|
||||
if ((!tc || !tc->matchesCompilerCommand(tcd.compilerPath))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}();
|
||||
const bool noCompilers = [k, data] {
|
||||
const QList<Id> allLanguages = ToolChainManager::allLanguages();
|
||||
for (const ToolChainDescription &tcd : data->toolChains) {
|
||||
if (!Utils::contains(allLanguages,
|
||||
[&tcd](const Id &language) { return language == tcd.language; }))
|
||||
continue;
|
||||
ToolChain *tc = ToolChainKitAspect::toolChain(k, tcd.language);
|
||||
if (tc && tc->matchesCompilerCommand(tcd.compilerPath)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}();
|
||||
|
||||
bool haveCMakePreset = false;
|
||||
if (!data->cmakePreset.isEmpty()) {
|
||||
const auto presetConfigItem = CMakeConfigurationKitAspect::cmakePresetConfigItem(k);
|
||||
const auto kitConfigHashItem = CMakeConfigurationKitAspect::kitDefaultConfigHashItem(k);
|
||||
|
||||
const QString presetName = presetConfigItem.expandedValue(k);
|
||||
const bool haveSameKitConfigHash = kitConfigHashItem.isNull()
|
||||
? true
|
||||
: data->cmakePresetDefaultConfigHash
|
||||
== kitConfigHashItem.value;
|
||||
|
||||
if (data->cmakePreset != presetName || !haveSameKitConfigHash)
|
||||
if (data->cmakePreset != presetName)
|
||||
return false;
|
||||
|
||||
ensureBuildDirectory(*data, k);
|
||||
haveCMakePreset = true;
|
||||
}
|
||||
|
||||
const QList<Id> allLanguages = ToolChainManager::allLanguages();
|
||||
for (const ToolChainDescription &tcd : data->toolChains) {
|
||||
if (!Utils::contains(allLanguages, [&tcd](const Id& language) {return language == tcd.language;}))
|
||||
continue;
|
||||
ToolChain *tc = ToolChainKitAspect::toolChain(k, tcd.language);
|
||||
if ((!tc || !tc->matchesCompilerCommand(tcd.compilerPath)) && !haveCMakePreset) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!compilersMatch && !(haveCMakePreset && noCompilers))
|
||||
return false;
|
||||
|
||||
qCDebug(cmInputLog) << k->displayName()
|
||||
<< "matches directoryData for" << data->buildDirectory.toUserOutput();
|
||||
<< "matches directoryData for" << data->buildDirectory.toUserOutput();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -930,7 +940,6 @@ Kit *CMakeProjectImporter::createKit(void *directoryData) const
|
||||
QString("%1 (CMake preset)").arg(data->cmakePresetDisplayname));
|
||||
|
||||
CMakeConfigurationKitAspect::setCMakePreset(k, data->cmakePreset);
|
||||
CMakeConfigurationKitAspect::setKitDefaultConfigHash(k);
|
||||
}
|
||||
if (!data->cmakePreset.isEmpty())
|
||||
ensureBuildDirectory(*data, k);
|
||||
|
||||
Reference in New Issue
Block a user