diff mbox

[Ada] Add support for not returning executable suffixes in executable names

Message ID 20100910093122.GA3654@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Sept. 10, 2010, 9:31 a.m. UTC
In some applications like IDEs, the project manager does not know whether
the user is compiling for the host or a cross-platform. As a result, the
IDE cannot know in advance which suffix will be added for executables
during the compilation (".exe", ".out",...) It is therefore better to simply
ignore suffixes in Executable_Of in such cases

Tested on x86_64-pc-linux-gnu, committed on trunk

2010-09-10  Emmanuel Briot  <briot@adacore.com>

	* prj-util.adb, prj-util.ads (Executable_Of): New parameter
	Include_Suffix.
diff mbox

Patch

Index: prj-util.adb
===================================================================
--- prj-util.adb	(revision 164000)
+++ prj-util.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 2001-2009, Free Software Foundation, Inc.         --
+--          Copyright (C) 2001-2010, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -105,12 +105,13 @@  package body Prj.Util is
    -------------------
 
    function Executable_Of
-     (Project  : Project_Id;
-      In_Tree  : Project_Tree_Ref;
-      Main     : File_Name_Type;
-      Index    : Int;
-      Ada_Main : Boolean := True;
-      Language : String := "") return File_Name_Type
+     (Project        : Project_Id;
+      In_Tree        : Project_Tree_Ref;
+      Main           : File_Name_Type;
+      Index          : Int;
+      Ada_Main       : Boolean := True;
+      Language       : String := "";
+      Include_Suffix : Boolean := True) return File_Name_Type
    is
       pragma Assert (Project /= No_Project);
 
@@ -145,6 +146,10 @@  package body Prj.Util is
          S_Suffix : File_Name_Type);
       --  Get the non empty suffixes in variables Spec_Suffix and Body_Suffix
 
+      function Add_Suffix (File : File_Name_Type) return File_Name_Type;
+      --  Return the name of the executable, based on File, and adding the
+      --  executable suffix if needed.
+
       ------------------
       -- Get_Suffixes --
       ------------------
@@ -165,6 +170,29 @@  package body Prj.Util is
          end if;
       end Get_Suffixes;
 
+      ----------------
+      -- Add_Suffix --
+      ----------------
+
+      function Add_Suffix (File : File_Name_Type) return File_Name_Type is
+         Saved_EEOT : constant Name_Id := Executable_Extension_On_Target;
+         Result     : File_Name_Type;
+
+      begin
+         if Include_Suffix then
+            if Executable_Suffix_Name /= No_Name then
+               Executable_Extension_On_Target := Executable_Suffix_Name;
+            end if;
+
+            Result :=  Executable_Name (File_Name_Type (Executable.Value));
+            Executable_Extension_On_Target := Saved_EEOT;
+            return Result;
+
+         else
+            return File;
+         end if;
+      end Add_Suffix;
+
    --  Start of processing for Executable_Of
 
    begin
@@ -237,22 +265,7 @@  package body Prj.Util is
            and then Executable.Value /= No_Name
            and then Length_Of_Name (Executable.Value) /= 0
          then
-            --  Get the executable name. If Executable_Suffix is defined,
-            --  make sure that it will be the extension of the executable.
-
-            declare
-               Saved_EEOT : constant Name_Id := Executable_Extension_On_Target;
-               Result     : File_Name_Type;
-
-            begin
-               if Executable_Suffix_Name /= No_Name then
-                  Executable_Extension_On_Target := Executable_Suffix_Name;
-               end if;
-
-               Result :=  Executable_Name (File_Name_Type (Executable.Value));
-               Executable_Extension_On_Target := Saved_EEOT;
-               return Result;
-            end;
+            return Add_Suffix (File_Name_Type (Executable.Value));
          end if;
       end if;
 
@@ -287,24 +300,7 @@  package body Prj.Util is
          Get_Name_String (Strip_Suffix (Main));
       end if;
 
-      --  Get the executable name. If Executable_Suffix is defined in the
-      --  configuration, make sure that it will be the extension of the
-      --  executable.
-
-      declare
-         Saved_EEOT : constant Name_Id := Executable_Extension_On_Target;
-         Result     : File_Name_Type;
-
-      begin
-         if Project.Config.Executable_Suffix /= No_Name then
-            Executable_Extension_On_Target :=
-              Project.Config.Executable_Suffix;
-         end if;
-
-         Result := Executable_Name (Name_Find);
-         Executable_Extension_On_Target := Saved_EEOT;
-         return Result;
-      end;
+      return Add_Suffix (Name_Find);
    end Executable_Of;
 
    --------------
Index: prj-util.ads
===================================================================
--- prj-util.ads	(revision 164000)
+++ prj-util.ads	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 2001-2008, Free Software Foundation, Inc.         --
+--          Copyright (C) 2001-2010, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -27,20 +27,26 @@ 
 
 package Prj.Util is
 
-   --  ??? throughout this spec, parameters are not well enough documented
-
    function Executable_Of
-     (Project  : Project_Id;
-      In_Tree  : Project_Tree_Ref;
-      Main     : File_Name_Type;
-      Index    : Int;
-      Ada_Main : Boolean := True;
-      Language : String := "") return File_Name_Type;
+     (Project        : Project_Id;
+      In_Tree        : Project_Tree_Ref;
+      Main           : File_Name_Type;
+      Index          : Int;
+      Ada_Main       : Boolean := True;
+      Language       : String := "";
+      Include_Suffix : Boolean := True) return File_Name_Type;
    --  Return the value of the attribute Builder'Executable for file Main in
    --  the project Project, if it exists. If there is no attribute Executable
    --  for Main, remove the suffix from Main; then, if the attribute
    --  Executable_Suffix is specified, add this suffix, otherwise add the
    --  standard executable suffix for the platform.
+   --
+   --  If Include_Suffix is true, then the ".exe" suffix (or any suffix defined
+   --  in the config and project files) will be added. Otherwise, such a suffix
+   --  is not added. In particular, the prefix should not be added if you are
+   --  potentially testing for cross-platforms, since the suffix might not be
+   --  known (its default value comes from the ...-gnatmake prefix).
+   --
    --  What is Ada_Main???
    --  What is Language???
 
@@ -60,8 +66,8 @@  package Prj.Util is
    function Value_Of
      (Variable : Variable_Value;
       Default  : String) return String;
-   --  Get the value of a single string variable. If Variable is
-   --  Nil_Variable_Value, is a string list or is defaulted, return Default.
+   --  Get the value of a single string variable. If Variable is a string list,
+   --  is Nil_Variable_Value,or is defaulted, return Default.
 
    function Value_Of
      (Index    : Name_Id;