From: Viljar Indus <in...@adacore.com> 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. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/diagnostics-sarif_emitter.adb | 7 +++++-- gcc/ada/osint.adb | 22 ++++++++++++++++++---- gcc/ada/osint.ads | 5 +++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/gcc/ada/diagnostics-sarif_emitter.adb b/gcc/ada/diagnostics-sarif_emitter.adb index bae2dc0a88e..d7f92343701 100644 --- a/gcc/ada/diagnostics-sarif_emitter.adb +++ b/gcc/ada/diagnostics-sarif_emitter.adb @@ -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; diff --git a/gcc/ada/osint.adb b/gcc/ada/osint.adb index 46334aa97af..26b0dbb1ae4 100644 --- a/gcc/ada/osint.adb +++ b/gcc/ada/osint.adb @@ -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 diff --git a/gcc/ada/osint.ads b/gcc/ada/osint.ads index 5dbbfd8fd7f..77aaf04a771 100644 --- a/gcc/ada/osint.ads +++ b/gcc/ada/osint.ads @@ -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; -- 2.43.0