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

bug 404125: Build output parser incorrectly handles compile lines compiling files outside of the workspace

This commit is contained in:
Andrew Gvozdev 2013-03-24 08:09:28 -04:00
parent 1e2973a031
commit 4f3ad71e87
3 changed files with 64 additions and 19 deletions

View file

@ -2043,30 +2043,73 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
* Test assigning entries for global provider.
*/
public void testEntriesProjectLevelGlobalProvider() throws Exception {
// Create model project and accompanied descriptions
String projectName = getName();
IProject project = ResourceHelper.createCDTProjectWithConfig(projectName);
ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project);
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
IFile file=ResourceHelper.createFile(project, "file.cpp");
ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true);
String languageId = ls.getLanguageId();
// create GCCBuildCommandParser
ILanguageSettingsProvider wspProvider = LanguageSettingsManager.getWorkspaceProvider(GCC_BUILD_COMMAND_PARSER_EXT);
GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getRawProvider(wspProvider);
parser.setResourceScope(AbstractBuildCommandParser.ResourceScope.PROJECT);
parser.clear();
// parse line
parser.startup(cfgDescription, null);
parser.startup(null, null);
parser.processLine("gcc -I/path0 file.cpp");
parser.shutdown();
// check populated entries
List<ICLanguageSettingEntry> expected = new ArrayList<ICLanguageSettingEntry>();
expected.add(new CIncludePathEntry("/path0", 0));
assertEquals(expected, parser.getSettingEntries(null, project, languageId));
assertEquals(expected, parser.getSettingEntries(null, null, LANG_CPP));
}
/**
* Parsing of file being compiled outside of workspace saving entries at project scope.
*/
public void testFileAbsolutePath_ProjectLevel() throws Exception {
// Create model project and accompanied descriptions
String projectName = getName();
IProject project = ResourceHelper.createCDTProjectWithConfig(projectName);
IFile file=ResourceHelper.createFile(project, "file.cpp");
ICConfigurationDescription[] cfgDescriptions = getConfigurationDescriptions(project);
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
ICLanguageSetting ls = cfgDescription.getLanguageSettingForFile(file.getProjectRelativePath(), true);
String languageId = ls.getLanguageId();
// create GCCBuildCommandParser
GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getExtensionProviderCopy(GCC_BUILD_COMMAND_PARSER_EXT, true);
parser.setResourceScope(AbstractBuildCommandParser.ResourceScope.PROJECT);
// parse line
parser.startup(cfgDescription, null);
parser.processLine("gcc "
+ "-I/path0 "
+ "/absolute/path/file.cpp");
parser.shutdown();
// check entries
List<ICLanguageSettingEntry> entries = parser.getSettingEntries(cfgDescription, project, languageId);
assertEquals(new CIncludePathEntry("/path0", 0), entries.get(0));
}
/**
* Parsing of file being compiled outside of workspace saving entries at project scope.
*/
public void testFileAbsolutePath_ProjectLevelGlobalProvider() throws Exception {
// create GCCBuildCommandParser
ILanguageSettingsProvider wspProvider = LanguageSettingsManager.getWorkspaceProvider(GCC_BUILD_COMMAND_PARSER_EXT);
GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getRawProvider(wspProvider);
parser.setResourceScope(AbstractBuildCommandParser.ResourceScope.PROJECT);
parser.clear();
// parse line
parser.startup(null, null);
parser.processLine("gcc "
+ "-I/path0 "
+ "/absolute/path/file.cpp");
parser.shutdown();
// check entries
List<ICLanguageSettingEntry> entries = parser.getSettingEntries(null, null, LANG_CPP);
assertEquals(new CIncludePathEntry("/path0", 0), entries.get(0));
}
}

View file

@ -164,9 +164,7 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting
}
break;
case PROJECT:
if (currentResource != null) {
rc = currentResource.getProject();
}
rc = currentProject;
break;
default:
break;
@ -215,7 +213,7 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting
@Override
protected List<String> parseOptions(String line) {
if (line == null || currentResource == null) {
if (line == null || (currentResource == null && resourceScope != ResourceScope.PROJECT)) {
return null;
}

View file

@ -460,9 +460,13 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
if (optionParser.parseOption(option)) {
ICLanguageSettingEntry entry = null;
if (isResolvingPaths && (optionParser.isForFile() || optionParser.isForFolder())) {
URI baseURI = mappedRootURI;
if (buildDirURI != null && !new Path(optionParser.parsedName).isAbsolute()) {
baseURI = efsProvider.append(mappedRootURI, buildDirURI.getPath());
URI baseURI = buildDirURI;
if (mappedRootURI != null) {
if (buildDirURI != null && !new Path(optionParser.parsedName).isAbsolute()) {
baseURI = efsProvider.append(mappedRootURI, buildDirURI.getPath());
} else {
baseURI = mappedRootURI;
}
}
entry = createResolvedPathEntry(optionParser, optionParser.parsedName, 0, baseURI);
} else {