1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-03-28 14:56:28 +01:00

Updated Main Tab for Core Build local launch configurations.

A new Main Tab was created for Core Build local projects based on the Main
Tab used for the classic Managed Build projects. It adds these
features:

* Option to select a different binary.
* Option to control launch pre-builds.

The default value for the binary is empty string. With empty string
the behaviour for binary selection stays the same as it was.

The project name is fixed and cannot be changed. A Core Build launch
configuration is created with the project and tied to it.

There is no option to select a build configuration, because for Core
Build projects this is selected via the LaunchBar's Launch Mode.

This change relates to #758. It affects all Core Build projects,
including CMake projects.
This commit is contained in:
Erwin Waterlander 2024-11-18 15:44:09 +00:00 committed by Jonah Graham
parent 9b6bb0711f
commit 5639ba9ff9
11 changed files with 88 additions and 59 deletions

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.debug.core; singleton:=true
Bundle-Version: 8.8.600.qualifier
Bundle-Version: 8.8.700.qualifier
Bundle-Activator: org.eclipse.cdt.debug.core.CDebugCorePlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin

View file

@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.cdt.debug.core.launch;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashSet;
@ -23,14 +24,18 @@ import org.eclipse.cdt.core.build.IToolChainManager;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.IBinary;
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.debug.internal.core.InternalDebugCoreMessages;
import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.variables.VariablesPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.launchbar.core.target.ILaunchTarget;
import org.eclipse.launchbar.core.target.launch.LaunchConfigurationTargetedDelegate;
@ -121,6 +126,28 @@ public abstract class CoreBuildLaunchConfigDelegate extends LaunchConfigurationT
return exeFile;
}
/**
* @since 8.8
*/
protected String getProgramPath(ILaunchConfiguration configuration, IBinary exeFile) throws CoreException {
String programName = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, ""); //$NON-NLS-1$
if (programName.isBlank()) {
return Paths.get(exeFile.getLocationURI()).toString();
} else {
IPath path = new Path(
VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(programName));
String fullPath;
if (path.isAbsolute()) {
fullPath = path.toOSString();
} else {
IProject project = getProject(configuration);
fullPath = project.getFile(path).getLocation().toOSString();
}
return fullPath;
}
}
@Override
protected IProject[] getBuildOrder(ILaunchConfiguration configuration, String mode) throws CoreException {
// 1. Extract project from configuration
@ -140,6 +167,16 @@ public abstract class CoreBuildLaunchConfigDelegate extends LaunchConfigurationT
@Override
public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, ILaunchTarget target,
IProgressMonitor monitor) throws CoreException {
// We will never get here if "build before launching" is disabled in the Workspace settings, even if in the
// CDT launch configuration "Use workspace settings" is not selected.
// The workspace setting is already considered in org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(),
// before the settings in the CDT launch configuration.
int autoBuild = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_BUILD_BEFORE_LAUNCH, 2);
if (autoBuild == 0) {
return false;
}
ICBuildConfiguration buildConfig = getBuildConfiguration(configuration, mode, target, monitor);
if (buildConfig != null) {
IProject project = getProject(configuration);

View file

@ -14,6 +14,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
@ -66,6 +67,10 @@ public class CoreBuildLocalLaunchConfigProvider extends AbstractLaunchConfigProv
// Set the project and the connection
IProject project = descriptor.getAdapter(IProject.class);
// CMainTab2 expects these attributes when calling CLaunchConfigurationTab.getContext()
// Using empty string for default Core Build program.
workingCopy.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, project.getName());
workingCopy.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, ""); //$NON-NLS-1$
workingCopy.setMappedResources(new IResource[] { project });
}

View file

@ -12,7 +12,6 @@ package org.eclipse.cdt.debug.internal.core.launch;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@ -55,7 +54,7 @@ public class CoreBuildLocalRunLaunchDelegate extends CoreBuildLaunchConfigDelega
String[] arguments = CommandLineUtil.argumentsToArray(args);
List<String> command = new ArrayList<>(1 + arguments.length);
command.add(Paths.get(exeFile.getLocationURI()).toString());
command.add(getProgramPath(configuration, exeFile));
command.addAll(Arrays.asList(arguments));
ProcessBuilder builder = new ProcessBuilder(command);

View file

@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-SymbolicName: org.eclipse.cdt.dsf.gdb;singleton:=true
Bundle-Version: 7.1.300.qualifier
Bundle-Version: 7.1.400.qualifier
Bundle-Activator: org.eclipse.cdt.dsf.gdb.internal.GdbPlugin
Bundle-Localization: plugin
Require-Bundle: org.eclipse.core.runtime,

View file

@ -19,6 +19,7 @@ import java.util.concurrent.ExecutionException;
import org.eclipse.cdt.core.build.ICBuildConfiguration;
import org.eclipse.cdt.core.build.IToolChain;
import org.eclipse.cdt.core.model.IBinary;
import org.eclipse.cdt.debug.core.launch.CoreBuildLaunchConfigDelegate;
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
import org.eclipse.cdt.dsf.concurrent.ImmediateExecutor;
@ -86,8 +87,8 @@ public class CoreBuildLocalDebugLaunchDelegate extends CoreBuildLaunchConfigDele
gdbLaunch.setGDBPath(gdbPath != null ? gdbPath.toString() : "gdb"); //$NON-NLS-1$
String gdbVersion = gdbLaunch.getGDBVersion();
Path exeFile = Paths.get(getBinary(buildConfig).getLocationURI());
gdbLaunch.setProgramPath(exeFile.toString());
IBinary exeFile = getBinary(buildConfig);
gdbLaunch.setProgramPath(getProgramPath(configuration, exeFile));
gdbLaunch.setServiceFactory(new GdbDebugServicesFactory(gdbVersion, configuration));

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.launch; singleton:=true
Bundle-Version: 10.4.600.qualifier
Bundle-Version: 10.4.700.qualifier
Bundle-Activator: org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin

View file

@ -52,6 +52,7 @@ public class LaunchMessages extends NLS {
public static String CommonBuildTab_Default;
public static String CommonBuildTab_NotFound;
public static String CommonBuildTab_Toolchain;
public static String CoreBuildMainTab_Keep_empty_for_auto_selection;
public static String CoreBuildTab_Build;
public static String CoreBuildTab_NoOptions;
public static String CoreFileLaunchDelegate_Launching_postmortem_debugger;

View file

@ -55,6 +55,7 @@ LocalAttachLaunchDelegate_CDT_Launch_Error=CDT Launch Error
CommonBuildTab_Default=Default (%s)
CommonBuildTab_NotFound=No suitable toolchains found
CommonBuildTab_Toolchain=Toolchain
CoreBuildMainTab_Keep_empty_for_auto_selection=keep empty for automatic selection
CoreBuildTab_Build=Build Settings
CoreBuildTab_NoOptions=No build options required.
CoreFileLaunchDelegate_Launching_postmortem_debugger=Launching postmortem debugger

View file

@ -93,7 +93,7 @@ public class CMainTab2 extends CAbstractMainTab {
*/
protected Combo fCoreTypeCombo;
private final boolean fDontCheckProgram;
private boolean fDontCheckProgram;
private final boolean fSpecifyCoreFile;
private final boolean fIncludeBuildSettings;
@ -111,6 +111,13 @@ public class CMainTab2 extends CAbstractMainTab {
fIncludeBuildSettings = (flags & INCLUDE_BUILD_SETTINGS) != 0;
}
/**
* @since 10.4
*/
protected void setDontCheckProgram(boolean dontCheck) {
fDontCheckProgram = dontCheck;
}
@Override
public void createControl(Composite parent) {
Composite comp = new Composite(parent, SWT.NONE);

View file

@ -10,73 +10,51 @@
*******************************************************************************/
package org.eclipse.cdt.launch.ui.corebuild;
import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.cdt.launch.internal.ui.LaunchMessages;
import org.eclipse.cdt.launch.ui.CMainTab2;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
/**
* @since 9.1
*/
public class CoreBuildMainTab extends AbstractLaunchConfigurationTab {
private Text projectName;
public class CoreBuildMainTab extends CMainTab2 {
/*
* A Core Build launch configuration is created immediately upon the Core Build project creation.
* It cannot be created by hand and it is not duplicatable and can't be renamed.
* The launch configuration is tied to the project. The project name may not be changed.
*/
@Override
public void createControl(Composite parent) {
Composite comp = new Composite(parent, SWT.NONE);
comp.setLayout(new GridLayout());
Label label = new Label(comp, SWT.NONE);
label.setText("This launch configuration was automatically created.");
label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
label = new Label(comp, SWT.NONE);
label.setText("Project:");
projectName = new Text(comp, SWT.READ_ONLY | SWT.BORDER);
projectName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
setControl(comp);
protected void createProjectGroup(Composite parent, int colSpan) {
super.createProjectGroup(parent, colSpan);
fProjText.setEnabled(false);
fProjButton.setVisible(false);
}
@Override
public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
// none
protected void createExeFileGroup(Composite parent, int colSpan) {
super.createExeFileGroup(parent, colSpan);
fProgText.setMessage(LaunchMessages.CoreBuildMainTab_Keep_empty_for_auto_selection);
}
/*
* For Core Build projects the build configuration is hidden and it is selected
* via the LaunchBar Launch Mode. We remove the BuildConfigCombo.
*/
@Override
public void initializeFrom(ILaunchConfiguration configuration) {
try {
for (IResource resource : configuration.getMappedResources()) {
if (resource instanceof IProject) {
projectName.setText(resource.getName());
break;
}
}
} catch (CoreException e) {
LaunchUIPlugin.log(e.getStatus());
}
protected void createBuildConfigCombo(Composite parent, int colspan) {
fBuildConfigCombo = null;
}
/*
* Don't check the program name if it is empty. When the program name is empty the default
* CoreBuild binary is used.
*/
@Override
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
// TODO Auto-generated method stub
public boolean isValid(ILaunchConfiguration config) {
String programName = fProgText.getText().trim();
setDontCheckProgram(programName.isEmpty());
return super.isValid(config);
}
@Override
public String getName() {
return "Main";
}
}