CMakePM: Set CMakePM project settings via CMakePresets's vendor field

The field name is "qt.io/QtCreator/1.0":

```
  "vendor": {
    "qt.io/QtCreator/1.0": {
       "AskBeforePresetsReload": false,
       "AskReConfigureInitialParams": false,
       "AutorunCMake": false,
       "PackageManagerAutoSetup": false,
       "ShowAdvancedOptionsByDefault": true,
       "ShowSourceSubFolders": false,
       "UseJunctionsForSourceAndBuildDirectories": true
    }
  }
```

Fixes: QTCREATORBUG-25972
Fixes: QTCREATORBUG-29559
Fixes: QTCREATORBUG-30385
Change-Id: Ifac0d10eebda85f8d97e7a1387325a555101ea6d
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Cristian Adam
2024-05-24 17:24:04 +02:00
parent fffa067a00
commit 1a5f61adca
4 changed files with 65 additions and 5 deletions

View File

@@ -121,6 +121,14 @@ Internal::PresetsData CMakeProject::combinePresets(Internal::PresetsData &cmakeP
result.include = cmakeUserPresetsData.include; result.include = cmakeUserPresetsData.include;
} }
result.vendor = cmakePresetsData.vendor;
if (result.vendor) {
if (cmakeUserPresetsData.vendor)
result.vendor->insert(cmakeUserPresetsData.vendor.value());
} else {
result.vendor = cmakeUserPresetsData.vendor;
}
auto combinePresetsInternal = [](auto &presetsHash, auto combinePresetsInternal = [](auto &presetsHash,
auto &presets, auto &presets,
auto &userPresets, auto &userPresets,

View File

@@ -12,6 +12,7 @@
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectimporter.h>
#include <projectexplorer/projectpanelfactory.h> #include <projectexplorer/projectpanelfactory.h>
#include <utils/hostosinfo.h> #include <utils/hostosinfo.h>
@@ -122,7 +123,13 @@ CMakeSpecificSettings::CMakeSpecificSettings(Project *p, bool autoApply)
if (project) { if (project) {
// Re-read the settings. Reading in constructor is too early // Re-read the settings. Reading in constructor is too early
connect(project, &Project::settingsLoaded, this, [this] { connect(project, &Project::settingsLoaded, this, [this] { readSettings(); });
connect(project->projectImporter(), &ProjectImporter::cmakePresetsUpdated, this, [this] {
// clear settings first
Store data;
project->setNamedSettings(Constants::Settings::GENERAL_ID, variantFromStore(data));
readSettings(); readSettings();
}); });
} }
@@ -133,10 +140,25 @@ void CMakeSpecificSettings::readSettings()
if (!project) { if (!project) {
AspectContainer::readSettings(); AspectContainer::readSettings();
} else { } else {
const Store data = storeFromVariant(project->namedSettings(Constants::Settings::GENERAL_ID)); Store data = storeFromVariant(project->namedSettings(Constants::Settings::GENERAL_ID));
if (data.isEmpty()) {
CMakeProject *cmakeProject = static_cast<CMakeProject *>(project);
if (cmakeProject->presetsData().havePresets && cmakeProject->presetsData().vendor) {
useGlobalSettings = false;
data = storeFromMap(cmakeProject->presetsData().vendor.value());
fromMap(data);
// Write the new loaded CMakePresets settings into .user file
writeSettings();
} else {
useGlobalSettings = true;
AspectContainer::readSettings();
}
} else {
useGlobalSettings = data.value(Constants::Settings::USE_GLOBAL_SETTINGS, true).toBool(); useGlobalSettings = data.value(Constants::Settings::USE_GLOBAL_SETTINGS, true).toBool();
fromMap(data); fromMap(data);
} }
}
} }
void CMakeSpecificSettings::writeSettings() const void CMakeSpecificSettings::writeSettings() const

View File

@@ -435,6 +435,30 @@ bool parseBuildPresets(const QJsonValue &jsonValue,
return true; return true;
} }
bool parseVendor(const QJsonValue &jsonValue, std::optional<QVariantMap> &vendorSettings)
{
// The whole section is optional
if (jsonValue.isUndefined())
return true;
if (!jsonValue.isObject())
return false;
const QJsonObject object = jsonValue.toObject();
const QJsonValue qtIo = object.value("qt.io/QtCreator/1.0");
if (qtIo.isUndefined())
return true;
if (!qtIo.isObject())
return false;
const QJsonObject qtIoObject = qtIo.toObject();
vendorSettings = QVariantMap();
for (const QString &settingKey : qtIoObject.keys()) {
const QJsonValue settingValue = qtIoObject.value(settingKey);
vendorSettings->insert(settingKey, settingValue.toVariant());
}
return true;
}
const PresetsData &PresetsParser::presetsData() const const PresetsData &PresetsParser::presetsData() const
{ {
return m_presetsData; return m_presetsData;
@@ -502,6 +526,12 @@ bool PresetsParser::parse(const Utils::FilePath &jsonFile, QString &errorMessage
return false; return false;
} }
// optional
if (!parseVendor(root.value("vendor"), m_presetsData.vendor)) {
errorMessage = ::CMakeProjectManager::Tr::tr("Invalid \"vendor\" section in %1 file")
.arg(jsonFile.fileName());
}
return true; return true;
} }

View File

@@ -142,7 +142,7 @@ public:
int version = 0; int version = 0;
bool havePresets = false; bool havePresets = false;
QVersionNumber cmakeMinimimRequired; QVersionNumber cmakeMinimimRequired;
QHash<QString, QString> vendor; std::optional<QVariantMap> vendor;
std::optional<QStringList> include; std::optional<QStringList> include;
Utils::FilePath fileDir; Utils::FilePath fileDir;
QList<PresetsDetails::ConfigurePreset> configurePresets; QList<PresetsDetails::ConfigurePreset> configurePresets;