From: Viljar Indus Date: Wed, 25 Feb 2026 12:29:46 +0000 (+0200) Subject: ada: Create the SARIF file in the current cwd X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3a2f48a243fdd73c63af196a9c186cd7abe4b96d;p=thirdparty%2Fgcc.git 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. ".gnat.sarif" Now the SARIF file is always generated in the cwd ".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 --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.