]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix various issues in the SARIF report
authorViljar Indus <indus@adacore.com>
Mon, 20 Jan 2025 18:04:59 +0000 (20:04 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 5 Jun 2025 08:18:35 +0000 (10:18 +0200)
gcc/ada/ChangeLog:

* diagnostics-sarif_emitter.adb (Print_Invocations): fix
commandLine and executionSuccessful nodes.
Fix typo in the name for startLine.
* osint.adb (Modified Get_Current_Dir) Fix generation of
the current directory.
(Relative_Path): Avoid relative paths starting with a
path separator.
* osint.ads: Update the documentation for Relative_Path.

gcc/ada/diagnostics-sarif_emitter.adb
gcc/ada/osint.adb
gcc/ada/osint.ads

index bae2dc0a88e6aebe5139d6a8c07fd3899038a436..d7f923437012640545c7bd3c126c3666d8ef680d 100644 (file)
@@ -66,7 +66,7 @@ package body Diagnostics.SARIF_Emitter is
    N_RUNS                  : constant String := "runs";
    N_SCHEMA                : constant String := "$schema";
    N_START_COLUMN          : constant String := "startColumn";
-   N_START_LINE            : constant String := "strartLine";
+   N_START_LINE            : constant String := "startLine";
    N_TEXT                  : constant String := "text";
    N_TOOL                  : constant String := "tool";
    N_URI                   : constant String := "uri";
@@ -687,6 +687,9 @@ package body Diagnostics.SARIF_Emitter is
       function Compose_Command_Line return String is
          Buffer : Bounded_String;
       begin
+         Find_Program_Name;
+         Append (Buffer, Name_Buffer (1 .. Name_Len));
+         Append (Buffer, ' ');
          Append (Buffer, Get_First_Main_File_Name);
          for I in 1 .. Compilation_Switches_Last loop
             declare
@@ -718,7 +721,7 @@ package body Diagnostics.SARIF_Emitter is
 
       --  Print executionSuccessful
 
-      Write_Boolean_Attribute (N_EXECUTION_SUCCESSFUL, Compilation_Errors);
+      Write_Boolean_Attribute (N_EXECUTION_SUCCESSFUL, not Compilation_Errors);
 
       End_Block;
       NL_And_Indent;
index 46334aa97af1ca8dda211e62f4e5a2815a228362..26b0dbb1ae462fabdf2b4bb81ccc1ef0f79366d0 100644 (file)
@@ -1439,11 +1439,17 @@ package body Osint is
    ---------------------
 
    function Get_Current_Dir return String is
-      Current_Dir : String (1 .. Max_Path + 1);
-      Last        : Natural;
+      Path_Len : Natural := Max_Path;
+      Buffer   : String (1 .. 1 + Max_Path + 1);
+
    begin
-      Get_Current_Dir (Current_Dir'Address, Last'Address);
-      return Current_Dir (1 .. Last);
+      Get_Current_Dir (Buffer'Address, Path_Len'Address);
+
+      if Path_Len = 0 then
+         raise Program_Error;
+      end if;
+
+      return Buffer (1 .. Path_Len);
    end Get_Current_Dir;
 
    -------------------
@@ -2801,6 +2807,14 @@ package body Osint is
          Append (Rel_Path, ".." & System.OS_Lib.Directory_Separator);
       end loop;
 
+      --  Avoid starting the relative path with a directory separator
+
+      if Last < Norm_Path'Length
+        and then Is_Directory_Separator (Norm_Path (Norm_Path'First + Last))
+      then
+         Last := Last + 1;
+      end if;
+
       --  Add the rest of the path from the common point
 
       Append
index 5dbbfd8fd7ff1feb9f3be284d23365c8dbaa3986..77aaf04a77127655fe45a7a972d65e3a255de45c 100644 (file)
@@ -236,6 +236,11 @@ package Osint is
    function Relative_Path (Path : String; Ref : String) return String;
    --  Given an absolute path Path calculate its relative path from a reference
    --  directory Ref.
+   --
+   --  If the paths are the same it will return ".".
+   --
+   --  If the paths are on different drives on Windows based systems then it
+   --  will return the normalized version of Path.
 
    function Relocate_Path
      (Prefix : String;