Skip to content

Commit

Permalink
Updated Main Tab for Core Build local launch configurations.
Browse files Browse the repository at this point in the history
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 eclipse-cdt#758. It affects all Core Build projects,
including CMake projects.
  • Loading branch information
ewaterlander authored and jonahgraham committed Nov 27, 2024
1 parent 9b6bb07 commit 5639ba9
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 59 deletions.
2 changes: 1 addition & 1 deletion debug/org.eclipse.cdt.debug.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,14 +24,18 @@
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;
Expand Down Expand Up @@ -121,6 +126,28 @@ protected IBinary getBinary(ICBuildConfiguration buildConfig) throws CoreExcepti
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
Expand All @@ -140,6 +167,16 @@ public static String getBuildAttributeName(String mode) {
@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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;
Expand Down Expand Up @@ -66,6 +67,10 @@ protected void populateLaunchConfiguration(ILaunchDescriptor descriptor, ILaunch

// 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 });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

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;
Expand Down Expand Up @@ -55,7 +54,7 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun

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);
Expand Down
2 changes: 1 addition & 1 deletion dsf-gdb/org.eclipse.cdt.dsf.gdb/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

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;
Expand Down Expand Up @@ -86,8 +87,8 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun
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));

Expand Down
2 changes: 1 addition & 1 deletion launch/org.eclipse.cdt.launch/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -111,6 +111,13 @@ public CMainTab2(int flags) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

@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);
}
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 setDefaults(ILaunchConfigurationWorkingCopy configuration) {
// none
protected void createProjectGroup(Composite parent, int colSpan) {
super.createProjectGroup(parent, colSpan);
fProjText.setEnabled(false);
fProjButton.setVisible(false);
}

@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 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 performApply(ILaunchConfigurationWorkingCopy configuration) {
// TODO Auto-generated method stub

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 String getName() {
return "Main";
public boolean isValid(ILaunchConfiguration config) {
String programName = fProgText.getText().trim();
setDontCheckProgram(programName.isEmpty());
return super.isValid(config);
}

}

0 comments on commit 5639ba9

Please sign in to comment.