public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-896] [Ada] Enable using absolute paths in -fdiagnostics-format=json output
@ 2022-06-01  8:46 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2022-06-01  8:46 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:65818fc9550ffda7724504e38c8d2005f6c4f2ca

commit r13-896-g65818fc9550ffda7724504e38c8d2005f6c4f2ca
Author: Ghjuvan Lacambre <lacambre@adacore.com>
Date:   Fri May 6 18:53:57 2022 +0200

    [Ada] Enable using absolute paths in -fdiagnostics-format=json output
    
    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.

Diff:
---
 .../building_executable_programs_with_gnat.rst     |  6 ++++--
 gcc/ada/errout.adb                                 | 24 +++++++++++++++++++---
 gcc/ada/gnat_ugn.texi                              | 10 +++++----
 gcc/ada/switch-c.adb                               |  3 ++-
 gcc/ada/usage.adb                                  |  2 +-
 5 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst b/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst
index ed6b463efde..29293e1f847 100644
--- a/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst
+++ b/gcc/ada/doc/gnat_ugn/building_executable_programs_with_gnat.rst
@@ -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)
diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb
index 8658c38d559..e3aa0ed6304 100644
--- a/gcc/ada/errout.adb
+++ b/gcc/ada/errout.adb
@@ -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"":");
diff --git a/gcc/ada/gnat_ugn.texi b/gcc/ada/gnat_ugn.texi
index 1664c4912e0..a2a2990b6d7 100644
--- a/gcc/ada/gnat_ugn.texi
+++ b/gcc/ada/gnat_ugn.texi
@@ -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
diff --git a/gcc/ada/switch-c.adb b/gcc/ada/switch-c.adb
index 522cdf658ed..feac8bdaff5 100644
--- a/gcc/ada/switch-c.adb
+++ b/gcc/ada/switch-c.adb
@@ -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;
diff --git a/gcc/ada/usage.adb b/gcc/ada/usage.adb
index a3d59b60e1b..7d11ae53696 100644
--- a/gcc/ada/usage.adb
+++ b/gcc/ada/usage.adb
@@ -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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-01  8:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-01  8:46 [gcc r13-896] [Ada] Enable using absolute paths in -fdiagnostics-format=json output Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).