From 8b8003302557999e8d62adb8360bf35d490f6da4 Mon Sep 17 00:00:00 2001 From: Martin Weber Date: Fri, 27 Aug 2021 19:38:40 +0200 Subject: [PATCH] Bug 575623 - jsoncdb parser does not support the "arguments" element from the compilation database Change-Id: I66f7b7261518e24d6f0fba223cd6a2d56e83e0c4 Signed-off-by: Martin Weber --- .../eclipse/cdt/jsoncdb/core/CommandEntry.java | 18 +++++++++++++++--- .../core/CompileCommandsJsonParser.java | 5 ++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/jsoncdb/org.eclipse.cdt.jsoncdb.core/src/org/eclipse/cdt/jsoncdb/core/CommandEntry.java b/jsoncdb/org.eclipse.cdt.jsoncdb.core/src/org/eclipse/cdt/jsoncdb/core/CommandEntry.java index 78da5aa0a3b..f24b76e732a 100644 --- a/jsoncdb/org.eclipse.cdt.jsoncdb.core/src/org/eclipse/cdt/jsoncdb/core/CommandEntry.java +++ b/jsoncdb/org.eclipse.cdt.jsoncdb.core/src/org/eclipse/cdt/jsoncdb/core/CommandEntry.java @@ -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.
+ * See the JSON Compilation Database Format Specification. + * + * @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.
+ * 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.
+ * 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. */ diff --git a/jsoncdb/org.eclipse.cdt.jsoncdb.core/src/org/eclipse/cdt/jsoncdb/core/CompileCommandsJsonParser.java b/jsoncdb/org.eclipse.cdt.jsoncdb.core/src/org/eclipse/cdt/jsoncdb/core/CompileCommandsJsonParser.java index 95a36778eef..9be7d1f79d4 100644 --- a/jsoncdb/org.eclipse.cdt.jsoncdb.core/src/org/eclipse/cdt/jsoncdb/core/CompileCommandsJsonParser.java +++ b/jsoncdb/org.eclipse.cdt.jsoncdb.core/src/org/eclipse/cdt/jsoncdb/core/CompileCommandsJsonParser.java @@ -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) {