1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-21 21:52:10 +02:00

Bug 563006 - CDB settings provider/parser doesn't support "arguments"

One flaw with this implementation is that the "arguments" coming from
the CDB do not have shell quoting and shell escaping of quotes whereas
the current implementations of Build Output parsers assume some form of
shell quoting. This means that simply joining strings of arguments with
spaces will be missing the expected shell quoting and possibly misparsed
by the build output parsers.
It is not clear to be at this point if this should be fixed or not as it
might involve revamping the existing build output parsers to add the
concept of shell/environment and this could also affect potential
extenders.

In this current form, simple cases with no spacing and quote escaping
involved work correctly and is still a nice improvement.

Change-Id: Ia81796e63c748318b34696998ac4a467712e5f96
Signed-off-by: Marc-Andre Laperle <malaperle@gmail.com>
This commit is contained in:
Marc-Andre Laperle 2020-05-10 15:11:11 -04:00 committed by Marc-André Laperle
parent 063301deca
commit d017917f35
3 changed files with 55 additions and 3 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 Marc-Andre Laperle.
* Copyright (c) 2019, 2020 Marc-Andre Laperle.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@ -88,11 +88,17 @@ public class CompilationDatabaseParserTest extends BaseTestCase {
}
private void createTestProject() throws Exception {
createTestProject(true, true, true, true, true);
createTestProject(true, true, true, true, true, false);
}
private void createTestProject(boolean useAbsoluteSourcePath, boolean haveCommandDir, boolean validCommandDir,
boolean haveCommandLine, boolean validCommandLine) throws Exception {
createTestProject(useAbsoluteSourcePath, haveCommandDir, validCommandDir, haveCommandLine, validCommandLine,
false);
}
private void createTestProject(boolean useAbsoluteSourcePath, boolean haveCommandDir, boolean validCommandDir,
boolean haveCommandLine, boolean validCommandLine, boolean haveCommandArguments) throws Exception {
fProject = ResourceHelper.createCDTProjectWithConfig(getName());
fFolder = ResourceHelper.createFolder(fProject, "folder");
@ -140,6 +146,10 @@ public class CompilationDatabaseParserTest extends BaseTestCase {
else
command.command = "foo";
}
if (haveCommandArguments) {
command.arguments = new String[] { "g++", "-I" + fFolder.getLocation().toOSString(), "-DFOO=2",
sourceFilePath };
}
// Command for proj/test.cpp
CompileCommand command2 = new CompileCommand();
@ -162,6 +172,11 @@ public class CompilationDatabaseParserTest extends BaseTestCase {
command2.command = "foo";
}
if (haveCommandArguments) {
command2.arguments = new String[] { "g++", "-I" + fFolder.getLocation().toOSString(), "-DFOO=3",
sourceFilePath2 };
}
CompileCommand[] commands = new CompileCommand[2];
commands[0] = command;
commands[1] = command2;
@ -820,6 +835,34 @@ public class CompilationDatabaseParserTest extends BaseTestCase {
assertFalse(CDataUtil.isExcluded(tu.getPath(), resCfgDescription.getSourceEntries()));
}
public void testParseCDB_CommandArguments() throws Exception {
createTestProject(true, true, true, false, false, true);
ICProject cProject = CCorePlugin.getDefault().getCoreModel().create(fProject);
ICElement ce = CCorePlugin.getDefault().getCoreModel().create(fOutsideCdbSourceFile.getFullPath());
ITranslationUnit tu = (ITranslationUnit) ce;
assertFalse(
CDataUtil.isExcluded(tu.getPath(), getConfigurationDescription(fProject, false).getSourceEntries()));
CompilationDatabaseParser parser = (CompilationDatabaseParser) LanguageSettingsManager
.getExtensionProviderCopy(COMPILATION_DATABASE_PARSER_EXT, true);
assertTrue(parser.isEmpty());
parser.setBuildParserId(GCC_BUILD_COMMAND_PARSER_EXT);
parser.setCompilationDataBasePathProperty(fCdbFile.getLocation().toOSString());
addLanguageSettingsProvider(parser);
ICConfigurationDescription cfgDescription = getConfigurationDescription(fProject, true);
parser.processCompileCommandsFile(null, cfgDescription);
CoreModel.getDefault().setProjectDescription(cfgDescription.getProjectDescription().getProject(),
cfgDescription.getProjectDescription());
joingLanguageSettingsJobs();
assertExpectedEntries(parser);
ICConfigurationDescription resCfgDescription = getConfigurationDescription(fProject, false);
}
public void testClear() throws Exception {
createTestProject();

View file

@ -308,7 +308,12 @@ public class CompilationDatabaseParser extends LanguageSettingsSerializableProvi
}
}
outputParser.processLine(c.getCommand());
String command = c.getCommand();
if (command != null) {
outputParser.processLine(command);
} else if (c.getArguments() != null) {
outputParser.processLine(String.join(" ", c.getArguments())); //$NON-NLS-1$
}
parseCmdsMonitor.worked(1);
}
LanguageSettingsStorage storage = outputParser.copyStorage();

View file

@ -18,6 +18,7 @@ public class CompileCommand {
public String directory;
public String command;
public String file;
public String[] arguments;
public String getDirectory() {
return directory;
@ -31,4 +32,7 @@ public class CompileCommand {
return file;
}
public String[] getArguments() {
return arguments;
}
}