1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Support arguments and working directory in launching Core Build projects for Local

Added the CArgumentsTab to the Core Build launch configuration for the
Local target. This enables users to set command line arguments and
specify a working directory.
This commit is contained in:
Erwin Waterlander 2024-06-12 10:20:38 +01:00 committed by Jonah Graham
parent a65d3d7f28
commit 33194960c3
4 changed files with 30 additions and 4 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.400.qualifier
Bundle-Version: 8.8.500.qualifier
Bundle-Activator: org.eclipse.cdt.debug.core.CDebugCorePlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin

View file

@ -10,18 +10,25 @@
*******************************************************************************/
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.List;
import org.eclipse.cdt.core.build.ICBuildConfiguration;
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.core.launch.CoreBuildLaunchConfigDelegate;
import org.eclipse.cdt.debug.internal.core.InternalDebugCoreMessages;
import org.eclipse.cdt.utils.CommandLineUtil;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.variables.VariablesPlugin;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
@ -38,7 +45,24 @@ public class CoreBuildLocalRunLaunchDelegate extends CoreBuildLaunchConfigDelega
IBinary exeFile = getBinary(buildConfig);
try {
ProcessBuilder builder = new ProcessBuilder(Paths.get(exeFile.getLocationURI()).toString());
String args = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, ""); //$NON-NLS-1$
if (args.length() != 0) {
args = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(args);
}
String[] arguments = CommandLineUtil.argumentsToArray(args);
List<String> command = new ArrayList<>(1 + arguments.length);
command.add(Paths.get(exeFile.getLocationURI()).toString());
command.addAll(Arrays.asList(arguments));
ProcessBuilder builder = new ProcessBuilder(command);
String workingDirectory = configuration
.getAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, ""); //$NON-NLS-1$
if (!workingDirectory.isBlank()) {
builder.directory(new File(workingDirectory));
}
buildConfig.setBuildEnvironment(builder.environment());
Process process = builder.start();
DebugPlugin.newProcess(launch, process, exeFile.getPath().lastSegment());

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.400.qualifier
Bundle-Version: 10.4.500.qualifier
Bundle-Activator: org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin

View file

@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.cdt.launch.internal.corebuild;
import org.eclipse.cdt.launch.ui.CArgumentsTab;
import org.eclipse.cdt.launch.ui.corebuild.CoreBuildMainTab;
import org.eclipse.cdt.launch.ui.corebuild.CoreBuildTab;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
@ -22,8 +23,9 @@ public class LocalLaunchConfigurationTabGroup extends AbstractLaunchConfiguratio
public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
ILaunchConfigurationTab mainTab = new CoreBuildMainTab();
ILaunchConfigurationTab buildTab = new CoreBuildTab();
ILaunchConfigurationTab argumentsTab = new CArgumentsTab();
setTabs(new ILaunchConfigurationTab[] { mainTab, buildTab });
setTabs(new ILaunchConfigurationTab[] { mainTab, buildTab, argumentsTab });
}
}