From 83ae0cb93446145f30e6c05551a58b064492e130 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Fri, 1 Apr 2016 16:22:07 +0200 Subject: [PATCH] CMake: Mark cmake as imperfect and disable RunConfigurations as necessary CMake does not know whether a build target was configured out of the current build or removed entirely, so implement the relevant marker. Mark all of the "vanished" RunConfigurations as disabled. Also remove one unnecessary level of indirection when setting up RunConfigurations. Change-Id: I30a21581823b4bff5a5be29480e64423b9379983 Task-number: QTCREATORBUG-15950 Reviewed-by: Tim Jenssen --- .../cmakeprojectmanager/cmakeproject.cpp | 57 ++++++++----------- .../cmakeprojectmanager/cmakeproject.h | 3 +- 2 files changed, 25 insertions(+), 35 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp index 4cc2f612ca6..b7dcd0eaa69 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp @@ -219,6 +219,7 @@ void CMakeProject::parseCMakeOutput() bdm->clearFiles(); // Some of the FileNodes in files() were deleted! updateApplicationAndDeploymentTargets(); + updateTargetRunConfigurations(t); createGeneratedCodeModelSupport(); @@ -267,8 +268,6 @@ void CMakeProject::parseCMakeOutput() emit fileListChanged(); emit cmakeBc->emitBuildTypeChanged(); - - updateRunConfigurations(); } bool CMakeProject::needsConfiguration() const @@ -281,6 +280,11 @@ bool CMakeProject::requiresTargetPanel() const return !targets().isEmpty(); } +bool CMakeProject::knowsAllBuildExecutables() const +{ + return false; +} + bool CMakeProject::supportsKit(Kit *k, QString *errorMessage) const { if (!CMakeKitInformation::cmakeTool(k)) { @@ -549,46 +553,33 @@ QStringList CMakeProject::filesGeneratedFrom(const QString &sourceFile) const } } -void CMakeProject::updateRunConfigurations() -{ - foreach (Target *t, targets()) - updateTargetRunConfigurations(t); -} - -// TODO Compare with updateDefaultRunConfigurations(); void CMakeProject::updateTargetRunConfigurations(Target *t) { - // create new and remove obsolete RCs using the factories - t->updateDefaultRunConfigurations(); + // *Update* existing runconfigurations (no need to update new ones!): + QHash buildTargetHash; + const QList buildTargetList = buildTargets(); + foreach (const CMakeBuildTarget &bt, buildTargetList) { + if (bt.targetType != ExecutableType || bt.executable.isEmpty()) + continue; - // *Update* runconfigurations: - QMultiMap existingRunConfigurations; - foreach (ProjectExplorer::RunConfiguration *rc, t->runConfigurations()) { - if (CMakeRunConfiguration* cmakeRC = qobject_cast(rc)) - existingRunConfigurations.insert(cmakeRC->title(), cmakeRC); + buildTargetHash.insert(bt.title, &bt); } - foreach (const CMakeBuildTarget &ct, buildTargets()) { - if (ct.targetType != ExecutableType) + foreach (RunConfiguration *rc, t->runConfigurations()) { + auto cmakeRc = qobject_cast(rc); + if (!cmakeRc) continue; - if (ct.executable.isEmpty()) - continue; - QList list = existingRunConfigurations.values(ct.title); - if (!list.isEmpty()) { - // Already exists, so override the settings... - foreach (CMakeRunConfiguration *rc, list) { - rc->setExecutable(ct.executable); - rc->setBaseWorkingDirectory(ct.workingDirectory); - rc->setEnabled(true); - } + + auto btIt = buildTargetHash.constFind(cmakeRc->title()); + cmakeRc->setEnabled(btIt != buildTargetHash.constEnd()); + if (btIt != buildTargetHash.constEnd()) { + cmakeRc->setExecutable(btIt.value()->executable); + cmakeRc->setBaseWorkingDirectory(btIt.value()->workingDirectory); } } - if (t->runConfigurations().isEmpty()) { - // Oh no, no run configuration, - // create a custom executable run configuration - t->addRunConfiguration(new QtSupport::CustomExecutableRunConfiguration(t)); - } + // create new and remove obsolete RCs using the factories + t->updateDefaultRunConfigurations(); } void CMakeProject::updateApplicationAndDeploymentTargets() diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.h b/src/plugins/cmakeprojectmanager/cmakeproject.h index fabdc6da146..f6616ef9d8c 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.h +++ b/src/plugins/cmakeprojectmanager/cmakeproject.h @@ -105,6 +105,7 @@ public: bool needsConfiguration() const override; bool requiresTargetPanel() const override; + bool knowsAllBuildExecutables() const override; bool supportsKit(ProjectExplorer::Kit *k, QString *errorMessage = 0) const override; @@ -124,8 +125,6 @@ private: void handleParsingStarted(); void parseCMakeOutput(); - void updateRunConfigurations(); - void buildTree(Internal::CMakeProjectNode *rootNode, QList list); void gatherFileNodes(ProjectExplorer::FolderNode *parent, QList &list) const; ProjectExplorer::FolderNode *findOrCreateFolder(Internal::CMakeProjectNode *rootNode, QString directory);