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

Bug 575623 - jsoncdb parser does not support the "arguments" element from the compilation database

Change-Id: I66f7b7261518e24d6f0fba223cd6a2d56e83e0c4
Signed-off-by: Martin Weber <fifteenknots505@gmail.com>
This commit is contained in:
Martin Weber 2021-08-27 19:38:40 +02:00 committed by Marc-Andre Laperle
parent 2d90c17c5b
commit 8b80033025
2 changed files with 19 additions and 4 deletions

View file

@ -12,16 +12,20 @@
package org.eclipse.cdt.jsoncdb.core;
/**
* Represents a parsed command entry of a compile_commands.json file.
* @author weber
* Represents a parsed command entry of a compile_commands.json file.<br>
* See the <a href="https://clang.llvm.org/docs/JSONCompilationDatabase.html">JSON Compilation Database Format Specification</a>.
*
* @author Martin Weber
*/
class CommandEntry {
private String directory;
private String command;
private String[] arguments;
private String file;
/**
* Gets the build directory as a String.
* Gets the working directory of the compilation the build directory as a String.<br>
* The specification states: All paths specified in the command or file fields must be either absolute or relative to this directory.
*/
public String getDirectory() {
return directory;
@ -34,6 +38,14 @@ class CommandEntry {
return command;
}
/**
* Gets the command-line to compile the source file split up into arguments.<br>
* Either {@link #getCommand()} or {@link #getArguments()} will return a non-null value.
*/
public String[] getArguments() {
return arguments;
}
/**
* Gets the source file path as a String.
*/

View file

@ -211,7 +211,10 @@ public class CompileCommandsJsonParser {
// NOTE that this is the absolute file system path of the source file in
// CMake-notation (directory separator are forward slashes, even on windows)
final String file = sourceFileInfo.getFile();
final String cmdLine = sourceFileInfo.getCommand();
String cmdLine = sourceFileInfo.getCommand();
if (cmdLine == null) {
cmdLine = String.join(" ", sourceFileInfo.getArguments()); //$NON-NLS-1$
}
if (file != null && !file.isEmpty() && cmdLine != null && !cmdLine.isEmpty()) {
ParserDetection.ParserDetectionResult pdr = fastDetermineDetector(cmdLine);
if (pdr != null) {