[Ada] new gnatbind switches

Arnaud Charlet charlet@adacore.com
Thu Jun 7 14:00:00 GMT 2007


Tested on i686-linux, committed on trunk

A new switch -R is added for gnatbind. When gnatbind is called with this
new switch, no files are generated and the list of the sources in the
closure of the main are listed on standard output (except the sources in
the runtime).
Another new switch -Z is added to gnatbind. When switches -e, -K, -l or
-R are used, the output to the standard output is formatted: title,
leading spaces and empty line at the end. When -Z is also used, this
formating is suppresed so that the output is mor suitable for scripts.

Gnatbind now also accepts response files.
The test for this is to put gnatbind arguments into a response file and
invoke gnatbind as "gnatbind @<response file>".

2007-06-06  Vincent Celier  <celier@adacore.com>

	* bindusg.adb: Add line for @<response file>
	Add lines for new switches -R and -Z

	* gnatbind.adb (Gnatbind): Do not include sources from the GNAT
	hierarchy in the list of files of the closure when -R is used
	(Gnatbind): Accept arguments starting with '@' to indicate response
	files and take the arguments from the response files.
	If List_Closure is set, display the referenced files

-------------- next part --------------
Index: bindusg.adb
===================================================================
--- bindusg.adb	(revision 124068)
+++ bindusg.adb	(working copy)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                B o d y                                   --
 --                                                                          --
---          Copyright (C) 1992-2006, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2007, 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- --
@@ -54,6 +54,11 @@ package body Bindusg is
       Write_Eol;
       Write_Eol;
 
+      --  Line for @response_file
+
+      Write_Line ("  @<resp_file> Get arguments from response file");
+      Write_Eol;
+
       --  Line for -aO switch
 
       Write_Line ("  -aOdir    Specify library files search path");
@@ -176,6 +181,11 @@ package body Bindusg is
       Write_Line ("  -r        List restrictions that could be applied " &
                   "to this partition");
 
+      --  Line for -R switch
+
+      Write_Line
+        ("  -R        List sources referenced in closure (implies -c)");
+
       --  Line for -s switch
 
       Write_Line ("  -s        Require all source files to be present");
@@ -233,6 +243,13 @@ package body Bindusg is
 
       --  Line for --RTS
 
+      --  Line for -Z switch
+
+      Write_Line ("  -Z        " &
+                  "Zero formatting in auxiliary outputs (-e, -K, -l, -R)");
+
+      --  Line for --RTS
+
       Write_Line ("  --RTS=dir specify the default source and " &
                   "object search path");
 
Index: gnatbind.adb
===================================================================
--- gnatbind.adb	(revision 124068)
+++ gnatbind.adb	(working copy)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2006, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2007, 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- --
@@ -36,6 +36,7 @@ with Casing;   use Casing;
 with Csets;
 with Debug;    use Debug;
 with Fmap;
+with Fname;    use Fname;
 with Gnatvsn;  use Gnatvsn;
 with Namet;    use Namet;
 with Opt;      use Opt;
@@ -50,6 +51,9 @@ with Targparm; use Targparm;
 with Types;    use Types;
 
 with System.Case_Util; use System.Case_Util;
+with System.OS_Lib;    use System.OS_Lib;
+
+with Ada.Command_Line.Response_File; use Ada.Command_Line;
 
 procedure Gnatbind is
 
@@ -427,7 +431,28 @@ begin
          Next_Argv : String (1 .. Len_Arg (Next_Arg));
       begin
          Fill_Arg (Next_Argv'Address, Next_Arg);
-         Scan_Bind_Arg (Next_Argv);
+
+         if Next_Argv'Length > 0 then
+            if Next_Argv (1) = '@' then
+               if Next_Argv'Length > 1 then
+                  declare
+                     Arguments : constant Argument_List :=
+                                   Response_File.Arguments_From
+                                     (Response_File_Name        =>
+                                        Next_Argv (2 .. Next_Argv'Last),
+                                      Recursive                 => True,
+                                      Ignore_Non_Existing_Files => True);
+                  begin
+                     for J in Arguments'Range loop
+                        Scan_Bind_Arg (Arguments (J).all);
+                     end loop;
+                  end;
+               end if;
+
+            else
+               Scan_Bind_Arg (Next_Argv);
+            end if;
+         end if;
       end;
 
       Next_Arg := Next_Arg + 1;
@@ -666,7 +691,7 @@ begin
         and then ALIs.Table (ALIs.First).Main_Program = None
         and then not No_Main_Subprogram
       then
-         Error_Msg_Name_1 := Main_Lib_File;
+         Error_Msg_File_1 := Main_Lib_File;
          Error_Msg ("% does not contain a unit that can be a main program");
       end if;
 
@@ -689,26 +714,68 @@ begin
          Find_Elab_Order;
 
          if Errors_Detected = 0 then
+            --  Display elaboration order if -l was specified
+
             if Elab_Order_Output then
-               Write_Eol;
-               Write_Str ("ELABORATION ORDER");
-               Write_Eol;
+               if not Zero_Formatting then
+                  Write_Eol;
+                  Write_Str ("ELABORATION ORDER");
+                  Write_Eol;
+               end if;
 
                for J in Elab_Order.First .. Elab_Order.Last loop
                   if not Units.Table (Elab_Order.Table (J)).SAL_Interface then
-                     Write_Str ("   ");
+                     if not Zero_Formatting then
+                        Write_Str ("   ");
+                     end if;
+
                      Write_Unit_Name
                        (Units.Table (Elab_Order.Table (J)).Uname);
                      Write_Eol;
                   end if;
                end loop;
 
-               Write_Eol;
+               if not Zero_Formatting then
+                  Write_Eol;
+               end if;
             end if;
 
             if not Check_Only then
                Gen_Output_File (Output_File_Name.all);
             end if;
+
+            --  Display list of sources in the closure (except predefined
+            --  sources) if -R was used.
+
+            if List_Closure then
+               if not Zero_Formatting then
+                  Write_Eol;
+                  Write_Str ("REFERENCED SOURCES");
+                  Write_Eol;
+               end if;
+
+               for J in reverse Elab_Order.First .. Elab_Order.Last loop
+
+                  --  Do not include the sources of the runtime
+
+                  if not Is_Internal_File_Name
+                           (Units.Table (Elab_Order.Table (J)).Sfile)
+                  then
+                     if not Zero_Formatting then
+                        Write_Str ("   ");
+                     end if;
+
+                     Write_Str
+                       (Get_Name_String
+                          (Units.Table (Elab_Order.Table (J)).Sfile));
+                     Write_Eol;
+                  end if;
+               end loop;
+
+               if not Zero_Formatting then
+                  Write_Eol;
+               end if;
+            end if;
          end if;
       end if;
 


More information about the Gcc-patches mailing list