diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/CompilationDatabaseParserTest.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/CompilationDatabaseParserTest.java index 09877e1ae60..3e77a2bfda7 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/CompilationDatabaseParserTest.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/CompilationDatabaseParserTest.java @@ -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(); diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/language/settings/providers/CompilationDatabaseParser.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/language/settings/providers/CompilationDatabaseParser.java index 3bc795e6399..008b05e9c11 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/language/settings/providers/CompilationDatabaseParser.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/language/settings/providers/CompilationDatabaseParser.java @@ -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(); diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/language/settings/providers/CompileCommand.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/language/settings/providers/CompileCommand.java index 3675d94dc07..fa58863dee4 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/language/settings/providers/CompileCommand.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/language/settings/providers/CompileCommand.java @@ -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; + } }