From f18214b407320b9b2f86ebdb36ece59a86ab9d1f Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Thu, 31 Jan 2019 18:23:10 +0100 Subject: [PATCH] ProjectExplorer: Allow project managers to provide uniquification ... for otherwise identically-named targets. It happens quite often in larger qmake projects that some applications in a nested SUBDIRS structure get the same name (e.g. a tool and its autotest). It was until now impossible for a user to differentiate between the corresponding run configurations: In the list of run configs, we just appended numbers, and in the UI element for manually creating run configs, the strings were even entirely identical. For a practical example, open tests.pro in qtbase and count the number of run configs called "test". Now we detect such collisions early and append the relative path of the project file to the display names of the affected run configurations. For now, this is only done for qmake projects: The problem cannot occur with qbs, and we don't have any complaints about cmake. The infrastructure is generic, however. Fixes: QTCREATORBUG-9563 Change-Id: Ic076df9b5a8bda7c9a1f88df683f33c837eaa197 Reviewed-by: hjk --- src/plugins/projectexplorer/buildtargetinfo.h | 1 + src/plugins/projectexplorer/runconfiguration.cpp | 13 ++++++++++++- src/plugins/projectexplorer/runconfiguration.h | 1 + src/plugins/qmakeprojectmanager/qmakeproject.cpp | 6 ++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/plugins/projectexplorer/buildtargetinfo.h b/src/plugins/projectexplorer/buildtargetinfo.h index 0aa5011dda1..38cadea9912 100644 --- a/src/plugins/projectexplorer/buildtargetinfo.h +++ b/src/plugins/projectexplorer/buildtargetinfo.h @@ -41,6 +41,7 @@ class PROJECTEXPLORER_EXPORT BuildTargetInfo public: QString buildKey; // Used to identify this BuildTargetInfo object in its list. QString displayName; + QString displayNameUniquifier; Utils::FileName targetFilePath; Utils::FileName projectFilePath; diff --git a/src/plugins/projectexplorer/runconfiguration.cpp b/src/plugins/projectexplorer/runconfiguration.cpp index 475eeb9dca3..2c8e2384955 100644 --- a/src/plugins/projectexplorer/runconfiguration.cpp +++ b/src/plugins/projectexplorer/runconfiguration.cpp @@ -49,6 +49,7 @@ #include #include +#include #include #include #include @@ -466,6 +467,7 @@ RunConfigurationFactory::availableCreators(Target *parent) const rci.id = m_runConfigBaseId; rci.buildKey = ti.buildKey; rci.displayName = displayName; + rci.displayNameUniquifier = ti.displayNameUniquifier; rci.creationMode = ti.isQtcRunnable || !hasAnyQtcRunnable ? RunConfigurationCreationInfo::AlwaysCreate : RunConfigurationCreationInfo::ManualCreationOnly; @@ -540,7 +542,7 @@ RunConfiguration *RunConfigurationCreationInfo::create(Target *target) const rc->m_buildKey = buildKey; rc->doAdditionalSetup(*this); - rc->setDefaultDisplayName(displayName); + rc->setDisplayName(displayName); return rc; } @@ -575,6 +577,15 @@ const QList RunConfigurationFactory::creatorsForTa if (factory->canHandle(parent)) items.append(factory->availableCreators(parent)); } + QHash> itemsPerDisplayName; + for (RunConfigurationCreationInfo &item : items) + itemsPerDisplayName[item.displayName] << &item; + for (auto it = itemsPerDisplayName.cbegin(); it != itemsPerDisplayName.cend(); ++it) { + if (it.value().size() == 1) + continue; + for (RunConfigurationCreationInfo * const rci : it.value()) + rci->displayName += rci->displayNameUniquifier; + } return items; } diff --git a/src/plugins/projectexplorer/runconfiguration.h b/src/plugins/projectexplorer/runconfiguration.h index c454f7e0ade..c0443ae07e2 100644 --- a/src/plugins/projectexplorer/runconfiguration.h +++ b/src/plugins/projectexplorer/runconfiguration.h @@ -234,6 +234,7 @@ public: Core::Id id; QString buildKey; QString displayName; + QString displayNameUniquifier; CreationMode creationMode = AlwaysCreate; bool useTerminal = false; }; diff --git a/src/plugins/qmakeprojectmanager/qmakeproject.cpp b/src/plugins/qmakeprojectmanager/qmakeproject.cpp index 894163ab47c..6e92cf45d2c 100644 --- a/src/plugins/qmakeprojectmanager/qmakeproject.cpp +++ b/src/plugins/qmakeprojectmanager/qmakeproject.cpp @@ -1029,6 +1029,12 @@ void QmakeProject::updateBuildSystemData() bti.projectFilePath = node->filePath(); bti.workingDirectory = FileName::fromString(workingDir); bti.displayName = bti.projectFilePath.toFileInfo().completeBaseName(); + const FileName relativePathInProject + = bti.projectFilePath.relativeChildPath(projectDirectory()); + if (!relativePathInProject.isEmpty()) { + bti.displayNameUniquifier = QString::fromLatin1(" (%1)") + .arg(relativePathInProject.toUserOutput()); + } bti.buildKey = bti.projectFilePath.toString(); bti.isQtcRunnable = config.contains("qtc_runnable");