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>
<parameter <parameter
name="defaultAttributes" name="defaultAttributes"
value="-c -v"> value="-E -v ${plugin_state_location}/${specs_file}">
</parameter> </parameter>
</run> </run>
</externalScannerInfoProvider> </externalScannerInfoProvider>

View file

@ -128,7 +128,7 @@ public class MakeCorePlugin extends Plugin {
scInfo.setESIProviderCommandEnabled(true); scInfo.setESIProviderCommandEnabled(true);
scInfo.setUseDefaultESIProviderCmd(true); scInfo.setUseDefaultESIProviderCmd(true);
scInfo.setESIProviderCommand(new Path("gcc")); //$NON-NLS-1$ 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.setESIProviderConsoleParserId(GCC_SPECS_CONSOLE_PARSER_ID);
scInfo.setMakeBuilderConsoleParserId(GCC_SCANNER_INFO_CONSOLE_PARSER_ID); scInfo.setMakeBuilderConsoleParserId(GCC_SCANNER_INFO_CONSOLE_PARSER_ID);
} catch (CoreException e) { } catch (CoreException e) {

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.make.core.scannerconfig; package org.eclipse.cdt.make.core.scannerconfig;
import java.util.List; import java.util.List;
import java.util.Map;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
@ -21,16 +22,22 @@ import org.eclipse.core.resources.IResource;
* @author vhirsl * @author vhirsl
*/ */
public interface IScannerInfoCollector { 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 * Contribute to resource's scanner configuration
* *
* @param resource * @param resource
* @param includes * @param includes
* @param symbols * @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, public void contributeToScannerConfig(IResource resource,
List includes, List includes,
List symbols, List symbols,
List targetSpecificOptions); Map extraInfo);
} }

View file

@ -16,7 +16,6 @@ import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.StringTokenizer;
import org.eclipse.cdt.core.CCProjectNature; import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CCorePlugin; 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.MakeMessages;
import org.eclipse.cdt.make.internal.core.StreamMonitor; 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.gnu.GCCScannerConfigUtil;
import org.eclipse.cdt.make.internal.core.scannerconfig.util.ScannerConfigUtil;
import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
@ -54,7 +54,7 @@ public class DefaultExternalScannerInfoProvider implements IExternalScannerInfoP
private IPath fWorkingDirectory; private IPath fWorkingDirectory;
private IPath fCompileCommand; private IPath fCompileCommand;
private String fCompileArguments; private String[] fCompileArguments;
/* (non-Javadoc) /* (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) * @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,8 +144,7 @@ public class DefaultExternalScannerInfoProvider implements IExternalScannerInfoP
private boolean initialize(IProject currentProject, IScannerConfigBuilderInfo buildInfo, List targetSpecificOptions) { private boolean initialize(IProject currentProject, IScannerConfigBuilderInfo buildInfo, List targetSpecificOptions) {
boolean rc = false; boolean rc = false;
if (buildInfo.isDefaultESIProviderCmd()) { fWorkingDirectory = currentProject.getLocation();
fWorkingDirectory = MakeCorePlugin.getWorkingDirectory();
String targetFile = "dummy"; //$NON-NLS-1$ String targetFile = "dummy"; //$NON-NLS-1$
try { try {
if (currentProject.hasNature(CCProjectNature.CC_NATURE_ID)) { if (currentProject.hasNature(CCProjectNature.CC_NATURE_ID)) {
@ -162,14 +161,14 @@ public class DefaultExternalScannerInfoProvider implements IExternalScannerInfoP
if (!path2File.toFile().exists()) { if (!path2File.toFile().exists()) {
GCCScannerConfigUtil.createSpecs(); GCCScannerConfigUtil.createSpecs();
} }
targetSpecificOptions.add(targetFile);
}
else {
fWorkingDirectory = currentProject.getLocation();
}
fCompileCommand = buildInfo.getESIProviderCommand(); fCompileCommand = buildInfo.getESIProviderCommand();
if (fCompileCommand != null) { 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; rc = true;
} }
return rc; return rc;
@ -183,17 +182,12 @@ public class DefaultExternalScannerInfoProvider implements IExternalScannerInfoP
String[] rv = null; String[] rv = null;
// commandArguments may have multiple arguments; tokenizing // commandArguments may have multiple arguments; tokenizing
int nTokens = 0; int nTokens = 0;
if (fCompileArguments != null && fCompileArguments.length() > 0) { if (fCompileArguments != null && fCompileArguments.length > 0) {
StringTokenizer tokenizer = new StringTokenizer(fCompileArguments, " ");//$NON-NLS-1$ nTokens = fCompileArguments.length;
nTokens = tokenizer.countTokens();
if (nTokens > 0) {
rv = new String[nTokens + tso.size()]; rv = new String[nTokens + tso.size()];
for (int i = 0; tokenizer.hasMoreTokens(); ++i) { System.arraycopy(fCompileArguments, 0, rv, 0, nTokens);
rv[i] = tokenizer.nextToken();
} }
} else {
}
if (rv == null) {
rv = new String[tso.size()]; rv = new String[tso.size()];
} }
for (int i = 0; i < tso.size(); ++i) { for (int i = 0; i < tso.size(); ++i) {

View file

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

View file

@ -80,9 +80,9 @@ public class ScannerInfoCollector implements IScannerInfoCollector {
} }
/* (non-Javadoc) /* (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; IProject project;
if (resource == null || (project = resource.getProject()) == null) { if (resource == null || (project = resource.getProject()) == null) {
TraceUtil.outputError("IScannerInfoCollector.contributeToScannerConfig : ", "resource or project is null"); //$NON-NLS-1$ //$NON-NLS-2$ 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(); String projectName = project.getName();
contribute(projectName, discoveredIncludes, includes, true); contribute(projectName, discoveredIncludes, includes, true);
contribute(projectName, discoveredSymbols, symbols, false); 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) { 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.IScannerInfoCollector;
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoConsoleParser; 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.IScannerInfoConsoleParserUtility;
import org.eclipse.cdt.make.internal.core.scannerconfig.util.ScannerConfigUtil;
import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil; import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* Parses gcc and g++ output for -I and -D parameters. * Parses gcc and g++ output for -I and -D parameters.
@ -67,17 +70,7 @@ public class GCCScannerInfoConsoleParser implements IScannerInfoConsoleParser {
} }
// Known patterns: // Known patterns:
// (a) gcc|g++ ... -Dxxx -Iyyy ... // (a) gcc|g++ ... -Dxxx -Iyyy ...
ArrayList allTokens = new ArrayList(); ArrayList allTokens = new ArrayList(Arrays.asList(ScannerConfigUtil.tokenizeStringWithQuotes(line)));
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]);
}
}
if (allTokens.size() <= 1) if (allTokens.size() <= 1)
return false; return false;
Iterator I = allTokens.iterator(); Iterator I = allTokens.iterator();
@ -181,7 +174,9 @@ public class GCCScannerInfoConsoleParser implements IScannerInfoConsoleParser {
} }
// Contribute discovered includes and symbols to the ScannerInfoCollector // Contribute discovered includes and symbols to the ScannerInfoCollector
if (translatedIncludes.size() > 0 || symbols.size() > 0) { 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$ TraceUtil.outputTrace("Discovered scanner info for file \'" + fileName + '\'', //$NON-NLS-1$
"Include paths", includes, translatedIncludes, "Defined symbols", symbols); //$NON-NLS-1$ //$NON-NLS-2$ "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; package org.eclipse.cdt.make.internal.core.scannerconfig.util;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@ -248,4 +249,25 @@ public final class ScannerConfigUtil {
} }
return newSumPaths; 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,8 +323,6 @@ public class ScannerInfoConsoleParserUtility implements IScannerInfoConsoleParse
String include = (String) i.next(); String include = (String) i.next();
IPath includePath = new Path(include); IPath includePath = new Path(include);
if (!includePath.isAbsolute()) { 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 // First try the current working directory
IPath cwd = getWorkingDirectory(); IPath cwd = getWorkingDirectory();
if (!cwd.isAbsolute()) { if (!cwd.isAbsolute()) {
@ -360,16 +358,13 @@ public class ScannerInfoConsoleParserUtility implements IScannerInfoConsoleParse
IPath candidatePath = cwd.append(includePath); IPath candidatePath = cwd.append(includePath);
File dir = candidatePath.toFile(); File dir = candidatePath.toFile();
if (dir.exists()) { include = candidatePath.toString();
translatedIncludes.add(candidatePath.toString()); if (!dir.exists()) {
continue; TraceUtil.outputError("Nonexistent include path: ", include); //$NON-NLS-1$
} generateMarker(file, -1, "Nonexistent include path: "+include, //$NON-NLS-1$
else {
generateMarker(file, -1, "Nonexistent include path: "+include,
IMarkerGenerator.SEVERITY_WARNING, fileName); IMarkerGenerator.SEVERITY_WARNING, fileName);
} }
} }
}
// TODO VMIR for now add unresolved paths as well // TODO VMIR for now add unresolved paths as well
translatedIncludes.add(include); translatedIncludes.add(include);
} }