From 4657563e4a68008d4fa7bf8ac69c2a5f39d786a9 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Tue, 10 Mar 2020 15:52:15 +0100 Subject: [PATCH] ProjectExplorer: Try harder not to lose custom project settings ... when a kit disappears. This can easily happen, for instance due to a Qt version update via the installer, and until now resulted in the disappearance of all user customizations of build and run configurations. We now store some additional data when serializing a target, and use it to recreate a kit of the same type upon restoring. While the resulting configurations are not guaranteed to be functional, they should contain all the customizations, which the user can then copy over to a proper kit. Fixes: QTCREATORBUG-23023 Change-Id: I659d52808b2f8a308e6aa094e8ef2ee60d586952 Reviewed-by: hjk --- src/plugins/projectexplorer/project.cpp | 21 +++++++++++++++++++-- src/plugins/projectexplorer/target.cpp | 14 ++++++++++++-- src/plugins/projectexplorer/target.h | 3 +++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/plugins/projectexplorer/project.cpp b/src/plugins/projectexplorer/project.cpp index e7e6599ed91..7376ecd6ea5 100644 --- a/src/plugins/projectexplorer/project.cpp +++ b/src/plugins/projectexplorer/project.cpp @@ -31,6 +31,7 @@ #include "deployconfiguration.h" #include "editorconfiguration.h" #include "kit.h" +#include "kitinformation.h" #include "makestep.h" #include "projectexplorer.h" #include "projectmacroexpander.h" @@ -39,6 +40,7 @@ #include "runcontrol.h" #include "session.h" #include "target.h" +#include "taskhub.h" #include "userfileaccessor.h" #include @@ -57,6 +59,7 @@ #include #include #include +#include #include @@ -757,8 +760,22 @@ void Project::createTargetFromMap(const QVariantMap &map, int index) Kit *k = KitManager::kit(id); if (!k) { - qWarning("Warning: No kit '%s' found. Continuing.", qPrintable(id.toString())); - return; + Core::Id deviceTypeId = Core::Id::fromSetting(targetMap.value(Target::deviceTypeKey())); + if (!deviceTypeId.isValid()) + deviceTypeId = Constants::DESKTOP_DEVICE_TYPE; + const QString formerKitName = targetMap.value(Target::displayNameKey()).toString(); + k = KitManager::registerKit([deviceTypeId, &formerKitName](Kit *kit) { + const QString tempKitName = Utils::makeUniquelyNumbered( + tr("Replacement for \"%1\"").arg(formerKitName), + Utils::transform(KitManager::kits(), &Kit::unexpandedDisplayName)); + kit->setUnexpandedDisplayName(tempKitName); + DeviceTypeKitAspect::setDeviceTypeId(kit, deviceTypeId); + kit->setup(); + }, id); + TaskHub::addTask(BuildSystemTask(Task::Warning, tr("Project \"%1\" was configured for " + "kit \"%2\" with id %3, which does not exist anymore. The new kit \"%4\" was " + "created in its place, in an attempt not to lose custom project settings.") + .arg(displayName(), formerKitName, id.toString(), k->displayName()))); } auto t = std::make_unique(this, k, Target::_constructor_tag{}); diff --git a/src/plugins/projectexplorer/target.cpp b/src/plugins/projectexplorer/target.cpp index 96bff5606b4..6687f4dfbef 100644 --- a/src/plugins/projectexplorer/target.cpp +++ b/src/plugins/projectexplorer/target.cpp @@ -259,6 +259,16 @@ QString Target::toolTip() const return d->m_kit->toHtml(); } +QString Target::displayNameKey() +{ + return QString("ProjectExplorer.ProjectConfiguration.DisplayName"); +} + +QString Target::deviceTypeKey() +{ + return QString("DeviceType"); +} + void Target::addBuildConfiguration(BuildConfiguration *bc) { QTC_ASSERT(bc && !d->m_buildConfigurations.contains(bc), return); @@ -499,15 +509,15 @@ QVariantMap Target::toMap() const return QVariantMap(); QVariantMap map; + map.insert(displayNameKey(), displayName()); + map.insert(deviceTypeKey(), DeviceTypeKitAspect::deviceTypeId(kit()).toSetting()); { // FIXME: For compatibility within the 4.11 cycle, remove this block later. // This is only read by older versions of Creator, but even there not actively used. const char CONFIGURATION_ID_KEY[] = "ProjectExplorer.ProjectConfiguration.Id"; - const char DISPLAY_NAME_KEY[] = "ProjectExplorer.ProjectConfiguration.DisplayName"; const char DEFAULT_DISPLAY_NAME_KEY[] = "ProjectExplorer.ProjectConfiguration.DefaultDisplayName"; map.insert(QLatin1String(CONFIGURATION_ID_KEY), id().toSetting()); - map.insert(QLatin1String(DISPLAY_NAME_KEY), displayName()); map.insert(QLatin1String(DEFAULT_DISPLAY_NAME_KEY), displayName()); } diff --git a/src/plugins/projectexplorer/target.h b/src/plugins/projectexplorer/target.h index 652b5624a6f..7ccd4e7901e 100644 --- a/src/plugins/projectexplorer/target.h +++ b/src/plugins/projectexplorer/target.h @@ -69,6 +69,9 @@ public: QString displayName() const; QString toolTip() const; + static QString displayNameKey(); + static QString deviceTypeKey(); + // Build configuration void addBuildConfiguration(BuildConfiguration *bc); bool removeBuildConfiguration(BuildConfiguration *bc);