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

XlcBuiltinSpecsDetector to take compiler from toolchain,

some cleanup
This commit is contained in:
Andrew Gvozdev 2012-03-28 16:22:05 -04:00
parent 3bdc50cd6e
commit be44991629
5 changed files with 47 additions and 40 deletions

View file

@ -16,14 +16,13 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.IErrorParser2;
import org.eclipse.cdt.core.IMarkerGenerator;
import org.eclipse.cdt.core.errorparsers.RegexErrorParser;
import org.eclipse.cdt.core.errorparsers.RegexErrorPattern;
import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.internal.core.ConsoleOutputSniffer;
import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
@ -36,9 +35,6 @@ import org.eclipse.core.runtime.jobs.Job;
* Abstract class for providers parsing compiler option from build command when it
* is present in build output.
*
* Note: IErrorParser interface is used here to work around {@link ConsoleOutputSniffer} having
* no access from CDT core to build packages. TODO - elaborate?
*
* @since 7.2
*/
public abstract class AbstractBuildCommandParser extends AbstractLanguageSettingsOutputScanner {
@ -169,7 +165,7 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting
if (settingsFolder.isAccessible())
rule = currentProject.getFile(".settings/language.settings.xml");
} catch (CoreException e) {
CCorePlugin.log(e);
MakeCorePlugin.log(e);
}
}
}

View file

@ -50,8 +50,10 @@ public class GCCBuiltinSpecsDetector extends ToolchainBuiltinSpecsDetector imple
return optionParsers;
}
private List<String> makeList(final String line) {
return new ArrayList<String>() {{ add(line); }};
private List<String> makeList(String line) {
List<String> list = new ArrayList<String>();
list.add(line);
return list;
}
@Override

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2011 Andrew Gvozdev and others.
* Copyright (c) 2009, 2012 Andrew Gvozdev and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -18,7 +18,7 @@ import org.eclipse.core.resources.IResource;
/**
* Class to detect built-in compiler settings.
* The paths are converted to cygwin "filesystem" representation. Then
* The paths are converted to cygwin "filesystem" representation.
*
*/
public class GCCBuiltinSpecsDetectorCygwin extends GCCBuiltinSpecsDetector {

View file

@ -30,11 +30,19 @@ import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
*/
public abstract class ToolchainBuiltinSpecsDetector extends AbstractBuiltinSpecsDetector {
private Map<String, ITool> toolMap = new HashMap<String, ITool>();
/**
* TODO
* Concrete compiler specs detectors need to supply Toolchain ID.
*
* Tool-chain id must be supplied for global providers where we don't
* have configuration description to figure that out programmatically.
*/
protected abstract String getToolchainId();
/**
* Finds a tool handling given language in the tool-chain.
* This returns the first tool found.
*/
private ITool getTool(String languageId) {
ITool langTool = toolMap.get(languageId);
if (langTool != null) {
@ -42,8 +50,17 @@ public abstract class ToolchainBuiltinSpecsDetector extends AbstractBuiltinSpecs
}
String toolchainId = getToolchainId();
IToolChain toolchain = ManagedBuildManager.getExtensionToolChain(toolchainId);
if (toolchain != null) {
for (IToolChain toolchain = ManagedBuildManager.getExtensionToolChain(toolchainId);toolchain != null;toolchain = toolchain.getSuperClass()) {
ITool tool = getTool(languageId, toolchain);
if (tool != null) {
return tool;
}
}
ManagedBuilderCorePlugin.error("Unable to find tool in toolchain="+toolchainId+" for language="+languageId);
return null;
}
private ITool getTool(String languageId, IToolChain toolchain) {
ITool[] tools = toolchain.getTools();
for (ITool tool : tools) {
IInputType[] inputTypes = tool.getInputTypes();
@ -55,20 +72,18 @@ public abstract class ToolchainBuiltinSpecsDetector extends AbstractBuiltinSpecs
}
}
}
}
ManagedBuilderCorePlugin.error("Unable to find tool in toolchain="+toolchainId+" for language="+languageId);
return null;
}
@Override
protected String getCompilerCommand(String languageId) {
ITool tool = getTool(languageId);
String compiler = tool.getToolCommand();
if (compiler.length() == 0) {
String compilerCommand = tool.getToolCommand();
if (compilerCommand.isEmpty()) {
String msg = "Unable to find compiler command in toolchain="+getToolchainId();
ManagedBuilderCorePlugin.error(msg);
}
return compiler;
return compilerCommand;
}
@Override
@ -79,7 +94,7 @@ public abstract class ToolchainBuiltinSpecsDetector extends AbstractBuiltinSpecs
if (srcFileExtensions != null && srcFileExtensions.length > 0) {
ext = srcFileExtensions[0];
}
if (ext == null || ext.length() == 0) {
if (ext == null || ext.isEmpty()) {
ManagedBuilderCorePlugin.error("Unable to find file extension for language "+languageId);
}
return ext;

View file

@ -24,14 +24,11 @@ import org.eclipse.cdt.managedbuilder.language.settings.providers.ToolchainBuilt
/**
* Language settings provider to detect built-in compiler settings for IBM XLC compiler.
* Note that currently this class is hardwired to GCC toolchain
* {@code cdt.managedbuild.toolchain.gnu.base}.
* Note that currently this class is hardwired to GCC toolchain {@code cdt.managedbuild.toolchain.gnu.base}.
*/
public class XlcBuiltinSpecsDetector extends ToolchainBuiltinSpecsDetector implements ILanguageSettingsEditableProvider {
// must match the toolchain definition in org.eclipse.cdt.managedbuilder.core.buildDefinitions extension point
// FIXME - ill defined XLC toolchain
// private static final String XLC_TOOLCHAIN_ID = "cdt.managedbuild.toolchain.xlc.exe.debug"; //$NON-NLS-1$
private static final String GCC_TOOLCHAIN_ID = "cdt.managedbuild.toolchain.gnu.base"; //$NON-NLS-1$
private static final String XLC_TOOLCHAIN_ID = "cdt.managedbuild.toolchain.xlc.exe.debug"; //$NON-NLS-1$
private static final Pattern OPTIONS_PATTERN = Pattern.compile("-[^\\s\"']*(\\s*((\".*?\")|('.*?')|([^-\\s][^\\s]+)))?"); //$NON-NLS-1$
private static final int OPTION_GROUP = 0;
@ -58,8 +55,7 @@ public class XlcBuiltinSpecsDetector extends ToolchainBuiltinSpecsDetector imple
@Override
protected String getToolchainId() {
// return XLC_TOOLCHAIN_ID;
return GCC_TOOLCHAIN_ID;
return XLC_TOOLCHAIN_ID;
}
@Override
@ -80,7 +76,6 @@ public class XlcBuiltinSpecsDetector extends ToolchainBuiltinSpecsDetector imple
return options;
}
@Override
public XlcBuiltinSpecsDetector cloneShallow() throws CloneNotSupportedException {
return (XlcBuiltinSpecsDetector) super.cloneShallow();
@ -91,5 +86,4 @@ public class XlcBuiltinSpecsDetector extends ToolchainBuiltinSpecsDetector imple
return (XlcBuiltinSpecsDetector) super.clone();
}
}