aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorViljar Indus <indus@adacore.com>2024-10-11 16:34:36 +0300
committerMarc Poulhiès <dkm@gcc.gnu.org>2024-11-04 16:57:57 +0100
commite6d88c002305f4840d4add9316e551c5ae04333d (patch)
treefbffdc87b53fbe273d96bb1e2a540114718b87d6
parent8314fdc7f352c2cd90fe0bfd6a87af48807bf65c (diff)
downloadgcc-e6d88c002305f4840d4add9316e551c5ae04333d.zip
gcc-e6d88c002305f4840d4add9316e551c5ae04333d.tar.gz
gcc-e6d88c002305f4840d4add9316e551c5ae04333d.tar.bz2
ada: Add Invocation node to the SARIF report
Add an invocation node to the SARIF report that contains the command line use to activate gnat and whether the execution was successful or not. gcc/ada/ChangeLog: * diagnostics-sarif_emitter.adb (Print_Runs): Add printing for the invocation node that consists of a single invocations that is composed of the commandLine and executionSuccessful attributes.
-rw-r--r--gcc/ada/diagnostics-sarif_emitter.adb81
1 files changed, 80 insertions, 1 deletions
diff --git a/gcc/ada/diagnostics-sarif_emitter.adb b/gcc/ada/diagnostics-sarif_emitter.adb
index fe251f9..b6035c2 100644
--- a/gcc/ada/diagnostics-sarif_emitter.adb
+++ b/gcc/ada/diagnostics-sarif_emitter.adb
@@ -28,6 +28,10 @@ with Diagnostics.JSON_Utils; use Diagnostics.JSON_Utils;
with Gnatvsn; use Gnatvsn;
with Output; use Output;
with Sinput; use Sinput;
+with Lib; use Lib;
+with Namet; use Namet;
+with Osint; use Osint;
+with Errout; use Errout;
package body Diagnostics.SARIF_Emitter is
@@ -94,6 +98,19 @@ package body Diagnostics.SARIF_Emitter is
-- ...
-- ]
+ procedure Print_Invocations;
+ -- Print an invocations node that consists of
+ -- * a single invocation node that consists of:
+ -- * commandLine
+ -- * executionSuccessful
+ --
+ -- "invocations": [
+ -- {
+ -- "commandLine": <command line arguments provided to the GNAT FE>,
+ -- "executionSuccessful": ["true"|"false"],
+ -- }
+ -- ]
+
procedure Print_Artifact_Change (A : Artifact_Change);
-- Print an ArtifactChange node
--
@@ -573,6 +590,63 @@ package body Diagnostics.SARIF_Emitter is
Write_Char (']');
end Print_Fixes;
+ -----------------------
+ -- Print_Invocations --
+ -----------------------
+
+ procedure Print_Invocations is
+
+ function Compose_Command_Line return String;
+ -- Composes the original command line from the parsed main file name and
+ -- relevant compilation switches
+
+ function Compose_Command_Line return String is
+ Buffer : Bounded_String;
+ begin
+ Append (Buffer, Get_First_Main_File_Name);
+ for I in 1 .. Compilation_Switches_Last loop
+ declare
+ Switch : constant String := Get_Compilation_Switch (I).all;
+ begin
+ if Buffer.Length + Switch'Length + 1 <= Buffer.Max_Length then
+ Append (Buffer, ' ' & Switch);
+ end if;
+ end;
+ end loop;
+
+ return +Buffer;
+ end Compose_Command_Line;
+
+ begin
+ Write_Str ("""" & "invocations" & """" & ": " & "[");
+ Begin_Block;
+ NL_And_Indent;
+
+ Write_Char ('{');
+ Begin_Block;
+ NL_And_Indent;
+
+ -- Print commandLine
+
+ Write_String_Attribute ("commandLine", Compose_Command_Line);
+ Write_Char (',');
+ NL_And_Indent;
+
+ -- Print executionSuccessful
+
+ Write_String_Attribute
+ ("executionSuccessful",
+ (if Compilation_Errors then "false" else "true"));
+
+ End_Block;
+ NL_And_Indent;
+ Write_Char ('}');
+
+ End_Block;
+ NL_And_Indent;
+ Write_Char (']');
+ end Print_Invocations;
+
------------------
-- Print_Region --
------------------
@@ -1052,6 +1126,12 @@ package body Diagnostics.SARIF_Emitter is
Write_Char (',');
NL_And_Indent;
+ -- A run consists of an invocation
+ Print_Invocations;
+
+ Write_Char (',');
+ NL_And_Indent;
+
-- A run consists of results
Print_Results (Diags);
@@ -1076,7 +1156,6 @@ package body Diagnostics.SARIF_Emitter is
------------------------
procedure Print_SARIF_Report (Diags : Diagnostic_List) is
-
begin
Write_Char ('{');
Begin_Block;