From 33194960c373fbf7387612f54a84d6d7d653ccaa Mon Sep 17 00:00:00 2001 From: Erwin Waterlander Date: Wed, 12 Jun 2024 10:20:38 +0100 Subject: [PATCH] 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. --- .../META-INF/MANIFEST.MF | 2 +- .../CoreBuildLocalRunLaunchDelegate.java | 26 ++++++++++++++++++- .../META-INF/MANIFEST.MF | 2 +- .../LocalLaunchConfigurationTabGroup.java | 4 ++- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.core/META-INF/MANIFEST.MF b/debug/org.eclipse.cdt.debug.core/META-INF/MANIFEST.MF index c2b3dba51e9..4c015e3d1b8 100644 --- a/debug/org.eclipse.cdt.debug.core/META-INF/MANIFEST.MF +++ b/debug/org.eclipse.cdt.debug.core/META-INF/MANIFEST.MF @@ -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 diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/launch/CoreBuildLocalRunLaunchDelegate.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/launch/CoreBuildLocalRunLaunchDelegate.java index d754a6c6a68..35f1ad88ac0 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/launch/CoreBuildLocalRunLaunchDelegate.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/launch/CoreBuildLocalRunLaunchDelegate.java @@ -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 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()); diff --git a/launch/org.eclipse.cdt.launch/META-INF/MANIFEST.MF b/launch/org.eclipse.cdt.launch/META-INF/MANIFEST.MF index f3f62aef380..d7cb042814d 100644 --- a/launch/org.eclipse.cdt.launch/META-INF/MANIFEST.MF +++ b/launch/org.eclipse.cdt.launch/META-INF/MANIFEST.MF @@ -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 diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/corebuild/LocalLaunchConfigurationTabGroup.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/corebuild/LocalLaunchConfigurationTabGroup.java index 9ddf6f93d97..1bcb4e8852e 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/corebuild/LocalLaunchConfigurationTabGroup.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/corebuild/LocalLaunchConfigurationTabGroup.java @@ -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 }); } }