1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-19 23:15:24 +02:00

bug 396411: JUnit failure: cdt.managedbuilder.core.tests.ManagedBuildCoreTests20.testScannerInfoInterface

This commit is contained in:
Andrew Gvozdev 2012-12-16 07:17:43 -05:00
parent 963f1bf26e
commit 0a4170fed0
3 changed files with 49 additions and 32 deletions

View file

@ -204,7 +204,7 @@ public class ManagedBuildCoreTests20 extends TestCase {
/** /**
* Convert path to OS specific representation * Convert path to OS specific representation
*/ */
private String toOSString(String path) { private String toOSLocation(String path) {
File file = new File(path); File file = new File(path);
try { try {
path = file.getCanonicalPath(); path = file.getCanonicalPath();
@ -213,7 +213,14 @@ public class ManagedBuildCoreTests20 extends TestCase {
return path; return path;
} }
/**
* Convert path to OS specific representation
*/
private String toOSString(String path) {
return new Path(path).toOSString();
}
/** /**
* The purpose of this test is to exercise the build path info interface. * The purpose of this test is to exercise the build path info interface.
* To get to that point, a new project/config has to be created in the test * To get to that point, a new project/config has to be created in the test
@ -240,24 +247,24 @@ public class ManagedBuildCoreTests20 extends TestCase {
if (new Path("C:\\home\\tester/include").isAbsolute()) { if (new Path("C:\\home\\tester/include").isAbsolute()) {
// Windows // Windows
expectedPaths = new String[] { expectedPaths = new String[] {
toOSString("/usr/include"), toOSLocation("/usr/include"),
toOSString("/opt/gnome/include"), toOSLocation("/opt/gnome/include"),
toOSString("C:\\home\\tester/include"), toOSLocation("C:\\home\\tester/include"),
// relative paths make 2 entries // relative paths make 2 entries
project.getLocation().append("includes").toOSString(), buildCWD.append("../includes").toOSString(),
"includes", // FIXME this is incorrect, the original entry set via extension point is "../includes" toOSString("includes"),
"/usr/gnu/include", // Not converted to OS string due to being flagged as ICSettingEntry.RESOLVED "/usr/gnu/include", // Not converted to OS string due to being flagged as ICSettingEntry.RESOLVED
}; };
} else { } else {
// Unix // Unix
expectedPaths = new String[] { expectedPaths = new String[] {
toOSString("/usr/include"), toOSLocation("/usr/include"),
toOSString("/opt/gnome/include"), toOSLocation("/opt/gnome/include"),
buildCWD.append("C:\\home\\tester/include").toOSString(), // added on Unix being relative path
toOSLocation("C:\\home\\tester/include"),
// relative paths make 2 entries // relative paths make 2 entries
buildCWD.append("C:\\home\\tester/include").toOSString(), buildCWD.append("../includes").toOSString(),
"C:\\home\\tester/include", toOSString("includes"),
project.getLocation().append("includes").toOSString(),
"includes", // FIXME this is incorrect, the original entry set via extension point is "../includes"
"/usr/gnu/include", // Not converted to OS string due to being flagged as ICSettingEntry.RESOLVED "/usr/gnu/include", // Not converted to OS string due to being flagged as ICSettingEntry.RESOLVED
}; };
} }

View file

@ -1841,11 +1841,10 @@ public class Builder extends HoldsOptions implements IBuilder, IMatchKeyProvider
// } // }
if(!buildPath.isAbsolute()){ if(!buildPath.isAbsolute()){
buildPath = project.getFullPath().append(buildPath);
IStringVariableManager mngr = VariablesPlugin.getDefault().getStringVariableManager(); IStringVariableManager mngr = VariablesPlugin.getDefault().getStringVariableManager();
// build dir may not exist yet and non-existent paths will resolve to empty string by VariablesPlugin
result = buildPath.toString(); // so append relative part outside of expression, i.e. ${workspace_loc:/Project}/BuildDir
result = mngr.generateVariableExpression("workspace_loc", result); //$NON-NLS-1$ result = mngr.generateVariableExpression("workspace_loc", project.getFullPath().toString()) + Path.SEPARATOR + buildPath.toString(); //$NON-NLS-1$
} else { } else {
result = buildPath.toString(); result = buildPath.toString();
} }

View file

@ -148,7 +148,7 @@ public class LanguageSettingsScannerInfoProvider implements IScannerInfoProvider
*/ */
private static IPath getBuildCWD(ICConfigurationDescription cfgDescription) { private static IPath getBuildCWD(ICConfigurationDescription cfgDescription) {
IPath buildCWD = cfgDescription.getBuildSetting().getBuilderCWD(); IPath buildCWD = cfgDescription.getBuildSetting().getBuilderCWD();
if (buildCWD==null) { if (buildCWD == null) {
IProject project = cfgDescription.getProjectDescription().getProject(); IProject project = cfgDescription.getProjectDescription().getProject();
buildCWD = project.getLocation(); buildCWD = project.getLocation();
} else { } else {
@ -178,7 +178,7 @@ public class LanguageSettingsScannerInfoProvider implements IScannerInfoProvider
* Resolve location to file system location in a configuration context. * Resolve location to file system location in a configuration context.
* Resolving includes replacing build/environment variables with values, making relative path absolute etc. * Resolving includes replacing build/environment variables with values, making relative path absolute etc.
* *
* @param location - location to resolve. If relative, it is taken to be rooted in build working directory. * @param location - location to resolve. If relative, it is taken to be rooted in project directory.
* @param cfgDescription - the configuration context. * @param cfgDescription - the configuration context.
* @return resolved file system location. * @return resolved file system location.
*/ */
@ -192,24 +192,35 @@ public class LanguageSettingsScannerInfoProvider implements IScannerInfoProvider
CCorePlugin.log(e); CCorePlugin.log(e);
} }
// use OS file separators (i.e. '\' on Windows) // use OS file separators (i.e. '\' on Windows)
if (java.io.File.separatorChar != '/') { if (java.io.File.separatorChar != IPath.SEPARATOR) {
location = location.replace('/', java.io.File.separatorChar); location = location.replace(IPath.SEPARATOR, java.io.File.separatorChar);
} }
// note that we avoid using org.eclipse.core.runtime.Path for manipulations being careful IPath locPath = new Path(location);
// to preserve "../" segments and not let collapsing them which is not correct for symbolic links. if (locPath.isAbsolute() && locPath.getDevice() == null) {
Path locPath = new Path(location); IPath buildCWD = getBuildCWD(cfgDescription);
if (locPath.isAbsolute() && locPath.getDevice()==null) {
// prepend device (C:) for Windows // prepend device (C:) for Windows
IPath buildCWD = getBuildCWD(cfgDescription);
String device = buildCWD.getDevice(); String device = buildCWD.getDevice();
if (device!=null) if (device != null) {
// note that we avoid using org.eclipse.core.runtime.Path for manipulations being careful
// to preserve "../" segments and not let collapsing them which is not correct for symbolic links.
location = device + location; location = device + location;
}
} }
if (!locPath.isAbsolute()) { if (!locPath.isAbsolute()) {
// consider relative path to be from build working directory ICProjectDescription projectDescription = cfgDescription.getProjectDescription();
IPath buildCWD = getBuildCWD(cfgDescription); if (projectDescription != null) {
location = buildCWD.toOSString() + locPath; IProject project = projectDescription.getProject();
if (project != null) {
IPath projectLocation = project.getLocation();
if (projectLocation != null) {
// again, we avoid using org.eclipse.core.runtime.Path for manipulations being careful
// to preserve "../" segments and not let collapsing them which is not correct for symbolic links.
location = projectLocation.addTrailingSeparator().toOSString() + locPath.toOSString();
}
}
}
} }
return location; return location;
} }
@ -222,7 +233,7 @@ public class LanguageSettingsScannerInfoProvider implements IScannerInfoProvider
* @param cfgDescription - configuration description for resolving entries. * @param cfgDescription - configuration description for resolving entries.
* @return array of the locations. * @return array of the locations.
*/ */
private String[] convertToLocations(LinkedHashSet<ICLanguageSettingEntry> entriesPath, ICConfigurationDescription cfgDescription){ private String[] convertToLocations(LinkedHashSet<ICLanguageSettingEntry> entriesPath, ICConfigurationDescription cfgDescription) {
List<String> locations = new ArrayList<String>(entriesPath.size()); List<String> locations = new ArrayList<String>(entriesPath.size());
for (ICLanguageSettingEntry entry : entriesPath) { for (ICLanguageSettingEntry entry : entriesPath) {
ACPathEntry entryPath = (ACPathEntry)entry; ACPathEntry entryPath = (ACPathEntry)entry;
@ -261,7 +272,7 @@ public class LanguageSettingsScannerInfoProvider implements IScannerInfoProvider
IPath unresolvedPath = entryPath.getLocation(); IPath unresolvedPath = entryPath.getLocation();
if (!unresolvedPath.isAbsolute()) { if (!unresolvedPath.isAbsolute()) {
IPath expandedPath = expandVariables(unresolvedPath, cfgDescription); IPath expandedPath = expandVariables(unresolvedPath, cfgDescription);
if (!expandedPath.isAbsolute()) { if (!expandedPath.isEmpty() && !expandedPath.isAbsolute()) {
locations.add(expandedPath.toOSString()); locations.add(expandedPath.toOSString());
} }
} }