From: Viljar Indus <[email protected]>

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.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/errout.adb |  4 ++--
 gcc/ada/osint.adb  | 17 +++++++++++++++++
 gcc/ada/osint.ads  |  4 ++++
 3 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb
index c29375d77b6..eed926f692e 100644
--- a/gcc/ada/errout.adb
+++ b/gcc/ada/errout.adb
@@ -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;
 
diff --git a/gcc/ada/osint.adb b/gcc/ada/osint.adb
index 1e467e681c5..c4ca08dc320 100644
--- a/gcc/ada/osint.adb
+++ b/gcc/ada/osint.adb
@@ -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 --
    ------------------
diff --git a/gcc/ada/osint.ads b/gcc/ada/osint.ads
index 9cda79de7ef..21c39ad562d 100644
--- a/gcc/ada/osint.ads
+++ b/gcc/ada/osint.ads
@@ -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.
-- 
2.53.0

Reply via email to