mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-30 20:35:38 +02:00
bug 404125: Build output parser incorrectly handles compile lines compiling files outside of the workspace
This commit is contained in:
parent
1e2973a031
commit
4f3ad71e87
3 changed files with 64 additions and 19 deletions
|
@ -2043,30 +2043,73 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
|
||||||
* Test assigning entries for global provider.
|
* Test assigning entries for global provider.
|
||||||
*/
|
*/
|
||||||
public void testEntriesProjectLevelGlobalProvider() throws Exception {
|
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
|
// create GCCBuildCommandParser
|
||||||
ILanguageSettingsProvider wspProvider = LanguageSettingsManager.getWorkspaceProvider(GCC_BUILD_COMMAND_PARSER_EXT);
|
ILanguageSettingsProvider wspProvider = LanguageSettingsManager.getWorkspaceProvider(GCC_BUILD_COMMAND_PARSER_EXT);
|
||||||
GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getRawProvider(wspProvider);
|
GCCBuildCommandParser parser = (GCCBuildCommandParser) LanguageSettingsManager.getRawProvider(wspProvider);
|
||||||
parser.setResourceScope(AbstractBuildCommandParser.ResourceScope.PROJECT);
|
parser.setResourceScope(AbstractBuildCommandParser.ResourceScope.PROJECT);
|
||||||
|
parser.clear();
|
||||||
|
|
||||||
// parse line
|
// parse line
|
||||||
parser.startup(cfgDescription, null);
|
parser.startup(null, null);
|
||||||
parser.processLine("gcc -I/path0 file.cpp");
|
parser.processLine("gcc -I/path0 file.cpp");
|
||||||
parser.shutdown();
|
parser.shutdown();
|
||||||
|
|
||||||
// check populated entries
|
// check populated entries
|
||||||
List<ICLanguageSettingEntry> expected = new ArrayList<ICLanguageSettingEntry>();
|
List<ICLanguageSettingEntry> expected = new ArrayList<ICLanguageSettingEntry>();
|
||||||
expected.add(new CIncludePathEntry("/path0", 0));
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,9 +164,7 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PROJECT:
|
case PROJECT:
|
||||||
if (currentResource != null) {
|
rc = currentProject;
|
||||||
rc = currentResource.getProject();
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -215,7 +213,7 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<String> parseOptions(String line) {
|
protected List<String> parseOptions(String line) {
|
||||||
if (line == null || currentResource == null) {
|
if (line == null || (currentResource == null && resourceScope != ResourceScope.PROJECT)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -460,9 +460,13 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
|
||||||
if (optionParser.parseOption(option)) {
|
if (optionParser.parseOption(option)) {
|
||||||
ICLanguageSettingEntry entry = null;
|
ICLanguageSettingEntry entry = null;
|
||||||
if (isResolvingPaths && (optionParser.isForFile() || optionParser.isForFolder())) {
|
if (isResolvingPaths && (optionParser.isForFile() || optionParser.isForFolder())) {
|
||||||
URI baseURI = mappedRootURI;
|
URI baseURI = buildDirURI;
|
||||||
if (buildDirURI != null && !new Path(optionParser.parsedName).isAbsolute()) {
|
if (mappedRootURI != null) {
|
||||||
baseURI = efsProvider.append(mappedRootURI, buildDirURI.getPath());
|
if (buildDirURI != null && !new Path(optionParser.parsedName).isAbsolute()) {
|
||||||
|
baseURI = efsProvider.append(mappedRootURI, buildDirURI.getPath());
|
||||||
|
} else {
|
||||||
|
baseURI = mappedRootURI;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
entry = createResolvedPathEntry(optionParser, optionParser.parsedName, 0, baseURI);
|
entry = createResolvedPathEntry(optionParser, optionParser.parsedName, 0, baseURI);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue