]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Create the SARIF file in the current cwd
authorViljar Indus <indus@adacore.com>
Wed, 25 Feb 2026 12:29:46 +0000 (14:29 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 28 May 2026 08:52:48 +0000 (10:52 +0200)
Previously we used to create the SARIF file next to the specified
source file e.g. "<Specified_Source_File_Path>.gnat.sarif"

Now the SARIF file is always generated in the cwd
"<Source_File_Name>.gnat.sarif" similarly to how gcc handles its sarif
files.

gcc/ada/ChangeLog:

* errout.adb (Output_Messages): use the source file name without
the directory path when constructing the name of the SARIF file.
* osint.adb (Strip_Directory): New method for extracting the file name
from a given path.
* osint.ads (Strip_Directory): Likewise.

gcc/ada/errout.adb
gcc/ada/osint.adb
gcc/ada/osint.ads

index c29375d77b6449a25b4622e72b019d5df8a31148..eed926f692e470182d6bce4e08a34f295ec2bc58 100644 (file)
@@ -2950,8 +2950,8 @@ package body Errout is
       E          : Error_Msg_Id;
       Err_Flag   : Boolean;
 
-      Sarif_File_Name       : constant String :=
-        Get_First_Main_File_Name & ".gnat.sarif";
+      Sarif_File_Name : constant String :=
+        Strip_Directory (Get_First_Main_File_Name) & ".gnat.sarif";
 
       Printer : Erroutc.SARIF_Emitter.SARIF_Printer;
 
index 1e467e681c5a10b580c5a7fcfa5484aba15e9229..c4ca08dc32084311d48aa1e02ea5bd589421767a 100644 (file)
@@ -3048,6 +3048,23 @@ package body Osint is
       return Name;
    end Strip_Directory;
 
+   ---------------------
+   -- Strip_Directory --
+   ---------------------
+
+   function Strip_Directory (Name : String) return String is
+   begin
+      pragma Assert (not Is_Directory_Separator (Name (Name'Last)));
+
+      for I in reverse Name'Range loop
+         if Is_Directory_Separator (Name (I)) then
+            return Name (I + 1 .. Name'Last);
+         end if;
+      end loop;
+
+      return Name;
+   end Strip_Directory;
+
    ------------------
    -- Strip_Suffix --
    ------------------
index 9cda79de7efb5d0da964c320d465825172944607..21c39ad562dd01ac1de5da1c9742d728985339f6 100644 (file)
@@ -181,6 +181,10 @@ package Osint is
    --  Strips the prefix directory name (if any) from Name. Returns the
    --  stripped name. Name cannot end with a directory separator.
 
+   function Strip_Directory (Name : String) return String;
+   --  Strips the prefix directory name (if any) from Name. Returns the
+   --  stripped name. Name cannot end with a directory separator.
+
    function Strip_Suffix (Name : File_Name_Type) return File_Name_Type;
    --  Strips the suffix (the last '.' and whatever comes after it) from Name.
    --  Returns the stripped name.