From 50ee6428ad2977c4a71b91a5b40a63f872256036 Mon Sep 17 00:00:00 2001 From: Erwin Waterlander Date: Mon, 18 Nov 2024 15:44:09 +0000 Subject: [PATCH] New 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. This change relates to #758. It affects all Core Build projects, including CMake projects. --- .../launch/CoreBuildLaunchConfigDelegate.java | 11 ++++ .../CoreBuildLocalLaunchConfigProvider.java | 5 ++ .../CoreBuildLocalRunLaunchDelegate.java | 20 +++++++- .../META-INF/MANIFEST.MF | 2 +- .../LocalLaunchConfigurationTabGroup.java | 4 +- .../launch/internal/ui/LaunchMessages.java | 1 + .../internal/ui/LaunchMessages.properties | 1 + .../org/eclipse/cdt/launch/ui/CMainTab2.java | 9 +++- .../ui/corebuild/CoreBuildMainTab2.java | 51 +++++++++++++++++++ 9 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/corebuild/CoreBuildMainTab2.java diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/launch/CoreBuildLaunchConfigDelegate.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/launch/CoreBuildLaunchConfigDelegate.java index 007c39fe546..bb4e60221a7 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/launch/CoreBuildLaunchConfigDelegate.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/launch/CoreBuildLaunchConfigDelegate.java @@ -23,6 +23,7 @@ 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; @@ -140,6 +141,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); diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/launch/CoreBuildLocalLaunchConfigProvider.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/launch/CoreBuildLocalLaunchConfigProvider.java index 9f1a970d0a3..83217390a18 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/launch/CoreBuildLocalLaunchConfigProvider.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/launch/CoreBuildLocalLaunchConfigProvider.java @@ -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; @@ -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 }); } 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 ffcfcd597ad..89f95060884 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 @@ -26,9 +26,12 @@ 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.resources.IProject; 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.DebugPlugin; @@ -48,6 +51,8 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun IBinary exeFile = getBinary(buildConfig); try { + String programName = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, ""); //$NON-NLS-1$ + String args = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, ""); //$NON-NLS-1$ if (args.length() != 0) { args = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(args); @@ -55,7 +60,20 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun String[] arguments = CommandLineUtil.argumentsToArray(args); List command = new ArrayList<>(1 + arguments.length); - command.add(Paths.get(exeFile.getLocationURI()).toString()); + if (programName.isBlank()) { + command.add(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(); + } + command.add(fullPath); + } command.addAll(Arrays.asList(arguments)); ProcessBuilder builder = new ProcessBuilder(command); diff --git a/launch/org.eclipse.cdt.launch/META-INF/MANIFEST.MF b/launch/org.eclipse.cdt.launch/META-INF/MANIFEST.MF index 02b137933b9..f3f62aef380 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.600.qualifier +Bundle-Version: 10.4.400.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 a77fe952a98..3636caa3d49 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 @@ -11,7 +11,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.CoreBuildMainTab2; import org.eclipse.cdt.launch.ui.corebuild.CoreBuildTab; import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup; import org.eclipse.debug.ui.EnvironmentTab; @@ -22,7 +22,7 @@ public class LocalLaunchConfigurationTabGroup extends AbstractLaunchConfiguratio @Override public void createTabs(ILaunchConfigurationDialog dialog, String mode) { - ILaunchConfigurationTab mainTab = new CoreBuildMainTab(); + ILaunchConfigurationTab mainTab = new CoreBuildMainTab2(); ILaunchConfigurationTab buildTab = new CoreBuildTab(); ILaunchConfigurationTab argumentsTab = new CArgumentsTab(); ILaunchConfigurationTab environmentTab = new EnvironmentTab(); diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/LaunchMessages.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/LaunchMessages.java index 945f83e21c2..43072c93477 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/LaunchMessages.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/LaunchMessages.java @@ -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; diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/LaunchMessages.properties b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/LaunchMessages.properties index cd420e37c48..2f9d5e7c33d 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/LaunchMessages.properties +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/LaunchMessages.properties @@ -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 diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CMainTab2.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CMainTab2.java index 44c90a15bdf..ba7f9cda8e8 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CMainTab2.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CMainTab2.java @@ -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 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); diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/corebuild/CoreBuildMainTab2.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/corebuild/CoreBuildMainTab2.java new file mode 100644 index 00000000000..52bcc7d55f9 --- /dev/null +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/corebuild/CoreBuildMainTab2.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2024 Intel Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package org.eclipse.cdt.launch.ui.corebuild; + +import org.eclipse.cdt.launch.internal.ui.LaunchMessages; +import org.eclipse.cdt.launch.ui.CMainTab2; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.swt.widgets.Composite; + +/** + * @since 10.4 + */ +public class CoreBuildMainTab2 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 + protected void createProjectGroup(Composite parent, int colSpan) { + super.createProjectGroup(parent, colSpan); + fProjText.setEnabled(false); + fProjButton.setVisible(false); + } + + @Override + protected void createExeFileGroup(Composite parent, int colSpan) { + super.createExeFileGroup(parent, colSpan); + fProgText.setMessage(LaunchMessages.CoreBuildMainTab_Keep_empty_for_auto_selection); + } + + /* + * Don't check the program name if it is empty. When the program name is empty the default + * CoreBuild binary is used. + */ + @Override + public boolean isValid(ILaunchConfiguration config) { + String programName = fProgText.getText().trim(); + setDontCheckProgram(programName.isEmpty()); + return super.isValid(config); + } +}