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

Fixed bugs with macro resolution in path entry calculation

This commit is contained in:
Mikhail Sennikovsky 2005-11-28 11:48:35 +00:00
parent a39da76e9e
commit 1ca39e56f9

View file

@ -1168,33 +1168,47 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
/** /**
*/ */
private String processPath(String path, int context, Object obj) { private List processPath(List list, String path, int context, Object obj) {
final String EMPTY = ""; //$NON-NLS-1$ final String EMPTY = ""; //$NON-NLS-1$
final String QUOTE = "\""; //$NON-NLS-1$ if (path != null) {
if (context != 0) {
if (path == null) { return EMPTY; } try {
String s = path; String paths[] = ManagedBuildManager.getBuildMacroProvider().resolveStringListValue(path, EMPTY, " ", context, obj); //$NON-NLS-1$
if (context != 0) { if (paths != null) {
try { for(int i = 0; i < paths.length; i++){
s = ManagedBuildManager.getBuildMacroProvider().resolveValue(s, EMPTY, " ", context, obj); //$NON-NLS-1$ list.add(checkPath(paths[i]));
} catch (BuildMacroException e) { }
}
} catch (BuildMacroException e) {
}
} else {
list.add(checkPath(path));
} }
} }
if (s == null) { s = path; } return list;
}
private String checkPath(String p){
final String QUOTE = "\""; //$NON-NLS-1$
final String EMPTY = ""; //$NON-NLS-1$
if (s.length()> 1 && s.startsWith(QUOTE) && s.endsWith(QUOTE)) { if(p == null)
s = s.substring(1, s.length()-1); return EMPTY;
if (p.length()> 1 && p.startsWith(QUOTE) && p.endsWith(QUOTE)) {
p = p.substring(1, p.length()-1);
} }
if ( ".".equals(s) ) { //$NON-NLS-1$ if ( ".".equals(p) ) { //$NON-NLS-1$
String cwd = getCWD(); String cwd = getCWD();
if (cwd.length()>0) { s = cwd; } if (cwd.length()>0) { p = cwd; }
} }
if (!(new Path(s)).isAbsolute()) { if (!(new Path(p)).isAbsolute()) {
String cwd = getCWD(); String cwd = getCWD();
if (cwd.length()>0) { s = cwd + "/" + s; } //$NON-NLS-1$ if (cwd.length()>0) { p = cwd + "/" + p; } //$NON-NLS-1$
} }
return s; return p;
} }
/** /**
@ -1204,7 +1218,7 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
public IPathEntry[] getManagedBuildValues() { public IPathEntry[] getManagedBuildValues() {
List entries = new ArrayList(); List entries = new ArrayList();
int i=0; int i=0;
IPathEntry[] a = getManagedBuildValues(IPathEntry.CDT_INCLUDE_FILE); IPathEntry[] a = getManagedBuildValues(IPathEntry.CDT_INCLUDE);
if (a != null) { for (i=0; i<a.length; i++) entries.add(a[i]); } if (a != null) { for (i=0; i<a.length; i++) entries.add(a[i]); }
a = getManagedBuildValues(IPathEntry.CDT_LIBRARY); a = getManagedBuildValues(IPathEntry.CDT_LIBRARY);
if (a != null) { for (i=0; i<a.length; i++) entries.add(a[i]); } if (a != null) { for (i=0; i<a.length; i++) entries.add(a[i]); }
@ -1220,7 +1234,7 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
public IPathEntry[] getManagedBuildBuiltIns() { public IPathEntry[] getManagedBuildBuiltIns() {
List entries = new ArrayList(); List entries = new ArrayList();
int i=0; int i=0;
IPathEntry[] a = getManagedBuildBuiltIns(IPathEntry.CDT_INCLUDE_FILE); IPathEntry[] a = getManagedBuildBuiltIns(IPathEntry.CDT_INCLUDE);
if (a != null) { for (i=0; i<a.length; i++) entries.add(a[i]); } if (a != null) { for (i=0; i<a.length; i++) entries.add(a[i]); }
a = getManagedBuildBuiltIns(IPathEntry.CDT_LIBRARY); a = getManagedBuildBuiltIns(IPathEntry.CDT_LIBRARY);
if (a != null) { for (i=0; i<a.length; i++) entries.add(a[i]); } if (a != null) { for (i=0; i<a.length; i++) entries.add(a[i]); }
@ -1239,9 +1253,9 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
List entries = getOptionValues(entryType, false); List entries = getOptionValues(entryType, false);
// for includes, get env variables values; useless for other entry types // for includes, get env variables values; useless for other entry types
if (entryType == IPathEntry.CDT_INCLUDE_FILE) { if (entryType == IPathEntry.CDT_INCLUDE) {
IEnvironmentVariableProvider env = ManagedBuildManager.getEnvironmentVariableProvider(); IEnvironmentVariableProvider env = ManagedBuildManager.getEnvironmentVariableProvider();
entries = addIncludes(entries, env.getBuildPaths(getDefaultConfiguration(), IEnvVarBuildPath.BUILDPATH_INCLUDE), Path.EMPTY, null); entries = addIncludes(entries, env.getBuildPaths(getDefaultConfiguration(), IEnvVarBuildPath.BUILDPATH_INCLUDE), Path.EMPTY, 0, null);
} }
return (IPathEntry[])entries.toArray(new IPathEntry[entries.size()]); return (IPathEntry[])entries.toArray(new IPathEntry[entries.size()]);
} }
@ -1308,7 +1322,7 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
IPath resPath = Path.EMPTY; IPath resPath = Path.EMPTY;
// check that entryType is correct // check that entryType is correct
if (entryType != IPathEntry.CDT_INCLUDE_FILE && if (entryType != IPathEntry.CDT_INCLUDE &&
//TODO: we need to implement the proper CDT_LIBRARY handling //TODO: we need to implement the proper CDT_LIBRARY handling
//calculating the CDT_LIBRARY entries from the managed build //calculating the CDT_LIBRARY entries from the managed build
//options is disabled for now, we need to define a new option type //options is disabled for now, we need to define a new option type
@ -1337,20 +1351,21 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
!applicabilityCalculator.isOptionUsedInCommandLine(obj, t[i], op[j])) continue; !applicabilityCalculator.isOptionUsedInCommandLine(obj, t[i], op[j])) continue;
try { try {
if (entryType == IPathEntry.CDT_INCLUDE_FILE && if (entryType == IPathEntry.CDT_INCLUDE &&
op[j].getValueType() == IOption.INCLUDE_PATH) op[j].getValueType() == IOption.INCLUDE_PATH)
{ {
OptionContextData ocd = new OptionContextData(op[j], t[i]); OptionContextData ocd = new OptionContextData(op[j], t[i]);
addIncludes(entries, builtIns ? op[j].getBuiltIns() : op[j].getIncludePaths(), resPath, ocd); addIncludes(entries, builtIns ? op[j].getBuiltIns() : op[j].getIncludePaths(), resPath, IBuildMacroProvider.CONTEXT_OPTION, ocd);
} else if (entryType == IPathEntry.CDT_LIBRARY && } else if (entryType == IPathEntry.CDT_LIBRARY &&
op[j].getValueType() == IOption.LIBRARIES) op[j].getValueType() == IOption.LIBRARIES)
{ {
OptionContextData ocd = new OptionContextData(op[j], t[i]); OptionContextData ocd = new OptionContextData(op[j], t[i]);
addLibraries(entries, builtIns ? op[j].getBuiltIns() : op[j].getLibraries(), resPath, ocd); addLibraries(entries, builtIns ? op[j].getBuiltIns() : op[j].getLibraries(), resPath, IBuildMacroProvider.CONTEXT_OPTION, ocd);
} else if (entryType == IPathEntry.CDT_MACRO && } else if (entryType == IPathEntry.CDT_MACRO &&
op[j].getValueType() == IOption.PREPROCESSOR_SYMBOLS) op[j].getValueType() == IOption.PREPROCESSOR_SYMBOLS)
{ {
addSymbols(entries, builtIns ? op[j].getBuiltIns() : op[j].getDefinedSymbols(), resPath); OptionContextData ocd = new OptionContextData(op[j], t[i]);
addSymbols(entries, builtIns ? op[j].getBuiltIns() : op[j].getDefinedSymbols(), resPath, IBuildMacroProvider.CONTEXT_OPTION, ocd);
} else { continue; } } else { continue; }
} catch (BuildException e) {} } catch (BuildException e) {}
} }
@ -1365,14 +1380,29 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
* @param resPath * @param resPath
* @param ocd * @param ocd
*/ */
protected List addIncludes(List entries, String[] values, IPath resPath, OptionContextData ocd) { protected List addIncludes(List entries, String[] values, IPath resPath, int context ,Object obj) {
if (values != null) { return addPaths(entries, values, resPath, context, obj, IPathEntry.CDT_INCLUDE);
}
protected List addPaths(List entries, String[] values, IPath resPath, int context ,Object obj, int type){
if (values != null && values.length > 0) {
List list = new ArrayList();
for (int k=0; k<values.length; k++) { for (int k=0; k<values.length; k++) {
if (ocd != null) { processPath(list, values[k], context, obj);
values[k] = processPath(values[k], IBuildMacroProvider.CONTEXT_OPTION, ocd); }
Iterator iter = list.iterator();
while(iter.hasNext()){
IPathEntry entry = null;
switch(type){
case IPathEntry.CDT_INCLUDE:
entry = CoreModel.newIncludeEntry(resPath, Path.EMPTY, new Path((String)iter.next()), true);
break;
case IPathEntry.CDT_LIBRARY:
entry = CoreModel.newLibraryEntry(resPath, Path.EMPTY, new Path((String)iter.next()), null, null, null, true);
break;
} }
IPathEntry entry = CoreModel.newIncludeEntry(resPath, Path.EMPTY, new Path(processPath(values[k], 0, null)), true); if (entry != null && !entries.contains(entry)) { entries.add(entry); }
if (!entries.contains(entry)) { entries.add(entry); }
} }
} }
return entries; return entries;
@ -1385,17 +1415,8 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
* @param resPath * @param resPath
* @param ocd * @param ocd
*/ */
protected List addLibraries(List entries, String[] values, IPath resPath, OptionContextData ocd) { protected List addLibraries(List entries, String[] values, IPath resPath, int context, Object obj) {
if (values != null) { return addPaths(entries, values, resPath, context, obj, IPathEntry.CDT_LIBRARY);
for (int k=0; k<values.length; k++) {
if (ocd != null) {
values[k] = processPath(values[k], IBuildMacroProvider.CONTEXT_OPTION, ocd);
}
IPathEntry entry = CoreModel.newLibraryEntry(resPath, Path.EMPTY, new Path(processPath(values[k], 0, null)), null, null, null, true);
if (!entries.contains(entry)) { entries.add(entry); }
}
}
return entries;
} }
/** /**
@ -1404,11 +1425,26 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
* @param values * @param values
* @param resPath * @param resPath
*/ */
protected List addSymbols(List entries, String[] values, IPath resPath) { protected List addSymbols(List entries, String[] values, IPath resPath, int context, Object obj) {
if (values == null) return entries; if (values == null) return entries;
for (int i=0; i<values.length; i++) { for (int i=0; i<values.length; i++) {
if (values[i].length() == 0) continue; try {
String[] tokens = values[i].split("="); //$NON-NLS-1$ String res[] = ManagedBuildManager.getBuildMacroProvider().resolveStringListValue(values[i],
"", " ", context, obj); //$NON-NLS-1$ //$NON-NLS-2$
if(res != null){
for(int k = 0; k < res.length; k++)
createMacroEntry(entries, res[k], resPath);
}
} catch (BuildMacroException e) {
}
}
return entries;
}
private List createMacroEntry(List entries, String val, IPath resPath){
if (val != null && val.length() != 0){
String[] tokens = val.split("="); //$NON-NLS-1$
String key = tokens[0].trim(); String key = tokens[0].trim();
String value = (tokens.length > 1) ? tokens[1].trim() : new String(); String value = (tokens.length > 1) ? tokens[1].trim() : new String();
// Make sure the current entries do not contain a duplicate // Make sure the current entries do not contain a duplicate