]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Remove .EXE suffix from GNAT.Command_Line error messages
authorPiotr Trojanek <trojanek@adacore.com>
Wed, 4 Mar 2026 16:05:33 +0000 (17:05 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 28 May 2026 08:52:51 +0000 (10:52 +0200)
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.

gcc/ada/libgnat/g-comlin.adb

index 81a850451bcd39eda001cb59881b3b99b34068ba..18905cc135e67d148755a79e423f427dcdcbcf48 100644 (file)
@@ -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;