1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1996-2010, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with GNAT
.Directory_Operations
; use GNAT
.Directory_Operations
;
29 with Hostparm
; use Hostparm
;
30 with Makeutl
; use Makeutl
;
31 with MLib
.Tgt
; use MLib
.Tgt
;
34 with Namet
; use Namet
;
36 with Osint
; use Osint
;
40 with Prj
.Ext
; use Prj
.Ext
;
42 with Prj
.Tree
; use Prj
.Tree
;
43 with Prj
.Util
; use Prj
.Util
;
45 with Snames
; use Snames
;
49 with Types
; use Types
;
50 with VMS_Conv
; use VMS_Conv
;
51 with VMS_Cmds
; use VMS_Cmds
;
53 with Ada
.Characters
.Handling
; use Ada
.Characters
.Handling
;
54 with Ada
.Command_Line
; use Ada
.Command_Line
;
55 with Ada
.Text_IO
; use Ada
.Text_IO
;
57 with GNAT
.OS_Lib
; use GNAT
.OS_Lib
;
60 Project_Node_Tree
: Project_Node_Tree_Ref
;
61 Project_File
: String_Access
;
62 Project
: Prj
.Project_Id
;
63 Current_Verbosity
: Prj
.Verbosity
:= Prj
.Default
;
64 Tool_Package_Name
: Name_Id
:= No_Name
;
66 B_Start
: String_Ptr
:= new String'("b~");
67 -- Prefix of binder generated file, changed to b__ for VMS
69 Old_Project_File_Used : Boolean := False;
70 -- This flag indicates a switch -p (for gnatxref and gnatfind) for
71 -- an old fashioned project file. -p cannot be used in conjunction
74 Temp_File_Name : Path_Name_Type := No_Path;
75 -- The name of the temporary text file to put a list of source/object
76 -- files to pass to a tool.
78 ASIS_Main : String_Access := null;
79 -- Main for commands Check, Metric and Pretty, when -U is used
81 package First_Switches is new Table.Table
82 (Table_Component_Type => String_Access,
83 Table_Index_Type => Integer,
86 Table_Increment => 100,
87 Table_Name => "Gnatcmd.First_Switches");
88 -- A table to keep the switches from the project file
90 package Carg_Switches is new Table.Table
91 (Table_Component_Type => String_Access,
92 Table_Index_Type => Integer,
95 Table_Increment => 100,
96 Table_Name => "Gnatcmd.Carg_Switches");
97 -- A table to keep the switches following -cargs for ASIS tools
99 package Rules_Switches is new Table.Table
100 (Table_Component_Type => String_Access,
101 Table_Index_Type => Integer,
102 Table_Low_Bound => 1,
104 Table_Increment => 100,
105 Table_Name => "Gnatcmd.Rules_Switches");
106 -- A table to keep the switches following -rules for gnatcheck
108 package Library_Paths is new Table.Table (
109 Table_Component_Type => String_Access,
110 Table_Index_Type => Integer,
111 Table_Low_Bound => 1,
113 Table_Increment => 100,
114 Table_Name => "Make.Library_Path");
116 -- Packages of project files to pass to Prj.Pars.Parse, depending on the
117 -- tool. We allocate objects because we cannot declare aliased objects
118 -- as we are in a procedure, not a library level package.
120 subtype SA is String_Access;
122 Naming_String : constant SA := new String'("naming");
123 Binder_String
: constant SA
:= new String'("binder");
124 Builder_String : constant SA := new String'("builder");
125 Compiler_String
: constant SA
:= new String'("compiler");
126 Check_String : constant SA := new String'("check");
127 Synchronize_String
: constant SA
:= new String'("synchronize");
128 Eliminate_String : constant SA := new String'("eliminate");
129 Finder_String
: constant SA
:= new String'("finder");
130 Linker_String : constant SA := new String'("linker");
131 Gnatls_String
: constant SA
:= new String'("gnatls");
132 Pretty_String : constant SA := new String'("pretty_printer");
133 Stack_String
: constant SA
:= new String'("stack");
134 Gnatstub_String : constant SA := new String'("gnatstub");
135 Metric_String
: constant SA
:= new String'("metrics");
136 Xref_String : constant SA := new String'("cross_reference");
138 Packages_To_Check_By_Binder
: constant String_List_Access
:=
139 new String_List
'((Naming_String, Binder_String));
141 Packages_To_Check_By_Check : constant String_List_Access :=
143 ((Naming_String
, Builder_String
, Check_String
, Compiler_String
));
145 Packages_To_Check_By_Sync
: constant String_List_Access
:=
146 new String_List
'((Naming_String, Synchronize_String, Compiler_String));
148 Packages_To_Check_By_Eliminate : constant String_List_Access :=
149 new String_List'((Naming_String
, Eliminate_String
, Compiler_String
));
151 Packages_To_Check_By_Finder
: constant String_List_Access
:=
152 new String_List
'((Naming_String, Finder_String));
154 Packages_To_Check_By_Linker : constant String_List_Access :=
155 new String_List'((Naming_String
, Linker_String
));
157 Packages_To_Check_By_Gnatls
: constant String_List_Access
:=
158 new String_List
'((Naming_String, Gnatls_String));
160 Packages_To_Check_By_Pretty : constant String_List_Access :=
161 new String_List'((Naming_String
, Pretty_String
, Compiler_String
));
163 Packages_To_Check_By_Stack
: constant String_List_Access
:=
164 new String_List
'((Naming_String, Stack_String));
166 Packages_To_Check_By_Gnatstub : constant String_List_Access :=
167 new String_List'((Naming_String
, Gnatstub_String
, Compiler_String
));
169 Packages_To_Check_By_Metric
: constant String_List_Access
:=
170 new String_List
'((Naming_String, Metric_String, Compiler_String));
172 Packages_To_Check_By_Xref : constant String_List_Access :=
173 new String_List'((Naming_String
, Xref_String
));
175 Packages_To_Check
: String_List_Access
:= Prj
.All_Packages
;
177 ----------------------------------
178 -- Declarations for GNATCMD use --
179 ----------------------------------
181 The_Command
: Command_Type
;
182 -- The command specified in the invocation of the GNAT driver
184 Command_Arg
: Positive := 1;
185 -- The index of the command in the arguments of the GNAT driver
187 My_Exit_Status
: Exit_Status
:= Success
;
188 -- The exit status of the spawned tool. Used to set the correct VMS
191 Current_Work_Dir
: constant String := Get_Current_Dir
;
192 -- The path of the working directory
194 All_Projects
: Boolean := False;
195 -- Flag used for GNAT CHECK, GNAT PRETTY, GNAT METRIC, and GNAT STACK to
196 -- indicate that the underlying tool (gnatcheck, gnatpp or gnatmetric)
197 -- should be invoked for all sources of all projects.
199 -----------------------
200 -- Local Subprograms --
201 -----------------------
203 procedure Add_To_Carg_Switches
(Switch
: String_Access
);
204 -- Add a switch to the Carg_Switches table. If it is the first one, put the
205 -- switch "-cargs" at the beginning of the table.
207 procedure Add_To_Rules_Switches
(Switch
: String_Access
);
208 -- Add a switch to the Rules_Switches table. If it is the first one, put
209 -- the switch "-crules" at the beginning of the table.
211 procedure Check_Files
;
212 -- For GNAT LIST, GNAT PRETTY, GNAT METRIC, and GNAT STACK, check if a
213 -- project file is specified, without any file arguments and without a
214 -- switch -files=. If it is the case, invoke the GNAT tool with the proper
215 -- list of files, derived from the sources of the project.
217 function Check_Project
218 (Project
: Project_Id
;
219 Root_Project
: Project_Id
) return Boolean;
220 -- Returns True if Project = Root_Project or if we want to consider all
221 -- sources of all projects. For GNAT METRIC, also returns True if Project
222 -- is extended by Root_Project.
224 procedure Check_Relative_Executable
(Name
: in out String_Access
);
225 -- Check if an executable is specified as a relative path. If it is, and
226 -- the path contains directory information, fail. Otherwise, prepend the
227 -- exec directory. This procedure is only used for GNAT LINK when a project
228 -- file is specified.
230 function Configuration_Pragmas_File
return Path_Name_Type
;
231 -- Return an argument, if there is a configuration pragmas file to be
232 -- specified for Project, otherwise return No_Name. Used for gnatstub (GNAT
233 -- STUB), gnatpp (GNAT PRETTY), gnatelim (GNAT ELIM), and gnatmetric (GNAT
236 function Mapping_File
return Path_Name_Type
;
237 -- Create and return the path name of a mapping file. Used for gnatstub
238 -- (GNAT STUB), gnatpp (GNAT PRETTY), gnatelim (GNAT ELIM), and gnatmetric
241 procedure Delete_Temp_Config_Files
;
242 -- Delete all temporary config files. The caller is responsible for
243 -- ensuring that Keep_Temporary_Files is False.
245 procedure Get_Closure
;
246 -- Get the sources in the closure of the ASIS_Main and add them to the
247 -- list of arguments.
249 function Index
(Char
: Character; Str
: String) return Natural;
250 -- Returns first occurrence of Char in Str, returns 0 if Char not in Str
252 procedure Non_VMS_Usage
;
253 -- Display usage for platforms other than VMS
255 procedure Process_Link
;
256 -- Process GNAT LINK, when there is a project file specified
258 procedure Set_Library_For
259 (Project
: Project_Id
;
260 Libraries_Present
: in out Boolean);
261 -- If Project is a library project, add the correct -L and -l switches to
262 -- the linker invocation.
264 procedure Set_Libraries
is
265 new For_Every_Project_Imported
(Boolean, Set_Library_For
);
266 -- Add the -L and -l switches to the linker for all of the library
269 procedure Test_If_Relative_Path
270 (Switch
: in out String_Access
;
272 -- Test if Switch is a relative search path switch. If it is and it
273 -- includes directory information, prepend the path with Parent. This
274 -- subprogram is only called when using project files.
276 --------------------------
277 -- Add_To_Carg_Switches --
278 --------------------------
280 procedure Add_To_Carg_Switches
(Switch
: String_Access
) is
282 -- If the Carg_Switches table is empty, put "-cargs" at the beginning
284 if Carg_Switches
.Last
= 0 then
285 Carg_Switches
.Increment_Last
;
286 Carg_Switches
.Table
(Carg_Switches
.Last
) := new String'("-cargs");
289 Carg_Switches.Increment_Last;
290 Carg_Switches.Table (Carg_Switches.Last) := Switch;
291 end Add_To_Carg_Switches;
293 ---------------------------
294 -- Add_To_Rules_Switches --
295 ---------------------------
297 procedure Add_To_Rules_Switches (Switch : String_Access) is
299 -- If the Rules_Switches table is empty, put "-rules" at the beginning
301 if Rules_Switches.Last = 0 then
302 Rules_Switches.Increment_Last;
303 Rules_Switches.Table (Rules_Switches.Last) := new String'("-rules");
306 Rules_Switches
.Increment_Last
;
307 Rules_Switches
.Table
(Rules_Switches
.Last
) := Switch
;
308 end Add_To_Rules_Switches
;
314 procedure Check_Files
is
315 Add_Sources
: Boolean := True;
316 Unit
: Prj
.Unit_Index
;
317 Subunit
: Boolean := False;
318 FD
: File_Descriptor
:= Invalid_FD
;
322 procedure Add_To_Response_File
324 Check_File
: Boolean := True);
325 -- Include the file name passed as parameter in the response file for
326 -- the tool being called. If the response file can not be written then
327 -- the file name is passed in the parameter list of the tool. If the
328 -- Check_File parameter is True then the procedure verifies the
329 -- existence of the file before adding it to the response file.
331 --------------------------
332 -- Add_To_Response_File --
333 --------------------------
335 procedure Add_To_Response_File
337 Check_File
: Boolean := True)
342 Add_Str_To_Name_Buffer
(File_Name
);
344 if not Check_File
or else
345 Is_Regular_File
(Name_Buffer
(1 .. Name_Len
))
347 if FD
/= Invalid_FD
then
348 Name_Len
:= Name_Len
+ 1;
349 Name_Buffer
(Name_Len
) := ASCII
.LF
;
351 Status
:= Write
(FD
, Name_Buffer
(1)'Address, Name_Len
);
353 if Status
/= Name_Len
then
354 Osint
.Fail
("disk full");
357 Last_Switches
.Increment_Last
;
358 Last_Switches
.Table
(Last_Switches
.Last
) :=
359 new String'(File_Name);
362 end Add_To_Response_File;
364 -- Start of processing for Check_Files
367 -- Check if there is at least one argument that is not a switch or if
368 -- there is a -files= switch.
370 for Index in 1 .. Last_Switches.Last loop
371 if Last_Switches.Table (Index).all'Length > 7
372 and then Last_Switches.Table (Index) (1 .. 7) = "-files="
374 Add_Sources := False;
377 elsif Last_Switches.Table (Index) (1) /= '-' then
381 and then Last_Switches.Table (Index - 1).all /= "-o")
383 (The_Command = Pretty
384 and then Last_Switches.Table (Index - 1).all /= "-o"
385 and then Last_Switches.Table (Index - 1).all /= "-of")
387 (The_Command = Metric
389 Last_Switches.Table (Index - 1).all /= "-o" and then
390 Last_Switches.Table (Index - 1).all /= "-og" and then
391 Last_Switches.Table (Index - 1).all /= "-ox" and then
392 Last_Switches.Table (Index - 1).all /= "-d")
394 (The_Command /= Check and then
395 The_Command /= Pretty and then
396 The_Command /= Metric)
398 Add_Sources := False;
404 -- If all arguments are switches and there is no switch -files=, add
405 -- the path names of all the sources of the main project.
409 -- For gnatcheck, gnatpp, and gnatmetric, create a temporary file
410 -- and put the list of sources in it. For gnatstack create a
411 -- temporary file with the list of .ci files.
413 if The_Command = Check or else
414 The_Command = Pretty or else
415 The_Command = Metric or else
418 Tempdir.Create_Temp_File (FD, Temp_File_Name);
419 Last_Switches.Increment_Last;
420 Last_Switches.Table (Last_Switches.Last) :=
421 new String'("-files=" & Get_Name_String
(Temp_File_Name
));
428 -- Gnatstack needs to add the .ci file for the binder generated
429 -- files corresponding to all of the library projects and main
430 -- units belonging to the application.
432 if The_Command
= Stack
then
433 Proj
:= Project_Tree
.Projects
;
434 while Proj
/= null loop
435 if Check_Project
(Proj
.Project
, Project
) then
437 Main
: String_List_Id
;
440 -- Include binder generated files for main programs
442 Main
:= Proj
.Project
.Mains
;
443 while Main
/= Nil_String
loop
446 (Proj
.Project
.Object_Directory
.Name
) &
450 (Project_Tree
.String_Elements
.Table
454 -- When looking for the .ci file for a binder
455 -- generated file, look for both b~xxx and b__xxx
456 -- as gprbuild always uses b__ as the prefix of
459 if not Is_Regular_File
(Name_Buffer
(1 .. Name_Len
))
460 and then B_Start
.all /= "b__"
464 (Proj
.Project
.Object_Directory
.Name
) &
468 (Project_Tree
.String_Elements
.Table
474 Project_Tree
.String_Elements
.Table
(Main
).Next
;
477 if Proj
.Project
.Library
then
479 -- Include the .ci file for the binder generated
480 -- files that contains the initialization and
481 -- finalization of the library.
485 (Proj
.Project
.Object_Directory
.Name
) &
487 Get_Name_String
(Proj
.Project
.Library_Name
) &
490 -- When looking for the .ci file for a binder
491 -- generated file, look for both b~xxx and b__xxx
492 -- as gprbuild always uses b__ as the prefix of
495 if not Is_Regular_File
(Name_Buffer
(1 .. Name_Len
))
496 and then B_Start
.all /= "b__"
500 (Proj
.Project
.Object_Directory
.Name
) &
502 Get_Name_String
(Proj
.Project
.Library_Name
) &
513 Unit
:= Units_Htable
.Get_First
(Project_Tree
.Units_HT
);
514 while Unit
/= No_Unit_Index
loop
516 -- For gnatls, we only need to put the library units, body or
517 -- spec, but not the subunits.
519 if The_Command
= List
then
520 if Unit
.File_Names
(Impl
) /= null
521 and then not Unit
.File_Names
(Impl
).Locally_Removed
523 -- There is a body, check if it is for this project
526 or else Unit
.File_Names
(Impl
).Project
= Project
530 if Unit
.File_Names
(Spec
) = null
531 or else Unit
.File_Names
(Spec
).Locally_Removed
533 -- We have a body with no spec: we need to check if
534 -- this is a subunit, because gnatls will complain
538 Src_Ind
: constant Source_File_Index
:=
539 Sinput
.P
.Load_Project_File
545 Sinput
.P
.Source_File_Is_Subunit
(Src_Ind
);
550 Last_Switches
.Increment_Last
;
551 Last_Switches
.Table
(Last_Switches
.Last
) :=
555 (Impl).Display_File));
559 elsif Unit.File_Names (Spec) /= null
560 and then not Unit.File_Names (Spec).Locally_Removed
562 -- We have a spec with no body. Check if it is for this
565 if All_Projects or else
566 Unit.File_Names (Spec).Project = Project
568 Last_Switches.Increment_Last;
569 Last_Switches.Table (Last_Switches.Last) :=
570 new String'(Get_Name_String
571 (Unit
.File_Names
(Spec
).Display_File
));
575 -- For gnatstack, we put the .ci files corresponding to the
576 -- different units, including the binder generated files. We
577 -- only need to do that for the library units, body or spec,
578 -- but not the subunits.
580 elsif The_Command
= Stack
then
581 if Unit
.File_Names
(Impl
) /= null
582 and then not Unit
.File_Names
(Impl
).Locally_Removed
584 -- There is a body. Check if .ci files for this project
588 (Unit
.File_Names
(Impl
).Project
, Project
)
592 if Unit
.File_Names
(Spec
) = null
593 or else Unit
.File_Names
(Spec
).Locally_Removed
595 -- We have a body with no spec: we need to check
596 -- if this is a subunit, because .ci files are not
597 -- generated for subunits.
600 Src_Ind
: constant Source_File_Index
:=
601 Sinput
.P
.Load_Project_File
607 Sinput
.P
.Source_File_Is_Subunit
(Src_Ind
);
615 (Impl
).Project
. Object_Directory
.Name
) &
618 (Unit
.File_Names
(Impl
).Display_File
),
623 elsif Unit
.File_Names
(Spec
) /= null
624 and then not Unit
.File_Names
(Spec
).Locally_Removed
626 -- Spec with no body, check if it is for this project
629 (Unit
.File_Names
(Spec
).Project
, Project
)
634 (Spec
).Project
. Object_Directory
.Name
) &
637 (Get_Name_String
(Unit
.File_Names
(Spec
).File
),
643 -- For gnatcheck, gnatsync, gnatpp and gnatmetric, put all
644 -- sources of the project, or of all projects if -U was
647 for Kind
in Spec_Or_Body
loop
648 if Unit
.File_Names
(Kind
) /= null
649 and then Check_Project
650 (Unit
.File_Names
(Kind
).Project
, Project
)
651 and then not Unit
.File_Names
(Kind
).Locally_Removed
656 (Unit
.File_Names
(Kind
).Path
.Display_Name
) &
658 Check_File
=> False);
663 Unit
:= Units_Htable
.Get_Next
(Project_Tree
.Units_HT
);
667 if FD
/= Invalid_FD
then
671 Osint
.Fail
("disk full");
681 function Check_Project
682 (Project
: Project_Id
;
683 Root_Project
: Project_Id
) return Boolean
688 if Project
= No_Project
then
691 elsif All_Projects
or else Project
= Root_Project
then
694 elsif The_Command
= Metric
then
695 Proj
:= Root_Project
;
696 while Proj
.Extends
/= No_Project
loop
697 if Project
= Proj
.Extends
then
701 Proj
:= Proj
.Extends
;
708 -------------------------------
709 -- Check_Relative_Executable --
710 -------------------------------
712 procedure Check_Relative_Executable
(Name
: in out String_Access
) is
713 Exec_File_Name
: constant String := Name
.all;
716 if not Is_Absolute_Path
(Exec_File_Name
) then
717 for Index
in Exec_File_Name
'Range loop
718 if Exec_File_Name
(Index
) = Directory_Separator
then
719 Fail
("relative executable (""" &
721 """) with directory part not allowed " &
722 "when using project files");
726 Get_Name_String
(Project
.Exec_Directory
.Name
);
728 if Name_Buffer
(Name_Len
) /= Directory_Separator
then
729 Name_Len
:= Name_Len
+ 1;
730 Name_Buffer
(Name_Len
) := Directory_Separator
;
733 Name_Buffer
(Name_Len
+ 1 ..
734 Name_Len
+ Exec_File_Name
'Length) :=
736 Name_Len
:= Name_Len
+ Exec_File_Name
'Length;
737 Name
:= new String'(Name_Buffer (1 .. Name_Len));
739 end Check_Relative_Executable;
741 --------------------------------
742 -- Configuration_Pragmas_File --
743 --------------------------------
745 function Configuration_Pragmas_File return Path_Name_Type is
747 Prj.Env.Create_Config_Pragmas_File (Project, Project_Tree);
748 return Project.Config_File_Name;
749 end Configuration_Pragmas_File;
751 ------------------------------
752 -- Delete_Temp_Config_Files --
753 ------------------------------
755 procedure Delete_Temp_Config_Files is
758 pragma Warnings (Off, Success);
761 -- This should only be called if Keep_Temporary_Files is False
763 pragma Assert (not Keep_Temporary_Files);
765 if Project /= No_Project then
766 Proj := Project_Tree.Projects;
767 while Proj /= null loop
768 if Proj.Project.Config_File_Temp then
769 Delete_Temporary_File
770 (Project_Tree, Proj.Project.Config_File_Name);
777 -- If a temporary text file that contains a list of files for a tool
778 -- has been created, delete this temporary file.
780 if Temp_File_Name /= No_Path then
781 Delete_Temporary_File (Project_Tree, Temp_File_Name);
783 end Delete_Temp_Config_Files;
789 procedure Get_Closure is
790 Args : constant Argument_List :=
791 (1 => new String'("-q"),
792 2 => new String'("-b"),
793 3 => new String'("-P"),
796 6 => new String'("-bargs"),
797 7 => new String'("-R"),
798 8 => new String'("-Z"));
799 -- Arguments for the invocation of gnatmake which are added to the
800 -- Last_Arguments list by this procedure.
802 FD : File_Descriptor;
803 -- File descriptor for the temp file that will get the output of the
804 -- invocation of gnatmake.
806 Name : Path_Name_Type;
807 -- Path of the file FD
809 GN_Name : constant String := Program_Name ("gnatmake", "gnat").all;
812 GN_Path : constant String_Access := Locate_Exec_On_Path (GN_Name);
815 Return_Code : Integer;
818 pragma Warnings (Off, Unused);
820 File : Ada.Text_IO.File_Type;
821 Line : String (1 .. 250);
823 -- Used to read file if there is an error, it is good enough to display
824 -- just 250 characters if the first line of the file is very long.
827 Path : Path_Name_Type;
830 if GN_Path = null then
831 Put_Line (Standard_Error, "could not locate " & GN_Name);
835 -- Create the temp file
837 Tempdir.Create_Temp_File (FD, Name);
839 -- And close it, because on VMS Spawn with a file descriptor created
840 -- with Create_Temp_File does not redirect output.
844 -- Spawn "gnatmake -q -b -P <project> <main> -bargs -R -Z"
847 (Program_Name => GN_Path.all,
849 Output_File => Get_Name_String (Name),
851 Return_Code => Return_Code,
854 -- Read the output of the invocation of gnatmake
856 Open (File, In_File, Get_Name_String (Name));
858 -- If it was unsuccessful, display the first line in the file and exit
861 if Return_Code /= 0 then
862 Get_Line (File, Line, Last);
864 if not Keep_Temporary_Files then
870 Put_Line (Standard_Error, Line (1 .. Last));
872 (Standard_Error, "could not get closure of " & ASIS_Main.all);
876 -- Get each file name in the file, find its path and add it the
877 -- list of arguments.
879 while not End_Of_File (File) loop
880 Get_Line (File, Line, Last);
883 Unit := Units_Htable.Get_First (Project_Tree.Units_HT);
884 while Unit /= No_Unit_Index loop
885 if Unit.File_Names (Spec) /= null
887 Get_Name_String (Unit.File_Names (Spec).File) =
890 Path := Unit.File_Names (Spec).Path.Name;
893 elsif Unit.File_Names (Impl) /= null
895 Get_Name_String (Unit.File_Names (Impl).File) =
898 Path := Unit.File_Names (Impl).Path.Name;
902 Unit := Units_Htable.Get_Next (Project_Tree.Units_HT);
905 Last_Switches.Increment_Last;
907 if Path /= No_Path then
908 Last_Switches.Table (Last_Switches.Last) :=
909 new String'(Get_Name_String
(Path
));
912 Last_Switches
.Table
(Last_Switches
.Last
) :=
913 new String'(Line (1 .. Last));
917 if not Keep_Temporary_Files then
929 function Index (Char : Character; Str : String) return Natural is
931 for Index in Str'Range loop
932 if Str (Index) = Char then
944 function Mapping_File return Path_Name_Type is
945 Result : Path_Name_Type;
947 Prj.Env.Create_Mapping_File
949 Language => Name_Ada,
950 In_Tree => Project_Tree,
959 procedure Process_Link is
960 Look_For_Executable : Boolean := True;
961 Libraries_Present : Boolean := False;
962 Path_Option : constant String_Access :=
963 MLib.Linker_Library_Path_Option;
964 Prj : Project_Id := Project;
967 Skip_Executable : Boolean := False;
970 -- Add the default search directories, to be able to find
971 -- libgnat in call to MLib.Utl.Lib_Directory.
973 Add_Default_Search_Dirs;
975 Library_Paths.Set_Last (0);
977 -- Check if there are library project files
979 if MLib.Tgt.Support_For_Libraries /= None then
980 Set_Libraries (Project, Libraries_Present);
983 -- If there are, add the necessary additional switches
985 if Libraries_Present then
987 -- Add -L<lib_dir> -lgnarl -lgnat -Wl,-rpath,<lib_dir>
989 Last_Switches.Increment_Last;
990 Last_Switches.Table (Last_Switches.Last) :=
991 new String'("-L" & MLib
.Utl
.Lib_Directory
);
992 Last_Switches
.Increment_Last
;
993 Last_Switches
.Table
(Last_Switches
.Last
) :=
994 new String'("-lgnarl");
995 Last_Switches.Increment_Last;
996 Last_Switches.Table (Last_Switches.Last) :=
997 new String'("-lgnat");
999 -- If Path_Option is not null, create the switch ("-Wl,-rpath," or
1000 -- equivalent) with all the library dirs plus the standard GNAT
1003 if Path_Option
/= null then
1005 Option
: String_Access
;
1006 Length
: Natural := Path_Option
'Length;
1010 if MLib
.Separate_Run_Path_Options
then
1012 -- We are going to create one switch of the form
1013 -- "-Wl,-rpath,dir_N" for each directory to consider.
1015 -- One switch for each library directory
1018 Library_Paths
.First
.. Library_Paths
.Last
1020 Last_Switches
.Increment_Last
;
1022 (Last_Switches
.Last
) := new String'
1024 Last_Switches.Table (Index).all);
1027 -- One switch for the standard GNAT library dir
1029 Last_Switches.Increment_Last;
1031 (Last_Switches.Last) := new String'
1032 (Path_Option
.all & MLib
.Utl
.Lib_Directory
);
1035 -- First, compute the exact length for the switch
1038 Library_Paths
.First
.. Library_Paths
.Last
1040 -- Add the length of the library dir plus one for the
1041 -- directory separator.
1045 Library_Paths
.Table
(Index
)'Length + 1;
1048 -- Finally, add the length of the standard GNAT library dir
1050 Length
:= Length
+ MLib
.Utl
.Lib_Directory
'Length;
1051 Option
:= new String (1 .. Length
);
1052 Option
(1 .. Path_Option
'Length) := Path_Option
.all;
1053 Current
:= Path_Option
'Length;
1055 -- Put each library dir followed by a dir separator
1058 Library_Paths
.First
.. Library_Paths
.Last
1063 Library_Paths
.Table
(Index
)'Length) :=
1064 Library_Paths
.Table
(Index
).all;
1067 Library_Paths
.Table
(Index
)'Length + 1;
1068 Option
(Current
) := Path_Separator
;
1071 -- Finally put the standard GNAT library dir
1075 Current
+ MLib
.Utl
.Lib_Directory
'Length) :=
1076 MLib
.Utl
.Lib_Directory
;
1078 -- And add the switch to the last switches
1080 Last_Switches
.Increment_Last
;
1081 Last_Switches
.Table
(Last_Switches
.Last
) :=
1088 -- Check if the first ALI file specified can be found, either in the
1089 -- object directory of the main project or in an object directory of a
1090 -- project file extended by the main project. If the ALI file can be
1091 -- found, replace its name with its absolute path.
1093 Skip_Executable
:= False;
1095 Switch_Loop
: for J
in 1 .. Last_Switches
.Last
loop
1097 -- If we have an executable just reset the flag
1099 if Skip_Executable
then
1100 Skip_Executable
:= False;
1102 -- If -o, set flag so that next switch is not processed
1104 elsif Last_Switches
.Table
(J
).all = "-o" then
1105 Skip_Executable
:= True;
1111 Switch
: constant String :=
1112 Last_Switches
.Table
(J
).all;
1113 ALI_File
: constant String (1 .. Switch
'Length + 4) :=
1116 Test_Existence
: Boolean := False;
1119 Last
:= Switch
'Length;
1121 -- Skip real switches
1123 if Switch
'Length /= 0
1124 and then Switch
(Switch
'First) /= '-'
1126 -- Append ".ali" if file name does not end with it
1128 if Switch
'Length <= 4
1129 or else Switch
(Switch
'Last - 3 .. Switch
'Last) /= ".ali"
1131 Last
:= ALI_File
'Last;
1134 -- If file name includes directory information, stop if ALI
1137 if Is_Absolute_Path
(ALI_File
(1 .. Last
)) then
1138 Test_Existence
:= True;
1141 for K
in Switch
'Range loop
1143 or else Switch
(K
) = Directory_Separator
1145 Test_Existence
:= True;
1151 if Test_Existence
then
1152 if Is_Regular_File
(ALI_File
(1 .. Last
)) then
1156 -- Look in object directories if ALI file exists
1161 Dir
: constant String :=
1162 Get_Name_String
(Prj
.Object_Directory
.Name
);
1166 ALI_File
(1 .. Last
))
1168 -- We have found the correct project, so we
1169 -- replace the file with the absolute path.
1171 Last_Switches
.Table
(J
) :=
1172 new String'(Dir & ALI_File (1 .. Last));
1180 -- Go to the project being extended, if any
1183 exit Project_Loop when Prj = No_Project;
1184 end loop Project_Loop;
1189 end loop Switch_Loop;
1191 -- If a relative path output file has been specified, we add the exec
1194 for J in reverse 1 .. Last_Switches.Last - 1 loop
1195 if Last_Switches.Table (J).all = "-o" then
1196 Check_Relative_Executable
1197 (Name => Last_Switches.Table (J + 1));
1198 Look_For_Executable := False;
1203 if Look_For_Executable then
1204 for J in reverse 1 .. First_Switches.Last - 1 loop
1205 if First_Switches.Table (J).all = "-o" then
1206 Look_For_Executable := False;
1207 Check_Relative_Executable
1208 (Name => First_Switches.Table (J + 1));
1214 -- If no executable is specified, then find the name of the first ALI
1215 -- file on the command line and issue a -o switch with the absolute path
1216 -- of the executable in the exec directory.
1218 if Look_For_Executable then
1219 for J in 1 .. Last_Switches.Last loop
1220 Arg := Last_Switches.Table (J);
1223 if Arg'Length /= 0 and then Arg (Arg'First) /= '-' then
1225 and then Arg (Arg'Last - 3 .. Arg'Last) = ".ali"
1227 Last := Arg'Last - 4;
1229 elsif Is_Regular_File (Arg.all & ".ali") then
1234 Last_Switches.Increment_Last;
1235 Last_Switches.Table (Last_Switches.Last) :=
1237 Get_Name_String
(Project
.Exec_Directory
.Name
);
1238 Last_Switches
.Increment_Last
;
1239 Last_Switches
.Table
(Last_Switches
.Last
) :=
1240 new String'(Name_Buffer (1 .. Name_Len) &
1242 (Base_Name (Arg (Arg'First .. Last))));
1250 ---------------------
1251 -- Set_Library_For --
1252 ---------------------
1254 procedure Set_Library_For
1255 (Project : Project_Id;
1256 Libraries_Present : in out Boolean)
1258 Path_Option : constant String_Access :=
1259 MLib.Linker_Library_Path_Option;
1262 -- Case of library project
1264 if Project.Library then
1265 Libraries_Present := True;
1267 -- Add the -L switch
1269 Last_Switches.Increment_Last;
1270 Last_Switches.Table (Last_Switches.Last) :=
1271 new String'("-L" & Get_Name_String
(Project
.Library_Dir
.Name
));
1273 -- Add the -l switch
1275 Last_Switches
.Increment_Last
;
1276 Last_Switches
.Table
(Last_Switches
.Last
) :=
1277 new String'("-l" & Get_Name_String (Project.Library_Name));
1279 -- Add the directory to table Library_Paths, to be processed later
1280 -- if library is not static and if Path_Option is not null.
1282 if Project.Library_Kind /= Static
1283 and then Path_Option /= null
1285 Library_Paths.Increment_Last;
1286 Library_Paths.Table (Library_Paths.Last) :=
1287 new String'(Get_Name_String
(Project
.Library_Dir
.Name
));
1290 end Set_Library_For
;
1292 ---------------------------
1293 -- Test_If_Relative_Path --
1294 ---------------------------
1296 procedure Test_If_Relative_Path
1297 (Switch
: in out String_Access
;
1301 Makeutl
.Test_If_Relative_Path
1302 (Switch
, Parent
, Including_Non_Switch
=> False, Including_RTS
=> True);
1303 end Test_If_Relative_Path
;
1309 procedure Non_VMS_Usage
is
1313 Put_Line
("List of available commands");
1316 for C
in Command_List
'Range loop
1318 -- No usage for VMS only command or for Sync
1320 if not Command_List
(C
).VMS_Only
and then C
/= Sync
then
1321 if Targparm
.AAMP_On_Target
then
1327 Put
(To_Lower
(Command_List
(C
).Cname
.all));
1330 -- Never call gnatstack with a prefix
1333 Put
(Command_List
(C
).Unixcmd
.all);
1335 Put
(Program_Name
(Command_List
(C
).Unixcmd
.all, "gnat").all);
1339 Sws
: Argument_List_Access
renames Command_List
(C
).Unixsws
;
1342 for J
in Sws
'Range loop
1354 Put_Line
("All commands except chop, krunch and preprocess " &
1355 "accept project file switches -vPx, -Pprj and -Xnam=val");
1359 -------------------------------------
1360 -- Start of processing for GNATCmd --
1361 -------------------------------------
1369 Project_Node_Tree
:= new Project_Node_Tree_Data
;
1370 Prj
.Tree
.Initialize
(Project_Node_Tree
);
1372 Prj
.Initialize
(Project_Tree
);
1375 Last_Switches
.Set_Last
(0);
1377 First_Switches
.Init
;
1378 First_Switches
.Set_Last
(0);
1380 Carg_Switches
.Set_Last
(0);
1381 Rules_Switches
.Init
;
1382 Rules_Switches
.Set_Last
(0);
1384 VMS_Conv
.Initialize
;
1386 -- Add the default search directories, to be able to find system.ads in the
1387 -- subsequent call to Targparm.Get_Target_Parameters.
1389 Add_Default_Search_Dirs
;
1391 -- Get target parameters so that AAMP_On_Target will be set, for testing in
1392 -- Osint.Program_Name to handle the mapping of GNAAMP tool names.
1394 Targparm
.Get_Target_Parameters
;
1396 -- Put the command line in environment variable GNAT_DRIVER_COMMAND_LINE,
1397 -- so that the spawned tool may know the way the GNAT driver was invoked.
1400 Add_Str_To_Name_Buffer
(Command_Name
);
1402 for J
in 1 .. Argument_Count
loop
1403 Add_Char_To_Name_Buffer
(' ');
1404 Add_Str_To_Name_Buffer
(Argument
(J
));
1407 Setenv
("GNAT_DRIVER_COMMAND_LINE", Name_Buffer
(1 .. Name_Len
));
1409 -- Add the directory where the GNAT driver is invoked in front of the path,
1410 -- if the GNAT driver is invoked with directory information. Do not do this
1411 -- for VMS, where the notion of path does not really exist.
1415 Command
: constant String := Command_Name
;
1418 for Index
in reverse Command
'Range loop
1419 if Command
(Index
) = Directory_Separator
then
1421 Absolute_Dir
: constant String :=
1423 (Command
(Command
'First .. Index
));
1425 PATH
: constant String :=
1426 Absolute_Dir
& Path_Separator
& Getenv
("PATH").all;
1429 Setenv
("PATH", PATH
);
1438 -- If on VMS, or if VMS emulation is on, convert VMS style /qualifiers,
1439 -- filenames and pathnames to Unix style.
1442 or else To_Lower
(Getenv
("EMULATE_VMS").all) = "true"
1444 VMS_Conversion
(The_Command
);
1446 B_Start
:= new String'("b__");
1448 -- If not on VMS, scan the command line directly
1451 if Argument_Count = 0 then
1457 if Argument_Count > Command_Arg
1458 and then Argument (Command_Arg) = "-v"
1460 Verbose_Mode := True;
1461 Command_Arg := Command_Arg + 1;
1463 elsif Argument_Count > Command_Arg
1464 and then Argument (Command_Arg) = "-dn"
1466 Keep_Temporary_Files := True;
1467 Command_Arg := Command_Arg + 1;
1474 The_Command := Real_Command_Type'Value (Argument (Command_Arg));
1476 if Command_List (The_Command).VMS_Only then
1480 & Command_List (The_Command).Cname.all
1481 & """ can only be used on VMS");
1485 when Constraint_Error =>
1487 -- Check if it is an alternate command
1490 Alternate : Alternate_Command;
1493 Alternate := Alternate_Command'Value
1494 (Argument (Command_Arg));
1495 The_Command := Corresponding_To (Alternate);
1498 when Constraint_Error =>
1500 Fail ("Unknown command: " & Argument (Command_Arg));
1504 -- Get the arguments from the command line and from the eventual
1505 -- argument file(s) specified on the command line.
1507 for Arg in Command_Arg + 1 .. Argument_Count loop
1509 The_Arg : constant String := Argument (Arg);
1512 -- Check if an argument file is specified
1514 if The_Arg (The_Arg'First) = '@
' then
1516 Arg_File : Ada.Text_IO.File_Type;
1517 Line : String (1 .. 256);
1521 -- Open the file and fail if the file cannot be found
1526 The_Arg (The_Arg'First + 1 .. The_Arg'Last));
1531 (Standard_Error, "Cannot open argument file """);
1534 The_Arg (The_Arg'First + 1 .. The_Arg'Last));
1536 Put_Line (Standard_Error, """");
1540 -- Read line by line and put the content of each non-
1541 -- empty line in the Last_Switches table.
1543 while not End_Of_File (Arg_File) loop
1544 Get_Line (Arg_File, Line, Last);
1547 Last_Switches.Increment_Last;
1548 Last_Switches.Table (Last_Switches.Last) :=
1549 new String'(Line
(1 .. Last
));
1557 -- It is not an argument file; just put the argument in
1558 -- the Last_Switches table.
1560 Last_Switches
.Increment_Last
;
1561 Last_Switches
.Table
(Last_Switches
.Last
) :=
1562 new String'(The_Arg);
1570 Program : String_Access;
1571 Exec_Path : String_Access;
1574 if The_Command = Stack then
1576 -- Never call gnatstack with a prefix
1578 Program := new String'(Command_List
(The_Command
).Unixcmd
.all);
1582 Program_Name
(Command_List
(The_Command
).Unixcmd
.all, "gnat");
1585 -- For the tools where the GNAT driver processes the project files,
1586 -- allow shared library projects to import projects that are not shared
1587 -- library projects, to avoid adding a switch for these tools. For the
1588 -- builder (gnatmake), if a shared library project imports a project
1589 -- that is not a shared library project and the appropriate switch is
1590 -- not specified, the invocation of gnatmake will fail.
1592 Opt
.Unchecked_Shared_Lib_Imports
:= True;
1594 -- Locate the executable for the command
1596 Exec_Path
:= Locate_Exec_On_Path
(Program
.all);
1598 if Exec_Path
= null then
1599 Put_Line
(Standard_Error
, "could not locate " & Program
.all);
1603 -- If there are switches for the executable, put them as first switches
1605 if Command_List
(The_Command
).Unixsws
/= null then
1606 for J
in Command_List
(The_Command
).Unixsws
'Range loop
1607 First_Switches
.Increment_Last
;
1608 First_Switches
.Table
(First_Switches
.Last
) :=
1609 Command_List
(The_Command
).Unixsws
(J
);
1613 -- For BIND, CHECK, ELIM, FIND, LINK, LIST, METRIC, PRETTY, STACK, STUB,
1614 -- SYNC and XREF, look for project file related switches.
1618 Tool_Package_Name
:= Name_Binder
;
1619 Packages_To_Check
:= Packages_To_Check_By_Binder
;
1621 Tool_Package_Name
:= Name_Check
;
1622 Packages_To_Check
:= Packages_To_Check_By_Check
;
1624 Tool_Package_Name
:= Name_Eliminate
;
1625 Packages_To_Check
:= Packages_To_Check_By_Eliminate
;
1627 Tool_Package_Name
:= Name_Finder
;
1628 Packages_To_Check
:= Packages_To_Check_By_Finder
;
1630 Tool_Package_Name
:= Name_Linker
;
1631 Packages_To_Check
:= Packages_To_Check_By_Linker
;
1633 Tool_Package_Name
:= Name_Gnatls
;
1634 Packages_To_Check
:= Packages_To_Check_By_Gnatls
;
1636 Tool_Package_Name
:= Name_Metrics
;
1637 Packages_To_Check
:= Packages_To_Check_By_Metric
;
1639 Tool_Package_Name
:= Name_Pretty_Printer
;
1640 Packages_To_Check
:= Packages_To_Check_By_Pretty
;
1642 Tool_Package_Name
:= Name_Stack
;
1643 Packages_To_Check
:= Packages_To_Check_By_Stack
;
1645 Tool_Package_Name
:= Name_Gnatstub
;
1646 Packages_To_Check
:= Packages_To_Check_By_Gnatstub
;
1648 Tool_Package_Name
:= Name_Synchronize
;
1649 Packages_To_Check
:= Packages_To_Check_By_Sync
;
1651 Tool_Package_Name
:= Name_Cross_Reference
;
1652 Packages_To_Check
:= Packages_To_Check_By_Xref
;
1654 Tool_Package_Name
:= No_Name
;
1657 if Tool_Package_Name
/= No_Name
then
1659 -- Check that the switches are consistent. Detect project file
1660 -- related switches.
1662 Inspect_Switches
: declare
1663 Arg_Num
: Positive := 1;
1664 Argv
: String_Access
;
1666 procedure Remove_Switch
(Num
: Positive);
1667 -- Remove a project related switch from table Last_Switches
1673 procedure Remove_Switch
(Num
: Positive) is
1675 Last_Switches
.Table
(Num
.. Last_Switches
.Last
- 1) :=
1676 Last_Switches
.Table
(Num
+ 1 .. Last_Switches
.Last
);
1677 Last_Switches
.Decrement_Last
;
1680 -- Start of processing for Inspect_Switches
1683 while Arg_Num
<= Last_Switches
.Last
loop
1684 Argv
:= Last_Switches
.Table
(Arg_Num
);
1686 if Argv
(Argv
'First) = '-' then
1687 if Argv
'Length = 1 then
1689 ("switch character cannot be followed by a blank");
1692 -- The two style project files (-p and -P) cannot be used
1695 if (The_Command
= Find
or else The_Command
= Xref
)
1696 and then Argv
(2) = 'p'
1698 Old_Project_File_Used
:= True;
1699 if Project_File
/= null then
1700 Fail
("-P and -p cannot be used together");
1704 -- --subdirs=... Specify Subdirs
1706 if Argv
'Length > Makeutl
.Subdirs_Option
'Length
1710 Argv
'First + Makeutl
.Subdirs_Option
'Length - 1) =
1711 Makeutl
.Subdirs_Option
1716 (Argv'First + Makeutl.Subdirs_Option'Length ..
1719 Remove_Switch (Arg_Num);
1721 -- -aPdir Add dir to the project search path
1723 elsif Argv'Length > 3
1724 and then Argv (Argv'First + 1 .. Argv'First + 2) = "aP"
1726 Prj.Env.Add_Directories
1727 (Project_Node_Tree.Project_Path,
1728 Argv (Argv'First + 3 .. Argv'Last));
1730 Remove_Switch (Arg_Num);
1732 -- -eL Follow links for files
1734 elsif Argv.all = "-eL" then
1735 Follow_Links_For_Files := True;
1736 Follow_Links_For_Dirs := True;
1738 Remove_Switch (Arg_Num);
1740 -- -vPx Specify verbosity while parsing project files
1742 elsif Argv'Length = 4
1743 and then Argv (Argv'First + 1 .. Argv'First + 2) = "vP"
1745 case Argv (Argv'Last) is
1747 Current_Verbosity := Prj.Default;
1749 Current_Verbosity := Prj.Medium;
1751 Current_Verbosity := Prj.High;
1753 Fail ("Invalid switch: " & Argv.all);
1756 Remove_Switch (Arg_Num);
1758 -- -Pproject_file Specify project file to be used
1760 elsif Argv (Argv'First + 1) = 'P
' then
1762 -- Only one -P switch can be used
1764 if Project_File /= null then
1767 & ": second project file forbidden (first is """
1771 -- The two style project files (-p and -P) cannot be
1774 elsif Old_Project_File_Used then
1775 Fail ("-p and -P cannot be used together");
1777 elsif Argv'Length = 2 then
1779 -- There is space between -P and the project file
1780 -- name. -P cannot be the last option.
1782 if Arg_Num = Last_Switches.Last then
1783 Fail ("project file name missing after -P");
1786 Remove_Switch (Arg_Num);
1787 Argv := Last_Switches.Table (Arg_Num);
1789 -- After -P, there must be a project file name,
1790 -- not another switch.
1792 if Argv (Argv'First) = '-' then
1793 Fail ("project file name missing after -P");
1796 Project_File := new String'(Argv
.all);
1801 -- No space between -P and project file name
1804 new String'(Argv (Argv'First + 2 .. Argv'Last));
1807 Remove_Switch (Arg_Num);
1809 -- -Xexternal=value Specify an external reference to be
1810 -- used in project files
1812 elsif Argv'Length >= 5
1813 and then Argv (Argv'First + 1) = 'X
'
1816 Equal_Pos : constant Natural :=
1819 Argv (Argv'First + 2 .. Argv'Last));
1821 if Equal_Pos >= Argv'First + 3
1822 and then Equal_Pos /= Argv'Last
1824 Add (Project_Node_Tree,
1826 Argv (Argv'First + 2 .. Equal_Pos - 1),
1827 Value => Argv (Equal_Pos + 1 .. Argv'Last));
1831 & " is not a valid external assignment.");
1835 Remove_Switch (Arg_Num);
1838 (The_Command = Check or else
1839 The_Command = Sync or else
1840 The_Command = Pretty or else
1841 The_Command = Metric or else
1842 The_Command = Stack or else
1844 and then Argv'Length = 2
1845 and then Argv (2) = 'U
'
1847 All_Projects := True;
1848 Remove_Switch (Arg_Num);
1851 Arg_Num := Arg_Num + 1;
1854 elsif ((The_Command = Check and then Argv (Argv'First) /= '+')
1855 or else The_Command = Sync
1856 or else The_Command = Metric
1857 or else The_Command = Pretty)
1858 and then Project_File /= null
1859 and then All_Projects
1861 if ASIS_Main /= null then
1862 Fail ("cannot specify more than one main after -U");
1865 Remove_Switch (Arg_Num);
1869 Arg_Num := Arg_Num + 1;
1872 end Inspect_Switches;
1875 -- If there is a project file specified, parse it, get the switches
1876 -- for the tool and setup PATH environment variables.
1878 if Project_File /= null then
1879 Prj.Pars.Set_Verbosity (To => Current_Verbosity);
1882 (Project => Project,
1883 In_Tree => Project_Tree,
1884 In_Node_Tree => Project_Node_Tree,
1885 Project_File_Name => Project_File.all,
1886 Flags => Gnatmake_Flags,
1887 Packages_To_Check => Packages_To_Check);
1889 if Project = Prj.No_Project then
1890 Fail ("""" & Project_File.all & """ processing failed");
1893 -- Check if a package with the name of the tool is in the project
1894 -- file and if there is one, get the switches, if any, and scan them.
1897 Pkg : constant Prj.Package_Id :=
1899 (Name => Tool_Package_Name,
1900 In_Packages => Project.Decl.Packages,
1901 In_Tree => Project_Tree);
1903 Element : Package_Element;
1905 Switches_Array : Array_Element_Id;
1907 The_Switches : Prj.Variable_Value;
1908 Current : Prj.String_List_Id;
1909 The_String : String_Element;
1911 Main : String_Access := null;
1914 if Pkg /= No_Package then
1915 Element := Project_Tree.Packages.Table (Pkg);
1917 -- Packages Gnatls and Gnatstack have a single attribute
1918 -- Switches, that is not an associative array.
1920 if The_Command = List or else The_Command = Stack then
1923 (Variable_Name => Snames.Name_Switches,
1924 In_Variables => Element.Decl.Attributes,
1925 In_Tree => Project_Tree);
1927 -- Packages Binder (for gnatbind), Cross_Reference (for
1928 -- gnatxref), Linker (for gnatlink), Finder (for gnatfind),
1929 -- Pretty_Printer (for gnatpp), Eliminate (for gnatelim), Check
1930 -- (for gnatcheck), and Metric (for gnatmetric) have an
1931 -- attributed Switches, an associative array, indexed by the
1932 -- name of the file.
1934 -- They also have an attribute Default_Switches, indexed by the
1935 -- name of the programming language.
1938 -- First check if there is a single main
1940 for J in 1 .. Last_Switches.Last loop
1941 if Last_Switches.Table (J) (1) /= '-' then
1943 Main := Last_Switches.Table (J);
1952 if Main /= null then
1955 (Name => Name_Switches,
1956 In_Arrays => Element.Decl.Arrays,
1957 In_Tree => Project_Tree);
1959 Add_Str_To_Name_Buffer (Main.all);
1960 The_Switches := Prj.Util.Value_Of
1961 (Index => Name_Find,
1963 In_Array => Switches_Array,
1964 In_Tree => Project_Tree);
1967 if The_Switches.Kind = Prj.Undefined then
1970 (Name => Name_Default_Switches,
1971 In_Arrays => Element.Decl.Arrays,
1972 In_Tree => Project_Tree);
1973 The_Switches := Prj.Util.Value_Of
1976 In_Array => Switches_Array,
1977 In_Tree => Project_Tree);
1981 -- If there are switches specified in the package of the
1982 -- project file corresponding to the tool, scan them.
1984 case The_Switches.Kind is
1985 when Prj.Undefined =>
1990 Switch : constant String :=
1991 Get_Name_String (The_Switches.Value);
1994 if Switch'Length > 0 then
1995 First_Switches.Increment_Last;
1996 First_Switches.Table (First_Switches.Last) :=
1997 new String'(Switch
);
2002 Current
:= The_Switches
.Values
;
2003 while Current
/= Prj
.Nil_String
loop
2004 The_String
:= Project_Tree
.String_Elements
.
2008 Switch
: constant String :=
2009 Get_Name_String
(The_String
.Value
);
2012 if Switch
'Length > 0 then
2013 First_Switches
.Increment_Last
;
2014 First_Switches
.Table
(First_Switches
.Last
) :=
2015 new String'(Switch);
2019 Current := The_String.Next;
2025 if The_Command = Bind
2026 or else The_Command = Link
2027 or else The_Command = Elim
2029 Change_Dir (Get_Name_String (Project.Object_Directory.Name));
2032 -- Set up the env vars for project path files
2034 Prj.Env.Set_Ada_Paths
2035 (Project, Project_Tree, Including_Libraries => False);
2037 -- For gnatcheck, gnatstub, gnatmetric, gnatpp and gnatelim, create
2038 -- a configuration pragmas file, if necessary.
2040 if The_Command = Pretty
2041 or else The_Command = Metric
2042 or else The_Command = Stub
2043 or else The_Command = Elim
2044 or else The_Command = Check
2045 or else The_Command = Sync
2047 -- If there are switches in package Compiler, put them in the
2048 -- Carg_Switches table.
2051 Pkg : constant Prj.Package_Id :=
2053 (Name => Name_Compiler,
2054 In_Packages => Project.Decl.Packages,
2055 In_Tree => Project_Tree);
2057 Element : Package_Element;
2059 Switches_Array : Array_Element_Id;
2061 The_Switches : Prj.Variable_Value;
2062 Current : Prj.String_List_Id;
2063 The_String : String_Element;
2065 Main : String_Access := null;
2069 if Pkg /= No_Package then
2071 -- First, check if there is a single main specified.
2073 for J in 1 .. Last_Switches.Last loop
2074 if Last_Switches.Table (J) (1) /= '-' then
2076 Main := Last_Switches.Table (J);
2085 Element := Project_Tree.Packages.Table (Pkg);
2087 -- If there is a single main and there is compilation
2088 -- switches specified in the project file, use them.
2090 if Main /= null and then not All_Projects then
2091 Name_Len := Main'Length;
2092 Name_Buffer (1 .. Name_Len) := Main.all;
2093 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
2094 Main_Id := Name_Find;
2098 (Name => Name_Switches,
2099 In_Arrays => Element.Decl.Arrays,
2100 In_Tree => Project_Tree);
2101 The_Switches := Prj.Util.Value_Of
2104 In_Array => Switches_Array,
2105 In_Tree => Project_Tree);
2108 -- Otherwise, get the Default_Switches ("Ada")
2110 if The_Switches.Kind = Undefined then
2113 (Name => Name_Default_Switches,
2114 In_Arrays => Element.Decl.Arrays,
2115 In_Tree => Project_Tree);
2116 The_Switches := Prj.Util.Value_Of
2119 In_Array => Switches_Array,
2120 In_Tree => Project_Tree);
2123 -- If there are switches specified, put them in the
2124 -- Carg_Switches table.
2126 case The_Switches.Kind is
2127 when Prj.Undefined =>
2132 Switch : constant String :=
2133 Get_Name_String (The_Switches.Value);
2135 if Switch'Length > 0 then
2136 Add_To_Carg_Switches (new String'(Switch
));
2141 Current
:= The_Switches
.Values
;
2142 while Current
/= Prj
.Nil_String
loop
2144 Project_Tree
.String_Elements
.Table
(Current
);
2147 Switch
: constant String :=
2148 Get_Name_String
(The_String
.Value
);
2150 if Switch
'Length > 0 then
2151 Add_To_Carg_Switches
(new String'(Switch));
2155 Current := The_String.Next;
2161 -- If -cargs is one of the switches, move the following switches
2162 -- to the Carg_Switches table.
2164 for J in 1 .. First_Switches.Last loop
2165 if First_Switches.Table (J).all = "-cargs" then
2171 -- Move the switches that are before -rules when the
2172 -- command is CHECK.
2175 while K <= First_Switches.Last
2177 (The_Command /= Check
2178 or else First_Switches.Table (K).all /= "-rules")
2180 Add_To_Carg_Switches (First_Switches.Table (K));
2184 if K > First_Switches.Last then
2185 First_Switches.Set_Last (J - 1);
2189 while K <= First_Switches.Last loop
2191 First_Switches.Table (Last) :=
2192 First_Switches.Table (K);
2196 First_Switches.Set_Last (Last);
2204 for J in 1 .. Last_Switches.Last loop
2205 if Last_Switches.Table (J).all = "-cargs" then
2211 -- Move the switches that are before -rules when the
2212 -- command is CHECK.
2215 while K <= Last_Switches.Last
2217 (The_Command /= Check
2218 or else Last_Switches.Table (K).all /= "-rules")
2220 Add_To_Carg_Switches (Last_Switches.Table (K));
2224 if K > Last_Switches.Last then
2225 Last_Switches.Set_Last (J - 1);
2229 while K <= Last_Switches.Last loop
2231 Last_Switches.Table (Last) :=
2232 Last_Switches.Table (K);
2236 Last_Switches.Set_Last (Last);
2245 CP_File : constant Path_Name_Type := Configuration_Pragmas_File;
2246 M_File : constant Path_Name_Type := Mapping_File;
2249 if CP_File /= No_Path then
2250 if The_Command = Elim then
2251 First_Switches.Increment_Last;
2252 First_Switches.Table (First_Switches.Last) :=
2253 new String'("-C" & Get_Name_String
(CP_File
));
2256 Add_To_Carg_Switches
2257 (new String'("-gnatec=" & Get_Name_String (CP_File)));
2261 if M_File /= No_Path then
2262 Add_To_Carg_Switches
2263 (new String'("-gnatem=" & Get_Name_String
(M_File
)));
2266 -- For gnatcheck, also indicate a global configuration pragmas
2267 -- file and, if -U is not used, a local one.
2269 if The_Command
= Check
then
2271 Pkg
: constant Prj
.Package_Id
:=
2273 (Name
=> Name_Builder
,
2274 In_Packages
=> Project
.Decl
.Packages
,
2275 In_Tree
=> Project_Tree
);
2277 Variable
: Variable_Value
:=
2280 Attribute_Or_Array_Name
=>
2281 Name_Global_Configuration_Pragmas
,
2283 In_Tree
=> Project_Tree
);
2286 if (Variable
= Nil_Variable_Value
2287 or else Length_Of_Name
(Variable
.Value
) = 0)
2288 and then Pkg
/= No_Package
2293 Attribute_Or_Array_Name
=>
2294 Name_Global_Config_File
,
2296 In_Tree
=> Project_Tree
);
2299 if Variable
/= Nil_Variable_Value
2300 and then Length_Of_Name
(Variable
.Value
) /= 0
2302 Add_To_Carg_Switches
2304 ("-gnatec=" & Get_Name_String (Variable.Value)));
2308 if not All_Projects then
2310 Pkg : constant Prj.Package_Id :=
2312 (Name => Name_Compiler,
2313 In_Packages => Project.Decl.Packages,
2314 In_Tree => Project_Tree);
2316 Variable : Variable_Value :=
2319 Attribute_Or_Array_Name =>
2320 Name_Local_Configuration_Pragmas,
2322 In_Tree => Project_Tree);
2325 if (Variable = Nil_Variable_Value
2326 or else Length_Of_Name (Variable.Value) = 0)
2327 and then Pkg /= No_Package
2332 Attribute_Or_Array_Name =>
2333 Name_Local_Config_File,
2335 In_Tree => Project_Tree);
2338 if Variable /= Nil_Variable_Value
2339 and then Length_Of_Name (Variable.Value) /= 0
2341 Add_To_Carg_Switches
2344 Get_Name_String
(Variable
.Value
)));
2352 if The_Command
= Link
then
2356 if The_Command
= Link
or else The_Command
= Bind
then
2358 -- For files that are specified as relative paths with directory
2359 -- information, we convert them to absolute paths, with parent
2360 -- being the current working directory if specified on the command
2361 -- line and the project directory if specified in the project
2362 -- file. This is what gnatmake is doing for linker and binder
2365 for J
in 1 .. Last_Switches
.Last
loop
2366 GNATCmd
.Test_If_Relative_Path
2367 (Last_Switches
.Table
(J
), Current_Work_Dir
);
2370 Get_Name_String
(Project
.Directory
.Name
);
2373 Project_Dir
: constant String := Name_Buffer
(1 .. Name_Len
);
2375 for J
in 1 .. First_Switches
.Last
loop
2376 GNATCmd
.Test_If_Relative_Path
2377 (First_Switches
.Table
(J
), Project_Dir
);
2381 elsif The_Command
= Stub
then
2383 File_Index
: Integer := 0;
2384 Dir_Index
: Integer := 0;
2385 Last
: constant Integer := Last_Switches
.Last
;
2386 Lang
: constant Language_Ptr
:=
2387 Get_Language_From_Name
(Project
, "ada");
2390 for Index
in 1 .. Last
loop
2391 if Last_Switches
.Table
(Index
)
2392 (Last_Switches
.Table
(Index
)'First) /= '-'
2394 File_Index
:= Index
;
2399 -- If the project file naming scheme is not standard, and if
2400 -- the file name ends with the spec suffix, then indicate to
2401 -- gnatstub the name of the body file with a -o switch.
2403 if not Is_Standard_GNAT_Naming
(Lang
.Config
.Naming_Data
) then
2404 if File_Index
/= 0 then
2406 Spec
: constant String :=
2408 (Last_Switches
.Table
(File_Index
).all);
2409 Last
: Natural := Spec
'Last;
2412 Get_Name_String
(Lang
.Config
.Naming_Data
.Spec_Suffix
);
2414 if Spec
'Length > Name_Len
2415 and then Spec
(Last
- Name_Len
+ 1 .. Last
) =
2416 Name_Buffer
(1 .. Name_Len
)
2418 Last
:= Last
- Name_Len
;
2420 (Lang
.Config
.Naming_Data
.Body_Suffix
);
2421 Last_Switches
.Increment_Last
;
2422 Last_Switches
.Table
(Last_Switches
.Last
) :=
2424 Last_Switches.Increment_Last;
2425 Last_Switches.Table (Last_Switches.Last) :=
2426 new String'(Spec
(Spec
'First .. Last
) &
2427 Name_Buffer
(1 .. Name_Len
));
2433 -- Add the directory of the spec as the destination directory
2434 -- of the body, if there is no destination directory already
2437 if File_Index
/= 0 then
2438 for Index
in File_Index
+ 1 .. Last
loop
2439 if Last_Switches
.Table
(Index
)
2440 (Last_Switches
.Table
(Index
)'First) /= '-'
2447 if Dir_Index
= 0 then
2448 Last_Switches
.Increment_Last
;
2449 Last_Switches
.Table
(Last_Switches
.Last
) :=
2451 (Dir_Name (Last_Switches.Table (File_Index).all));
2457 -- For gnatmetric, the generated files should be put in the object
2458 -- directory. This must be the first switch, because it may be
2459 -- overridden by a switch in package Metrics in the project file or
2460 -- by a command line option. Note that we don't add the -d= switch
2461 -- if there is no object directory available.
2463 if The_Command = Metric
2464 and then Project.Object_Directory /= No_Path_Information
2466 First_Switches.Increment_Last;
2467 First_Switches.Table (2 .. First_Switches.Last) :=
2468 First_Switches.Table (1 .. First_Switches.Last - 1);
2469 First_Switches.Table (1) :=
2471 Get_Name_String
(Project
.Object_Directory
.Name
));
2474 -- For gnat check, -rules and the following switches need to be the
2475 -- last options, so move all these switches to table Rules_Switches.
2477 if The_Command
= Check
then
2480 -- Set to rank of options preceding "-rules"
2482 In_Rules_Switches
: Boolean;
2483 -- Set to True when options "-rules" is found
2486 New_Last
:= First_Switches
.Last
;
2487 In_Rules_Switches
:= False;
2489 for J
in 1 .. First_Switches
.Last
loop
2490 if In_Rules_Switches
then
2491 Add_To_Rules_Switches
(First_Switches
.Table
(J
));
2493 elsif First_Switches
.Table
(J
).all = "-rules" then
2495 In_Rules_Switches
:= True;
2499 if In_Rules_Switches
then
2500 First_Switches
.Set_Last
(New_Last
);
2503 New_Last
:= Last_Switches
.Last
;
2504 In_Rules_Switches
:= False;
2506 for J
in 1 .. Last_Switches
.Last
loop
2507 if In_Rules_Switches
then
2508 Add_To_Rules_Switches
(Last_Switches
.Table
(J
));
2510 elsif Last_Switches
.Table
(J
).all = "-rules" then
2512 In_Rules_Switches
:= True;
2516 if In_Rules_Switches
then
2517 Last_Switches
.Set_Last
(New_Last
);
2522 -- For gnat check, sync, metric or pretty with -U + a main, get the
2523 -- list of sources from the closure and add them to the arguments.
2525 if ASIS_Main
/= null then
2528 -- On VMS, set up the env var again for source dirs file. This is
2529 -- because the call to gnatmake has set this env var to another
2530 -- file that has now been deleted.
2532 if Hostparm
.OpenVMS
then
2534 -- First make sure that the recorded file names are empty
2536 Prj
.Env
.Initialize
(Project_Tree
);
2538 Prj
.Env
.Set_Ada_Paths
2539 (Project
, Project_Tree
, Including_Libraries
=> False);
2542 -- For gnat check, gnat sync, gnat pretty, gnat metric, gnat list,
2543 -- and gnat stack, if no file has been put on the command line, call
2544 -- tool with all the sources of the main project.
2546 elsif The_Command
= Check
or else
2547 The_Command
= Sync
or else
2548 The_Command
= Pretty
or else
2549 The_Command
= Metric
or else
2550 The_Command
= List
or else
2557 -- Gather all the arguments and invoke the executable
2560 The_Args
: Argument_List
2561 (1 .. First_Switches
.Last
+
2562 Last_Switches
.Last
+
2563 Carg_Switches
.Last
+
2564 Rules_Switches
.Last
);
2565 Arg_Num
: Natural := 0;
2568 for J
in 1 .. First_Switches
.Last
loop
2569 Arg_Num
:= Arg_Num
+ 1;
2570 The_Args
(Arg_Num
) := First_Switches
.Table
(J
);
2573 for J
in 1 .. Last_Switches
.Last
loop
2574 Arg_Num
:= Arg_Num
+ 1;
2575 The_Args
(Arg_Num
) := Last_Switches
.Table
(J
);
2578 for J
in 1 .. Carg_Switches
.Last
loop
2579 Arg_Num
:= Arg_Num
+ 1;
2580 The_Args
(Arg_Num
) := Carg_Switches
.Table
(J
);
2583 for J
in 1 .. Rules_Switches
.Last
loop
2584 Arg_Num
:= Arg_Num
+ 1;
2585 The_Args
(Arg_Num
) := Rules_Switches
.Table
(J
);
2588 -- If Display_Command is on, only display the generated command
2590 if Display_Command
then
2591 Put
(Standard_Error
, "generated command -->");
2592 Put
(Standard_Error
, Exec_Path
.all);
2594 for Arg
in The_Args
'Range loop
2595 Put
(Standard_Error
, " ");
2596 Put
(Standard_Error
, The_Args
(Arg
).all);
2599 Put
(Standard_Error
, "<--");
2600 New_Line
(Standard_Error
);
2604 if Verbose_Mode
then
2605 Output
.Write_Str
(Exec_Path
.all);
2607 for Arg
in The_Args
'Range loop
2608 Output
.Write_Char
(' ');
2609 Output
.Write_Str
(The_Args
(Arg
).all);
2616 Exit_Status
(Spawn
(Exec_Path
.all, The_Args
));
2623 if not Keep_Temporary_Files
then
2624 Prj
.Delete_All_Temp_Files
(Project_Tree
);
2625 Delete_Temp_Config_Files
;
2628 Set_Exit_Status
(Failure
);
2631 if not Keep_Temporary_Files
then
2632 Prj
.Delete_All_Temp_Files
(Project_Tree
);
2633 Delete_Temp_Config_Files
;
2636 -- Since GNATCmd is normally called from DCL (the VMS shell), it must
2637 -- return an understandable VMS exit status. However the exit status
2638 -- returned *to* GNATCmd is a Posix style code, so we test it and return
2639 -- just a simple success or failure on VMS.
2641 if Hostparm
.OpenVMS
and then My_Exit_Status
/= Success
then
2642 Set_Exit_Status
(Failure
);
2644 Set_Exit_Status
(My_Exit_Status
);