mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Updated handling of frameworks, bug 69529.
This commit is contained in:
parent
e5fa863d5c
commit
a75ebb1cf4
3 changed files with 27 additions and 31 deletions
|
@ -87,16 +87,16 @@ public class InclusionTests extends PreprocessorTestsBase {
|
||||||
IFolder f0 = importFolder(".framework");
|
IFolder f0 = importFolder(".framework");
|
||||||
importFolder("f1.framework");
|
importFolder("f1.framework");
|
||||||
importFolder("f1");
|
importFolder("f1");
|
||||||
importFolder("f1/f2.framework");
|
importFolder("f1.framework/f2");
|
||||||
importFolder("f3");
|
importFolder("f3");
|
||||||
IFile base = importFile("base.cpp", content);
|
IFile base = importFile("base.cpp", content);
|
||||||
|
|
||||||
importFile(".framework/one.h", "1");
|
importFile(".framework/one.h", "1");
|
||||||
importFile("f1.framework/two.h", "2");
|
importFile("f1.framework/two.h", "2");
|
||||||
importFile("f1/f2.framework/three.h", "3");
|
importFile("f1.framework/f2/three.h", "3");
|
||||||
|
|
||||||
String[] path = {
|
String[] path = {
|
||||||
f0.getLocation().removeLastSegments(1) + "/__framework__.framework/__filename__"
|
f0.getLocation().removeLastSegments(1) + "/__framework__.framework/__header__"
|
||||||
};
|
};
|
||||||
IScannerInfo scannerInfo = new ExtendedScannerInfo(Collections.EMPTY_MAP, path, new String[]{}, null);
|
IScannerInfo scannerInfo = new ExtendedScannerInfo(Collections.EMPTY_MAP, path, new String[]{}, null);
|
||||||
CodeReader reader= new CodeReader(base.getLocation().toString());
|
CodeReader reader= new CodeReader(base.getLocation().toString());
|
||||||
|
@ -104,7 +104,7 @@ public class InclusionTests extends PreprocessorTestsBase {
|
||||||
|
|
||||||
// first file is not picked up (no framework)
|
// first file is not picked up (no framework)
|
||||||
validateInteger("2");
|
validateInteger("2");
|
||||||
// third file is not picked up (framework must be a single folder)
|
validateInteger("3");
|
||||||
validateEOF();
|
validateEOF();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,8 +210,8 @@ public class InclusionTests extends PreprocessorTestsBase {
|
||||||
|
|
||||||
CodeReader reader= new CodeReader(base.getLocation().toString());
|
CodeReader reader= new CodeReader(base.getLocation().toString());
|
||||||
ParserLanguage lang[]= {ParserLanguage.C, ParserLanguage.CPP};
|
ParserLanguage lang[]= {ParserLanguage.C, ParserLanguage.CPP};
|
||||||
for (int i = 0; i < lang.length; i++) {
|
for (ParserLanguage element : lang) {
|
||||||
initializeScanner(reader, lang[i], ParserMode.COMPLETE_PARSE, new ScannerInfo());
|
initializeScanner(reader, element, ParserMode.COMPLETE_PARSE, new ScannerInfo());
|
||||||
validateToken(IToken.t_int);
|
validateToken(IToken.t_int);
|
||||||
validateIdentifier("var");
|
validateIdentifier("var");
|
||||||
validateToken(IToken.tASSIGN);
|
validateToken(IToken.tASSIGN);
|
||||||
|
|
|
@ -30,15 +30,15 @@ public interface IScannerInfo {
|
||||||
/**
|
/**
|
||||||
* Returns an array of paths that are searched when processing an include directive.
|
* Returns an array of paths that are searched when processing an include directive.
|
||||||
* see {@link IExtendedScannerInfo#getLocalIncludePath()}
|
* see {@link IExtendedScannerInfo#getLocalIncludePath()}
|
||||||
*
|
* <p>
|
||||||
* In order to handle framework includes used on Apple Computers you can make use of
|
* In order to handle framework includes used on Apple Computers you can make use of
|
||||||
* the two variables: '__framework__' and '__filename__'.
|
* the two variables: '__framework__' and '__header__'.
|
||||||
* <br> E.g.: /System/Library/Frameworks/__framework__.framework/Headers/__filename__,
|
* <br> E.g.: /System/Library/Frameworks/__framework__.framework/Headers/__header__,
|
||||||
* /System/Library/Frameworks/__framework__.framework/PrivateHeaders/__filename__
|
* /System/Library/Frameworks/__framework__.framework/PrivateHeaders/__header__
|
||||||
* would handle the framework search for '/System/Library/Frameworks'
|
* would handle the framework search for '/System/Library/Frameworks'
|
||||||
*
|
* <br> The variables are handled only, if a search path element makes use of both of the variables.
|
||||||
* The variables are handled only, if a search path element makes use of both of the variables.
|
* The __framework__ variable will receive the first segment of the include, the __header__ variable
|
||||||
* Such a search path element is not used for directives that are not of the form 'folder/name'.
|
* the rest. Such a search path element is not used for directives with a single segment (e.g. 'header.h')
|
||||||
*/
|
*/
|
||||||
public String[] getIncludePaths();
|
public String[] getIncludePaths();
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ import java.io.File;
|
||||||
final class IncludeSearchPathElement {
|
final class IncludeSearchPathElement {
|
||||||
private static final boolean NON_SLASH_SEPARATOR = File.separatorChar != '/';
|
private static final boolean NON_SLASH_SEPARATOR = File.separatorChar != '/';
|
||||||
public static final String FRAMEWORK_VAR = "__framework__"; //$NON-NLS-1$
|
public static final String FRAMEWORK_VAR = "__framework__"; //$NON-NLS-1$
|
||||||
public static final String FILE_VAR = "__filename__"; //$NON-NLS-1$
|
public static final String FILE_VAR = "__header__"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
|
||||||
private final String fPath;
|
private final String fPath;
|
||||||
|
@ -42,39 +42,35 @@ final class IncludeSearchPathElement {
|
||||||
|
|
||||||
public String getLocation(String includeDirective) {
|
public String getLocation(String includeDirective) {
|
||||||
if (fIsFrameworkDirectory) {
|
if (fIsFrameworkDirectory) {
|
||||||
int lastSep = lastSeparator(includeDirective);
|
int firstSep = firstSeparator(includeDirective);
|
||||||
if (lastSep < 0) {
|
if (firstSep < 1) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String framework = includeDirective.substring(0, lastSep);
|
String framework = includeDirective.substring(0, firstSep);
|
||||||
if (lastSeparator(framework) != -1 || framework.length() == 0) {
|
String file= includeDirective.substring(firstSep+1);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
String file= includeDirective.substring(lastSep+1);
|
|
||||||
if (file.length() == 0)
|
if (file.length() == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
StringBuilder buf= new StringBuilder(fPath);
|
StringBuilder buf= new StringBuilder(fPath);
|
||||||
replaceAll(buf, FRAMEWORK_VAR, framework);
|
replace(buf, FRAMEWORK_VAR, framework);
|
||||||
replaceAll(buf, FILE_VAR, file);
|
replace(buf, FILE_VAR, file);
|
||||||
return ScannerUtility.reconcilePath(buf.toString());
|
return ScannerUtility.reconcilePath(buf.toString());
|
||||||
}
|
}
|
||||||
return ScannerUtility.createReconciledPath(fPath, includeDirective);
|
return ScannerUtility.createReconciledPath(fPath, includeDirective);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int lastSeparator(String path) {
|
private int firstSeparator(String path) {
|
||||||
int lastSep= path.lastIndexOf('/');
|
int firstSep= path.indexOf('/');
|
||||||
if (NON_SLASH_SEPARATOR) {
|
if (NON_SLASH_SEPARATOR) {
|
||||||
lastSep= Math.max(lastSep, path.lastIndexOf(File.separatorChar));
|
firstSep= Math.max(firstSep, path.indexOf(File.separatorChar));
|
||||||
}
|
}
|
||||||
return lastSep;
|
return firstSep;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void replaceAll(StringBuilder buf, String find, final String replace) {
|
private void replace(StringBuilder buf, String find, final String replace) {
|
||||||
for (int idx= buf.indexOf(find); idx > 0; idx= buf.indexOf(find, idx)) {
|
int idx= buf.indexOf(find);
|
||||||
|
if (idx >= 0) {
|
||||||
buf.replace(idx, idx+find.length(), replace);
|
buf.replace(idx, idx+find.length(), replace);
|
||||||
idx+= replace.length();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue