1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 18:26:01 +02:00

patch from vlad.

PR 59971 - [Scanner Config] Cannot change default scanner info command,
No PR - improvement in transformation of relative to absolute paths

Also a change in IScannerInfoCollector interface to allow console parsers 
to contribute arbitrary information (like compiler version info, imacros, 
target specific options, ...) to the collector.
This commit is contained in:
David Inglis 2004-05-07 20:44:28 +00:00
parent 5d46138a5d
commit 41201a534a
9 changed files with 110 additions and 94 deletions

View file

@ -119,7 +119,7 @@
</parameter>
<parameter
name="defaultAttributes"
value="-c -v">
value="-E -v ${plugin_state_location}/${specs_file}">
</parameter>
</run>
</externalScannerInfoProvider>

View file

@ -128,7 +128,7 @@ public class MakeCorePlugin extends Plugin {
scInfo.setESIProviderCommandEnabled(true);
scInfo.setUseDefaultESIProviderCmd(true);
scInfo.setESIProviderCommand(new Path("gcc")); //$NON-NLS-1$
scInfo.setESIProviderArguments("-c -v"); //$NON-NLS-1$
scInfo.setESIProviderArguments("-E -v ${plugin_state_location}/${specs_file}"); //$NON-NLS-1$
scInfo.setESIProviderConsoleParserId(GCC_SPECS_CONSOLE_PARSER_ID);
scInfo.setMakeBuilderConsoleParserId(GCC_SCANNER_INFO_CONSOLE_PARSER_ID);
} catch (CoreException e) {

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.make.core.scannerconfig;
import java.util.List;
import java.util.Map;
import org.eclipse.core.resources.IResource;
@ -21,16 +22,22 @@ import org.eclipse.core.resources.IResource;
* @author vhirsl
*/
public interface IScannerInfoCollector {
// for a list of target specific options i.e. -pthread, -ansi, -no_
public static Integer TARGET_SPECIFIC_OPTION = new Integer(1) ;
public static Integer IMACROS = new Integer(2);
public static Integer COMPILER_VERSION_INFO = new Integer(3);
/**
* Contribute to resource's scanner configuration
*
* @param resource
* @param includes
* @param symbols
* @param targetSpecificOptions
* @param extraInfo - a map of key - list pairs, where key is the type of extra info
* i.e. target specific options or imacros commands,...
*/
public void contributeToScannerConfig(IResource resource,
List includes,
List symbols,
List targetSpecificOptions);
Map extraInfo);
}

View file

@ -16,7 +16,6 @@ import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
import java.util.StringTokenizer;
import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CCorePlugin;
@ -32,6 +31,7 @@ import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector;
import org.eclipse.cdt.make.internal.core.MakeMessages;
import org.eclipse.cdt.make.internal.core.StreamMonitor;
import org.eclipse.cdt.make.internal.core.scannerconfig.gnu.GCCScannerConfigUtil;
import org.eclipse.cdt.make.internal.core.scannerconfig.util.ScannerConfigUtil;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@ -54,7 +54,7 @@ public class DefaultExternalScannerInfoProvider implements IExternalScannerInfoP
private IPath fWorkingDirectory;
private IPath fCompileCommand;
private String fCompileArguments;
private String[] fCompileArguments;
/* (non-Javadoc)
* @see org.eclipse.cdt.make.core.scannerconfig.IExternalScannerInfoProvider#invokeProvider(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.resources.IProject, org.eclipse.cdt.make.core.scannerconfig.IScannerConfigBuilderInfo, java.util.List, org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector)
@ -144,32 +144,31 @@ public class DefaultExternalScannerInfoProvider implements IExternalScannerInfoP
private boolean initialize(IProject currentProject, IScannerConfigBuilderInfo buildInfo, List targetSpecificOptions) {
boolean rc = false;
if (buildInfo.isDefaultESIProviderCmd()) {
fWorkingDirectory = MakeCorePlugin.getWorkingDirectory();
String targetFile = "dummy"; //$NON-NLS-1$
try {
if (currentProject.hasNature(CCProjectNature.CC_NATURE_ID)) {
targetFile = GCCScannerConfigUtil.CPP_SPECS_FILE;
}
else if (currentProject.hasNature(CProjectNature.C_NATURE_ID)) {
targetFile = GCCScannerConfigUtil.C_SPECS_FILE;
}
} catch (CoreException e) {
//TODO VMIR better error handling
MakeCorePlugin.log(e.getStatus());
fWorkingDirectory = currentProject.getLocation();
String targetFile = "dummy"; //$NON-NLS-1$
try {
if (currentProject.hasNature(CCProjectNature.CC_NATURE_ID)) {
targetFile = GCCScannerConfigUtil.CPP_SPECS_FILE;
}
IPath path2File = fWorkingDirectory.append(targetFile);
if (!path2File.toFile().exists()) {
GCCScannerConfigUtil.createSpecs();
else if (currentProject.hasNature(CProjectNature.C_NATURE_ID)) {
targetFile = GCCScannerConfigUtil.C_SPECS_FILE;
}
targetSpecificOptions.add(targetFile);
} catch (CoreException e) {
//TODO VMIR better error handling
MakeCorePlugin.log(e.getStatus());
}
else {
fWorkingDirectory = currentProject.getLocation();
IPath path2File = fWorkingDirectory.append(targetFile);
if (!path2File.toFile().exists()) {
GCCScannerConfigUtil.createSpecs();
}
fCompileCommand = buildInfo.getESIProviderCommand();
if (fCompileCommand != null) {
fCompileArguments = buildInfo.getESIProviderArguments();
fCompileArguments = ScannerConfigUtil.tokenizeStringWithQuotes(buildInfo.getESIProviderArguments());
for (int i = 0; i < fCompileArguments.length; ++i) {
fCompileArguments[i] = fCompileArguments[i].replaceAll("\\$\\{plugin_state_location\\}", //$NON-NLS-1$
MakeCorePlugin.getWorkingDirectory().toString());
fCompileArguments[i] = fCompileArguments[i].replaceAll("\\$\\{specs_file\\}", targetFile); //$NON-NLS-1$
}
rc = true;
}
return rc;
@ -183,17 +182,12 @@ public class DefaultExternalScannerInfoProvider implements IExternalScannerInfoP
String[] rv = null;
// commandArguments may have multiple arguments; tokenizing
int nTokens = 0;
if (fCompileArguments != null && fCompileArguments.length() > 0) {
StringTokenizer tokenizer = new StringTokenizer(fCompileArguments, " ");//$NON-NLS-1$
nTokens = tokenizer.countTokens();
if (nTokens > 0) {
rv = new String[nTokens + tso.size()];
for (int i = 0; tokenizer.hasMoreTokens(); ++i) {
rv[i] = tokenizer.nextToken();
}
}
if (fCompileArguments != null && fCompileArguments.length > 0) {
nTokens = fCompileArguments.length;
rv = new String[nTokens + tso.size()];
System.arraycopy(fCompileArguments, 0, rv, 0, nTokens);
}
if (rv == null) {
else {
rv = new String[tso.size()];
}
for (int i = 0; i < tso.size(); ++i) {

View file

@ -166,7 +166,7 @@ public class ScannerConfigInfoFactory {
if (isDefaultESIProviderCmd()) {
String attributes = getESIProviderParameter("defaultAttributes"); //$NON-NLS-1$
if (attributes == null) {
attributes = "-c -v"; //$NON-NLS-1$
attributes = "-E -v ${plugin_state_location}/{specs_file}"; //$NON-NLS-1$
}
return attributes;
}

View file

@ -80,9 +80,9 @@ public class ScannerInfoCollector implements IScannerInfoCollector {
}
/* (non-Javadoc)
* @see org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector#contributeToScannerConfig(org.eclipse.core.resources.IResource, java.util.List, java.util.List, java.util.List)
* @see org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector#contributeToScannerConfig(org.eclipse.core.resources.IResource, java.util.List, java.util.List, java.util.Map)
*/
public synchronized void contributeToScannerConfig(IResource resource, List includes, List symbols, List targetSpecificOptions) {
public void contributeToScannerConfig(IResource resource, List includes, List symbols, Map extraInfo) {
IProject project;
if (resource == null || (project = resource.getProject()) == null) {
TraceUtil.outputError("IScannerInfoCollector.contributeToScannerConfig : ", "resource or project is null"); //$NON-NLS-1$ //$NON-NLS-2$
@ -96,7 +96,10 @@ public class ScannerInfoCollector implements IScannerInfoCollector {
String projectName = project.getName();
contribute(projectName, discoveredIncludes, includes, true);
contribute(projectName, discoveredSymbols, symbols, false);
contribute(projectName, discoveredTSO, targetSpecificOptions, false);
contribute(projectName,
discoveredTSO,
(extraInfo == null) ? null : (List) extraInfo.get(IScannerInfoCollector.TARGET_SPECIFIC_OPTION),
false);
}
}
catch (CoreException e) {

View file

@ -16,12 +16,15 @@ import org.eclipse.cdt.core.IMarkerGenerator;
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector;
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoConsoleParser;
import org.eclipse.cdt.make.internal.core.scannerconfig.IScannerInfoConsoleParserUtility;
import org.eclipse.cdt.make.internal.core.scannerconfig.util.ScannerConfigUtil;
import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* Parses gcc and g++ output for -I and -D parameters.
@ -67,17 +70,7 @@ public class GCCScannerInfoConsoleParser implements IScannerInfoConsoleParser {
}
// Known patterns:
// (a) gcc|g++ ... -Dxxx -Iyyy ...
ArrayList allTokens = new ArrayList();
String[] tokens = line.split("\"");
for (int i = 0; i < tokens.length; ++i) {
if (i % 2 == 0) { // even tokens need further tokenization
String[] sTokens = tokens[i].split("\\s");
allTokens.addAll(Arrays.asList(sTokens));
}
else {
allTokens.add(tokens[i]);
}
}
ArrayList allTokens = new ArrayList(Arrays.asList(ScannerConfigUtil.tokenizeStringWithQuotes(line)));
if (allTokens.size() <= 1)
return false;
Iterator I = allTokens.iterator();
@ -181,7 +174,9 @@ public class GCCScannerInfoConsoleParser implements IScannerInfoConsoleParser {
}
// Contribute discovered includes and symbols to the ScannerInfoCollector
if (translatedIncludes.size() > 0 || symbols.size() > 0) {
fCollector.contributeToScannerConfig(project, translatedIncludes, symbols, targetSpecificOptions);
Map extraInfo = new HashMap();
extraInfo.put(IScannerInfoCollector.TARGET_SPECIFIC_OPTION, targetSpecificOptions);
fCollector.contributeToScannerConfig(project, translatedIncludes, symbols, extraInfo);
TraceUtil.outputTrace("Discovered scanner info for file \'" + fileName + '\'', //$NON-NLS-1$
"Include paths", includes, translatedIncludes, "Defined symbols", symbols); //$NON-NLS-1$ //$NON-NLS-2$

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.make.internal.core.scannerconfig.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
@ -248,4 +249,25 @@ public final class ScannerConfigUtil {
}
return newSumPaths;
}
/**
* Tokenizes string with quuotes
*
* @param String
* @return String[]
*/
public static String[] tokenizeStringWithQuotes(String line) {
ArrayList allTokens = new ArrayList();
String[] tokens = line.split("\""); //$NON-NLS-1$
for (int i = 0; i < tokens.length; ++i) {
if (i % 2 == 0) { // even tokens need further tokenization
String[] sTokens = tokens[i].split("\\s"); //$NON-NLS-1$
allTokens.addAll(Arrays.asList(sTokens));
}
else {
allTokens.add(tokens[i]);
}
}
return (String[]) allTokens.toArray(new String[allTokens.size()]);
}
}

View file

@ -323,52 +323,47 @@ public class ScannerInfoConsoleParserUtility implements IScannerInfoConsoleParse
String include = (String) i.next();
IPath includePath = new Path(include);
if (!includePath.isAbsolute()) {
// check if it is a relative path
if (include.startsWith("..") || include.startsWith(".")) { //$NON-NLS-1$ //$NON-NLS-2$
// First try the current working directory
IPath cwd = getWorkingDirectory();
if (!cwd.isAbsolute()) {
cwd = fProject.getLocation().append(cwd);
}
// check if the cwd is the right one
// appending fileName to cwd should yield file path
IPath filePath = cwd.append(fileName);
if (!filePath.toString().equalsIgnoreCase(file.getLocation().toString())) {
// must be the cwd is wrong
// check if file name starts with ".."
if (fileName.startsWith("..")) { //$NON-NLS-1$
// probably multiple choices for cwd, hopeless
TraceUtil.outputError("Unable to determine working directory for ", fileName); //$NON-NLS-1$
generateMarker(file, -1, "Unable to determine working directory for", //$NON-NLS-1$
IMarkerGenerator.SEVERITY_WARNING, fileName);
break;
}
else {
// remove common segments at the end
IPath tPath = new Path(fileName);
if (fileName.startsWith(".")) { //$NON-NLS-1$
tPath = tPath.removeFirstSegments(1);
}
// get the file path from the file
filePath = file.getLocation();
IPath lastFileSegment = filePath.removeFirstSegments(filePath.segmentCount() - tPath.segmentCount());
if (lastFileSegment.matchingFirstSegments(tPath) == tPath.segmentCount()) {
cwd = filePath.removeLastSegments(tPath.segmentCount());
}
}
}
IPath candidatePath = cwd.append(includePath);
File dir = candidatePath.toFile();
if (dir.exists()) {
translatedIncludes.add(candidatePath.toString());
continue;
// First try the current working directory
IPath cwd = getWorkingDirectory();
if (!cwd.isAbsolute()) {
cwd = fProject.getLocation().append(cwd);
}
// check if the cwd is the right one
// appending fileName to cwd should yield file path
IPath filePath = cwd.append(fileName);
if (!filePath.toString().equalsIgnoreCase(file.getLocation().toString())) {
// must be the cwd is wrong
// check if file name starts with ".."
if (fileName.startsWith("..")) { //$NON-NLS-1$
// probably multiple choices for cwd, hopeless
TraceUtil.outputError("Unable to determine working directory for ", fileName); //$NON-NLS-1$
generateMarker(file, -1, "Unable to determine working directory for", //$NON-NLS-1$
IMarkerGenerator.SEVERITY_WARNING, fileName);
break;
}
else {
generateMarker(file, -1, "Nonexistent include path: "+include,
IMarkerGenerator.SEVERITY_WARNING, fileName);
// remove common segments at the end
IPath tPath = new Path(fileName);
if (fileName.startsWith(".")) { //$NON-NLS-1$
tPath = tPath.removeFirstSegments(1);
}
// get the file path from the file
filePath = file.getLocation();
IPath lastFileSegment = filePath.removeFirstSegments(filePath.segmentCount() - tPath.segmentCount());
if (lastFileSegment.matchingFirstSegments(tPath) == tPath.segmentCount()) {
cwd = filePath.removeLastSegments(tPath.segmentCount());
}
}
}
IPath candidatePath = cwd.append(includePath);
File dir = candidatePath.toFile();
include = candidatePath.toString();
if (!dir.exists()) {
TraceUtil.outputError("Nonexistent include path: ", include); //$NON-NLS-1$
generateMarker(file, -1, "Nonexistent include path: "+include, //$NON-NLS-1$
IMarkerGenerator.SEVERITY_WARNING, fileName);
}
}
// TODO VMIR for now add unresolved paths as well
translatedIncludes.add(include);