1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 14:12:10 +02:00

Add binary parsers to new build system. Clean up some toolchain stuff.

new build configs now support binary parsers which are by default
driven from the toolchains. Ran into problem with new versions of
toolchains. Added versioning info to toolchains to take that into
account.

Change-Id: Ie1fb7755e84239b525dca0ae11759027a0b44574
This commit is contained in:
Doug Schaefer 2016-05-10 12:45:02 -04:00 committed by Gerrit Code Review @ Eclipse.org
parent 49e921843f
commit 2c4921bca0
22 changed files with 309 additions and 207 deletions

View file

@ -47,6 +47,8 @@ import org.eclipse.core.runtime.PlatformObject;
public class GCCToolChain extends PlatformObject implements IToolChain { public class GCCToolChain extends PlatformObject implements IToolChain {
private final IToolChainProvider provider; private final IToolChainProvider provider;
private final String id;
private final String version;
private final String name; private final String name;
private final Path path; private final Path path;
private final String prefix; private final String prefix;
@ -55,17 +57,19 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
protected String[] compileCommands; protected String[] compileCommands;
public GCCToolChain(IToolChainProvider provider, String name) { public GCCToolChain(IToolChainProvider provider, String id, String version) {
this(provider, name, null, null); this(provider, id, version, null, null);
} }
public GCCToolChain(IToolChainProvider provider, String name, Path path) { public GCCToolChain(IToolChainProvider provider, String id, String version, Path path) {
this(provider, name, path, null); this(provider, id, version, path, null);
} }
public GCCToolChain(IToolChainProvider provider, String name, Path path, String prefix) { public GCCToolChain(IToolChainProvider provider, String id, String version, Path path, String prefix) {
this.provider = provider; this.provider = provider;
this.name = name; this.id = id;
this.version = version;
this.name = id + " - " + version; //$NON-NLS-1$
this.path = path; this.path = path;
this.prefix = prefix; this.prefix = prefix;
@ -84,6 +88,16 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
return provider; return provider;
} }
@Override
public String getId() {
return id;
}
@Override
public String getVersion() {
return version;
}
@Override @Override
public String getName() { public String getName() {
return name; return name;
@ -101,6 +115,20 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
return null; return null;
} }
@Override
public String getBinaryParserId() {
// Assume local builds
// TODO be smarter and use the id which should be the target
switch (Platform.getOS()) {
case Platform.OS_WIN32:
return CCorePlugin.PLUGIN_ID + ".PE"; //$NON-NLS-1$
case Platform.OS_MACOSX:
return CCorePlugin.PLUGIN_ID + ".MachO64"; //$NON-NLS-1$
default:
return CCorePlugin.PLUGIN_ID + ".ELF"; //$NON-NLS-1$
}
}
protected void addDiscoveryOptions(List<String> command) { protected void addDiscoveryOptions(List<String> command) {
command.add("-E"); //$NON-NLS-1$ command.add("-E"); //$NON-NLS-1$
command.add("-P"); //$NON-NLS-1$ command.add("-P"); //$NON-NLS-1$

View file

@ -28,6 +28,8 @@ public class GCCPathToolChainProvider implements IToolChainProvider {
private static final String ID = "org.eclipse.cdt.build.gcc.core.gccPathProvider"; //$NON-NLS-1$ private static final String ID = "org.eclipse.cdt.build.gcc.core.gccPathProvider"; //$NON-NLS-1$
private static final Pattern gccPattern = Pattern.compile("(.*-)?(gcc|g\\+\\+|clang|clang\\+\\+)"); //$NON-NLS-1$ private static final Pattern gccPattern = Pattern.compile("(.*-)?(gcc|g\\+\\+|clang|clang\\+\\+)"); //$NON-NLS-1$
private static final Pattern versionPattern = Pattern.compile(".*(gcc|LLVM) version .*"); //$NON-NLS-1$
private static final Pattern targetPattern = Pattern.compile("Target: (.*)"); //$NON-NLS-1$
@Override @Override
public String getId() { public String getId() {
@ -36,7 +38,7 @@ public class GCCPathToolChainProvider implements IToolChainProvider {
@Override @Override
public void init(IToolChainManager manager) { public void init(IToolChainManager manager) {
Set<String> versions = new HashSet<>(); Set<String> names = new HashSet<>();
String path = System.getenv("PATH"); //$NON-NLS-1$ String path = System.getenv("PATH"); //$NON-NLS-1$
for (String dirStr : path.split(File.pathSeparator)) { for (String dirStr : path.split(File.pathSeparator)) {
@ -47,27 +49,13 @@ public class GCCPathToolChainProvider implements IToolChainProvider {
if (matcher.matches()) { if (matcher.matches()) {
String prefix = matcher.group(1); String prefix = matcher.group(1);
String command = dirStr + File.separatorChar + file; String command = dirStr + File.separatorChar + file;
String version = getVersion(command);
if (version != null && !versions.contains(version)) {
versions.add(version);
manager.addToolChain(new GCCToolChain(this, version, dir.toPath(), prefix));
}
}
}
}
}
}
private static Pattern versionPattern = Pattern.compile(".*(gcc|LLVM) version .*"); //$NON-NLS-1$
private static Pattern targetPattern = Pattern.compile("Target: (.*)"); //$NON-NLS-1$
private String getVersion(String command) {
try { try {
Process proc = new ProcessBuilder(new String[] { command, "-v" }).redirectErrorStream(true) //$NON-NLS-1$ Process proc = new ProcessBuilder(new String[] { command, "-v" }).redirectErrorStream(true) //$NON-NLS-1$
.start(); .start();
String version = null; String version = null;
String target = null; String target = null;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()))) { try (BufferedReader reader = new BufferedReader(
new InputStreamReader(proc.getInputStream()))) {
for (String line = reader.readLine(); line != null; line = reader.readLine()) { for (String line = reader.readLine(); line != null; line = reader.readLine()) {
Matcher versionMatcher = versionPattern.matcher(line); Matcher versionMatcher = versionPattern.matcher(line);
if (versionMatcher.matches()) { if (versionMatcher.matches()) {
@ -81,17 +69,19 @@ public class GCCPathToolChainProvider implements IToolChainProvider {
} }
} }
} }
if (version != null) { if (target != null && version != null) {
if (target != null) { String name = target + " - " + version; //$NON-NLS-1$
return version + " " + target; //$NON-NLS-1$ if (!names.contains(name)) {
} else { names.add(name);
return version; manager.addToolChain(new GCCToolChain(this, target, version, dir.toPath(), prefix));
} }
} else {
return null;
} }
} catch (IOException e) { } catch (IOException e) {
return null; Activator.log(e);
}
}
}
}
} }
} }

View file

@ -38,7 +38,7 @@ public class Msys2ToolChainProvider implements IToolChainProvider {
String installLocation = registry.getCurrentUserValue(compKey, "InstallLocation"); //$NON-NLS-1$ String installLocation = registry.getCurrentUserValue(compKey, "InstallLocation"); //$NON-NLS-1$
Path gccPath = Paths.get(installLocation + "\\mingw64\\bin\\gcc.exe"); //$NON-NLS-1$ Path gccPath = Paths.get(installLocation + "\\mingw64\\bin\\gcc.exe"); //$NON-NLS-1$
if (Files.exists(gccPath)) { if (Files.exists(gccPath)) {
manager.addToolChain(new GCCToolChain(this, "msys2.x86_64", gccPath.getParent())); //$NON-NLS-1$ manager.addToolChain(new GCCToolChain(this, "msys2.x86_64", "", gccPath.getParent())); //$NON-NLS-1$ //$NON-NLS-2$
} }
} }
} }

View file

@ -30,13 +30,12 @@ import org.eclipse.core.runtime.IProgressMonitor;
public class CMakeBuildConfiguration extends CBuildConfiguration { public class CMakeBuildConfiguration extends CBuildConfiguration {
public CMakeBuildConfiguration(IBuildConfiguration config, String name) { public CMakeBuildConfiguration(IBuildConfiguration config, String name) throws CoreException {
super(config, name); super(config, name);
} }
public CMakeBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain) { public CMakeBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain) {
super(config, name); super(config, name, toolChain);
setToolChain(toolChain);
} }
@Override @Override
@ -54,7 +53,7 @@ public class CMakeBuildConfiguration extends CBuildConfiguration {
// TODO assuming cmake is in the path here, probably need a // TODO assuming cmake is in the path here, probably need a
// preference in case it isn't. // preference in case it isn't.
List<String> command = Arrays.asList("cmake", //$NON-NLS-1$ List<String> command = Arrays.asList("cmake", //$NON-NLS-1$
"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON", new File(project.getLocationURI()).getAbsolutePath()); "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON", new File(project.getLocationURI()).getAbsolutePath()); //$NON-NLS-1$
ProcessBuilder processBuilder = new ProcessBuilder(command).directory(buildDir.toFile()); ProcessBuilder processBuilder = new ProcessBuilder(command).directory(buildDir.toFile());
Process process = processBuilder.start(); Process process = processBuilder.start();
outStream.write(String.join(" ", command) + '\n'); //$NON-NLS-1$ outStream.write(String.join(" ", command) + '\n'); //$NON-NLS-1$
@ -63,8 +62,8 @@ public class CMakeBuildConfiguration extends CBuildConfiguration {
// TODO need to figure out which builder to call. Hardcoding to make // TODO need to figure out which builder to call. Hardcoding to make
// for now. // for now.
List<String> command = Arrays.asList("make"); List<String> command = Arrays.asList("make"); //$NON-NLS-1$
ProcessBuilder processBuilder = new ProcessBuilder(command).directory(buildDir.toFile()); //$NON-NLS-1$ ProcessBuilder processBuilder = new ProcessBuilder(command).directory(buildDir.toFile());
Process process = processBuilder.start(); Process process = processBuilder.start();
outStream.write(String.join(" ", command) + '\n'); //$NON-NLS-1$ outStream.write(String.join(" ", command) + '\n'); //$NON-NLS-1$
@ -74,7 +73,7 @@ public class CMakeBuildConfiguration extends CBuildConfiguration {
project.refreshLocal(IResource.DEPTH_INFINITE, monitor); project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
return new IProject[] { project }; return new IProject[] { project };
} catch (IOException e) { } catch (IOException e) {
throw new CoreException(Activator.errorStatus("Building " + project.getName(), e)); throw new CoreException(Activator.errorStatus(String.format("Building %s", project.getName()), e));
} }
} }

View file

@ -26,6 +26,7 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.eclipse.cdt.core.CCProjectNature; import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
@ -34,6 +35,7 @@ import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive; import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
import org.eclipse.cdt.core.build.ICBuildConfiguration;
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsChangeEvent; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsChangeEvent;
import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsChangeListener; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsChangeListener;
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager;
@ -68,6 +70,7 @@ import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileInfo; import org.eclipse.core.filesystem.IFileInfo;
import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.filesystem.URIUtil; import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
@ -603,6 +606,34 @@ public class CModelManager implements IResourceChangeListener, IContentTypeChang
public BinaryParserConfig[] getBinaryParser(IProject project) { public BinaryParserConfig[] getBinaryParser(IProject project) {
BinaryParserConfig[] parsers = binaryParsersMap.get(project); BinaryParserConfig[] parsers = binaryParsersMap.get(project);
if (parsers == null) {
try {
// Check for new style build configs first
Set<String> parserIds = new HashSet<>();
for (IBuildConfiguration config : project.getBuildConfigs()) {
if (!IBuildConfiguration.DEFAULT_CONFIG_NAME.equals(config.getName())) {
ICBuildConfiguration cconfig = config.getAdapter(ICBuildConfiguration.class);
if (cconfig != null) {
parserIds.add(cconfig.getBinaryParserId());
}
}
}
if (!parserIds.isEmpty()) {
String[] ids = parserIds.toArray(new String[parserIds.size()]);
parsers = new BinaryParserConfig[parserIds.size()];
for (int i = 0; i < parsers.length; ++i) {
String id = ids[i];
IBinaryParser parser = CCorePlugin.getDefault().getBinaryParser(id);
if (parser != null) {
parsers[i] = new BinaryParserConfig(parser, id);
}
}
}
} catch (CoreException e) {
CCorePlugin.log(e);
parsers = null;
}
if (parsers == null) { if (parsers == null) {
ICProjectDescription desc = CCorePlugin.getDefault().getProjectDescription(project, false); ICProjectDescription desc = CCorePlugin.getDefault().getProjectDescription(project, false);
if (desc != null) { if (desc != null) {
@ -623,6 +654,7 @@ public class CModelManager implements IResourceChangeListener, IContentTypeChang
} }
} }
} }
}
if (parsers == null) { if (parsers == null) {
try { try {
BinaryParserConfig config = new BinaryParserConfig(CCorePlugin.getDefault().getDefaultBinaryParser(), CCorePlugin.DEFAULT_BINARY_PARSER_UNIQ_ID); BinaryParserConfig config = new BinaryParserConfig(CCorePlugin.getDefault().getDefaultBinaryParser(), CCorePlugin.DEFAULT_BINARY_PARSER_UNIQ_ID);

View file

@ -781,6 +781,33 @@ public class CCorePlugin extends Plugin {
return parser; return parser;
} }
/**
* Returns the binary parser with the given id.
*
* @param id id of binary parser
* @return binary parser
* @throws CoreException
* @since 6.0
*/
public IBinaryParser getBinaryParser(String id) throws CoreException {
IExtensionPoint extensionPoint = Platform.getExtensionRegistry()
.getExtensionPoint(CCorePlugin.PLUGIN_ID, BINARY_PARSER_SIMPLE_ID);
IExtension extension = extensionPoint.getExtension(id);
if (extension != null) {
IConfigurationElement element[] = extension.getConfigurationElements();
for (IConfigurationElement element2 : element) {
if (element2.getName().equalsIgnoreCase("cextension")) { //$NON-NLS-1$
return (IBinaryParser) element2.createExecutableExtension("run"); //$NON-NLS-1$
}
}
} else {
IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1,
CCorePlugin.getResourceString("CCorePlugin.exception.noBinaryFormat"), null); //$NON-NLS-1$
throw new CoreException(s);
}
return null;
}
public CoreModel getCoreModel() { public CoreModel getCoreModel() {
return fCoreModel; return fCoreModel;
} }

View file

@ -19,6 +19,7 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -47,9 +48,11 @@ import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.osgi.util.NLS; import org.eclipse.osgi.util.NLS;
import org.osgi.service.prefs.BackingStoreException; import org.osgi.service.prefs.BackingStoreException;
@ -66,15 +69,53 @@ public abstract class CBuildConfiguration extends PlatformObject
implements ICBuildConfiguration, IMarkerGenerator, IConsoleParser { implements ICBuildConfiguration, IMarkerGenerator, IConsoleParser {
private static final String TOOLCHAIN_TYPE = "cdt.toolChain.type"; //$NON-NLS-1$ private static final String TOOLCHAIN_TYPE = "cdt.toolChain.type"; //$NON-NLS-1$
private static final String TOOLCHAIN_NAME = "cdt.toolChain.name"; //$NON-NLS-1$ private static final String TOOLCHAIN_ID = "cdt.toolChain.id"; //$NON-NLS-1$
private static final String TOOLCHAIN_VERSION = "cdt.toolChain.version"; //$NON-NLS-1$
private final String name; private final String name;
private final IBuildConfiguration config; private final IBuildConfiguration config;
private IToolChain toolChain; private final IToolChain toolChain;
protected CBuildConfiguration(IBuildConfiguration config, String name) { protected CBuildConfiguration(IBuildConfiguration config, String name) throws CoreException {
this.config = config; this.config = config;
this.name = name; this.name = name;
Preferences settings = getSettings();
String typeId = settings.get(TOOLCHAIN_TYPE, ""); //$NON-NLS-1$
String id = settings.get(TOOLCHAIN_ID, ""); //$NON-NLS-1$
String version = settings.get(TOOLCHAIN_VERSION, ""); //$NON-NLS-1$
IToolChainManager toolChainManager = CCorePlugin.getService(IToolChainManager.class);
IToolChain tc = toolChainManager.getToolChain(typeId, id, version);
if (tc == null) {
// check for other versions
Collection<IToolChain> tcs = toolChainManager.getToolChains(typeId, id);
if (!tcs.isEmpty()) {
// TODO grab the newest version
tc = tcs.iterator().next();
} else {
throw new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID,
String.format("Toolchain missing for config: %s", config.getName())));
}
}
toolChain = tc;
}
public CBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain) {
this.config = config;
this.name = name;
this.toolChain = toolChain;
Preferences settings = getSettings();
settings.put(TOOLCHAIN_TYPE, toolChain.getProvider().getId());
settings.put(TOOLCHAIN_ID, toolChain.getId());
settings.put(TOOLCHAIN_VERSION, toolChain.getVersion());
try {
settings.flush();
} catch (BackingStoreException e) {
CCorePlugin.log(e);
}
} }
@Override @Override
@ -90,6 +131,11 @@ public abstract class CBuildConfiguration extends PlatformObject
return config.getProject(); return config.getProject();
} }
@Override
public String getBinaryParserId() throws CoreException {
return toolChain != null ? toolChain.getBinaryParserId() : CCorePlugin.DEFAULT_BINARY_PARSER_UNIQ_ID;
}
public IContainer getBuildContainer() throws CoreException { public IContainer getBuildContainer() throws CoreException {
// TODO should really be passing a monitor in here or create this in // TODO should really be passing a monitor in here or create this in
// a better spot. should also throw the core exception // a better spot. should also throw the core exception
@ -145,34 +191,9 @@ public abstract class CBuildConfiguration extends PlatformObject
@Override @Override
public IToolChain getToolChain() throws CoreException { public IToolChain getToolChain() throws CoreException {
if (toolChain == null) {
Preferences settings = getSettings();
String typeId = settings.get(TOOLCHAIN_TYPE, ""); //$NON-NLS-1$
String id = settings.get(TOOLCHAIN_NAME, ""); //$NON-NLS-1$
IToolChainManager toolChainManager = CCorePlugin.getService(IToolChainManager.class);
toolChain = toolChainManager.getToolChain(typeId, id);
if (toolChain == null) {
CCorePlugin.log(String.format("Toolchain missing for config: %s", config.getName()));
}
}
return toolChain; return toolChain;
} }
protected void setToolChain(IToolChain toolChain) {
this.toolChain = toolChain;
Preferences settings = getSettings();
settings.put(TOOLCHAIN_TYPE, toolChain.getProvider().getId());
settings.put(TOOLCHAIN_NAME, toolChain.getName());
try {
settings.flush();
} catch (BackingStoreException e) {
CCorePlugin.log(e);
}
}
@Override @Override
public IEnvironmentVariable getVariable(String name) { public IEnvironmentVariable getVariable(String name) {
// By default, none // By default, none

View file

@ -43,6 +43,8 @@ public interface ICBuildConfiguration extends IAdaptable, IScannerInfoProvider {
*/ */
IToolChain getToolChain() throws CoreException; IToolChain getToolChain() throws CoreException;
String getBinaryParserId() throws CoreException;
IEnvironmentVariable getVariable(String name) throws CoreException; IEnvironmentVariable getVariable(String name) throws CoreException;
IEnvironmentVariable[] getVariables() throws CoreException; IEnvironmentVariable[] getVariables() throws CoreException;

View file

@ -30,6 +30,10 @@ public interface IToolChain extends IAdaptable {
IToolChainProvider getProvider(); IToolChainProvider getProvider();
String getId();
String getVersion();
String getName(); String getName();
/** /**
@ -58,4 +62,6 @@ public interface IToolChain extends IAdaptable {
IResource[] getResourcesFromCommand(String[] command, URI buildDirectoryURI); IResource[] getResourcesFromCommand(String[] command, URI buildDirectoryURI);
String getBinaryParserId();
} }

View file

@ -21,10 +21,12 @@ public interface IToolChainManager {
IToolChainProvider getProvider(String providerId) throws CoreException; IToolChainProvider getProvider(String providerId) throws CoreException;
IToolChain getToolChain(String providerId, String name) throws CoreException; IToolChain getToolChain(String providerId, String id, String version) throws CoreException;
Collection<IToolChain> getToolChains(String providerId) throws CoreException; Collection<IToolChain> getToolChains(String providerId) throws CoreException;
Collection<IToolChain> getToolChains(String providerId, String id) throws CoreException;
/** /**
* Returns the list of toolchains that have the given properties. * Returns the list of toolchains that have the given properties.
* *

View file

@ -34,15 +34,17 @@ public interface IToolChainProvider {
} }
/** /**
* Called by the manager to dynamically create the named toolchain. * Called by the manager to dynamically create the toolchain.
* *
* @param name * @param name
* the name of the toolchain * the name of the toolchain
* @param version
* the version of the toolchain
* @param properties * @param properties
* the persisted settings for the toolchain * the persisted settings for the toolchain
* @return the toolchain initialized with the settings. * @return the toolchain initialized with the settings.
*/ */
default IToolChain getToolChain(String name) throws CoreException { default IToolChain getToolChain(String id, String version) throws CoreException {
// By default, assumes all toolchains were added at init time. // By default, assumes all toolchains were added at init time.
return null; return null;
} }

View file

@ -23,6 +23,7 @@ import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.core.build.ICBuildConfiguration; import org.eclipse.cdt.core.build.ICBuildConfiguration;
import org.eclipse.cdt.core.build.ICBuildConfigurationManager; import org.eclipse.cdt.core.build.ICBuildConfigurationManager;
import org.eclipse.cdt.core.build.ICBuildConfigurationProvider; import org.eclipse.cdt.core.build.ICBuildConfigurationProvider;
import org.eclipse.cdt.internal.core.model.CModelManager;
import org.eclipse.core.resources.IBuildConfiguration; import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IProjectDescription;
@ -153,6 +154,9 @@ public class CBuildConfigurationManager implements ICBuildConfigurationManager,
if (provider != null && provider.supports(buildConfig.getProject())) { if (provider != null && provider.supports(buildConfig.getProject())) {
config = provider.getProvider().getCBuildConfiguration(buildConfig, configName); config = provider.getProvider().getCBuildConfiguration(buildConfig, configName);
configs.put(buildConfig, config); configs.put(buildConfig, config);
// Also make sure we reset the binary parser cache for the new config
CModelManager.getDefault().resetBinaryParser(buildConfig.getProject());
} }
} }
} }

View file

@ -9,7 +9,6 @@ package org.eclipse.cdt.internal.core.build;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -28,7 +27,7 @@ public class ToolChainManager implements IToolChainManager {
private Map<String, IConfigurationElement> providerElements; private Map<String, IConfigurationElement> providerElements;
private Map<String, IToolChainProvider> providers; private Map<String, IToolChainProvider> providers;
private Map<String, Map<String, IToolChain>> toolChains; private Map<List<String>, IToolChain> toolChains;
private void init() { private void init() {
if (providerElements == null) { if (providerElements == null) {
@ -60,24 +59,22 @@ public class ToolChainManager implements IToolChainManager {
} }
} }
private List<String> getId(IToolChain toolChain) {
List<String> id = new ArrayList<>(3);
id.add(toolChain.getProvider().getId());
id.add(toolChain.getId());
id.add(toolChain.getVersion());
return id;
}
@Override @Override
public void addToolChain(IToolChain toolChain) { public void addToolChain(IToolChain toolChain) {
String providerId = toolChain.getProvider().getId(); toolChains.put(getId(toolChain), toolChain);
Map<String, IToolChain> provider = toolChains.get(providerId);
if (provider == null) {
provider = new HashMap<>();
toolChains.put(providerId, provider);
}
provider.put(toolChain.getName(), toolChain);
} }
@Override @Override
public void removeToolChain(IToolChain toolChain) { public void removeToolChain(IToolChain toolChain) {
String providerId = toolChain.getProvider().getId(); toolChains.remove(getId(toolChain));
Map<String, IToolChain> provider = toolChains.get(providerId);
if (provider != null) {
provider.remove(toolChain.getName());
}
} }
@Override @Override
@ -95,26 +92,24 @@ public class ToolChainManager implements IToolChainManager {
} }
@Override @Override
public IToolChain getToolChain(String providerId, String name) throws CoreException { public IToolChain getToolChain(String providerId, String id, String version) throws CoreException {
init(); init();
Map<String, IToolChain> provider = toolChains.get(providerId); List<String> tid = new ArrayList<>(3);
if (provider != null) { tid.add(providerId);
IToolChain toolChain = provider.get(name); tid.add(id);
tid.add(version);
IToolChain toolChain = toolChains.get(tid);
if (toolChain != null) { if (toolChain != null) {
return toolChain; return toolChain;
} }
}
// Try the provider // Try the provider
IToolChainProvider realProvider = providers.get(providerId); IToolChainProvider realProvider = providers.get(providerId);
if (realProvider != null) { if (realProvider != null) {
IToolChain toolChain = realProvider.getToolChain(name); toolChain = realProvider.getToolChain(id, version);
if (toolChain != null) { if (toolChain != null) {
if (provider == null) { toolChains.put(getId(toolChain), toolChain);
provider = new HashMap<>();
toolChains.put(providerId, provider);
}
provider.put(name, toolChain);
return toolChain; return toolChain;
} }
} }
@ -126,14 +121,15 @@ public class ToolChainManager implements IToolChainManager {
public Collection<IToolChain> getToolChainsMatching(Map<String, String> properties) { public Collection<IToolChain> getToolChainsMatching(Map<String, String> properties) {
init(); init();
List<IToolChain> tcs = new ArrayList<>(); List<IToolChain> tcs = new ArrayList<>();
for (Map<String, IToolChain> types : toolChains.values()) { for (IToolChain toolChain : toolChains.values()) {
tcLoop: for (IToolChain toolChain : types.values()) { boolean matches = true;
for (Map.Entry<String, String> property : properties.entrySet()) { for (Map.Entry<String, String> property : properties.entrySet()) {
if (!property.getValue().equals(toolChain.getProperty(property.getKey()))) { if (!property.getValue().equals(toolChain.getProperty(property.getKey()))) {
// doesn't match, move on to next toolchain matches = false;
continue tcLoop; break;
} }
} }
if (matches) {
tcs.add(toolChain); tcs.add(toolChain);
} }
} }
@ -143,12 +139,25 @@ public class ToolChainManager implements IToolChainManager {
@Override @Override
public Collection<IToolChain> getToolChains(String providerId) { public Collection<IToolChain> getToolChains(String providerId) {
init(); init();
Map<String, IToolChain> provider = toolChains.get(providerId); List<IToolChain> tcs = new ArrayList<>();
if (provider != null) { for (IToolChain toolChain : toolChains.values()) {
return Collections.unmodifiableCollection(provider.values()); if (toolChain.getProvider().getId().equals(providerId)) {
} else { tcs.add(toolChain);
return Collections.emptyList();
} }
} }
return tcs;
}
@Override
public Collection<IToolChain> getToolChains(String providerId, String id) throws CoreException {
init();
List<IToolChain> tcs = new ArrayList<>();
for (IToolChain toolChain : toolChains.values()) {
if (toolChain.getProvider().getId().equals(providerId) && toolChain.getId().equals(id)) {
tcs.add(toolChain);
}
}
return tcs;
}
} }

View file

@ -56,7 +56,7 @@ public class QtBuildConfiguration extends CBuildConfiguration implements ICBuild
private final String launchMode; private final String launchMode;
private Map<String, String> properties; private Map<String, String> properties;
public QtBuildConfiguration(IBuildConfiguration config, String name) { public QtBuildConfiguration(IBuildConfiguration config, String name) throws CoreException {
super(config, name); super(config, name);
Preferences settings = getSettings(); Preferences settings = getSettings();
@ -74,8 +74,7 @@ public class QtBuildConfiguration extends CBuildConfiguration implements ICBuild
QtBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain, IQtInstall qtInstall, QtBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain, IQtInstall qtInstall,
String launchMode) String launchMode)
throws CoreException { throws CoreException {
super(config, name); super(config, name, toolChain);
setToolChain(toolChain);
this.qtInstall = qtInstall; this.qtInstall = qtInstall;
this.launchMode = launchMode; this.launchMode = launchMode;
@ -206,7 +205,6 @@ public class QtBuildConfiguration extends CBuildConfiguration implements ICBuild
@Override @Override
public IScannerInfo getScannerInformation(IResource resource) { public IScannerInfo getScannerInformation(IResource resource) {
IProject project = resource.getProject();
IQtInstall qtInstall = getQtInstall(); IQtInstall qtInstall = getQtInstall();
String cxx = getProperty("QMAKE_CXX"); //$NON-NLS-1$ String cxx = getProperty("QMAKE_CXX"); //$NON-NLS-1$

View file

@ -50,10 +50,11 @@ public class QtBuildConfigurationProvider implements ICBuildConfigurationProvide
return new QtBuildConfiguration(config, name); return new QtBuildConfiguration(config, name);
} catch (CoreException e) { } catch (CoreException e) {
// Failed to create the build config. Return null so it gets recreated.
Activator.log(e); Activator.log(e);
}
return null; return null;
} }
}
@Override @Override
public ICBuildConfiguration getDefaultCBuildConfiguration(IProject project) { public ICBuildConfiguration getDefaultCBuildConfiguration(IProject project) {

View file

@ -53,11 +53,11 @@ public abstract class QtLaunchConfigurationDelegate extends LaunchConfigurationT
protected void populateToolChainProperties(ILaunchTarget target, Map<String, String> properties) { protected void populateToolChainProperties(ILaunchTarget target, Map<String, String> properties) {
String os = target.getAttribute(ILaunchTarget.ATTR_OS, null); String os = target.getAttribute(ILaunchTarget.ATTR_OS, null);
if (os != null) { if (os != null) {
properties.put(IToolChain.ATTR_OS, os); properties.put(IToolChain.ATTR_OS, os.toLowerCase());
} }
String arch = target.getAttribute(ILaunchTarget.ATTR_ARCH, null); String arch = target.getAttribute(ILaunchTarget.ATTR_ARCH, null);
if (arch != null) { if (arch != null) {
properties.put(IToolChain.ATTR_ARCH, arch); properties.put(IToolChain.ATTR_ARCH, arch.toLowerCase());
} }
} }

View file

@ -44,7 +44,7 @@ public class QtMinGWToolChainProvider implements IToolChainProvider {
try { try {
Files.walk(Paths.get(installLocation).resolve("Tools"), 1) //$NON-NLS-1$ Files.walk(Paths.get(installLocation).resolve("Tools"), 1) //$NON-NLS-1$
.filter((path) -> Files.exists(path.resolve(gcc))) .filter((path) -> Files.exists(path.resolve(gcc)))
.map((path) -> new GCCToolChain(this, "qt.mingw", path.resolve("bin"))) //$NON-NLS-1$ //$NON-NLS-2$ .map((path) -> new GCCToolChain(this, "qt.mingw", "", path.resolve("bin"))) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
.forEach(toolChain -> manager.addToolChain(toolChain)); .forEach(toolChain -> manager.addToolChain(toolChain));
} catch (IOException e) { } catch (IOException e) {
Activator.log(e); Activator.log(e);

View file

@ -150,4 +150,12 @@
labelProvider="org.eclipse.cdt.internal.qt.ui.launch.QtLaunchDescriptorLabelProvider"> labelProvider="org.eclipse.cdt.internal.qt.ui.launch.QtLaunchDescriptorLabelProvider">
</descriptorUI> </descriptorUI>
</extension> </extension>
<extension
point="org.eclipse.debug.ui.launchConfigurationTypeImages">
<launchConfigurationTypeImage
configTypeID="org.eclipse.cdt.qt.core.launchConfigurationType"
icon="icons/qt16.png"
id="org.eclipse.cdt.qt.core.launchConfigurationType.image">
</launchConfigurationTypeImage>
</extension>
</plugin> </plugin>

View file

@ -46,8 +46,6 @@ import org.eclipse.cdt.core.ErrorParserManager;
import org.eclipse.cdt.core.IConsoleParser; import org.eclipse.cdt.core.IConsoleParser;
import org.eclipse.cdt.core.build.CBuildConfiguration; import org.eclipse.cdt.core.build.CBuildConfiguration;
import org.eclipse.cdt.core.build.IToolChain; import org.eclipse.cdt.core.build.IToolChain;
import org.eclipse.cdt.core.build.IToolChainManager;
import org.eclipse.cdt.core.build.IToolChainProvider;
import org.eclipse.cdt.core.model.ICModelMarker; import org.eclipse.cdt.core.model.ICModelMarker;
import org.eclipse.cdt.core.model.ISourceRoot; import org.eclipse.cdt.core.model.ISourceRoot;
import org.eclipse.cdt.core.parser.ExtendedScannerInfo; import org.eclipse.cdt.core.parser.ExtendedScannerInfo;
@ -118,19 +116,12 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te
this.launchMode = name.substring(i + 1); this.launchMode = name.substring(i + 1);
} }
ArduinoBuildConfiguration(IBuildConfiguration config, String name, ArduinoBoard board, String launchMode) ArduinoBuildConfiguration(IBuildConfiguration config, String name, ArduinoBoard board, String launchMode, IToolChain toolChain)
throws CoreException { throws CoreException {
super(config, name); super(config, name, toolChain);
this.board = board; this.board = board;
this.launchMode = launchMode; this.launchMode = launchMode;
// Create the toolChain
IToolChainManager toolChainManager = Activator.getService(IToolChainManager.class);
IToolChainProvider provider = toolChainManager.getProvider(ArduinoToolChainProvider.ID);
IToolChain toolChain = new ArduinoToolChain(provider, this);
toolChainManager.addToolChain(toolChain);
setToolChain(toolChain);
// Store the board identifer // Store the board identifer
ArduinoPlatform platform = board.getPlatform(); ArduinoPlatform platform = board.getPlatform();
ArduinoPackage pkg = platform.getPackage(); ArduinoPackage pkg = platform.getPackage();
@ -148,8 +139,8 @@ public class ArduinoBuildConfiguration extends CBuildConfiguration implements Te
} }
ArduinoBuildConfiguration(IBuildConfiguration config, String name, ArduinoRemoteConnection target, ArduinoBuildConfiguration(IBuildConfiguration config, String name, ArduinoRemoteConnection target,
String launchMode) throws CoreException { String launchMode, IToolChain toolChain) throws CoreException {
this(config, name, target.getBoard(), launchMode); this(config, name, target.getBoard(), launchMode, toolChain);
// Store the menu settings // Store the menu settings
HierarchicalProperties menus = board.getMenus(); HierarchicalProperties menus = board.getMenus();

View file

@ -16,6 +16,9 @@ import org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection;
import org.eclipse.cdt.core.build.ICBuildConfiguration; import org.eclipse.cdt.core.build.ICBuildConfiguration;
import org.eclipse.cdt.core.build.ICBuildConfigurationManager; import org.eclipse.cdt.core.build.ICBuildConfigurationManager;
import org.eclipse.cdt.core.build.ICBuildConfigurationProvider; 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.build.IToolChainProvider;
import org.eclipse.core.resources.IBuildConfiguration; import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -65,8 +68,15 @@ public class ArduinoBuildConfigurationProvider implements ICBuildConfigurationPr
String configName = ArduinoBuildConfiguration.generateName(board, launchMode); String configName = ArduinoBuildConfiguration.generateName(board, launchMode);
IBuildConfiguration config = configManager.createBuildConfiguration(this, project, configName, IBuildConfiguration config = configManager.createBuildConfiguration(this, project, configName,
null); null);
// Create the toolChain
IToolChainManager toolChainManager = Activator.getService(IToolChainManager.class);
IToolChainProvider provider = toolChainManager.getProvider(ArduinoToolChainProvider.ID);
IToolChain toolChain = new ArduinoToolChain(provider, config);
toolChainManager.addToolChain(toolChain);
ArduinoBuildConfiguration arduinoConfig = new ArduinoBuildConfiguration(config, configName, board, ArduinoBuildConfiguration arduinoConfig = new ArduinoBuildConfiguration(config, configName, board,
launchMode); launchMode, toolChain);
arduinoConfig.setActive(null); arduinoConfig.setActive(null);
configManager.addBuildConfiguration(config, arduinoConfig); configManager.addBuildConfiguration(config, arduinoConfig);
return arduinoConfig; return arduinoConfig;
@ -98,7 +108,12 @@ public class ArduinoBuildConfigurationProvider implements ICBuildConfigurationPr
String configName = ArduinoBuildConfiguration.generateName(board, launchMode); String configName = ArduinoBuildConfiguration.generateName(board, launchMode);
IBuildConfiguration config = configManager.createBuildConfiguration(this, project, configName, IBuildConfiguration config = configManager.createBuildConfiguration(this, project, configName,
monitor); monitor);
ArduinoBuildConfiguration arduinoConfig = new ArduinoBuildConfiguration(config, configName, target, launchMode); IToolChainManager toolChainManager = Activator.getService(IToolChainManager.class);
IToolChainProvider provider = toolChainManager.getProvider(ArduinoToolChainProvider.ID);
IToolChain toolChain = new ArduinoToolChain(provider, config);
toolChainManager.addToolChain(toolChain);
ArduinoBuildConfiguration arduinoConfig = new ArduinoBuildConfiguration(config, configName, target, launchMode, toolChain);
configManager.addBuildConfiguration(config, arduinoConfig);
return arduinoConfig; return arduinoConfig;
} }

View file

@ -1,47 +1,19 @@
package org.eclipse.cdt.arduino.core.internal.build; package org.eclipse.cdt.arduino.core.internal.build;
import org.eclipse.cdt.arduino.core.internal.Activator;
import org.eclipse.cdt.build.gcc.core.GCCToolChain; import org.eclipse.cdt.build.gcc.core.GCCToolChain;
import org.eclipse.cdt.core.build.ICBuildConfiguration;
import org.eclipse.cdt.core.build.ICBuildConfigurationManager;
import org.eclipse.cdt.core.build.IToolChain; import org.eclipse.cdt.core.build.IToolChain;
import org.eclipse.cdt.core.build.IToolChainProvider; import org.eclipse.cdt.core.build.IToolChainProvider;
import org.eclipse.core.resources.IBuildConfiguration; import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
public class ArduinoToolChain extends GCCToolChain { public class ArduinoToolChain extends GCCToolChain {
private final ArduinoBuildConfiguration buildConfig; ArduinoToolChain(IToolChainProvider provider, IBuildConfiguration config) throws CoreException {
super(provider, config.getProject().getName() + '#' + config.getName(), ""); //$NON-NLS-1$
public ArduinoToolChain(IToolChainProvider provider, ArduinoBuildConfiguration config) {
super(provider, config.getProject().getName() + '#' + config.getName());
this.buildConfig = config;
} }
ArduinoToolChain(IToolChainProvider provider, String name) throws CoreException { public ArduinoToolChain(IToolChainProvider provider, String id, String version) {
super(provider, name); super(provider, id, version);
String[] segments = name.split("#"); //$NON-NLS-1$
if (segments.length == 2) {
String projectName = segments[0];
String configName = segments[1];
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
if (project != null) {
ICBuildConfigurationManager configManager = Activator.getService(ICBuildConfigurationManager.class);
IBuildConfiguration config = configManager.getBuildConfiguration(
configManager.getProvider(ArduinoBuildConfigurationProvider.ID), project, configName);
ICBuildConfiguration cconfig = config.getAdapter(ICBuildConfiguration.class);
buildConfig = cconfig.getAdapter(ArduinoBuildConfiguration.class);
} else {
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), "No project"));
}
} else {
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), "Bad Name"));
}
} }
@Override @Override
@ -54,9 +26,4 @@ public class ArduinoToolChain extends GCCToolChain {
} }
} }
// TODO do I really need this?
public ArduinoBuildConfiguration getBuildConfig() {
return buildConfig;
}
} }

View file

@ -14,8 +14,8 @@ public class ArduinoToolChainProvider implements IToolChainProvider {
} }
@Override @Override
public IToolChain getToolChain(String name) throws CoreException { public IToolChain getToolChain(String id, String version) throws CoreException {
return new ArduinoToolChain(this, name); return new ArduinoToolChain(this, id, version);
} }
} }