From 69e391fbe1449dd23c395e3021ab222e51637d28 Mon Sep 17 00:00:00 2001 From: John Cortell Date: Tue, 12 Apr 2011 16:35:04 +0000 Subject: [PATCH] Bug 342096 - Executables view shows binaries for all build configurations instead of just the active ones --- .../IProjectExecutablesProvider.java | 3 +- .../StandardExecutableProvider.java | 46 +++++++++++++++++-- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/IProjectExecutablesProvider.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/IProjectExecutablesProvider.java index c9b0c58d7e2..9a5baedd309 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/IProjectExecutablesProvider.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/IProjectExecutablesProvider.java @@ -36,7 +36,8 @@ public interface IProjectExecutablesProvider { List getProjectNatures(); /** - * Get the list of executables for the given project + * Get the list of executables for the active configuration of the given + * project * @param project the project to get the executables for * @param monitor progress monitor * @return the list of executables (which may be empty) diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/StandardExecutableProvider.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/StandardExecutableProvider.java index 8280f5f9aa9..52903c09f88 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/StandardExecutableProvider.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/executables/StandardExecutableProvider.java @@ -12,15 +12,19 @@ package org.eclipse.cdt.debug.core.executables; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.eclipse.cdt.core.CCProjectNature; import org.eclipse.cdt.core.CProjectNature; -import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.IBinary; import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICOutputEntry; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.internal.core.model.CModelManager; +import org.eclipse.cdt.internal.core.settings.model.CProjectDescriptionManager; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; @@ -52,9 +56,42 @@ public class StandardExecutableProvider implements IProjectExecutablesProvider { ICProject cproject = CModelManager.getDefault().create(project); try { - IBinary[] binaries = cproject.getBinaryContainer().getBinaries(); + // Start out by getting all binaries in all build configurations. If + // we can't filter based on the active configuration, we'll use this + // complete list + IBinary[] allBinaries = cproject.getBinaryContainer().getBinaries(); + if (allBinaries.length == 0) { + return executables; // save ourselves a lot of pointless busy work + } + + // Get the output directories of the active build configuration then + // go through the list of all binaries and pick only the ones that + // are in these output directories + List binaries = null; + ICProjectDescription projDesc = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); + if (projDesc != null) { + ICConfigurationDescription cfg = projDesc.getActiveConfiguration(); + if (cfg != null) { + binaries = new ArrayList(allBinaries.length); + ICOutputEntry[] cfgOutDirs = cfg.getBuildSetting().getOutputDirectories(); + for (IBinary allBinary : allBinaries) { + for (ICOutputEntry outdir : cfgOutDirs) { + if (outdir.getFullPath().isPrefixOf(allBinary.getPath())) { + binaries.add(allBinary); + break; + } + } + } + } + } - SubMonitor progress = SubMonitor.convert(monitor, binaries.length); + // If we weren't able to filter on the active configuration, + // consider binaries from all configurations + if (binaries == null) { + binaries = Arrays.asList(allBinaries); + } + + SubMonitor progress = SubMonitor.convert(monitor, binaries.size()); for (IBinary binary : binaries) { if (progress.isCanceled()) { @@ -78,7 +115,8 @@ public class StandardExecutableProvider implements IProjectExecutablesProvider { progress.worked(1); } - } catch (CModelException e) { + } catch (CoreException e) { + CDebugCorePlugin.log(e); } return executables;