https://gcc.gnu.org/g:5c784261810896b8536d6783c03dc6f56e3145b0

commit r17-883-g5c784261810896b8536d6783c03dc6f56e3145b0
Author: Piotr Trojanek <[email protected]>
Date:   Wed Mar 4 17:05:33 2026 +0100

    ada: Remove .EXE suffix from GNAT.Command_Line error messages
    
    The .EXE suffix in GNAT.Command_Line output causes diffs in testsuite 
results
    that run on different platforms.
    
    gcc/ada/ChangeLog:
    
            * libgnat/g-comlin.adb
            (Command_Name): New routine to strip platform-specific suffix.
            (Display_Help, Get_Opt): Use new routine.
            (Try_Help): Remove hardcoded ".exe" suffix; use new routine.

Diff:
---
 gcc/ada/libgnat/g-comlin.adb | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/gcc/ada/libgnat/g-comlin.adb b/gcc/ada/libgnat/g-comlin.adb
index 81a850451bcd..18905cc135e6 100644
--- a/gcc/ada/libgnat/g-comlin.adb
+++ b/gcc/ada/libgnat/g-comlin.adb
@@ -89,6 +89,10 @@ package body GNAT.Command_Line is
    --  converts the given string to canonical all lower case form, so that two
    --  file names compare equal if they refer to the same file.
 
+   function Command_Name return String;
+   --  Returns the command name of the current program without
+   --  platform-specific suffix, like ".exe" on Windows.
+
    procedure Internal_Initialize_Option_Scan
      (Parser                   : Opt_Parser;
       Switch_Char              : Character;
@@ -244,6 +248,21 @@ package body GNAT.Command_Line is
       end if;
    end Canonical_Case_File_Name;
 
+   ------------------
+   -- Command_Name --
+   ------------------
+
+   function Command_Name return String is
+      Target_Executable_Suffix : String_Access :=
+        GNAT.OS_Lib.Get_Target_Executable_Suffix;
+      Result : constant String :=
+        Base_Name (Ada.Command_Line.Command_Name,
+                   Suffix => Target_Executable_Suffix.all);
+   begin
+      Free (Target_Executable_Suffix);
+      return Result;
+   end Command_Name;
+
    ---------------
    -- Expansion --
    ---------------
@@ -3351,12 +3370,9 @@ package body GNAT.Command_Line is
       end if;
 
       if Config.Usage /= null then
-         Put_Line ("Usage: "
-                   & Base_Name
-                     (Ada.Command_Line.Command_Name) & " " & Config.Usage.all);
+         Put_Line ("Usage: " & Command_Name & " " & Config.Usage.all);
       else
-         Put_Line ("Usage: " & Base_Name (Ada.Command_Line.Command_Name)
-                   & " [switches] [arguments]");
+         Put_Line ("Usage: " & Command_Name & " [switches] [arguments]");
       end if;
 
       if Config.Help_Msg /= null and then Config.Help_Msg.all /= "" then
@@ -3590,11 +3606,12 @@ package body GNAT.Command_Line is
       when Invalid_Switch =>
          Free (Getopt_Switches);
 
-         --  Message inspired by "ls" on Unix
+         --  Message inspired by "ls" on Unix and by its Windows port, which
+         --  doesn't mention the ".exe" suffix.
 
          if not Quiet then
             Put_Line (Standard_Error,
-                      Base_Name (Ada.Command_Line.Command_Name)
+                      Command_Name
                       & ": unrecognized option '"
                       & Full_Switch (Parser)
                       & "'");
@@ -3661,8 +3678,7 @@ package body GNAT.Command_Line is
    begin
       Put_Line
         (Standard_Error,
-         "try """ & Base_Name (Ada.Command_Line.Command_Name, Suffix => ".exe")
-         & " --help"" for more information.");
+         "try """ & Command_Name & " --help"" for more information.");
    end Try_Help;
 
 end GNAT.Command_Line;

Reply via email to