https://gcc.gnu.org/g:3a2f48a243fdd73c63af196a9c186cd7abe4b96d
commit r17-873-g3a2f48a243fdd73c63af196a9c186cd7abe4b96d Author: Viljar Indus <[email protected]> Date: Wed Feb 25 14:29:46 2026 +0200 ada: Create the SARIF file in the current cwd 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. Diff: --- 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 c29375d77b64..eed926f692e4 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 1e467e681c5a..c4ca08dc3208 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 9cda79de7efb..21c39ad562dd 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.
