]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Enable using absolute paths in -fdiagnostics-format=json output
authorGhjuvan Lacambre <lacambre@adacore.com>
Fri, 6 May 2022 16:53:57 +0000 (18:53 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Wed, 1 Jun 2022 08:43:19 +0000 (08:43 +0000)
This commit makes GNAT use absolute paths in -fdiagnostics-format=json's
output when -gnatef is present on the command line. This makes life
easier for tools that ingest GNAT's output.

gcc/ada/

* doc/gnat_ugn/building_executable_programs_with_gnat.rst:
Document new behavior.
* errout.adb (Write_JSON_Location): Output absolute paths when
needed.
* switch-c.adb (Scan_Front_End_Switches): Update -gnatef
comment.
* usage.adb (Usage): Update description of -gnatef.
* gnat_ugn.texi: Regenerate.

gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst
gcc/ada/errout.adb
gcc/ada/gnat_ugn.texi
gcc/ada/switch-c.adb
gcc/ada/usage.adb

index ed6b463efdeb34d83f9a689bfbeca163b4848477..29293e1f847f029a8b1c660fc503d4ce9971546b 100644 (file)
@@ -1238,7 +1238,8 @@ Alphabetical List of All Switches
 :switch:`-fdiagnostics-format=json`
   Makes GNAT emit warning and error messages as JSON. Inhibits printing of
   text warning and errors messages except if :switch:`-gnatv` or
-  :switch:`-gnatl` are present.
+  :switch:`-gnatl` are present. Uses absolute file paths when used along
+  :switch:`-gnatef`.
 
 
 .. index:: -fdump-scos  (gcc)
@@ -1582,7 +1583,8 @@ Alphabetical List of All Switches
 .. index:: -gnatef  (gcc)
 
 :switch:`-gnatef`
-  Display full source path name in brief error messages.
+  Display full source path name in brief error messages and absolute paths in
+  :switch:`-fdiagnostics-format=json`'s output.
 
 
 .. index:: -gnateF  (gcc)
index 8658c38d559db8b629ac3c224bc6815bf2397d5d..e3aa0ed6304c615e91fae32c4804520173489cc8 100644 (file)
@@ -51,6 +51,7 @@ with Sinfo.Utils;    use Sinfo.Utils;
 with Snames;         use Snames;
 with Stand;          use Stand;
 with Stylesw;        use Stylesw;
+with System.OS_Lib;
 with Uname;          use Uname;
 
 package body Errout is
@@ -2082,6 +2083,7 @@ package body Errout is
       --  Return True if E is a continuation message.
 
       procedure Write_JSON_Escaped_String (Str : String_Ptr);
+      procedure Write_JSON_Escaped_String (Str : String);
       --  Write each character of Str, taking care of preceding each quote and
       --  backslash with a backslash. Note that this escaping differs from what
       --  GCC does.
@@ -2114,9 +2116,9 @@ package body Errout is
       -- Write_JSON_Escaped_String --
       -------------------------------
 
-      procedure Write_JSON_Escaped_String (Str : String_Ptr) is
+      procedure Write_JSON_Escaped_String (Str : String) is
       begin
-         for C of Str.all loop
+         for C of Str loop
             if C = '"' or else C = '\' then
                Write_Char ('\');
             end if;
@@ -2125,14 +2127,30 @@ package body Errout is
          end loop;
       end Write_JSON_Escaped_String;
 
+      -------------------------------
+      -- Write_JSON_Escaped_String --
+      -------------------------------
+
+      procedure Write_JSON_Escaped_String (Str : String_Ptr) is
+      begin
+         Write_JSON_Escaped_String (Str.all);
+      end Write_JSON_Escaped_String;
+
       -------------------------
       -- Write_JSON_Location --
       -------------------------
 
       procedure Write_JSON_Location (Sptr : Source_Ptr) is
+         Name : constant File_Name_Type :=
+           Full_Ref_Name (Get_Source_File_Index (Sptr));
       begin
          Write_Str ("{""file"":""");
-         Write_Name (Full_Ref_Name (Get_Source_File_Index (Sptr)));
+         if Full_Path_Name_For_Brief_Errors then
+            Write_JSON_Escaped_String
+              (System.OS_Lib.Normalize_Pathname (Get_Name_String (Name)));
+         else
+            Write_Name (Name);
+         end if;
          Write_Str (""",""line"":");
          Write_Int (Pos (Get_Physical_Line_Number (Sptr)));
          Write_Str (", ""column"":");
index 1664c4912e0302adbc3fa9c1f9329d8bab676159..a2a2990b6d766cc68ab84bf697e8d86f91c42283 100644 (file)
@@ -21,7 +21,7 @@
 
 @copying
 @quotation
-GNAT User's Guide for Native Platforms , Apr 22, 2022
+GNAT User's Guide for Native Platforms , May 24, 2022
 
 AdaCore
 
@@ -8552,7 +8552,8 @@ dynamically allocated objects.
 
 Makes GNAT emit warning and error messages as JSON. Inhibits printing of
 text warning and errors messages except if @code{-gnatv} or
-@code{-gnatl} are present.
+@code{-gnatl} are present. Uses absolute file paths when used along
+@code{-gnatef}.
 @end table
 
 @geindex -fdump-scos (gcc)
@@ -9037,7 +9038,8 @@ produced at run time.
 
 @item @code{-gnatef}
 
-Display full source path name in brief error messages.
+Display full source path name in brief error messages and absolute paths in
+@code{-fdiagnostics-format=json}’s output.
 @end table
 
 @geindex -gnateF (gcc)
@@ -29247,8 +29249,8 @@ to permit their use in free software.
 
 @printindex ge
 
-@anchor{cf}@w{                              }
 @anchor{gnat_ugn/gnat_utility_programs switches-related-to-project-files}@w{                              }
+@anchor{cf}@w{                              }
 
 @c %**end of body
 @bye
index 522cdf658edf15578b6a9478d0df6264db2833ab..feac8bdaff58893bf0cea74170d61897b33f9b33 100644 (file)
@@ -603,7 +603,8 @@ package body Switch.C is
                      Exception_Extra_Info := True;
                      Ptr := Ptr + 1;
 
-                  --  -gnatef (full source path for brief error messages)
+                  --  -gnatef (full source path for brief error messages and
+                  --  absolute paths for -fdiagnostics-format=json)
 
                   when 'f' =>
                      Store_Switch := False;
index a3d59b60e1b8bf0d3f6c1ec18bfcf3fe18329b86..7d11ae536968d631bbac88328845c4ab39c2ae29 100644 (file)
@@ -187,7 +187,7 @@ begin
    --  Line for -gnatef switch
 
    Write_Switch_Char ("ef");
-   Write_Line ("Full source path in brief error messages");
+   Write_Line ("Full source path in brief error messages and JSON output");
 
    --  Line for -gnateF switch