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

The active Launch Target is now saved in the ICBuildConfiguration (#1076)

In addition to the active launch mode and toolchain, the active Launch
Target is now used to determine the Core Build Configuration
(ICBuildConfiguration).

The build output folder name now ends with the name of the Launch Target
(eg: cmake.debug.win32.x86_64.Local)

Additionally, API added to allow the ISV to configure the build output
folder name.

The ICBuildConfigurationProvider implementations, shown below, have been
tidied up to use common code.

  CMakeBuildConfigurationProvider
  AutotoolsBuildConfigurationProvider
  MakefileBuildConfigurationProvider
  MesonBuildConfigurationProvider

Addresses Issue: CDT CMake Improvements #1000, IDE-82683-REQ-016 Launch
Targets used in ICBuildConfiguration
Addresses Issue: CDT CMake Improvements #1000, IDE-82683-REQ-018 Build
output folder name
This commit is contained in:
betamax 2025-02-12 17:30:48 +00:00 committed by GitHub
parent f0c74ed38d
commit fc083dad86
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
47 changed files with 1026 additions and 465 deletions

View file

@ -10,7 +10,156 @@ Below is the detailed descriptions of API changes and mitigation efforts API con
## API Changes in CDT 12.0.
### org.eclipse.cdt.cmake.core.properties refactored
### CDT's Core Build System refactored and improved
Many API changes were made in org.eclipse.cdt.core.build and its surrounding areas, such as CMake and Meson.
See [CDT Issue#1000](https://github.com/eclipse-cdt/cdt/issues/1000) for background information and motivation for this change.
The rest of this section attempts to capture the individual changes made to methods.
#### org.eclipse.cdt.core.build.ICBuildConfigurationProvider
Renamed method createBuildConfiguration to createCBuildConfiguration, which reflects it purpose of creating a new Core Build configuration. Also added the ILaunchTarget parameter.
Added method:
* createCBuildConfiguration(IProject, IToolChain, String, ILaunchTarget, IProgressMonitor)
Removed method:
* createBuildConfiguration(IProject, IToolChain, String, IProgressMonitor)
Added method allowing extenders to customize the Core Build output directory name.
* getCBuildConfigName(IProject, String, IToolChain, String, ILaunchTarget)
#### org.eclipse.cdt.core.build.CBuildConfiguration
Removed method:
* org.eclipse.cdt.core.build.CBuildConfiguration.setLaunchMode(String)
#### Simplified constructors in org.eclipse.cdt.core.build.CBuildConfiguration
The following constructors have been removed from CBuildConfiguration:
* org.eclipse.cdt.core.build.CBuildConfiguration.CBuildConfiguration(IBuildConfiguration, String, IToolChain)
* org.eclipse.cdt.core.build.CBuildConfiguration.CBuildConfiguration(IBuildConfiguration, String, IToolChain, String)
* org.eclipse.cdt.core.build.CBuildConfiguration.CBuildConfiguration(IBuildConfiguration, IToolChain)
Removing them simplified the API as these constructors were unneeded.
Instead use:
* org.eclipse.cdt.core.build.CBuildConfiguration.CBuildConfiguration(IBuildConfiguration, String)
* org.eclipse.cdt.core.build.CBuildConfiguration.CBuildConfiguration(IBuildConfiguration, String, IToolChain, String, ILaunchTarget)
The documentation on these constructors has been improved.
#### Simplified constructors in org.eclipse.cdt.cmake.core.CMakeBuildConfiguration
The following constructors have been removed from CMakeBuildConfiguration:
* org.eclipse.cdt.cmake.core.CMakeBuildConfiguration.CMakeBuildConfiguration(IBuildConfiguration, String, IToolChain)
* org.eclipse.cdt.cmake.core.CMakeBuildConfiguration.CMakeBuildConfiguration(IBuildConfiguration, String, IToolChain, ICMakeToolChainFile, String)
Instead use:
* org.eclipse.cdt.cmake.core.CMakeBuildConfiguration.CMakeBuildConfiguration(IBuildConfiguration, String, IToolChain, ICMakeToolChainFile, String, ILaunchTarget)
#### Simplified constructors in org.eclipse.cdt.core.autotools.core.AutotoolsBuildConfiguration
The following constructors have been removed from AutotoolsBuildConfiguration:
* org.eclipse.cdt.core.autotools.core.AutotoolsBuildConfiguration.AutotoolsBuildConfiguration(IBuildConfiguration, String, IToolChain, String)
* org.eclipse.cdt.core.autotools.core.AutotoolsBuildConfiguration.AutotoolsBuildConfiguration(IBuildConfiguration, String, IToolChain)
Instead use:
* org.eclipse.cdt.core.autotools.core.AutotoolsBuildConfiguration.AutotoolsBuildConfiguration(IBuildConfiguration, String, IToolChain, String, ILaunchTarget)
#### Simplified constructors in org.eclipse.cdt.core.build.StandardBuildConfiguration
The following constructors have been removed from StandardBuildConfiguration:
* org.eclipse.cdt.core.build.StandardBuildConfiguration.StandardBuildConfiguration(IBuildConfiguration, String, IToolChain, String)
Instead use:
* org.eclipse.cdt.core.build.StandardBuildConfiguration.StandardBuildConfiguration(IBuildConfiguration, String, IToolChain, String, ILaunchTarget)
#### Simplified constructors in org.eclipse.cdt.internal.meson.core.MesonBuildConfiguration
The following constructors have been removed from MesonBuildConfiguration:
* org.eclipse.cdt.internal.meson.core.MesonBuildConfiguration.MesonBuildConfiguration(IBuildConfiguration, String, IToolChain)
* org.eclipse.cdt.internal.meson.core.MesonBuildConfiguration.MesonBuildConfiguration(IBuildConfiguration, String, IToolChain, IMesonToolChainFile, String)
Instead use:
* org.eclipse.cdt.internal.meson.core.MesonBuildConfiguration.MesonBuildConfiguration(IBuildConfiguration, String, IToolChain, String, ILaunchTarget)
* org.eclipse.cdt.internal.meson.core.MesonBuildConfiguration.MesonBuildConfiguration(IBuildConfiguration, String, IToolChain, IMesonToolChainFile, String, ILaunchTarget)
#### org.eclipse.cdt.core.build.ICBuildConfiguration
Added method:
* org.eclipse.cdt.core.build.ICBuildConfiguration.getLaunchTarget()
#### org.eclipse.cdt.core.build.ICBuildConfigurationManager
The documentation has been improved.
Added method:
* org.eclipse.cdt.core.build.ICBuildConfigurationManager.getBuildConfiguration(IProject, IToolChain, String, ILaunchTarget, IProgressMonitor)
Removed method:
* org.eclipse.cdt.core.build.ICBuildConfigurationManager.getBuildConfiguration(IProject, IToolChain, String, IProgressMonitor)
* org.eclipse.cdt.core.build.ICBuildConfigurationManager.getBuildConfiguration(IProject, Map<String, String>, String, IProgressMonitor)
#### org.eclipse.cdt.debug.core.launch.CoreBuildLaunchConfigDelegate
Removed deprecated method:
* org.eclipse.cdt.debug.core.launch.CoreBuildLaunchConfigDelegate.getBuildConfiguration(IProject, String, ILaunchTarget, IProgressMonitor)
#### org.eclipse.launchbar.core.target.ILaunchTarget
Removed deprecated method:
* org.eclipse.launchbar.core.target.ILaunchTarget.getName()
#### org.eclipse.launchbar.core.target.ILaunchTargetManager
Added method:
* org.eclipse.launchbar.core.target.ILaunchTargetManager.getLocalLaunchTarget()
Added field:
* org.eclipse.launchbar.core.target.ILaunchTargetManager.localLaunchTargetId
#### org.eclipse.launchbar.core.target.LaunchTargetUtils
Added methods that can be used to check/fix the Launch Target name:
* org.eclipse.launchbar.core.target.LaunchTargetUtils.isInvalidName(String)
* org.eclipse.launchbar.core.target.LaunchTargetUtils.sanitizeName(String)
#### org.eclipse.cdt.debug.core
- Version bumped to 9.0.0
- Removed method (already deprecated):
- org.eclipse.cdt.debug.core.launch.CoreBuildLaunchConfigDelegate.getBuildConfiguration(IProject, String, ILaunchTarget, IProgressMonitor)
#### org.eclipse.launchbar.core.target
- Added method:
- org.eclipse.launchbar.core.target.ILaunchTargetManager.getLocalLaunchTarget()
- Added field:
- org.eclipse.launchbar.core.target.ILaunchTargetManager.localLaunchTargetId
- Added class:
- org.eclipse.launchbar.core.target.LaunchTargetUtils
#### org.eclipse.cdt.cmake.core.properties refactored
A significant simplification to the CMake build properties was completed, this included removing some API that was not used.
The following classes have been removed or modified in API breaking ways:

View file

@ -8,7 +8,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.tools.templates.core;bundle-version="2.0.0",
org.eclipse.tools.templates.freemarker;bundle-version="2.0.0",
org.eclipse.cdt.core;bundle-version="6.3.1",
org.eclipse.core.resources;bundle-version="3.12.0"
org.eclipse.core.resources;bundle-version="3.12.0",
org.eclipse.launchbar.core;bundle-version="[3.0.0,4.0.0)"
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %providerName

View file

@ -34,6 +34,7 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.launchbar.core.target.ILaunchTarget;
public class AutotoolsBuildConfiguration extends CBuildConfiguration {
@ -46,13 +47,9 @@ public class AutotoolsBuildConfiguration extends CBuildConfiguration {
super(config, name);
}
public AutotoolsBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain) {
super(config, name, toolChain, "run"); // TODO: why "run" //$NON-NLS-1$
}
public AutotoolsBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain,
String launchMode) {
super(config, name, toolChain, launchMode);
public AutotoolsBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain, String launchMode,
ILaunchTarget launchTarget) throws CoreException {
super(config, name, toolChain, launchMode, launchTarget);
}
@Override

View file

@ -18,6 +18,7 @@ import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.core.autotools.core.internal.Activator;
import org.eclipse.cdt.core.build.CBuildConfigUtils;
import org.eclipse.cdt.core.build.ICBuildConfiguration;
import org.eclipse.cdt.core.build.ICBuildConfigurationManager;
import org.eclipse.cdt.core.build.ICBuildConfigurationProvider;
@ -28,12 +29,14 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.launchbar.core.target.ILaunchTarget;
import org.eclipse.launchbar.core.target.ILaunchTargetManager;
public class AutotoolsBuildConfigurationProvider implements ICBuildConfigurationProvider {
public static final String ID = Activator.PLUGIN_ID + ".provider"; //$NON-NLS-1$
private ICBuildConfigurationManager configManager = Activator.getService(ICBuildConfigurationManager.class);
private final ILaunchTargetManager launchTargetManager = Activator.getService(ILaunchTargetManager.class);
@Override
public String getId() {
@ -64,7 +67,8 @@ public class AutotoolsBuildConfigurationProvider implements ICBuildConfiguration
}
if (toolChain != null) {
return new AutotoolsBuildConfiguration(config, name, toolChain);
return new AutotoolsBuildConfiguration(config, name, toolChain, "run", //$NON-NLS-1$
launchTargetManager.getLocalLaunchTarget());
}
// No valid combinations
return null;
@ -79,53 +83,23 @@ public class AutotoolsBuildConfigurationProvider implements ICBuildConfiguration
}
@Override
public ICBuildConfiguration createBuildConfiguration(IProject project, IToolChain toolChain, String launchMode,
IProgressMonitor monitor) throws CoreException {
// get matching toolchain file if any
Map<String, String> properties = new HashMap<>();
String os = toolChain.getProperty(IToolChain.ATTR_OS);
if (os != null && !os.isEmpty()) {
properties.put(IToolChain.ATTR_OS, os);
}
String arch = toolChain.getProperty(IToolChain.ATTR_ARCH);
if (arch != null && !arch.isEmpty()) {
properties.put(IToolChain.ATTR_ARCH, arch);
}
public ICBuildConfiguration createCBuildConfiguration(IProject project, IToolChain toolChain, String launchMode,
ILaunchTarget launchTarget, IProgressMonitor monitor) throws CoreException {
// Compute name to use for ICBuildConfiguration
String cBuildConfigName = getCBuildConfigName(project, "autotools", toolChain, launchMode, launchTarget); //$NON-NLS-1$
// create config
StringBuilder configName = new StringBuilder("autotools."); //$NON-NLS-1$
configName.append(launchMode);
if ("linux-container".equals(os)) { //$NON-NLS-1$
String osConfigName = toolChain.getProperty("linux-container-id"); //$NON-NLS-1$
osConfigName = osConfigName.replaceAll("/", "_"); //$NON-NLS-1$ //$NON-NLS-2$
configName.append('.');
configName.append(osConfigName);
} else {
if (os != null) {
configName.append('.');
configName.append(os);
}
if (arch != null && !arch.isEmpty()) {
configName.append('.');
configName.append(arch);
}
}
String name = configName.toString();
IBuildConfiguration config = null;
// reuse any IBuildConfiguration with the same name for the project
// so adding the CBuildConfiguration will override the old one stored
// by the CBuildConfigurationManager
if (configManager.hasConfiguration(this, project, name)) {
config = project.getBuildConfig(this.getId() + '/' + name);
}
if (config == null) {
config = configManager.createBuildConfiguration(this, project, name, monitor);
}
// Create Platform Build configuration
ICBuildConfigurationManager cBuildConfigManager = Activator.getService(ICBuildConfigurationManager.class);
IBuildConfiguration buildConfig = CBuildConfigUtils.createBuildConfiguration(this, project, cBuildConfigName,
cBuildConfigManager, monitor);
AutotoolsBuildConfiguration autotoolsConfig = new AutotoolsBuildConfiguration(config, name, toolChain,
launchMode);
configManager.addBuildConfiguration(config, autotoolsConfig);
return autotoolsConfig;
// Create Core Build configuration
ICBuildConfiguration cBuildConfig = new AutotoolsBuildConfiguration(buildConfig, cBuildConfigName, toolChain,
launchMode, launchTarget);
// Add the Platform Build/Core Build configuration combination
cBuildConfigManager.addBuildConfiguration(buildConfig, cBuildConfig);
return cBuildConfig;
}
}

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.make.core; singleton:=true
Bundle-Version: 7.6.600.qualifier
Bundle-Version: 8.0.0.qualifier
Bundle-Activator: org.eclipse.cdt.make.core.MakeCorePlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
@ -26,7 +26,8 @@ Require-Bundle: org.eclipse.cdt.core;bundle-version="[9.0.0,10.0.0)",
org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
org.eclipse.core.filesystem;bundle-version="1.2.0",
org.eclipse.tools.templates.core;bundle-version="2.0.0",
org.eclipse.tools.templates.freemarker;bundle-version="2.0.0"
org.eclipse.tools.templates.freemarker;bundle-version="2.0.0",
org.eclipse.launchbar.core;bundle-version="[3.0.0,4.0.0)"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-17
Automatic-Module-Name: org.eclipse.cdt.make.core

View file

@ -13,6 +13,7 @@ package org.eclipse.cdt.make.core;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.core.build.CBuildConfigUtils;
import org.eclipse.cdt.core.build.ICBuildConfiguration;
import org.eclipse.cdt.core.build.ICBuildConfigurationManager;
import org.eclipse.cdt.core.build.ICBuildConfigurationProvider;
@ -24,6 +25,8 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.launchbar.core.target.ILaunchTarget;
import org.eclipse.launchbar.core.target.ILaunchTargetManager;
/**
* @since 7.4
@ -31,6 +34,7 @@ import org.eclipse.core.runtime.Platform;
public class MakefileBuildConfigurationProvider implements ICBuildConfigurationProvider {
public static final String ID = "org.eclipse.cdt.make.core.provider"; //$NON-NLS-1$
private final ILaunchTargetManager launchTargetManager = MakeCorePlugin.getService(ILaunchTargetManager.class);
@Override
public String getId() {
@ -61,7 +65,8 @@ public class MakefileBuildConfigurationProvider implements ICBuildConfigurationP
}
if (toolChain != null) {
return new StandardBuildConfiguration(config, name, toolChain, "run"); //$NON-NLS-1$
return new StandardBuildConfiguration(config, name, toolChain, "run", //$NON-NLS-1$
launchTargetManager.getLocalLaunchTarget());
} else {
// No valid combinations
return null;
@ -71,43 +76,22 @@ public class MakefileBuildConfigurationProvider implements ICBuildConfigurationP
}
@Override
public ICBuildConfiguration createBuildConfiguration(IProject project, IToolChain toolChain, String launchMode,
IProgressMonitor monitor) throws CoreException {
ICBuildConfigurationManager configManager = MakeCorePlugin.getService(ICBuildConfigurationManager.class);
public ICBuildConfiguration createCBuildConfiguration(IProject project, IToolChain toolChain, String launchMode,
ILaunchTarget launchTarget, IProgressMonitor monitor) throws CoreException {
// Compute name to use for ICBuildConfiguration
String cBuildConfigName = getCBuildConfigName(project, "make", toolChain, launchMode, launchTarget); //$NON-NLS-1$
StringBuilder configName = new StringBuilder("make."); //$NON-NLS-1$
configName.append(launchMode);
String os = toolChain.getProperty(IToolChain.ATTR_OS);
if ("linux-container".equals(os)) { //$NON-NLS-1$
String osConfigName = toolChain.getProperty("linux-container-id"); //$NON-NLS-1$
osConfigName = osConfigName.replaceAll("/", "_"); //$NON-NLS-1$ //$NON-NLS-2$
configName.append('.');
configName.append(osConfigName);
} else {
if (os != null) {
configName.append('.');
configName.append(os);
}
String arch = toolChain.getProperty(IToolChain.ATTR_ARCH);
if (arch != null && !arch.isEmpty()) {
configName.append('.');
configName.append(arch);
}
}
String name = configName.toString();
IBuildConfiguration config = null;
// reuse any IBuildConfiguration with the same name for the project
// so adding the CBuildConfiguration will override the old one stored
// by the CBuildConfigurationManager
if (configManager.hasConfiguration(this, project, name)) {
config = project.getBuildConfig(this.getId() + '/' + name);
}
if (config == null) {
config = configManager.createBuildConfiguration(this, project, name, monitor);
}
StandardBuildConfiguration makeConfig = new StandardBuildConfiguration(config, name, toolChain, launchMode);
configManager.addBuildConfiguration(config, makeConfig);
return makeConfig;
// Create Platform Build configuration
ICBuildConfigurationManager cBuildConfigManager = MakeCorePlugin.getService(ICBuildConfigurationManager.class);
IBuildConfiguration buildConfig = CBuildConfigUtils.createBuildConfiguration(this, project, cBuildConfigName,
cBuildConfigManager, monitor);
// Create Core Build configuration
ICBuildConfiguration cBuildConfig = new StandardBuildConfiguration(buildConfig, cBuildConfigName, toolChain,
launchMode, launchTarget);
// Add the Platform Build/Core Build configuration combination
cBuildConfigManager.addBuildConfiguration(buildConfig, cBuildConfig);
return cBuildConfig;
}
}

View file

@ -9,7 +9,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.resources,
org.eclipse.cdt.core;bundle-version="6.4.0",
org.eclipse.tools.templates.core;bundle-version="2.0.0",
org.eclipse.tools.templates.freemarker;bundle-version="2.0.0"
org.eclipse.tools.templates.freemarker;bundle-version="2.0.0",
org.eclipse.launchbar.core;bundle-version="[3.0.0,4.0.0)"
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin

View file

@ -43,6 +43,7 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.launchbar.core.target.ILaunchTarget;
import org.osgi.service.prefs.BackingStoreException;
import org.osgi.service.prefs.Preferences;
@ -71,13 +72,14 @@ public class MesonBuildConfiguration extends CBuildConfiguration {
}
}
public MesonBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain) {
this(config, name, toolChain, null, "run"); //$NON-NLS-1$
public MesonBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain, String launchMode,
ILaunchTarget launchTarget) throws CoreException {
this(config, name, toolChain, null, launchMode, launchTarget);
}
public MesonBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain,
IMesonToolChainFile toolChainFile, String launchMode) {
super(config, name, toolChain, launchMode);
IMesonToolChainFile toolChainFile, String launchMode, ILaunchTarget launchTarget) throws CoreException {
super(config, name, toolChain, launchMode, launchTarget);
this.toolChainFile = toolChainFile;
if (toolChainFile != null) {

View file

@ -17,6 +17,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.core.build.CBuildConfigUtils;
import org.eclipse.cdt.core.build.ICBuildConfiguration;
import org.eclipse.cdt.core.build.ICBuildConfigurationManager;
import org.eclipse.cdt.core.build.ICBuildConfigurationProvider;
@ -30,13 +31,14 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.launchbar.core.target.ILaunchTarget;
import org.eclipse.launchbar.core.target.ILaunchTargetManager;
public class MesonBuildConfigurationProvider implements ICBuildConfigurationProvider {
public static final String ID = "org.eclipse.cdt.meson.core.provider"; //$NON-NLS-1$
private final static ILaunchTargetManager launchTargetManager = Activator.getService(ILaunchTargetManager.class);
private IMesonToolChainManager manager = Activator.getService(IMesonToolChainManager.class);
private ICBuildConfigurationManager configManager = Activator.getService(ICBuildConfigurationManager.class);
@Override
public String getId() {
@ -68,7 +70,8 @@ public class MesonBuildConfigurationProvider implements ICBuildConfigurationProv
}
if (toolChain != null) {
return new MesonBuildConfiguration(config, name, toolChain);
return new MesonBuildConfiguration(config, name, toolChain, "run", //$NON-NLS-1$
launchTargetManager.getLocalLaunchTarget());
}
// No valid combinations
return null;
@ -82,27 +85,27 @@ public class MesonBuildConfigurationProvider implements ICBuildConfigurationProv
}
if (tcFile != null && !toolChain.equals(tcFile.getToolChain())) {
// toolchain changed
return new MesonBuildConfiguration(config, name, tcFile.getToolChain(), tcFile,
mesonConfig.getLaunchMode());
return new MesonBuildConfiguration(config, name, tcFile.getToolChain(), tcFile, mesonConfig.getLaunchMode(),
launchTargetManager.getLocalLaunchTarget());
}
return mesonConfig;
}
@Override
public ICBuildConfiguration createBuildConfiguration(IProject project, IToolChain toolChain, String launchMode,
IProgressMonitor monitor) throws CoreException {
public ICBuildConfiguration createCBuildConfiguration(IProject project, IToolChain toolChain, String launchMode,
ILaunchTarget launchTarget, IProgressMonitor monitor) throws CoreException {
// get matching toolchain file if any
Map<String, String> properties = new HashMap<>();
String os = toolChain.getProperty(IToolChain.ATTR_OS);
if (os != null && !os.isEmpty()) {
properties.put(IToolChain.ATTR_OS, os);
}
String arch = toolChain.getProperty(IToolChain.ATTR_ARCH);
if (arch != null && !arch.isEmpty()) {
properties.put(IToolChain.ATTR_ARCH, arch);
}
IMesonToolChainFile file = manager.getToolChainFileFor(toolChain);
if (file == null) {
Map<String, String> properties = new HashMap<>();
String os = toolChain.getProperty(IToolChain.ATTR_OS);
if (os != null && !os.isEmpty()) {
properties.put(IToolChain.ATTR_OS, os);
}
String arch = toolChain.getProperty(IToolChain.ATTR_ARCH);
if (arch != null && !arch.isEmpty()) {
properties.put(IToolChain.ATTR_ARCH, arch);
}
Collection<IMesonToolChainFile> files = manager.getToolChainFilesMatching(properties);
if (!files.isEmpty()) {
file = files.iterator().next();
@ -110,39 +113,19 @@ public class MesonBuildConfigurationProvider implements ICBuildConfigurationProv
}
}
// create config
StringBuilder configName = new StringBuilder("meson."); //$NON-NLS-1$
configName.append(launchMode);
if ("linux-container".equals(os)) { //$NON-NLS-1$
String osConfigName = toolChain.getProperty("linux-container-id"); //$NON-NLS-1$
osConfigName = osConfigName.replaceAll("/", "_"); //$NON-NLS-1$ //$NON-NLS-2$
configName.append('.');
configName.append(osConfigName);
} else {
if (os != null) {
configName.append('.');
configName.append(os);
}
if (arch != null && !arch.isEmpty()) {
configName.append('.');
configName.append(arch);
}
}
String name = configName.toString();
IBuildConfiguration config = null;
// reuse any IBuildConfiguration with the same name for the project
// so adding the CBuildConfiguration will override the old one stored
// by the CBuildConfigurationManager
if (configManager.hasConfiguration(this, project, name)) {
config = project.getBuildConfig(this.getId() + '/' + name);
}
if (config == null) {
config = configManager.createBuildConfiguration(this, project, name, monitor);
}
// Compute name to use for ICBuildConfiguration
String cBuildConfigName = getCBuildConfigName(project, "meson", toolChain, launchMode, launchTarget); //$NON-NLS-1$
MesonBuildConfiguration mesonConfig = new MesonBuildConfiguration(config, name, toolChain, file, launchMode);
configManager.addBuildConfiguration(config, mesonConfig);
return mesonConfig;
// Create Platform Build configuration
ICBuildConfigurationManager cBuildConfigManager = Activator.getService(ICBuildConfigurationManager.class);
IBuildConfiguration buildConfig = CBuildConfigUtils.createBuildConfiguration(this, project, cBuildConfigName,
cBuildConfigManager, monitor);
// Create Core Build configuration
ICBuildConfiguration cBuildConfig = new MesonBuildConfiguration(buildConfig, cBuildConfigName, toolChain, file,
launchMode, launchTarget);
cBuildConfigManager.addBuildConfiguration(buildConfig, cBuildConfig);
return cBuildConfig;
}
}

View file

@ -22,6 +22,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.cdt.cmake.core.internal.Activator;
import org.eclipse.cdt.cmake.core.properties.CMakeGenerator;
import org.eclipse.cdt.cmake.core.properties.ICMakeGenerator;
import org.eclipse.cdt.cmake.core.properties.ICMakeProperties;
@ -34,6 +35,8 @@ import org.eclipse.cdt.utils.CommandLineUtil;
import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.launchbar.core.target.ILaunchTarget;
import org.eclipse.launchbar.core.target.ILaunchTargetManager;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -42,6 +45,10 @@ import org.junit.jupiter.api.Test;
* See the new interface {@link ICMakeBuildConfiguration}.
*/
public class CMakeBuildConfigurationTests extends BaseTestCase5 {
private static final String LAUNCH_MODE = "run";
private static final ILaunchTarget LOCAL_LAUNCH_TARGET = Activator.getService(ILaunchTargetManager.class)
.getLocalLaunchTarget();
private IBuildConfiguration buildConfig;
private IToolChain mockToolchain;
@ -68,7 +75,7 @@ public class CMakeBuildConfigurationTests extends BaseTestCase5 {
@Test
public void getCMakePropertiesTestSetGenerator() throws Exception {
CMakeBuildConfiguration cmBuildConfig = new CMakeBuildConfiguration(buildConfig, "cmBuildConfigName",
mockToolchain) {
mockToolchain, null, LAUNCH_MODE, LOCAL_LAUNCH_TARGET) {
@Override
public ICMakeProperties getCMakeProperties() {
@ -80,6 +87,7 @@ public class CMakeBuildConfigurationTests extends BaseTestCase5 {
// Call the new method on ICMakeBuildConfiguration to get the default CMake properties.
ICMakeProperties cMakeProperties = cmBuildConfig.getCMakeProperties();
assertThat(cMakeProperties.getGenerator(), is(CMakeGenerator.WatcomWMake));
}
@ -92,7 +100,7 @@ public class CMakeBuildConfigurationTests extends BaseTestCase5 {
public void getCMakePropertiesTestSetExtraArguments() throws Exception {
// Create a C Build Configuration using the default build config and an arbitrary name
CMakeBuildConfiguration cmBuildConfig = new CMakeBuildConfiguration(buildConfig, "cmBuildConfigName",
mockToolchain) {
mockToolchain, null, LAUNCH_MODE, LOCAL_LAUNCH_TARGET) {
@Override
public ICMakeProperties getCMakeProperties() {
@ -115,7 +123,7 @@ public class CMakeBuildConfigurationTests extends BaseTestCase5 {
public void getDefaultProperties() throws Exception {
// Create a C Build Configuration using the default build config and an arbitrary name
CMakeBuildConfiguration cmBuildConfig = new CMakeBuildConfiguration(buildConfig, "cmBuildConfigName",
mockToolchain) {
mockToolchain, null, LAUNCH_MODE, LOCAL_LAUNCH_TARGET) {
@Override
public Map<String, String> getDefaultProperties() {
@ -133,7 +141,7 @@ public class CMakeBuildConfigurationTests extends BaseTestCase5 {
public void getDefaultPropertiesTestExtraArgs() throws Exception {
// Create a C Build Configuration using the default build config and an arbitrary name
CMakeBuildConfiguration cmBuildConfig = new CMakeBuildConfiguration(buildConfig, "cmBuildConfigName",
mockToolchain) {
mockToolchain, null, LAUNCH_MODE, LOCAL_LAUNCH_TARGET) {
@Override
public Map<String, String> getDefaultProperties() {
var defs = new HashMap<>(super.getDefaultProperties());
@ -154,7 +162,7 @@ public class CMakeBuildConfigurationTests extends BaseTestCase5 {
public void customCMakeGeneratorEntryAuto() throws Exception {
// Create a C Build Configuration using the default build config and an arbitrary name
CMakeBuildConfiguration cmBuildConfig = new CMakeBuildConfiguration(buildConfig, "cmBuildConfigName",
mockToolchain) {
mockToolchain, null, LAUNCH_MODE, LOCAL_LAUNCH_TARGET) {
@Override
public Map<String, String> getDefaultProperties() {
var defs = new HashMap<>(super.getDefaultProperties());
@ -178,7 +186,7 @@ public class CMakeBuildConfigurationTests extends BaseTestCase5 {
public void customCMakeGeneratorEntryManual() throws Exception {
// Create a C Build Configuration using the default build config and an arbitrary name
CMakeBuildConfiguration cmBuildConfig = new CMakeBuildConfiguration(buildConfig, "cmBuildConfigName",
mockToolchain) {
mockToolchain, null, LAUNCH_MODE, LOCAL_LAUNCH_TARGET) {
@Override
public Map<String, String> getDefaultProperties() {
var defs = new HashMap<>(super.getDefaultProperties());
@ -227,7 +235,7 @@ public class CMakeBuildConfigurationTests extends BaseTestCase5 {
public void targetsAndCommandDefaults() throws Exception {
// Create a C Build Configuration using the default build config and an arbitrary name
CMakeBuildConfiguration cmBuildConfig = new CMakeBuildConfiguration(buildConfig, "cmBuildConfigName",
mockToolchain);
mockToolchain, null, LAUNCH_MODE, LOCAL_LAUNCH_TARGET);
// Call the new method on ICMakeBuildConfiguration to get the default CMake properties.
ICMakeProperties cMakeProperties = cmBuildConfig.getCMakeProperties();
@ -243,7 +251,7 @@ public class CMakeBuildConfigurationTests extends BaseTestCase5 {
public void targetsAndCommand() throws Exception {
// Create a C Build Configuration using the default build config and an arbitrary name
CMakeBuildConfiguration cmBuildConfig = new CMakeBuildConfiguration(buildConfig, "cmBuildConfigName",
mockToolchain) {
mockToolchain, null, LAUNCH_MODE, LOCAL_LAUNCH_TARGET) {
@Override
public Map<String, String> getDefaultProperties() {
var defs = new HashMap<>(super.getDefaultProperties());
@ -271,7 +279,7 @@ public class CMakeBuildConfigurationTests extends BaseTestCase5 {
public void extraArgumentsParseCorrectly() throws Exception {
// Create a C Build Configuration using the default build config and an arbitrary name
CMakeBuildConfiguration cmBuildConfig = new CMakeBuildConfiguration(buildConfig, "cmBuildConfigName",
mockToolchain) {
mockToolchain, null, LAUNCH_MODE, LOCAL_LAUNCH_TARGET) {
@Override
public Map<String, String> getDefaultProperties() {
var defs = new HashMap<>(super.getDefaultProperties());

View file

@ -64,6 +64,7 @@ import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.launchbar.core.target.ILaunchTarget;
/**
* @since 2.0
@ -91,13 +92,9 @@ public class CMakeBuildConfiguration extends CBuildConfiguration implements ICMa
toolChainFile = manager.getToolChainFileFor(getToolChain());
}
public CMakeBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain) {
this(config, name, toolChain, null, "run"); //$NON-NLS-1$
}
public CMakeBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain,
ICMakeToolChainFile toolChainFile, String launchMode) {
super(config, name, toolChain, launchMode);
ICMakeToolChainFile toolChainFile, String launchMode, ILaunchTarget launchTarget) {
super(config, name, toolChain, launchMode, launchTarget);
this.toolChainFile = toolChainFile;
}

View file

@ -15,6 +15,8 @@ import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.cmake.core.internal.Activator;
import org.eclipse.cdt.core.build.CBuildConfigUtils;
import org.eclipse.cdt.core.build.CBuildConfiguration;
import org.eclipse.cdt.core.build.ICBuildConfiguration;
import org.eclipse.cdt.core.build.ICBuildConfigurationManager;
import org.eclipse.cdt.core.build.ICBuildConfigurationProvider;
@ -25,6 +27,8 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.launchbar.core.target.ILaunchTarget;
import org.eclipse.launchbar.core.target.ILaunchTargetManager;
/**
* A ICBuildConfigurationProvider specialized for CMake
@ -40,9 +44,6 @@ public class CMakeBuildConfigurationProvider implements ICBuildConfigurationProv
public static final String ID = "org.eclipse.cdt.cmake.core.provider"; //$NON-NLS-1$
private ICMakeToolChainManager manager = Activator.getService(ICMakeToolChainManager.class);
private ICBuildConfigurationManager configManager = Activator.getService(ICBuildConfigurationManager.class);
@Override
public String getId() {
return ID;
@ -50,6 +51,9 @@ public class CMakeBuildConfigurationProvider implements ICBuildConfigurationProv
/**
* Extenders should override this method to construct their specialized build configuration.
*
* @see {@link CBuildConfiguration#CBuildConfiguration(IBuildConfiguration, String)} for common documentation on
* parameters.
*/
protected CMakeBuildConfiguration createCMakeBuildConfiguration(IBuildConfiguration config, String name)
throws CoreException {
@ -58,23 +62,21 @@ public class CMakeBuildConfigurationProvider implements ICBuildConfigurationProv
/**
* Extenders should override this method to construct their specialized build configuration.
*
* @param toolChainFile CMake toolchain file to associate with this CMakeBuildConfiguration. May be null.
*
* @see {@link CBuildConfiguration#CBuildConfiguration(IBuildConfiguration, String, IToolChain, String, ILaunchTarget)}
* for common documentation on other parameters.
*/
protected CMakeBuildConfiguration createCMakeBuildConfiguration(IBuildConfiguration config, String name,
IToolChain toolChain) {
return new CMakeBuildConfiguration(config, name, toolChain);
}
/**
* Extenders should override this method to construct their specialized build configuration.
*/
protected CMakeBuildConfiguration createCMakeBuildConfiguration(IBuildConfiguration config, String name,
IToolChain toolChain, ICMakeToolChainFile toolChainFile, String launchMode) {
return new CMakeBuildConfiguration(config, name, toolChain, toolChainFile, launchMode);
IToolChain toolChain, ICMakeToolChainFile toolChainFile, String launchMode, ILaunchTarget launchTarget) {
return new CMakeBuildConfiguration(config, name, toolChain, toolChainFile, launchMode, launchTarget);
}
@Override
public synchronized ICBuildConfiguration getCBuildConfiguration(IBuildConfiguration config, String name)
throws CoreException {
ILaunchTargetManager launchTargetManager = Activator.getService(ILaunchTargetManager.class);
if (config.getName().equals(IBuildConfiguration.DEFAULT_CONFIG_NAME)) {
IToolChain toolChain = null;
@ -97,7 +99,8 @@ public class CMakeBuildConfigurationProvider implements ICBuildConfigurationProv
}
if (toolChain != null) {
return createCMakeBuildConfiguration(config, name, toolChain);
return createCMakeBuildConfiguration(config, name, toolChain, null, "run", //$NON-NLS-1$
launchTargetManager.getLocalLaunchTarget());
} else {
// No valid combinations
return null;
@ -113,63 +116,48 @@ public class CMakeBuildConfigurationProvider implements ICBuildConfigurationProv
if (tcFile != null && !toolChain.equals(tcFile.getToolChain())) {
// toolchain changed
return createCMakeBuildConfiguration(config, name, tcFile.getToolChain(), tcFile,
cmakeConfig.getLaunchMode());
cmakeConfig.getLaunchMode(), launchTargetManager.getLocalLaunchTarget());
} else {
return cmakeConfig;
}
}
@Override
public ICBuildConfiguration createBuildConfiguration(IProject project, IToolChain toolChain, String launchMode,
IProgressMonitor monitor) throws CoreException {
public ICBuildConfiguration createCBuildConfiguration(IProject project, IToolChain toolChain, String launchMode,
ILaunchTarget launchTarget, IProgressMonitor monitor) throws CoreException {
// get matching toolchain file if any
Map<String, String> properties = new HashMap<>();
String os = toolChain.getProperty(IToolChain.ATTR_OS);
if (os != null && !os.isEmpty()) {
properties.put(IToolChain.ATTR_OS, os);
}
String arch = toolChain.getProperty(IToolChain.ATTR_ARCH);
if (arch != null && !arch.isEmpty()) {
properties.put(IToolChain.ATTR_ARCH, arch);
}
ICMakeToolChainManager manager = Activator.getService(ICMakeToolChainManager.class);
ICMakeToolChainFile file = manager.getToolChainFileFor(toolChain);
if (file == null) {
Map<String, String> properties = new HashMap<>();
String os = toolChain.getProperty(IToolChain.ATTR_OS);
if (os != null && !os.isEmpty()) {
properties.put(IToolChain.ATTR_OS, os);
}
String arch = toolChain.getProperty(IToolChain.ATTR_ARCH);
if (arch != null && !arch.isEmpty()) {
properties.put(IToolChain.ATTR_ARCH, arch);
}
Collection<ICMakeToolChainFile> files = manager.getToolChainFilesMatching(properties);
if (!files.isEmpty()) {
file = files.iterator().next();
}
}
// create config
StringBuilder configName = new StringBuilder("cmake."); //$NON-NLS-1$
configName.append(launchMode);
if ("linux-container".equals(os)) { //$NON-NLS-1$
String osConfigName = toolChain.getProperty("linux-container-id"); //$NON-NLS-1$
osConfigName = osConfigName.replaceAll("/", "_"); //$NON-NLS-1$ //$NON-NLS-2$
configName.append('.');
configName.append(osConfigName);
} else {
String fragment = toolChain.getBuildConfigNameFragment();
if (fragment != null && !fragment.isEmpty()) {
configName.append('.');
configName.append(fragment);
}
}
String name = configName.toString();
IBuildConfiguration config = null;
// reuse any IBuildConfiguration with the same name for the project
// so adding the CBuildConfiguration will override the old one stored
// by the CBuildConfigurationManager
if (configManager.hasConfiguration(this, project, name)) {
config = project.getBuildConfig(this.getId() + '/' + name);
}
if (config == null) {
config = configManager.createBuildConfiguration(this, project, name, monitor);
}
// Compute name to use for ICBuildConfiguration
String cBuildConfigName = getCBuildConfigName(project, "cmake", toolChain, launchMode, launchTarget); //$NON-NLS-1$
CMakeBuildConfiguration cmakeConfig = createCMakeBuildConfiguration(config, name, toolChain, file, launchMode);
configManager.addBuildConfiguration(config, cmakeConfig);
return cmakeConfig;
// Create Platform Build configuration
ICBuildConfigurationManager cBuildConfigManager = Activator.getService(ICBuildConfigurationManager.class);
IBuildConfiguration buildConfig = CBuildConfigUtils.createBuildConfiguration(this, project, cBuildConfigName,
cBuildConfigManager, monitor);
// Create Core Build configuration
ICBuildConfiguration cBuildConfig = createCMakeBuildConfiguration(buildConfig, cBuildConfigName, toolChain,
file, launchMode, launchTarget);
// Add the Platform Build/Core Build configuration combination
cBuildConfigManager.addBuildConfiguration(buildConfig, cBuildConfig);
return cBuildConfig;
}
}

View file

@ -16,7 +16,8 @@ Require-Bundle: org.eclipse.cdt.cmake.core,
org.eclipse.tools.templates.ui,
org.eclipse.tools.templates.freemarker,
org.eclipse.ui,
org.eclipse.ui.ide
org.eclipse.ui.ide,
org.eclipse.launchbar.core;bundle-version="[3.0.0,4.0.0)"
Import-Package: freemarker.template;version="[2.3.22,3.0.0)"
Automatic-Module-Name: org.eclipse.cdt.cmake.example
Bundle-Localization: plugin

View file

@ -19,6 +19,7 @@ import org.eclipse.cdt.cmake.core.properties.CMakeGenerator;
import org.eclipse.cdt.core.build.IToolChain;
import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.launchbar.core.target.ILaunchTarget;
/**
* An example CMake build configuration that demonstrates how an ISV can provide their own customisations.
@ -30,12 +31,8 @@ public class ExtendedCMakeBuildConfiguration extends CMakeBuildConfiguration {
}
public ExtendedCMakeBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain,
ICMakeToolChainFile toolChainFile, String launchMode) {
super(config, name, toolChain, toolChainFile, launchMode);
}
public ExtendedCMakeBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain) {
super(config, name, toolChain);
ICMakeToolChainFile toolChainFile, String launchMode, ILaunchTarget launchTarget) {
super(config, name, toolChain, toolChainFile, launchMode, launchTarget);
}
@Override

View file

@ -16,6 +16,7 @@ import org.eclipse.cdt.cmake.core.ICMakeToolChainFile;
import org.eclipse.cdt.core.build.IToolChain;
import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.launchbar.core.target.ILaunchTarget;
public class ExtendedCMakeBuildConfigurationProvider extends CMakeBuildConfigurationProvider {
@SuppressWarnings("hiding")
@ -34,14 +35,7 @@ public class ExtendedCMakeBuildConfigurationProvider extends CMakeBuildConfigura
@Override
protected CMakeBuildConfiguration createCMakeBuildConfiguration(IBuildConfiguration config, String name,
IToolChain toolChain) {
return new ExtendedCMakeBuildConfiguration(config, name, toolChain);
IToolChain toolChain, ICMakeToolChainFile toolChainFile, String launchMode, ILaunchTarget launchTarget) {
return new ExtendedCMakeBuildConfiguration(config, name, toolChain, toolChainFile, launchMode, launchTarget);
}
@Override
protected CMakeBuildConfiguration createCMakeBuildConfiguration(IBuildConfiguration config, String name,
IToolChain toolChain, ICMakeToolChainFile toolChainFile, String launchMode) {
return new ExtendedCMakeBuildConfiguration(config, name, toolChain, toolChainFile, launchMode);
}
}

View file

@ -46,7 +46,8 @@ Require-Bundle: org.eclipse.core.resources,
com.google.gson;bundle-version="[2.8.6,3.0.0)",
org.eclipse.cdt.debug.core,
org.eclipse.cdt.cmake.core,
org.eclipse.debug.core
org.eclipse.debug.core,
org.eclipse.launchbar.core;bundle-version="[3.0.0,4.0.0)"
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %providerName
Bundle-RequiredExecutionEnvironment: JavaSE-17

View file

@ -11,6 +11,8 @@
package org.eclipse.cdt.core.build;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -23,17 +25,43 @@ import org.eclipse.cdt.core.parser.IScannerInfoProvider;
import org.eclipse.cdt.core.testplugin.ResourceHelper;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase5;
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.cdt.debug.core.launch.CoreBuildLaunchBarTracker;
import org.eclipse.cdt.internal.core.language.settings.providers.LanguageSettingsScannerInfoProvider;
import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.launchbar.core.ILaunchBarManager;
import org.eclipse.launchbar.core.target.ILaunchTarget;
import org.eclipse.launchbar.core.target.ILaunchTargetManager;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class CBuildConfigurationManagerTests extends BaseTestCase5 {
protected ICBuildConfigurationManager configManager = CDebugCorePlugin
.getService(ICBuildConfigurationManager.class);
private IProject project;
private IToolChain mockToolchain;
private ICBuildConfigurationManager configManager = CDebugCorePlugin.getService(ICBuildConfigurationManager.class);
private ILaunchBarManager launchBarManager = CDebugCorePlugin.getService(ILaunchBarManager.class);
private ILaunchTargetManager launchTargetManager = CDebugCorePlugin.getService(ILaunchTargetManager.class);
private ILaunchTarget launchTarget;
@BeforeEach
public void setup() throws Exception {
// Create a CMake project
project = createCMakeProject();
// Setup a toolchain ready to use for creating the ICBuildConfiguration
mockToolchain = mock(IToolChain.class);
when(mockToolchain.getProperty(IToolChain.ATTR_OS)).thenReturn("osDummy");
when(mockToolchain.getProperty(IToolChain.ATTR_ARCH)).thenReturn("archDummy");
when(mockToolchain.getTypeId()).thenReturn("tc_typeId");
when(mockToolchain.getId()).thenReturn("tcId");
when(mockToolchain.getBuildConfigNameFragment()).thenReturn("buildConfigName");
}
/**
* Tests that CBuildConfigurationManager.getBuildConfiguration(IProject, IToolChain, String, IProgressMonitor)
@ -75,8 +103,7 @@ public class CBuildConfigurationManagerTests extends BaseTestCase5 {
*/
@Test
public void testResetCachedScannerInfoProvider() throws Exception {
// (1) create a CMake project
IProject project = createCMakeProject();
// (1) create a CMake project; performed in setup()
CMakeBuildConfigurationProvider provider = new CMakeBuildConfigurationProvider();
String buildConfigBaseName = "notDefaultName";
@ -96,17 +123,11 @@ public class CBuildConfigurationManagerTests extends BaseTestCase5 {
assertThat("scannerInfoProvider expected to be LanguageSettingsScannerInfoProvider",
scannerInfoProvider instanceof LanguageSettingsScannerInfoProvider);
// (3) Setup a toolchain ready to use for creating the valid ICBuildConfiguration
IToolChain mockToolchain = mock(IToolChain.class);
when(mockToolchain.getProperty(IToolChain.ATTR_OS)).thenReturn("osDummy");
when(mockToolchain.getProperty(IToolChain.ATTR_ARCH)).thenReturn("archDummy");
when(mockToolchain.getTypeId()).thenReturn("tc_typeId");
when(mockToolchain.getId()).thenReturn("tcId");
when(mockToolchain.getBuildConfigNameFragment()).thenReturn("buildConfigName");
// (3) Create the valid ICBuildConfiguration
ILaunchTarget launchTarget = launchTargetManager.getLocalLaunchTarget();
ICBuildConfiguration cBuildConfiguration = configManager.getBuildConfiguration(project, mockToolchain,
ILaunchManager.RUN_MODE, new NullProgressMonitor());
assertThat("The cBuildConfiguration should of type CBuildConfiguration",
ILaunchManager.RUN_MODE, launchTarget, new NullProgressMonitor());
assertThat("The cBuildConfiguration should be of type CBuildConfiguration",
cBuildConfiguration instanceof CBuildConfiguration);
CBuildConfiguration cbc = (CBuildConfiguration) cBuildConfiguration;
// Set this ICBuildConfiguration as the active build configuration
@ -118,6 +139,77 @@ public class CBuildConfigurationManagerTests extends BaseTestCase5 {
scannerInfoProvider instanceof ICBuildConfiguration);
}
/**
* Test {@link ICBuildConfigurationManager#getBuildConfiguration(IProject, IToolChain, String, ILaunchTarget, IProgressMonitor)}
*
* The new parameter, ILaunchTarget, was added in 9.0
*/
@Test
public void getBuildConfiguration0() throws Exception {
ILaunchTarget launchTarget = ILaunchTarget.NULL_TARGET;
ICBuildConfiguration cBuildConfiguration = configManager.getBuildConfiguration(project, mockToolchain,
ILaunchManager.DEBUG_MODE, launchTarget, new NullProgressMonitor());
assertThat(cBuildConfiguration.getToolChain().getTypeId(), is("tc_typeId"));
assertThat(cBuildConfiguration.getToolChain().getId(), is("tcId"));
assertThat(cBuildConfiguration.getLaunchMode(), is(ILaunchManager.DEBUG_MODE));
assertThat(cBuildConfiguration.getLaunchTarget(), is(launchTarget));
}
/**
* Test {@link ICBuildConfigurationManager#getBuildConfiguration(IProject, IToolChain, String, ILaunchTarget, IProgressMonitor)}
* is used correctly by CoreBuildLaunchBarTracker and that when the active launch target is changed, the active build
* configuration is set correctly containing the new launch target.
*/
@Test
public void getBuildConfiguration1() throws Exception {
/*
* After the project has been created, wait for the CoreBuildLaunchBarTracker to settle and finish processing.
*/
waitForLaunchBarTracker();
// Currently active launch target before we change anything is expected to be "Local"
assertThat(launchBarManager.getActiveLaunchTarget().getId(), is("Local"));
// Uncomment following line if debugging tests
// System.out.println("Active launch target id before=" + launchBarManager.getActiveLaunchTarget().getId());
launchTarget = launchTargetManager.addLaunchTarget(ILaunchTargetManager.localLaunchTargetTypeId, "id0");
assertThat(launchTarget.getId(), is("id0"));
/*
* After the launch target has been added, wait for the CoreBuildLaunchBarTracker to settle and finish processing.
*/
waitForLaunchBarTracker();
/*
* Active launch target now is expected to be "id0"
*/
assertThat(launchBarManager.getActiveLaunchTarget(), is(notNullValue()));
assertThat(launchBarManager.getActiveLaunchTarget().getId(), is("id0"));
/*
* By now, the active Build Configuration should have been set using our new Launch Target.
* So test by getting the active Build Configuration and inspect it's launch target. Expected to be the new "id0" value.
*/
IBuildConfiguration buildConfig = project.getActiveBuildConfig();
ICBuildConfiguration cBuildConfig = buildConfig.getAdapter(ICBuildConfiguration.class);
assertThat(cBuildConfig, is(notNullValue()));
// Check the active ICBuildConfiguration has the same launch target we set active previously
ILaunchTarget actualLaunchTarget = cBuildConfig.getLaunchTarget();
assertThat(actualLaunchTarget, is(notNullValue()));
assertThat(actualLaunchTarget.getId(), is(launchTarget.getId()));
assertThat(actualLaunchTarget.getTypeId(), is(launchTarget.getTypeId()));
// Uncomment following line if debugging tests
// System.out.println("Active launch target id after=" + launchBarManager.getActiveLaunchTarget().getId());
}
@AfterEach
public void removeLaunchTarget() throws Exception {
if (launchTarget != null) {
launchTargetManager.removeLaunchTarget(launchTarget);
}
}
private IProject createCMakeProject() throws Exception {
// Create a plain Eclipse project
IProject project = ResourceHelper.createProject(this.getName());
@ -128,4 +220,8 @@ public class CBuildConfigurationManagerTests extends BaseTestCase5 {
project.setDescription(description, null);
return project;
}
private void waitForLaunchBarTracker() throws OperationCanceledException, InterruptedException {
Job.getJobManager().join(CoreBuildLaunchBarTracker.JOB_FAMILY_CORE_BUILD_LAUNCH_BAR_TRACKER, null);
}
}

View file

@ -0,0 +1,113 @@
/*******************************************************************************
* Copyright (c) 2025 Renesas Electronics Europe.
*
* 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.core.build;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.nio.file.Path;
import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.core.testplugin.ResourceHelper;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase5;
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.launchbar.core.target.ILaunchTargetManager;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/**
* Tests org.eclipse.cdt.core.build.ICBuildConfigurationProvider.
*
* Relies on manifest declarations in /org.eclipse.cdt.core.tests/plugin.xml.
* See "org.eclipse.cdt.core.build.ICBuildConfigurationProviderTests.providerId" and
* "extendedCmakeNature2"
*/
public class ICBuildConfigurationProviderTests extends BaseTestCase5 {
private IProject project;
private IToolChain mockToolchain;
private ICBuildConfigurationManager configManager = CDebugCorePlugin.getService(ICBuildConfigurationManager.class);
private ILaunchTargetManager launchTargetManager = CDebugCorePlugin.getService(ILaunchTargetManager.class);
@BeforeEach
public void setup() throws Exception {
// Create a customized CMake project
project = createCustomizedCMakeProject();
// Setup a toolchain ready to use for creating the ICBuildConfiguration
mockToolchain = mock(IToolChain.class);
when(mockToolchain.getProperty(IToolChain.ATTR_OS)).thenReturn("osDummy");
when(mockToolchain.getProperty(IToolChain.ATTR_ARCH)).thenReturn("archDummy");
when(mockToolchain.getTypeId()).thenReturn("tc_typeId");
when(mockToolchain.getId()).thenReturn("tcId");
when(mockToolchain.getBuildConfigNameFragment()).thenReturn("buildConfigName");
}
/**
* Tests org.eclipse.cdt.core.build.ICBuildConfigurationProvider.getCBuildConfigName(IProject, String, IToolChain, String, ILaunchTarget)
* can be extended to provide a customized ICBuildConfiguration name and thereby a customized build output directory name.
*
* @see {@link ICBuildConfigurationProviderTestsProvider#getCBuildConfigName(IProject, String, IToolChain, String, org.eclipse.launchbar.core.target.ILaunchTarget)}
*/
@Test
public void getCBuildConfigName() throws Exception {
/*
* Test summary:
* 1) A ICBuildConfiguration is created using the provided toolchain, launch mode and launch target.
* Note, the key principle to the ICBuildConfigurationProvider being overriden successfully is the project nature.
* It uses a customized nature, declared in plugin.xml.
* When the project provider is accessed, the declaration of extension point="org.eclipse.cdt.core.buildConfigProvider" relates
* the customized nature, so the correct (ICBuildConfigurationProviderTestsProvider) provider is used.
*
* 2) ICBuildConfiguration2.getBuildDirectoryURI() queries the build output directory name. The correct value is specified
* by ICBuildConfigurationProviderTestsProvider.getCBuildConfigName.
*/
/*
* cmake because we extend CMakeBuildConfigurationProvider.
* run because ILaunchManager.RUN_MODE.
* buildConfigName because mockToolchain returns this from getBuildConfigNameFragment.
* Local because using Local launch target.
* customizedTest because ICBuildConfigurationProviderTestsProvider.getCBuildConfigName specifies this.
*/
final String expectedName = "cmake.run.buildConfigName.Local.customizedTest";
/*
* (1) Create ICBuildConfiguration, using our customized ICBuildConfigurationProviderTestsProvider
*/
ICBuildConfiguration cBuildConfiguration = configManager.getBuildConfiguration(project, mockToolchain,
ILaunchManager.RUN_MODE, launchTargetManager.getLocalLaunchTarget(), new NullProgressMonitor());
CBuildConfiguration cBuildConfig = (CBuildConfiguration) cBuildConfiguration;
assertThat(cBuildConfig.getName(), is(expectedName));
/*
* (2) Check last segment of build output directory name is expected.
*/
Path buildDirectory = cBuildConfig.getBuildDirectory();
String lastSegment = buildDirectory.getFileName().toString();
assertThat(lastSegment, is(expectedName));
}
private IProject createCustomizedCMakeProject() throws Exception {
// Create a plain Eclipse project
IProject project = ResourceHelper.createProject(this.getName());
// Add our customized CMake nature to the project
IProjectDescription description = project.getDescription();
description.setNatureIds(new String[] { CProjectNature.C_NATURE_ID, CCProjectNature.CC_NATURE_ID,
ICBuildConfigurationProviderTestsCMakeNature.ID });
project.setDescription(description, null);
return project;
}
}

View file

@ -0,0 +1,21 @@
/*******************************************************************************
* Copyright (c) 2025 Renesas Electronics Europe.
*
* 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.core.build;
import org.eclipse.cdt.cmake.core.CMakeNature;
/**
* Supporting class for test {@link ICBuildConfigurationProviderTests}
*/
public class ICBuildConfigurationProviderTestsCMakeNature extends CMakeNature {
public static final String ID = "org.eclipse.cdt.core.tests.extendedCmakeNature2"; //$NON-NLS-1$
}

View file

@ -0,0 +1,32 @@
/*******************************************************************************
* Copyright (c) 2025 Renesas Electronics Europe.
*
* 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.core.build;
import org.eclipse.cdt.cmake.core.CMakeBuildConfigurationProvider;
import org.eclipse.core.resources.IProject;
import org.eclipse.launchbar.core.target.ILaunchTarget;
/**
* Supporting class for test {@link ICBuildConfigurationProviderTests}
*/
public class ICBuildConfigurationProviderTestsProvider extends CMakeBuildConfigurationProvider {
@Override
public String getId() {
return "org.eclipse.cdt.core.build.ICBuildConfigurationProviderTests.providerId";
}
@Override
public String getCBuildConfigName(IProject project, String toolName, IToolChain toolchain, String launchMode,
ILaunchTarget launchTarget) {
return super.getCBuildConfigName(project, toolName, toolchain, launchMode, launchTarget) + ".customizedTest";
}
}

View file

@ -447,4 +447,23 @@
factoryClass="org.eclipse.cdt.core.resources.tests.TestExclusionFactory">
</exclusionFactory>
</extension>
<!-- For ICBuildConfigurationProviderTests -->
<extension
point="org.eclipse.cdt.core.buildConfigProvider">
<provider
class="org.eclipse.cdt.core.build.ICBuildConfigurationProviderTestsProvider"
id="org.eclipse.cdt.core.build.ICBuildConfigurationProviderTests.providerId"
natureId="org.eclipse.cdt.core.tests.extendedCmakeNature2">
</provider>
</extension>
<extension
id="extendedCmakeNature2"
name="extendedCmakeNature2"
point="org.eclipse.core.resources.natures">
<runtime>
<run
class="org.eclipse.cdt.core.build.ICBuildConfigurationProviderTestsCMakeNature">
</run>
</runtime>
</extension>
</plugin>

View file

@ -143,7 +143,8 @@ Require-Bundle: org.eclipse.cdt.core.native;bundle-version="[6.3.0,7.0.0)";visib
org.eclipse.ltk.core.refactoring;bundle-version="[3.13.0,4.0.0)",
org.eclipse.text;bundle-version="[3.12.300,4.0.0)",
com.google.gson;bundle-version="[2.8.6,3.0.0)",
org.eclipse.jdt.annotation;bundle-version="[2.0.0,3.0.0)";resolution:=optional
org.eclipse.jdt.annotation;bundle-version="[2.0.0,3.0.0)";resolution:=optional,
org.eclipse.launchbar.core;bundle-version="[3.0.0,4.0.0)"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-17
Automatic-Module-Name: org.eclipse.cdt.core

View file

@ -125,7 +125,7 @@ public class CCorePlugin extends Plugin {
public static final int STATUS_PDOM_TOO_LARGE = 4;
/**
* Toolchain not found when inflating a build configuration.
* Toolchain, launch mode or launch target not found when inflating a build configuration.
*
* @since 6.4
*/

View file

@ -0,0 +1,50 @@
/*******************************************************************************
* Copyright (c) 2025 Renesas Electronics Europe.
*
* 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.core.build;
import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
/**
* @since 9.0
*/
public class CBuildConfigUtils {
private CBuildConfigUtils() {
// empty
}
/**
* @param provider Core Build configuration provider. Must not be null.
* @param project Project in which the Platform Build configuration is created. Must not be null.
* @param cBuildConfigName The Core Build config name to be used as part of the the Platform Build configuration
* name. See {@link ICBuildConfigurationProvider#getCBuildConfigName}. Must not be null.
* @param cBuildConfigManager Core Build configuration manager. Must not be null.
* @param monitor
* @return a Platform Build Configuration.
* @throws CoreException
*/
public static IBuildConfiguration createBuildConfiguration(ICBuildConfigurationProvider provider, IProject project,
String cBuildConfigName, ICBuildConfigurationManager cBuildConfigManager, IProgressMonitor monitor)
throws CoreException {
IBuildConfiguration retVal = null;
// Try to reuse any IBuildConfiguration with the same name for the project
if (cBuildConfigManager.hasConfiguration(provider, project, cBuildConfigName)) {
retVal = project.getBuildConfig(provider.getId() + '/' + cBuildConfigName);
}
if (retVal == null) {
retVal = cBuildConfigManager.createBuildConfiguration(provider, project, cBuildConfigName, monitor);
}
return retVal;
}
}

View file

@ -26,6 +26,7 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;
@ -85,6 +86,8 @@ import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.launchbar.core.target.ILaunchTarget;
import org.eclipse.launchbar.core.target.ILaunchTargetManager;
import org.osgi.service.prefs.BackingStoreException;
import org.osgi.service.prefs.Preferences;
@ -114,6 +117,14 @@ public abstract class CBuildConfiguration extends PlatformObject implements ICBu
IMarkerGenerator, IConsoleParser2, IElementChangedListener {
private static final String LAUNCH_MODE = "cdt.launchMode"; //$NON-NLS-1$
/**
* Property name used to store the {@link ILaunchTarget#getTypeId()} in the ICBuildConfiguration properties.
*/
private static final String LAUNCH_TARGET_TYPE_ID = "cdt.launchTarget.typeId"; //$NON-NLS-1$
/**
* Property name used to store the {@link ILaunchTarget#getId()} in the ICBuildConfiguration properties.
*/
private static final String LAUNCH_TARGET_ID = "cdt.launchTarget.id"; //$NON-NLS-1$
private static final String NEED_REFRESH = "cdt.needScannerRefresh"; //$NON-NLS-1$
@ -124,7 +135,8 @@ public abstract class CBuildConfiguration extends PlatformObject implements ICBu
private final String name;
private final IBuildConfiguration config;
private final IToolChain toolChain;
private String launchMode;
private final String launchMode;
private final ILaunchTarget launchTarget;
private Object scannerInfoLock = new Object();
@ -133,51 +145,95 @@ public abstract class CBuildConfiguration extends PlatformObject implements ICBu
private ICommandLauncher launcher;
protected CBuildConfiguration(IBuildConfiguration config, String name) throws CoreException {
this.config = config;
this.name = name;
/**
* Use when a Core Build configuration already exists (eg was created using
* {@link #CBuildConfiguration(IBuildConfiguration, String, IToolChain, String, ILaunchTarget)}.
* The toolchain, launch mode and launch target are loaded from preferences.
*
* @param buildConfig Platform Build Configuration. Must not be null.
* @param cBuildConfigName Name to give the CMakeBuildConfiguration. Must not be null.
* @throws CoreException if this method fails. Reasons include:
* <ul>
* <li> Toolchain is missing,</li>
* <li> Launch mode missing,</li>
* <li> Launch Target is missing.</li>
* </ul>
*/
protected CBuildConfiguration(IBuildConfiguration buildConfig, String cBuildConfigName) throws CoreException {
this.config = Objects.requireNonNull(buildConfig, "buildConfig must not be null"); //$NON-NLS-1$
this.name = Objects.requireNonNull(cBuildConfigName, "cBuildConfigName must not be null"); //$NON-NLS-1$
/*
* Retrieve previously saved toolchain, launch mode and launch target from preferences.
* The STATUS_BUILD_CONFIG_NOT_VALID is used which causes CBuildConfigurationManager to quarantine this Build Configuration.
*/
Preferences settings = getSettings();
String typeId = settings.get(TOOLCHAIN_TYPE, ""); //$NON-NLS-1$
String id = settings.get(TOOLCHAIN_ID, ""); //$NON-NLS-1$
String typeId = settings.get(TOOLCHAIN_TYPE, null);
String id = settings.get(TOOLCHAIN_ID, null);
IToolChainManager toolChainManager = CCorePlugin.getService(IToolChainManager.class);
IToolChain tc = toolChainManager.getToolChain(typeId, id);
if (tc == null) {
// check for other versions
tc = toolChainManager.getToolChain(typeId, id);
if (tc == null) {
throw new CoreException(
new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, CCorePlugin.STATUS_BUILD_CONFIG_NOT_VALID,
String.format(Messages.CBuildConfiguration_ToolchainMissing, config.getName()), null));
}
throw new CoreException(
new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, CCorePlugin.STATUS_BUILD_CONFIG_NOT_VALID,
String.format(Messages.CBuildConfiguration_CBuildConfiguration_ToolchainMissing,
buildConfig.getName(), typeId, id),
null));
}
this.toolChain = tc;
this.launchMode = settings.get(LAUNCH_MODE, "run"); //$NON-NLS-1$
String launchMode = settings.get(LAUNCH_MODE, null);
if (launchMode == null || launchMode.isBlank()) {
throw new CoreException(
new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, CCorePlugin.STATUS_BUILD_CONFIG_NOT_VALID,
String.format(Messages.CBuildConfiguration_CBuildConfiguration_LaunchModeMissing,
buildConfig.getName(), launchMode),
null));
}
this.launchMode = launchMode;
String launchTargetTypeId = settings.get(LAUNCH_TARGET_TYPE_ID, null);
String launchTargetId = settings.get(LAUNCH_TARGET_ID, null);
ILaunchTargetManager launchTargetManager = CCorePlugin.getService(ILaunchTargetManager.class);
ILaunchTarget target = launchTargetManager.getLaunchTarget(launchTargetTypeId, launchTargetId);
if (target == null) {
throw new CoreException(
new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, CCorePlugin.STATUS_BUILD_CONFIG_NOT_VALID,
String.format(Messages.CBuildConfiguration_CBuildConfiguration_LaunchTargetMissing,
buildConfig.getName(), launchTargetTypeId, launchTargetId),
null));
}
this.launchTarget = target;
CoreModel.getDefault().addElementChangedListener(this);
}
protected CBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain) {
this(config, name, toolChain, "run"); //$NON-NLS-1$
}
/**
* @since 6.2
* Use when a Core Build configuration is created for the first time. The toolchain, launch mode and launch target
* are saved to preferences. This allows the Core Build configuration to retrieved later (maybe another workbench
* session), using {@link #CBuildConfiguration(IBuildConfiguration, String)}
*
* @param buildConfig Platform Build Configuration. Must not be null.
* @param cBuildConfigName Name to give the CMakeBuildConfiguration. Must not be null.
* @param toolChain Toolchain to associate with this CMakeBuildConfiguration. Must not be null.
* @param launchMode Launch mode (eg "debug") to associate with this CMakeBuildConfiguration. Must not be null.
* @param launchTarget Launch target to associate with this CMakeBuildConfiguration. Must not be null.
* @since 9.0
*/
protected CBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain, String launchMode) {
this.config = config;
this.name = name;
this.toolChain = toolChain;
this.launchMode = launchMode;
protected CBuildConfiguration(IBuildConfiguration buildConfig, String cBuildConfigName, IToolChain toolChain,
String launchMode, ILaunchTarget launchTarget) {
this.config = Objects.requireNonNull(buildConfig, "buildConfig must not be null"); //$NON-NLS-1$
this.name = Objects.requireNonNull(cBuildConfigName, "cBuildConfigName must not be null"); //$NON-NLS-1$
this.toolChain = Objects.requireNonNull(toolChain, "toolChain must not be null"); //$NON-NLS-1$
this.launchMode = Objects.requireNonNull(launchMode, "launchMode must not be null"); //$NON-NLS-1$
this.launchTarget = Objects.requireNonNull(launchTarget, "launchTarget must not be null"); //$NON-NLS-1$
Preferences settings = getSettings();
settings.put(TOOLCHAIN_TYPE, toolChain.getTypeId());
settings.put(TOOLCHAIN_ID, toolChain.getId());
if (launchMode != null) {
settings.put(LAUNCH_MODE, launchMode);
}
settings.put(LAUNCH_MODE, launchMode);
settings.put(LAUNCH_TARGET_TYPE_ID, launchTarget.getTypeId());
settings.put(LAUNCH_TARGET_ID, launchTarget.getId());
try {
settings.flush();
} catch (BackingStoreException e) {
@ -187,10 +243,6 @@ public abstract class CBuildConfiguration extends PlatformObject implements ICBu
CoreModel.getDefault().addElementChangedListener(this);
}
protected CBuildConfiguration(IBuildConfiguration config, IToolChain toolChain) {
this(config, DEFAULT_NAME, toolChain);
}
@Override
public IBuildConfiguration getBuildConfiguration() {
return config;
@ -208,18 +260,9 @@ public abstract class CBuildConfiguration extends PlatformObject implements ICBu
return launchMode;
}
/**
* @since 6.2
*/
protected void setLaunchMode(String launchMode) {
this.launchMode = launchMode;
Preferences settings = getSettings();
settings.put(LAUNCH_MODE, launchMode);
try {
settings.flush();
} catch (BackingStoreException e) {
CCorePlugin.log(e);
}
@Override
public ILaunchTarget getLaunchTarget() {
return launchTarget;
}
public IProject getProject() {

View file

@ -28,6 +28,7 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.launchbar.core.target.ILaunchTarget;
/**
* A Build configuration that simply spits out an error message on the console at build and clean time.
@ -42,6 +43,8 @@ public class ErrorBuildConfiguration extends PlatformObject implements ICBuildCo
private final IBuildConfiguration config;
private String errorMessage;
private static ICBuildConfigurationManager configManager = CCorePlugin
.getService(ICBuildConfigurationManager.class);
public static final String NAME = "!"; //$NON-NLS-1$
@ -56,6 +59,17 @@ public class ErrorBuildConfiguration extends PlatformObject implements ICBuildCo
throws CoreException {
return new ErrorBuildConfiguration(config, Messages.ErrorBuildConfiguration_What);
}
@Override
public ICBuildConfiguration createCBuildConfiguration(IProject project, IToolChain toolChain, String launchMode,
ILaunchTarget launchTarget, IProgressMonitor monitor) throws CoreException {
IBuildConfiguration errorBuildConfig = configManager.createBuildConfiguration(this, project,
"ErrorBuildConfiguration", monitor); //$NON-NLS-1$
ErrorBuildConfiguration errorCBuildConfiguration = new ErrorBuildConfiguration(errorBuildConfig,
Messages.ErrorBuildConfiguration_What);
configManager.addBuildConfiguration(errorBuildConfig, errorCBuildConfiguration);
return errorCBuildConfiguration;
}
}
public static final Provider PROVIDER = new Provider();
@ -93,31 +107,23 @@ public class ErrorBuildConfiguration extends PlatformObject implements ICBuildCo
@Override
public IScannerInfo getScannerInformation(IResource resource) {
// TODO Auto-generated method stub
return null;
}
@Override
public void subscribe(IResource resource, IScannerInfoChangeListener listener) {
// TODO Auto-generated method stub
}
@Override
public void unsubscribe(IResource resource, IScannerInfoChangeListener listener) {
// TODO Auto-generated method stub
}
@Override
public void setActive() {
// TODO Auto-generated method stub
}
@Override
public URI getBuildDirectoryURI() throws CoreException {
// TODO Auto-generated method stub
return null;
}
@ -128,19 +134,16 @@ public class ErrorBuildConfiguration extends PlatformObject implements ICBuildCo
@Override
public IToolChain getToolChain() throws CoreException {
// TODO Auto-generated method stub
return null;
}
@Override
public IEnvironmentVariable getVariable(String name) throws CoreException {
// TODO Auto-generated method stub
return null;
}
@Override
public IEnvironmentVariable[] getVariables() throws CoreException {
// TODO Auto-generated method stub
return null;
}
@ -149,5 +152,4 @@ public class ErrorBuildConfiguration extends PlatformObject implements ICBuildCo
// Return empty list to prevent possible NPE
return Collections.emptyList();
}
}

View file

@ -23,6 +23,7 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.launchbar.core.target.ILaunchTarget;
/**
* This is the root interface for "new style" CDT build configurations. Adapting
@ -74,6 +75,13 @@ public interface ICBuildConfiguration extends IAdaptable, IScannerInfoProvider {
return null;
}
/**
* @since 9.0
*/
default ILaunchTarget getLaunchTarget() {
return null;
}
/**
* Ids for the Binary Parsers to use when checking whether a file is a
* binary that can be launched.
@ -236,5 +244,4 @@ public interface ICBuildConfiguration extends IAdaptable, IScannerInfoProvider {
default boolean supportsProperties(Map<String, String> properties) {
return false;
}
}

View file

@ -10,12 +10,11 @@
*******************************************************************************/
package org.eclipse.cdt.core.build;
import java.util.Map;
import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.launchbar.core.target.ILaunchTarget;
/**
* The OSGi service that manages the mapping from platform build configuration
@ -49,54 +48,44 @@ public interface ICBuildConfigurationManager {
throws CoreException;
/**
* Create a new build configuration to be owned by a provider.
* Create a new Platform Build configuration to be owned by a Core Build config provider.
*
* @param provider
* @param project
* @param configName
* @param provider The project's Core Build config provider. Must not be null.
* @param project Project in which the Platform Build configuration is created. Must not be null.
* @param configName The Core Build config name to be used as part of the the Platform Build configuration
* name. Must not be null.
* @param monitor
* @return new build configuration
* @throws CoreException
* @return new Platform Build configuration. Not null.
* @throws CoreException Reasons include the reasons given in
* {@link IProject#setDescription(org.eclipse.core.resources.IProjectDescription, IProgressMonitor)}
*/
IBuildConfiguration createBuildConfiguration(ICBuildConfigurationProvider provider, IProject project,
String configName, IProgressMonitor monitor) throws CoreException;
/**
* Create a new build configuration for a given project using a given
* toolchain and builds for a given launch mode.
* Finds an existing Core Build configuration or creates a new one if one does not exist.
*
* @param project
* project for the config
* @param toolChain
* toolchain the build config will use
* @param launchMode
* launch mode the buld config will build for
* @return new build configuration
* @throws CoreException
* @since 6.1
* The project's ICBuildConfigurationProvider is used to attempt to get an existing configuration or create a new one.
*
* @param project Project to associate this Core Build Configuration to. Must not be null.
* @param toolChain Toolchain to associate with this ICBuildConfiguration. Must not be null.
* @param launchMode Launch mode (eg "debug") to associate with this ICBuildConfiguration. Must not be null.
* @param launchTarget Launch target to associate with this ICBuildConfiguration. Must not be null.
* @param monitor
* @return a Core Build configuration matching the supplied parameters. Not null.
* @throws CoreException Reasons include:
* <ul>
* <li> The project does not exist.</li>
* <li> The project is not open.</li>
* <li> The project's {@link ICBuildConfigurationProvider#getCBuildConfiguration(IBuildConfiguration, String)} fails.</li>
* <li> The project's {@link ICBuildConfigurationProvider} is not found.</li>
* <li> There is a problem accessing the toolchain.</li>
* </ul>
* @since 9.0
* @apiNote This should be renamed to getCBuildConfiguration as it returns a Core Build config.
*/
ICBuildConfiguration getBuildConfiguration(IProject project, IToolChain toolChain, String launchMode,
IProgressMonitor monitor) throws CoreException;
/**
* Create a new build configuration for a given project using a toolchain with
* the given properties and that builds for a given launch mode.
*
* @deprecated clients really need to pick which toolchain they want a build
* config for. This method pretty much picks one at random.
* @param project
* project for the config
* @param properties
* properties for the toolchain to be selected
* @param launchMode
* launch mode the buld config will build for
* @return new build configuration
* @throws CoreException
* @since 6.2
*/
@Deprecated
ICBuildConfiguration getBuildConfiguration(IProject project, Map<String, String> properties, String launchMode,
IProgressMonitor monitor) throws CoreException;
ILaunchTarget launchTarget, IProgressMonitor monitor) throws CoreException;
/**
* Called by providers to add new build configurations as they are created.

View file

@ -11,14 +11,17 @@
package org.eclipse.cdt.core.build;
import java.util.Collection;
import java.util.StringJoiner;
import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.launchbar.core.target.ILaunchTarget;
import org.eclipse.launchbar.core.target.LaunchTargetUtils;
/**
* A CBuildConfigurationProvider provides C build configurations.
* A CBuildConfigurationProvider provides Core Build configurations.
*
* @since 6.0
*/
@ -32,30 +35,77 @@ public interface ICBuildConfigurationProvider {
String getId();
/**
* Returns the ICBuildConfiguration that owns this build configuration.
* Returns the Core Build configuration that owns this Platform Build configuration.
*
* @param config
* @return CDT build configuration for the Platform build configuration
* @param buildConfig Platform Build Configuration. Must not be null.
* @param cBuildConfigName Name to give the ICBuildConfiguration. Must not be null.
* @return a Core Build configuration.
* @throws CoreException if this method fails. Reasons include:
* <ul>
* <li> Toolchain is missing,</li>
* <li> Launch mode missing,</li>
* <li> Launch Target is missing.</li>
* </ul>
*/
ICBuildConfiguration getCBuildConfiguration(IBuildConfiguration config, String name) throws CoreException;
ICBuildConfiguration getCBuildConfiguration(IBuildConfiguration buildConfig, String cBuildConfigName)
throws CoreException;
/**
* Create a new build configuration for a given project using a given
* toolchain and builds for a given launch mode.
* Create a new Platform Build/Core Build configuration combination.
*
* @param project
* project for the config
* @param toolChain
* toolchain the build config will use
* @param launchMode
* launch mode the buld config will build for
* @return new build configuration or null combination not supported
* @throws CoreException
* @since 6.1
* @param project Project to associate this Core Build configuration to. Must not be null.
* @param toolChain Toolchain to associate with this ICBuildConfiguration. Must not be null.
* @param launchMode Launch mode (eg "debug") to associate with this ICBuildConfiguration. Must not be null.
* @param launchTarget Launch target to associate with this ICBuildConfiguration. Must not be null.
* @param monitor
* @return a Core Build configuration.
* @throws CoreException if this method fails. Reasons include:
* <ul>
* <li> This project does not exist.</li>
* <li> This project is not open.</li>
* <li> The reasons given in {@link IProject#setDescription(org.eclipse.core.resources.IProjectDescription, IProgressMonitor)}.</li>
* </ul>
*
* @since 9.0
*/
default ICBuildConfiguration createBuildConfiguration(IProject project, IToolChain toolChain, String launchMode,
IProgressMonitor monitor) throws CoreException {
return null;
ICBuildConfiguration createCBuildConfiguration(IProject project, IToolChain toolChain, String launchMode,
ILaunchTarget launchTarget, IProgressMonitor monitor) throws CoreException;
/**
* Name used when creating a Core Build configuration, used by {@link #createCBuildConfiguration}.
* This is the name used when the build output directory is created.
* @param project Project associated with this ICBuildConfiguration. Must not be null.
* @param toolName Name of the build tool (eg: "cmake", "make"). Must not be null.
* @param toolchain Toolchain associated with this ICBuildConfiguration. Must not be null.
* @param launchMode Launch mode (eg "debug") associated with this ICBuildConfiguration. Must not be null.
* @param launchTarget Launch target associated with this ICBuildConfiguration. Must not be null.
* @see {@link ICBuildConfiguration2#getBuildDirectoryURI()}
*
* @return Name used when a Core Build configuration is created. Default implementation uses the following pattern <br>
* toolName.launchMode.toolchain OS.toolchain Arch.launchTarget Id
* <p>For example, a cmake build, in debug mode, using a GCC windows toolchain with the Local launch target:<br>
* "cmake.debug.win32.x86_64.Local"
* <p>A different pattern is used when running in a Docker container.
* @since 9.0
*/
default String getCBuildConfigName(IProject project, String toolName, IToolChain toolchain, String launchMode,
ILaunchTarget launchTarget) {
StringJoiner configName = new StringJoiner("."); //$NON-NLS-1$
configName.add(toolName);
configName.add(launchMode);
String os = toolchain.getProperty(IToolChain.ATTR_OS);
if ("linux-container".equals(os)) { //$NON-NLS-1$
String osConfigName = toolchain.getProperty("linux-container-id").replaceAll("/", "_"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
configName.add(osConfigName);
} else {
String fragment = toolchain.getBuildConfigNameFragment();
if (fragment != null && !fragment.isEmpty()) {
configName.add(fragment);
}
configName.add(LaunchTargetUtils.sanitizeName(launchTarget.getId()));
}
return configName.toString();
}
/**

View file

@ -39,6 +39,7 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.launchbar.core.target.ILaunchTarget;
/**
* A Standard Build Configuration that simply calls a specified command for
@ -75,9 +76,12 @@ public class StandardBuildConfiguration extends CBuildConfiguration {
setupEnvVars();
}
public StandardBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain, String launchMode)
throws CoreException {
super(config, name, toolChain, launchMode);
/**
* @since 9.0
*/
public StandardBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain, String launchMode,
ILaunchTarget launchTarget) throws CoreException {
super(config, name, toolChain, launchMode, launchTarget);
applyProperties();
setupEnvVars();
}

View file

@ -16,7 +16,6 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@ -30,7 +29,6 @@ import org.eclipse.cdt.core.build.ICBuildConfigurationManager;
import org.eclipse.cdt.core.build.ICBuildConfigurationManager2;
import org.eclipse.cdt.core.build.ICBuildConfigurationProvider;
import org.eclipse.cdt.core.build.IToolChain;
import org.eclipse.cdt.core.build.IToolChainManager;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.internal.core.model.CModelManager;
import org.eclipse.core.resources.IBuildConfiguration;
@ -48,6 +46,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.launchbar.core.target.ILaunchTarget;
import org.osgi.service.prefs.BackingStoreException;
import org.osgi.service.prefs.Preferences;
@ -138,7 +137,7 @@ public class CBuildConfigurationManager
return null;
}
public ICBuildConfigurationProvider getProvider(IProject project) throws CoreException {
public ICBuildConfigurationProvider getProvider(IProject project) {
initProviders();
for (Provider provider : providers.values()) {
if (provider.supports(project)) {
@ -202,11 +201,7 @@ public class CBuildConfigurationManager
ICBuildConfigurationProvider provider = null;
if (IBuildConfiguration.DEFAULT_CONFIG_NAME.equals(buildConfig.getName())) {
configName = ICBuildConfiguration.DEFAULT_NAME;
try {
provider = getProvider(buildConfig.getProject());
} catch (CoreException e) {
continue;
}
provider = getProvider(buildConfig.getProject());
} else {
String[] segments = buildConfig.getName().split("/"); //$NON-NLS-1$
if (segments.length == 2) {
@ -304,48 +299,58 @@ public class CBuildConfigurationManager
@Override
public ICBuildConfiguration getBuildConfiguration(IProject project, IToolChain toolChain, String launchMode,
IProgressMonitor monitor) throws CoreException {
// First see if we have one
for (IBuildConfiguration config : project.getBuildConfigs()) {
ICBuildConfiguration cconfig = getBuildConfiguration(config);
if (cconfig != null) {
IToolChain tc = cconfig.getToolChain();
if (tc != null && tc.equals(toolChain) && launchMode.equals(cconfig.getLaunchMode())) {
return cconfig;
ILaunchTarget launchTarget, IProgressMonitor monitor) throws CoreException {
// First check if a matching ICBuildConfiguration exists already
ICBuildConfiguration retVal = findCBuildConfiguration(project, toolChain, launchTarget, launchMode, monitor);
if (retVal == null) {
// No existing ICBuildConfiguration, so get ICBuildConfigurationProvider to create one
retVal = createCBuildConfig(project, toolChain, launchTarget, launchMode, monitor);
}
return retVal;
}
private ICBuildConfiguration findCBuildConfiguration(IProject project, IToolChain toolChain,
ILaunchTarget launchTarget, String launchMode, IProgressMonitor monitor) throws CoreException {
for (IBuildConfiguration buildConfig : project.getBuildConfigs()) {
ICBuildConfiguration cBuildConfig = getBuildConfiguration(buildConfig);
if (cBuildConfig != null) {
IToolChain tc = cBuildConfig.getToolChain();
ILaunchTarget lt = cBuildConfig.getLaunchTarget();
String lm = cBuildConfig.getLaunchMode();
if (tc != null && tc.equals(toolChain) && lt != null && lt.equals(launchTarget) && lm != null
&& lm.equals(launchMode)) {
return cBuildConfig;
}
}
}
return null;
}
// Nope, ask the provider to create one
private ICBuildConfiguration createCBuildConfig(IProject project, IToolChain toolChain, ILaunchTarget launchTarget,
String launchMode, IProgressMonitor monitor) throws CoreException {
ICBuildConfiguration retVal = null;
ICBuildConfigurationProvider provider = getProvider(project);
if (provider != null) {
// The provider will call us back to add in the new one
ICBuildConfiguration cconfig = provider.createBuildConfiguration(project, toolChain, launchMode, monitor);
if (cconfig != null) {
retVal = provider.createCBuildConfiguration(project, toolChain, launchMode, launchTarget, monitor);
if (retVal != null) {
/*
* The IScannerInfoProvider may be cached with an incorrect value if the ICBuildConfiguration is not
* available at the time it is checked. Now that one has been created, the previous value should be
* forgotten so the new cconfig can be used.
*/
CCorePlugin.getDefault().resetCachedScannerInfoProvider(project);
return retVal;
}
return cconfig;
} else {
return null;
throw new CoreException(
CCorePlugin.createStatus(String.format(Messages.CBuildConfigurationManager_CBuildConfigCreateFail,
project.getName(), toolChain.getName(), launchTarget.getId(), launchMode), null));
}
}
@Override
public ICBuildConfiguration getBuildConfiguration(IProject project, Map<String, String> properties,
String launchMode, IProgressMonitor monitor) throws CoreException {
IToolChainManager tcManager = CCorePlugin.getService(IToolChainManager.class);
Collection<IToolChain> toolchains = tcManager.getToolChainsMatching(properties);
if (toolchains.isEmpty()) {
return null;
}
IToolChain toolChain = toolchains.iterator().next();
return getBuildConfiguration(project, toolChain, launchMode, monitor);
throw new CoreException(
CCorePlugin.createStatus(String.format(Messages.CBuildConfigurationManager_CBuildConfigProviderNotFound,
project.getName(), toolChain.getName(), launchTarget.getId(), launchMode), null));
}
@Override

View file

@ -14,16 +14,19 @@ import org.eclipse.osgi.util.NLS;
public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.core.build.messages"; //$NON-NLS-1$
public static String CBuildConfiguration_CreateJob;
public static String CBuildConfiguration_ToolchainMissing;
public static String CBuildConfiguration_Location;
public static String CBuildConfiguration_RunningScannerInfo;
public static String CBuilder_ExceptionWhileBuilding;
public static String CBuilder_ExceptionWhileBuilding2;
public static String CBuilder_NotConfiguredCorrectly;
public static String CBuilder_NotConfiguredCorrectly2;
public static String CBuildConfiguration_CBuildConfiguration_LaunchModeMissing;
public static String CBuildConfiguration_CBuildConfiguration_LaunchTargetMissing;
public static String CBuildConfiguration_CBuildConfiguration_ToolchainMissing;
public static String CBuildConfiguration_CommandNotFound;
public static String CBuildConfiguration_BuildComplete;
public static String CBuildConfigurationManager_CBuildConfigCreateFail;
public static String CBuildConfigurationManager_CBuildConfigProviderNotFound;
public static String ErrorBuildConfiguration_What;
public static String ErrorBuildConfiguration_ErrorWritingToConsole;
public static String StandardBuildConfiguration_0;

View file

@ -16,10 +16,13 @@ StandardBuildConfiguration_0=Building in: %s\n
StandardBuildConfiguration_1=Build complete (%d errors, %d warnings): %s\n
StandardBuildConfiguration_Failure=Error: %s
CBuildConfiguration_BuildComplete=Build complete\n
CBuildConfiguration_CBuildConfiguration_LaunchModeMissing=Launch mode missing for build configuration=%s, launchMode=$s
CBuildConfiguration_CBuildConfiguration_LaunchTargetMissing=Launch Target is missing for build configuration=%s, typeId=%s, id=%s
CBuildConfiguration_CBuildConfiguration_ToolchainMissing=Toolchain is missing for build configuration=%s, typeId=%s, id=%s
CBuildConfiguration_CommandNotFound=Error: build command '%s' not found\n
CBuildConfiguration_CreateJob=Create Build Folder
CBuildConfiguration_Location=line %d, external location: %s
CBuildConfiguration_ToolchainMissing=Toolchain is missing for build configuration
CBuildConfiguration_RunningScannerInfo=Calculating scanner info for %s
CBuildConfigurationManager_CBuildConfigCreateFail=Project, %s, Core Build config provider failed to create a config, for toolchain=%s, launch target=%s, launch mode=%s
CBuildConfigurationManager_CBuildConfigProviderNotFound=Project %s Core Build config provider not found, for toolchain=%s, launch target=%s, launch mode=%s
ErrorBuildConfiguration_What=Unknown initialization error
ErrorBuildConfiguration_ErrorWritingToConsole=Error writing to console

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.900.qualifier
Bundle-Version: 9.0.0.qualifier
Bundle-Activator: org.eclipse.cdt.debug.core.CDebugCorePlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin

View file

@ -53,7 +53,15 @@ import org.eclipse.launchbar.core.target.TargetStatus;
* @since 8.3
*/
public class CoreBuildLaunchBarTracker implements ILaunchBarListener, ILaunchTargetListener {
/**
* Useful for testing. Allows tests to wait for LaunchBarTracker to finish processing.
* <pre>
* Job.getJobManager().join(CoreBuildLaunchBarTracker.JOB_FAMILY_CORE_BUILD_LAUNCH_BAR_TRACKER, null);
* </pre>
*
* @since 9.0
*/
public static final Object JOB_FAMILY_CORE_BUILD_LAUNCH_BAR_TRACKER = new Object();
private final ILaunchBarManager launchBarManager = CDebugCorePlugin.getService(ILaunchBarManager.class);
private final ICBuildConfigurationManager configManager = CDebugCorePlugin
.getService(ICBuildConfigurationManager.class);
@ -130,6 +138,12 @@ public class CoreBuildLaunchBarTracker implements ILaunchBarListener, ILaunchTar
// Pick core build config based on launch mode and toolchain for target
// Since this may create a new config, need to run it in a Job
Job job = new Job(InternalDebugCoreMessages.CoreBuildLaunchBarTracker_Job) {
@Override
public boolean belongsTo(Object family) {
return JOB_FAMILY_CORE_BUILD_LAUNCH_BAR_TRACKER == family;
}
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
@ -143,11 +157,14 @@ public class CoreBuildLaunchBarTracker implements ILaunchBarListener, ILaunchTar
if (testConfig != null && !(testConfig instanceof ErrorBuildConfiguration)) {
// Match launch mode run/debug.
if (testConfig.getLaunchMode().equals(lastMode.getIdentifier())) {
// Match toolchain.
for (IToolChain tc : tcs) {
if (testConfig.getToolChain().equals(tc)) {
buildConfig = testConfig;
break configs;
// Match launch target
if (testConfig.getLaunchTarget().equals(lastTarget)) {
// Match toolchain.
for (IToolChain tc : tcs) {
if (testConfig.getToolChain().equals(tc)) {
buildConfig = testConfig;
break configs;
}
}
}
}
@ -157,7 +174,7 @@ public class CoreBuildLaunchBarTracker implements ILaunchBarListener, ILaunchTar
if (buildConfig == null) {
for (IToolChain toolChain : tcs) {
buildConfig = configManager.getBuildConfiguration(finalProject, toolChain,
mode.getIdentifier(), monitor);
mode.getIdentifier(), lastTarget, monitor);
if (buildConfig != null) {
break;
}

View file

@ -11,7 +11,6 @@
package org.eclipse.cdt.debug.core.launch;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
@ -63,25 +62,6 @@ public abstract class CoreBuildLaunchConfigDelegate extends LaunchConfigurationT
return project != null ? new IProject[] { project } : new IProject[0];
}
/**
* @deprecated Use the version that takes the launch config so we can see if it
* know what toolchain to use.
*/
@Deprecated
protected ICBuildConfiguration getBuildConfiguration(IProject project, String mode, ILaunchTarget target,
IProgressMonitor monitor) throws CoreException {
// Pick build config based on toolchain for target
Map<String, String> properties = new HashMap<>();
properties.putAll(target.getAttributes());
Collection<IToolChain> tcs = toolChainManager.getToolChainsMatching(properties);
if (!tcs.isEmpty()) {
IToolChain toolChain = tcs.iterator().next();
return configManager.getBuildConfiguration(project, toolChain, mode, monitor);
} else {
return null;
}
}
/**
* @since 8.3
*/
@ -93,7 +73,7 @@ public abstract class CoreBuildLaunchConfigDelegate extends LaunchConfigurationT
String providerId = configuration.getAttribute(ICBuildConfiguration.TOOLCHAIN_TYPE, ""); //$NON-NLS-1$
IToolChain toolchain = toolChainManager.getToolChain(providerId, toolchainId);
if (toolchain != null) {
return configManager.getBuildConfiguration(project, toolchain, mode, monitor);
return configManager.getBuildConfiguration(project, toolchain, mode, target, monitor);
}
}
@ -101,7 +81,8 @@ public abstract class CoreBuildLaunchConfigDelegate extends LaunchConfigurationT
Map<String, String> properties = new HashMap<>();
properties.putAll(target.getAttributes());
for (IToolChain toolChain : toolChainManager.getToolChainsMatching(properties)) {
ICBuildConfiguration buildConfig = configManager.getBuildConfiguration(project, toolChain, mode, monitor);
ICBuildConfiguration buildConfig = configManager.getBuildConfiguration(project, toolChain, mode, target,
monitor);
if (buildConfig != null) {
return buildConfig;
}
@ -129,7 +110,7 @@ public abstract class CoreBuildLaunchConfigDelegate extends LaunchConfigurationT
/**
* Returns the full path to the binary.
*
* @since 8.8
* @since 9.0
* @param configuration
* @param buildConfig
* @return

View file

@ -49,7 +49,7 @@ Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.16.0,4.0.0)",
org.eclipse.ui;bundle-version="[3.2.0,4.0.0)",
org.eclipse.debug.ui;bundle-version="[3.7.0,4.0.0)",
org.eclipse.debug.core;bundle-version="[3.7.0,4.0.0)",
org.eclipse.cdt.debug.core;bundle-version="[7.0.0,9.0.0)",
org.eclipse.cdt.debug.core;bundle-version="[9.0.0,10.0.0)",
org.eclipse.cdt.ui;bundle-version="[9.0.0,10.0.0)",
org.eclipse.cdt.core;bundle-version="[9.0.0,10.0.0)",
org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",

View file

@ -531,7 +531,7 @@ public class ContainerLaunchConfigurationDelegate extends GdbLaunchDelegate {
String providerId = configuration.getAttribute(ICBuildConfiguration.TOOLCHAIN_TYPE, ""); //$NON-NLS-1$
IToolChain toolchain = toolChainManager.getToolChain(providerId, toolchainId);
if (toolchain != null) {
return configManager.getBuildConfiguration(project, toolchain, mode, monitor);
return configManager.getBuildConfiguration(project, toolchain, mode, target, monitor);
}
}
@ -539,7 +539,8 @@ public class ContainerLaunchConfigurationDelegate extends GdbLaunchDelegate {
Map<String, String> properties = new HashMap<>();
properties.putAll(target.getAttributes());
for (IToolChain toolChain : toolChainManager.getToolChainsMatching(properties)) {
ICBuildConfiguration buildConfig = configManager.getBuildConfiguration(project, toolChain, mode, monitor);
ICBuildConfiguration buildConfig = configManager.getBuildConfiguration(project, toolChain, mode, target,
monitor);
if (buildConfig != null) {
return buildConfig;
}

View file

@ -21,7 +21,7 @@ Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.2.0,4.0.0)",
org.eclipse.ui;bundle-version="[3.2.0,4.0.0)",
org.eclipse.cdt.core;bundle-version="[9.0.0,10.0.0)",
org.eclipse.cdt.ui;bundle-version="[9.0.0,10.0.0)",
org.eclipse.cdt.debug.core;bundle-version="[7.0.0,9.0.0)",
org.eclipse.cdt.debug.core;bundle-version="[9.0.0,10.0.0)",
org.eclipse.cdt.debug.ui;bundle-version="[7.0.0,9.0.0)",
org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
org.eclipse.core.variables;bundle-version="[3.1.100,4.0.0)",

View file

@ -196,7 +196,8 @@ public abstract class CommonBuildTab extends AbstractLaunchConfigurationTab {
String mode = getLaunchConfigurationDialog().getMode();
try {
buildConfig = bcManager.getBuildConfiguration(project, newToolchain, mode, new NullProgressMonitor());
buildConfig = bcManager.getBuildConfiguration(project, newToolchain, mode, getLaunchTarget(),
new NullProgressMonitor());
} catch (CoreException e) {
LaunchUIPlugin.log(e.getStatus());
}

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.launchbar.core;singleton:=true
Bundle-Version: 2.5.300.qualifier
Bundle-Version: 3.0.0
Bundle-Activator: org.eclipse.launchbar.core.internal.Activator
Bundle-Vendor: %providerName
Require-Bundle: org.eclipse.core.runtime,

View file

@ -21,7 +21,6 @@ public class Messages extends NLS {
public static String LaunchBarManager_0;
public static String LaunchBarManager_1;
public static String LaunchBarManager_2;
public static String LocalTarget_name;
public static String OK;
static {

View file

@ -15,5 +15,4 @@ ILaunchTarget_notSupported=getWorkingCopy is not supported for NULL_TARGET
LaunchBarManager_0=Launch Bar Initialization
LaunchBarManager_1=Active descriptor must be in the map of descriptors
LaunchBarManager_2=Mode is not supported by descriptor
LocalTarget_name=Local
OK=OK

View file

@ -11,7 +11,6 @@
package org.eclipse.launchbar.core.internal.target;
import org.eclipse.core.runtime.Platform;
import org.eclipse.launchbar.core.internal.Messages;
import org.eclipse.launchbar.core.target.ILaunchTarget;
import org.eclipse.launchbar.core.target.ILaunchTargetManager;
import org.eclipse.launchbar.core.target.ILaunchTargetProvider;
@ -23,9 +22,9 @@ public class LocalLaunchTargetProvider implements ILaunchTargetProvider {
@Override
public void init(ILaunchTargetManager targetManager) {
if (targetManager.getLaunchTarget(ILaunchTargetManager.localLaunchTargetTypeId,
Messages.LocalTarget_name) == null) {
ILaunchTargetManager.localLaunchTargetId) == null) {
ILaunchTarget target = targetManager.addLaunchTarget(ILaunchTargetManager.localLaunchTargetTypeId,
Messages.LocalTarget_name);
ILaunchTargetManager.localLaunchTargetId);
ILaunchTargetWorkingCopy wc = target.getWorkingCopy();
wc.setAttribute(ILaunchTarget.ATTR_OS, Platform.getOS());
wc.setAttribute(ILaunchTarget.ATTR_ARCH, Platform.getOSArch());

View file

@ -42,21 +42,10 @@ public interface ILaunchTarget extends IAdaptable {
/**
* The id for the target. It is unique for each type.
*
* @return id for the target.
* @return id (name) for the target.
*/
String getId();
/**
* The user consumable name of the target.
*
* @deprecated this will be the same as the id
* @return name of the target
*/
@Deprecated
default String getName() {
return getId();
}
/**
* The type of the target.
*

View file

@ -26,6 +26,17 @@ public interface ILaunchTargetManager {
* represents that machine.
*/
final String localLaunchTargetTypeId = "org.eclipse.launchbar.core.launchTargetType.local"; //$NON-NLS-1$
/**
* @since 3.0
*/
final String localLaunchTargetId = "Local"; //$NON-NLS-1$
/**
* @since 3.0
*/
default ILaunchTarget getLocalLaunchTarget() {
return getLaunchTarget(localLaunchTargetTypeId, localLaunchTargetId);
}
/**
* The list of all launch targets.

View file

@ -0,0 +1,48 @@
/*******************************************************************************
* Copyright (c) 2025 Renesas Electronics Europe.
*
* 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.launchbar.core.target;
import java.util.regex.Pattern;
/**
* @since 3.0
*/
public class LaunchTargetUtils {
/**
* Used to detect names with invalid characters. _ is allowed.
* Invalid characters include:
* spaces, tabs, newlines, most punctuation (eg +-,.), control chars (eg \n, \t, \r)
*/
private static final Pattern INVALID_NAME_PATTERN = Pattern
.compile("[^\\pL\\pM\\p{Nd}\\p{Nl}\\p{Pc}[\\p{InEnclosedAlphanumerics}&&\\p{So}]]"); //$NON-NLS-1$
private LaunchTargetUtils() {
// empty
}
/**
* Check for invalid characters.
* @param name The name to check.
* @return true if name contains characters in {@link #INVALID_NAME_PATTERN}.
*/
public static boolean isInvalidName(String name) {
return INVALID_NAME_PATTERN.matcher(name).find();
}
/**
* Replace any invalid characters with a safe value.
* @param name The name to check.
* @return name with any character in the {@link #INVALID_NAME_PATTERN} replaced with "_"
*/
public static String sanitizeName(String name) {
return INVALID_NAME_PATTERN.matcher(name).replaceAll("_"); //$NON-NLS-1$
}
}