1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2004-2011, 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 ------------------------------------------------------------------------------
28 with Err_Vars; use Err_Vars;
32 with Osint; use Osint;
33 with Output; use Output;
37 with Prj.Util; use Prj.Util;
39 with Snames; use Snames;
43 with Ada.Command_Line; use Ada.Command_Line;
44 with Ada.Unchecked_Deallocation;
46 with GNAT.Case_Util; use GNAT.Case_Util;
47 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
49 with GNAT.Regexp; use GNAT.Regexp;
51 package body Makeutl is
53 type Linker_Options_Data is record
55 Options : String_List_Id;
58 Linker_Option_Initial_Count : constant := 20;
60 Linker_Options_Buffer : String_List_Access :=
61 new String_List (1 .. Linker_Option_Initial_Count);
63 Last_Linker_Option : Natural := 0;
65 package Linker_Opts is new Table.Table (
66 Table_Component_Type => Linker_Options_Data,
67 Table_Index_Type => Integer,
70 Table_Increment => 100,
71 Table_Name => "Make.Linker_Opts");
73 procedure Add_Linker_Option (Option : String);
80 (Option : String_Access;
81 To : in out String_List_Access;
82 Last : in out Natural)
85 if Last = To'Last then
87 New_Options : constant String_List_Access :=
88 new String_List (1 .. To'Last * 2);
91 New_Options (To'Range) := To.all;
93 -- Set all elements of the original options to null to avoid
94 -- deallocation of copies.
96 To.all := (others => null);
109 To : in out String_List_Access;
110 Last : in out Natural)
113 Add (Option => new String'(Option), To => To, Last => Last);
116 -----------------------
117 -- Add_Linker_Option --
118 -----------------------
120 procedure Add_Linker_Option (Option : String) is
122 if Option'Length > 0 then
123 if Last_Linker_Option = Linker_Options_Buffer'Last then
125 New_Buffer : constant String_List_Access :=
127 (1 .. Linker_Options_Buffer'Last +
128 Linker_Option_Initial_Count);
130 New_Buffer (Linker_Options_Buffer'Range) :=
131 Linker_Options_Buffer.all;
132 Linker_Options_Buffer.all := (others => null);
133 Free (Linker_Options_Buffer);
134 Linker_Options_Buffer := New_Buffer;
138 Last_Linker_Option := Last_Linker_Option + 1;
139 Linker_Options_Buffer (Last_Linker_Option) := new String'(Option);
141 end Add_Linker_Option;
143 -------------------------
144 -- Base_Name_Index_For --
145 -------------------------
147 function Base_Name_Index_For
150 Index_Separator : Character) return File_Name_Type
152 Result : File_Name_Type;
156 Add_Str_To_Name_Buffer (Base_Name (Main));
158 -- Remove the extension, if any, that is the last part of the base name
159 -- starting with a dot and following some characters.
161 for J in reverse 2 .. Name_Len loop
162 if Name_Buffer (J) = '.' then
168 -- Add the index info, if index is different from 0
170 if Main_Index > 0 then
171 Add_Char_To_Name_Buffer (Index_Separator);
174 Img : constant String := Main_Index'Img;
176 Add_Str_To_Name_Buffer (Img (2 .. Img'Last));
182 end Base_Name_Index_For;
184 ------------------------------
185 -- Check_Source_Info_In_ALI --
186 ------------------------------
188 function Check_Source_Info_In_ALI
190 Tree : Project_Tree_Ref) return Boolean
195 -- Loop through units
197 for U in ALIs.Table (The_ALI).First_Unit ..
198 ALIs.Table (The_ALI).Last_Unit
200 -- Check if the file name is one of the source of the unit
202 Get_Name_String (Units.Table (U).Uname);
203 Name_Len := Name_Len - 2;
204 Unit_Name := Name_Find;
206 if File_Not_A_Source_Of (Tree, Unit_Name, Units.Table (U).Sfile) then
210 -- Loop to do same check for each of the withed units
212 for W in Units.Table (U).First_With .. Units.Table (U).Last_With loop
214 WR : ALI.With_Record renames Withs.Table (W);
217 if WR.Sfile /= No_File then
218 Get_Name_String (WR.Uname);
219 Name_Len := Name_Len - 2;
220 Unit_Name := Name_Find;
222 if File_Not_A_Source_Of (Tree, Unit_Name, WR.Sfile) then
230 -- Loop to check subunits and replaced sources
232 for D in ALIs.Table (The_ALI).First_Sdep ..
233 ALIs.Table (The_ALI).Last_Sdep
236 SD : Sdep_Record renames Sdep.Table (D);
239 Unit_Name := SD.Subunit_Name;
241 if Unit_Name = No_Name then
243 -- Check if this source file has been replaced by a source with
244 -- a different file name.
246 if Tree /= null and then Tree.Replaced_Source_Number > 0 then
248 Replacement : constant File_Name_Type :=
249 Replaced_Source_HTable.Get
250 (Tree.Replaced_Sources, SD.Sfile);
253 if Replacement /= No_File then
257 Get_Name_String (SD.Sfile) &
258 " has been replaced by " &
259 Get_Name_String (Replacement));
268 -- For separates, the file is no longer associated with the
269 -- unit ("proc-sep.adb" is not associated with unit "proc.sep")
270 -- so we need to check whether the source file still exists in
271 -- the source tree: it will if it matches the naming scheme
272 -- (and then will be for the same unit).
276 Project => No_Project,
277 Base_Name => SD.Sfile) = No_Source
279 -- If this is not a runtime file or if, when gnatmake switch
280 -- -a is used, we are not able to find this subunit in the
281 -- source directories, then recompilation is needed.
283 if not Fname.Is_Internal_File_Name (SD.Sfile)
285 (Check_Readonly_Files
286 and then Full_Source_Name (SD.Sfile) = No_File)
290 ("While parsing ALI file, file "
291 & Get_Name_String (SD.Sfile)
292 & " is indicated as containing subunit "
293 & Get_Name_String (Unit_Name)
294 & " but this does not match what was found while"
295 & " parsing the project. Will recompile");
306 end Check_Source_Info_In_ALI;
308 --------------------------------
309 -- Create_Binder_Mapping_File --
310 --------------------------------
312 function Create_Binder_Mapping_File
313 (Project_Tree : Project_Tree_Ref) return Path_Name_Type
315 Mapping_Path : Path_Name_Type := No_Path;
317 Mapping_FD : File_Descriptor := Invalid_FD;
318 -- A File Descriptor for an eventual mapping file
320 ALI_Unit : Unit_Name_Type := No_Unit_Name;
321 -- The unit name of an ALI file
323 ALI_Name : File_Name_Type := No_File;
324 -- The file name of the ALI file
326 ALI_Project : Project_Id := No_Project;
327 -- The project of the ALI file
330 OK : Boolean := False;
337 Tempdir.Create_Temp_File (Mapping_FD, Mapping_Path);
338 Record_Temp_File (Project_Tree.Shared, Mapping_Path);
340 if Mapping_FD /= Invalid_FD then
343 -- Traverse all units
345 Unit := Units_Htable.Get_First (Project_Tree.Units_HT);
346 while Unit /= No_Unit_Index loop
347 if Unit.Name /= No_Name then
349 -- If there is a body, put it in the mapping
351 if Unit.File_Names (Impl) /= No_Source
352 and then Unit.File_Names (Impl).Project /= No_Project
354 Get_Name_String (Unit.Name);
355 Add_Str_To_Name_Buffer ("%b");
356 ALI_Unit := Name_Find;
358 Lib_File_Name (Unit.File_Names (Impl).Display_File);
359 ALI_Project := Unit.File_Names (Impl).Project;
361 -- Otherwise, if there is a spec, put it in the mapping
363 elsif Unit.File_Names (Spec) /= No_Source
364 and then Unit.File_Names (Spec).Project /= No_Project
366 Get_Name_String (Unit.Name);
367 Add_Str_To_Name_Buffer ("%s");
368 ALI_Unit := Name_Find;
370 Lib_File_Name (Unit.File_Names (Spec).Display_File);
371 ALI_Project := Unit.File_Names (Spec).Project;
377 -- If we have something to put in the mapping then do it now.
378 -- However, if the project is extended, we don't put anything
379 -- in the mapping file, since we don't know where the ALI file
380 -- is: it might be in the extended project object directory as
381 -- well as in the extending project object directory.
383 if ALI_Name /= No_File
384 and then ALI_Project.Extended_By = No_Project
385 and then ALI_Project.Extends = No_Project
387 -- First check if the ALI file exists. If it does not, do
388 -- not put the unit in the mapping file.
391 ALI : constant String := Get_Name_String (ALI_Name);
394 -- For library projects, use the library ALI directory,
395 -- for other projects, use the object directory.
397 if ALI_Project.Library then
399 (ALI_Project.Library_ALI_Dir.Display_Name);
402 (ALI_Project.Object_Directory.Display_Name);
405 Add_Str_To_Name_Buffer (ALI);
406 Add_Char_To_Name_Buffer (ASCII.LF);
409 ALI_Path_Name : constant String :=
410 Name_Buffer (1 .. Name_Len);
414 (ALI_Path_Name (1 .. ALI_Path_Name'Last - 1))
416 -- First line is the unit name
418 Get_Name_String (ALI_Unit);
419 Add_Char_To_Name_Buffer (ASCII.LF);
423 Name_Buffer (1)'Address,
425 OK := Bytes = Name_Len;
429 -- Second line it the ALI file name
431 Get_Name_String (ALI_Name);
432 Add_Char_To_Name_Buffer (ASCII.LF);
436 Name_Buffer (1)'Address,
438 OK := (Bytes = Name_Len);
442 -- Third line it the ALI path name
447 ALI_Path_Name (1)'Address,
448 ALI_Path_Name'Length);
449 OK := (Bytes = ALI_Path_Name'Length);
451 -- If OK is False, it means we were unable to
452 -- write a line. No point in continuing with the
462 Unit := Units_Htable.Get_Next (Project_Tree.Units_HT);
465 Close (Mapping_FD, Status);
470 -- If the creation of the mapping file was successful, we add the switch
471 -- to the arguments of gnatbind.
479 end Create_Binder_Mapping_File;
485 function Create_Name (Name : String) return File_Name_Type is
488 Add_Str_To_Name_Buffer (Name);
492 function Create_Name (Name : String) return Name_Id is
495 Add_Str_To_Name_Buffer (Name);
499 function Create_Name (Name : String) return Path_Name_Type is
502 Add_Str_To_Name_Buffer (Name);
506 ----------------------------
507 -- Executable_Prefix_Path --
508 ----------------------------
510 function Executable_Prefix_Path return String is
511 Exec_Name : constant String := Command_Name;
513 function Get_Install_Dir (S : String) return String;
514 -- S is the executable name preceded by the absolute or relative path,
515 -- e.g. "c:\usr\bin\gcc.exe". Returns the absolute directory where "bin"
516 -- lies (in the example "C:\usr"). If the executable is not in a "bin"
517 -- directory, return "".
519 ---------------------
520 -- Get_Install_Dir --
521 ---------------------
523 function Get_Install_Dir (S : String) return String is
525 Path_Last : Integer := 0;
528 for J in reverse Exec'Range loop
529 if Exec (J) = Directory_Separator then
535 if Path_Last >= Exec'First + 2 then
536 To_Lower (Exec (Path_Last - 2 .. Path_Last));
539 if Path_Last < Exec'First + 2
540 or else Exec (Path_Last - 2 .. Path_Last) /= "bin"
541 or else (Path_Last - 3 >= Exec'First
542 and then Exec (Path_Last - 3) /= Directory_Separator)
547 return Normalize_Pathname
548 (Exec (Exec'First .. Path_Last - 4),
549 Resolve_Links => Opt.Follow_Links_For_Dirs)
550 & Directory_Separator;
553 -- Beginning of Executable_Prefix_Path
556 -- For VMS, the path returned is always /gnu/
558 if Hostparm.OpenVMS then
562 -- First determine if a path prefix was placed in front of the
565 for J in reverse Exec_Name'Range loop
566 if Exec_Name (J) = Directory_Separator then
567 return Get_Install_Dir (Exec_Name);
571 -- If we get here, the user has typed the executable name with no
575 Path : String_Access := Locate_Exec_On_Path (Exec_Name);
581 Dir : constant String := Get_Install_Dir (Path.all);
588 end Executable_Prefix_Path;
594 procedure Fail_Program
595 (Project_Tree : Project_Tree_Ref;
597 Flush_Messages : Boolean := True)
600 if Flush_Messages then
601 if Total_Errors_Detected /= 0 or else Warnings_Detected /= 0 then
606 Finish_Program (Project_Tree, E_Fatal, S => S);
613 procedure Finish_Program
614 (Project_Tree : Project_Tree_Ref;
615 Exit_Code : Osint.Exit_Code_Type := Osint.E_Success;
619 if not Debug.Debug_Flag_N then
620 Delete_Temp_Config_Files (Project_Tree);
622 if Project_Tree /= null then
623 Delete_All_Temp_Files (Project_Tree.Shared);
628 if Exit_Code /= E_Success then
635 -- Output Namet statistics
639 Exit_Program (Exit_Code);
642 --------------------------
643 -- File_Not_A_Source_Of --
644 --------------------------
646 function File_Not_A_Source_Of
647 (Project_Tree : Project_Tree_Ref;
649 Sfile : File_Name_Type) return Boolean
651 Unit : constant Unit_Index :=
652 Units_Htable.Get (Project_Tree.Units_HT, Uname);
654 At_Least_One_File : Boolean := False;
657 if Unit /= No_Unit_Index then
658 for F in Unit.File_Names'Range loop
659 if Unit.File_Names (F) /= null then
660 At_Least_One_File := True;
661 if Unit.File_Names (F).File = Sfile then
667 if not At_Least_One_File then
669 -- The unit was probably created initially for a separate unit
670 -- (which are initially created as IMPL when both suffixes are the
671 -- same). Later on, Override_Kind changed the type of the file,
672 -- and the unit is no longer valid in fact.
677 Verbose_Msg (Uname, "sources do not include ", Name_Id (Sfile));
682 end File_Not_A_Source_Of;
688 procedure Get_Switches
689 (Source : Prj.Source_Id;
691 Project_Tree : Project_Tree_Ref;
692 Value : out Variable_Value;
693 Is_Default : out Boolean)
697 (Source_File => Source.File,
698 Source_Lang => Source.Language.Name,
699 Source_Prj => Source.Project,
700 Pkg_Name => Pkg_Name,
701 Project_Tree => Project_Tree,
703 Is_Default => Is_Default);
710 procedure Get_Switches
711 (Source_File : File_Name_Type;
712 Source_Lang : Name_Id;
713 Source_Prj : Project_Id;
715 Project_Tree : Project_Tree_Ref;
716 Value : out Variable_Value;
717 Is_Default : out Boolean;
718 Test_Without_Suffix : Boolean := False;
719 Check_ALI_Suffix : Boolean := False)
721 Project : constant Project_Id :=
722 Ultimate_Extending_Project_Of (Source_Prj);
723 Pkg : constant Package_Id :=
726 In_Packages => Project.Decl.Packages,
727 Shared => Project_Tree.Shared);
733 if Source_File /= No_File then
734 Value := Prj.Util.Value_Of
735 (Name => Name_Id (Source_File),
736 Attribute_Or_Array_Name => Name_Switches,
738 Shared => Project_Tree.Shared,
739 Allow_Wildcards => True);
742 if Value = Nil_Variable_Value
743 and then Test_Without_Suffix
746 Get_Language_From_Name (Project, Get_Name_String (Source_Lang));
750 Naming : Lang_Naming_Data renames Lang.Config.Naming_Data;
751 SF_Name : constant String := Get_Name_String (Source_File);
752 Last : Positive := SF_Name'Length;
753 Name : String (1 .. Last + 3);
754 Spec_Suffix : String := Get_Name_String (Naming.Spec_Suffix);
755 Body_Suffix : String := Get_Name_String (Naming.Body_Suffix);
756 Truncated : Boolean := False;
759 Canonical_Case_File_Name (Spec_Suffix);
760 Canonical_Case_File_Name (Body_Suffix);
761 Name (1 .. Last) := SF_Name;
763 if Last > Body_Suffix'Length
764 and then Name (Last - Body_Suffix'Length + 1 .. Last) =
768 Last := Last - Body_Suffix'Length;
772 and then Last > Spec_Suffix'Length
773 and then Name (Last - Spec_Suffix'Length + 1 .. Last) =
777 Last := Last - Spec_Suffix'Length;
782 Add_Str_To_Name_Buffer (Name (1 .. Last));
784 Value := Prj.Util.Value_Of
786 Attribute_Or_Array_Name => Name_Switches,
788 Shared => Project_Tree.Shared,
789 Allow_Wildcards => True);
792 if Value = Nil_Variable_Value
793 and then Check_ALI_Suffix
795 Last := SF_Name'Length;
796 while Name (Last) /= '.' loop
801 Add_Str_To_Name_Buffer (Name (1 .. Last));
802 Add_Str_To_Name_Buffer ("ali");
804 Value := Prj.Util.Value_Of
806 Attribute_Or_Array_Name => Name_Switches,
808 Shared => Project_Tree.Shared,
809 Allow_Wildcards => True);
815 if Value = Nil_Variable_Value then
819 (Name => Source_Lang,
820 Attribute_Or_Array_Name => Name_Switches,
822 Shared => Project_Tree.Shared,
823 Force_Lower_Case_Index => True);
826 if Value = Nil_Variable_Value then
829 (Name => All_Other_Names,
830 Attribute_Or_Array_Name => Name_Switches,
832 Shared => Project_Tree.Shared,
833 Force_Lower_Case_Index => True);
836 if Value = Nil_Variable_Value then
839 (Name => Source_Lang,
840 Attribute_Or_Array_Name => Name_Default_Switches,
842 Shared => Project_Tree.Shared);
850 procedure Inform (N : File_Name_Type; Msg : String) is
852 Inform (Name_Id (N), Msg);
855 procedure Inform (N : Name_Id := No_Name; Msg : String) is
857 Osint.Write_Program_Name;
865 Name : constant String := Get_Name_String (N);
867 if Debug.Debug_Flag_F and then Is_Absolute_Path (Name) then
868 Write_Str (File_Name (Name));
881 ------------------------------
882 -- Initialize_Source_Record --
883 ------------------------------
885 procedure Initialize_Source_Record (Source : Prj.Source_Id) is
886 procedure Set_Object_Project
887 (Obj_Dir : String; Obj_Proj : Project_Id; Obj_Path : Path_Name_Type;
888 Stamp : Time_Stamp_Type);
889 -- Update information about object file, switches file,...
891 ------------------------
892 -- Set_Object_Project --
893 ------------------------
895 procedure Set_Object_Project
896 (Obj_Dir : String; Obj_Proj : Project_Id; Obj_Path : Path_Name_Type;
897 Stamp : Time_Stamp_Type) is
899 Source.Object_Project := Obj_Proj;
900 Source.Object_Path := Obj_Path;
901 Source.Object_TS := Stamp;
903 if Source.Language.Config.Dependency_Kind /= None then
905 Dep_Path : constant String :=
908 Get_Name_String (Source.Dep_Name),
909 Resolve_Links => Opt.Follow_Links_For_Files,
910 Directory => Obj_Dir);
912 Source.Dep_Path := Create_Name (Dep_Path);
913 Source.Dep_TS := Osint.Unknown_Attributes;
917 -- Get the path of the switches file, even if Opt.Check_Switches is
918 -- not set, as switch -s may be in the Builder switches that have not
922 Switches_Path : constant String :=
924 (Name => Get_Name_String (Source.Switches),
925 Resolve_Links => Opt.Follow_Links_For_Files,
926 Directory => Obj_Dir);
928 Source.Switches_Path := Create_Name (Switches_Path);
930 if Stamp /= Empty_Time_Stamp then
931 Source.Switches_TS := File_Stamp (Source.Switches_Path);
934 end Set_Object_Project;
936 Obj_Proj : Project_Id;
939 -- Nothing to do if source record has already been fully initialized
941 if Source.Initialized then
945 -- Systematically recompute the time stamp
947 Source.Source_TS := File_Stamp (Source.Path.Display_Name);
949 -- Parse the source file to check whether we have a subunit
951 if Source.Language.Config.Kind = Unit_Based
952 and then Source.Kind = Impl
953 and then Is_Subunit (Source)
958 if Source.Language.Config.Object_Generated
959 and then Is_Compilable (Source)
961 -- First, get the correct object file name and dependency file name
962 -- if the source is in a multi-unit file.
964 if Source.Index /= 0 then
967 (Source_File_Name => Source.File,
968 Source_Index => Source.Index,
970 Source.Language.Config.Multi_Unit_Object_Separator,
971 Object_File_Suffix =>
972 Source.Language.Config.Object_File_Suffix);
976 (Source.Object, Source.Language.Config.Dependency_Kind);
979 -- Find the object file for that source. It could be either in the
980 -- current project or in an extended project (it might actually not
981 -- exist yet in the ultimate extending project, but if not found
982 -- elsewhere that's where we'll expect to find it).
984 Obj_Proj := Source.Project;
985 while Obj_Proj /= No_Project loop
987 Dir : constant String := Get_Name_String
988 (Obj_Proj.Object_Directory.Display_Name);
990 Object_Path : constant String :=
993 Get_Name_String (Source.Object),
995 Opt.Follow_Links_For_Files,
998 Obj_Path : constant Path_Name_Type := Create_Name (Object_Path);
999 Stamp : Time_Stamp_Type := Empty_Time_Stamp;
1002 -- For specs, we do not check object files if there is a body.
1003 -- This saves a system call. On the other hand, we do need to
1004 -- know the object_path, in case the user has passed the .ads
1005 -- on the command line to compile the spec only.
1007 if Source.Kind /= Spec
1008 or else Source.Unit = No_Unit_Index
1009 or else Source.Unit.File_Names (Impl) = No_Source
1011 Stamp := File_Stamp (Obj_Path);
1014 if Stamp /= Empty_Time_Stamp
1015 or else (Obj_Proj.Extended_By = No_Project
1016 and then Source.Object_Project = No_Project)
1018 Set_Object_Project (Dir, Obj_Proj, Obj_Path, Stamp);
1021 Obj_Proj := Obj_Proj.Extended_By;
1025 elsif Source.Language.Config.Dependency_Kind = Makefile then
1027 Object_Dir : constant String :=
1029 (Source.Project.Object_Directory.Display_Name);
1030 Dep_Path : constant String :=
1032 (Name => Get_Name_String (Source.Dep_Name),
1034 Opt.Follow_Links_For_Files,
1035 Directory => Object_Dir);
1037 Source.Dep_Path := Create_Name (Dep_Path);
1038 Source.Dep_TS := Osint.Unknown_Attributes;
1042 Source.Initialized := True;
1043 end Initialize_Source_Record;
1045 ----------------------------
1046 -- Is_External_Assignment --
1047 ----------------------------
1049 function Is_External_Assignment
1050 (Env : Prj.Tree.Environment;
1051 Argv : String) return Boolean
1053 Start : Positive := 3;
1054 Finish : Natural := Argv'Last;
1056 pragma Assert (Argv'First = 1);
1057 pragma Assert (Argv (1 .. 2) = "-X");
1060 if Argv'Last < 5 then
1063 elsif Argv (3) = '"' then
1064 if Argv (Argv'Last) /= '"' or else Argv'Last < 7 then
1068 Finish := Argv'Last - 1;
1072 return Prj.Ext.Check
1073 (Self => Env.External,
1074 Declaration => Argv (Start .. Finish));
1075 end Is_External_Assignment;
1081 function Is_Subunit (Source : Prj.Source_Id) return Boolean is
1082 Src_Ind : Source_File_Index;
1085 if Source.Kind = Sep then
1088 -- A Spec, a file based language source or a body with a spec cannot be
1091 elsif Source.Kind = Spec
1092 or else Source.Unit = No_Unit_Index
1093 or else Other_Part (Source) /= No_Source
1098 -- Here, we are assuming that the language is Ada, as it is the only
1099 -- unit based language that we know.
1102 Sinput.P.Load_Project_File
1103 (Get_Name_String (Source.Path.Display_Name));
1105 return Sinput.P.Source_File_Is_Subunit (Src_Ind);
1108 -----------------------------
1109 -- Linker_Options_Switches --
1110 -----------------------------
1112 function Linker_Options_Switches
1113 (Project : Project_Id;
1114 Do_Fail : Fail_Proc;
1115 In_Tree : Project_Tree_Ref) return String_List
1117 procedure Recursive_Add
1119 In_Tree : Project_Tree_Ref;
1120 Dummy : in out Boolean);
1121 -- The recursive routine used to add linker options
1127 procedure Recursive_Add
1129 In_Tree : Project_Tree_Ref;
1130 Dummy : in out Boolean)
1132 pragma Unreferenced (Dummy);
1134 Linker_Package : Package_Id;
1135 Options : Variable_Value;
1140 (Name => Name_Linker,
1141 In_Packages => Proj.Decl.Packages,
1142 Shared => In_Tree.Shared);
1148 Attribute_Or_Array_Name => Name_Linker_Options,
1149 In_Package => Linker_Package,
1150 Shared => In_Tree.Shared);
1152 -- If attribute is present, add the project with the attribute to
1153 -- table Linker_Opts.
1155 if Options /= Nil_Variable_Value then
1156 Linker_Opts.Increment_Last;
1157 Linker_Opts.Table (Linker_Opts.Last) :=
1158 (Project => Proj, Options => Options.Values);
1162 procedure For_All_Projects is
1163 new For_Every_Project_Imported (Boolean, Recursive_Add);
1165 Dummy : Boolean := False;
1167 -- Start of processing for Linker_Options_Switches
1172 For_All_Projects (Project, In_Tree, Dummy, Imported_First => True);
1174 Last_Linker_Option := 0;
1176 for Index in reverse 1 .. Linker_Opts.Last loop
1178 Options : String_List_Id;
1179 Proj : constant Project_Id :=
1180 Linker_Opts.Table (Index).Project;
1182 Dir_Path : constant String :=
1183 Get_Name_String (Proj.Directory.Name);
1186 Options := Linker_Opts.Table (Index).Options;
1187 while Options /= Nil_String loop
1188 Option := In_Tree.Shared.String_Elements.Table (Options).Value;
1189 Get_Name_String (Option);
1191 -- Do not consider empty linker options
1193 if Name_Len /= 0 then
1194 Add_Linker_Option (Name_Buffer (1 .. Name_Len));
1196 -- Object files and -L switches specified with relative
1197 -- paths must be converted to absolute paths.
1199 Test_If_Relative_Path
1200 (Switch => Linker_Options_Buffer (Last_Linker_Option),
1203 Including_L_Switch => True);
1206 Options := In_Tree.Shared.String_Elements.Table (Options).Next;
1211 return Linker_Options_Buffer (1 .. Last_Linker_Option);
1212 end Linker_Options_Switches;
1218 package body Mains is
1220 package Names is new Table.Table
1221 (Table_Component_Type => Main_Info,
1222 Table_Index_Type => Integer,
1223 Table_Low_Bound => 1,
1224 Table_Initial => 10,
1225 Table_Increment => 100,
1226 Table_Name => "Makeutl.Mains.Names");
1227 -- The table that stores the mains
1229 Current : Natural := 0;
1230 -- The index of the last main retrieved from the table
1232 Count_Of_Mains_With_No_Tree : Natural := 0;
1233 -- Number of main units for which we do not know the project tree
1242 Location : Source_Ptr := No_Location;
1243 Project : Project_Id := No_Project;
1244 Tree : Project_Tree_Ref := null)
1247 if Current_Verbosity = High then
1248 Debug_Output ("Add_Main """ & Name & """ " & Index'Img
1250 & Boolean'Image (Tree /= null));
1254 Add_Str_To_Name_Buffer (Name);
1255 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1257 Names.Increment_Last;
1258 Names.Table (Names.Last) :=
1259 (Name_Find, Index, Location, No_Source, Project, Tree);
1261 if Tree /= null then
1262 Builder_Data (Tree).Number_Of_Mains :=
1263 Builder_Data (Tree).Number_Of_Mains + 1;
1266 Mains.Count_Of_Mains_With_No_Tree :=
1267 Mains.Count_Of_Mains_With_No_Tree + 1;
1271 --------------------
1272 -- Complete_Mains --
1273 --------------------
1275 procedure Complete_Mains
1276 (Flags : Processing_Flags;
1277 Root_Project : Project_Id;
1278 Project_Tree : Project_Tree_Ref)
1280 procedure Do_Complete (Project : Project_Id; Tree : Project_Tree_Ref);
1281 -- Check the mains for this specific project
1283 procedure Complete_All is new For_Project_And_Aggregated
1286 procedure Add_Multi_Unit_Sources
1287 (Tree : Project_Tree_Ref;
1288 Source : Prj.Source_Id);
1289 -- Add all units from the same file as the multi-unit Source.
1291 function Find_File_Add_Extension
1292 (Tree : Project_Tree_Ref;
1293 Root_Project : Project_Id;
1294 Base_Main : String) return Prj.Source_Id;
1295 -- Search for Main in the project, adding body or spec extensions.
1297 ----------------------------
1298 -- Add_Multi_Unit_Sources --
1299 ----------------------------
1301 procedure Add_Multi_Unit_Sources
1302 (Tree : Project_Tree_Ref;
1303 Source : Prj.Source_Id)
1305 Iter : Source_Iterator;
1306 Src : Prj.Source_Id;
1310 ("found multi-unit source file in project", Source.Project.Name);
1312 Iter := For_Each_Source
1313 (In_Tree => Tree, Project => Source.Project);
1315 while Element (Iter) /= No_Source loop
1316 Src := Element (Iter);
1318 if Src.File = Source.File
1319 and then Src.Index /= Source.Index
1321 if Src.File = Source.File then
1323 ("add main in project, index=" & Src.Index'Img);
1326 Names.Increment_Last;
1327 Names.Table (Names.Last) :=
1330 Location => No_Location,
1332 Project => Src.Project,
1335 Builder_Data (Tree).Number_Of_Mains :=
1336 Builder_Data (Tree).Number_Of_Mains + 1;
1341 end Add_Multi_Unit_Sources;
1343 -----------------------------
1344 -- Find_File_Add_Extension --
1345 -----------------------------
1347 function Find_File_Add_Extension
1348 (Tree : Project_Tree_Ref;
1349 Root_Project : Project_Id;
1350 Base_Main : String) return Prj.Source_Id
1352 Spec_Source : Prj.Source_Id := No_Source;
1353 Source : Prj.Source_Id := No_Source;
1354 Project : Project_Id := Root_Project;
1355 Iter : Source_Iterator;
1356 Suffix : File_Name_Type;
1358 while Source = No_Source
1359 and then Project /= No_Project
1361 Iter := For_Each_Source (Tree, Project);
1363 Source := Prj.Element (Iter);
1364 exit when Source = No_Source;
1366 if Source.Kind = Impl then
1367 Get_Name_String (Source.File);
1369 if Name_Len > Base_Main'Length
1370 and then Name_Buffer (1 .. Base_Main'Length) = Base_Main
1373 Source.Language.Config.Naming_Data.Body_Suffix;
1375 exit when Suffix /= No_File and then
1376 Name_Buffer (Base_Main'Length + 1 .. Name_Len) =
1377 Get_Name_String (Suffix);
1380 elsif Source.Kind = Spec then
1381 -- A spec needs to be taken into account unless there is
1382 -- also a body. So we delay the decision for them.
1384 Get_Name_String (Source.File);
1386 if Name_Len > Base_Main'Length
1387 and then Name_Buffer (1 .. Base_Main'Length) = Base_Main
1390 Source.Language.Config.Naming_Data.Spec_Suffix;
1392 if Suffix /= No_File
1394 Name_Buffer (Base_Main'Length + 1 .. Name_Len) =
1395 Get_Name_String (Suffix)
1397 Spec_Source := Source;
1405 Project := Project.Extends;
1408 if Source = No_Source then
1409 Source := Spec_Source;
1413 end Find_File_Add_Extension;
1419 procedure Do_Complete
1420 (Project : Project_Id; Tree : Project_Tree_Ref)
1423 if Mains.Number_Of_Mains (Tree) > 0
1424 or else Mains.Count_Of_Mains_With_No_Tree > 0
1426 -- Traverse in reverse order, since in the case of multi-unit
1427 -- files we will be adding extra files at the end, and there's
1428 -- no need to process them in turn.
1430 for J in reverse Names.First .. Names.Last loop
1432 File : Main_Info := Names.Table (J);
1433 Main_Id : File_Name_Type := File.File;
1434 Main : constant String := Get_Name_String (Main_Id);
1435 Base : constant String := Base_Name (Main);
1436 Source : Prj.Source_Id := No_Source;
1437 Is_Absolute : Boolean := False;
1440 if Base /= Main then
1441 if Is_Absolute_Path (Main) then
1442 Main_Id := Create_Name (Base);
1443 Is_Absolute := True;
1446 Absolute : constant String :=
1450 Resolve_Links => False);
1452 File.File := Create_Name (Absolute);
1453 Main_Id := Create_Name (Base);
1458 -- If no project or tree was specified for the main, it
1459 -- came from the command line.
1460 -- Note that the assignments below will not modify inside
1461 -- the table itself.
1463 if File.Project = null then
1464 File.Project := Project;
1467 if File.Tree = null then
1471 if File.Source = null then
1472 if Current_Verbosity = High then
1474 ("search for main """ & Main
1475 & '"' & File.Index'Img & " in "
1476 & Get_Name_String (Debug_Name (File.Tree))
1477 & ", project", Project.Name);
1480 -- First, look for the main as specified. We need to
1481 -- search for the base name though, and if needed
1482 -- check later that we found the correct file.
1484 Source := Find_Source
1485 (In_Tree => File.Tree,
1486 Project => File.Project,
1487 Base_Name => Main_Id,
1488 Index => File.Index);
1490 if Source = No_Source then
1491 Source := Find_File_Add_Extension
1492 (Tree, File.Project, Get_Name_String (Main_Id));
1496 and then Source /= No_Source
1497 and then File_Name_Type (Source.Path.Name) /=
1501 ("Found a non-matching file",
1502 Name_Id (Source.Path.Display_Name));
1503 Source := No_Source;
1506 if Source = No_Source then
1507 -- Still not found ? Maybe we have a unit name
1509 Unit : constant Unit_Index :=
1511 (File.Tree.Units_HT, Name_Id (Main_Id));
1514 if Unit /= No_Unit_Index then
1515 Source := Unit.File_Names (Impl);
1516 if Source = No_Source then
1517 Source := Unit.File_Names (Spec);
1523 if Source /= No_Source then
1525 -- If we have found a multi-unit source file but
1526 -- did not specify an index initially, we'll need
1527 -- to compile all the units from the same source
1530 if Source.Index /= 0
1531 and then File.Index = 0
1533 Add_Multi_Unit_Sources (File.Tree, Source);
1536 -- Now update the original Main, otherwise it will
1537 -- be reported as not found.
1540 ("found main in project", Source.Project.Name);
1541 Names.Table (J).File := Source.File;
1542 Names.Table (J).Project := File.Project;
1544 if Names.Table (J).Tree = null then
1545 Names.Table (J).Tree := File.Tree;
1547 Builder_Data (File.Tree).Number_Of_Mains :=
1548 Builder_Data (File.Tree).Number_Of_Mains + 1;
1549 Mains.Count_Of_Mains_With_No_Tree :=
1550 Mains.Count_Of_Mains_With_No_Tree - 1;
1553 Names.Table (J).Source := Source;
1555 elsif File.Location /= No_Location then
1557 -- If the main is declared in package Builder of
1558 -- the main project, report an error. If the main
1559 -- is on the command line, it may be a main from
1560 -- another project, so do nothing: if the main does
1561 -- not exist in another project, an error will be
1564 Error_Msg_File_1 := Main_Id;
1565 Error_Msg_Name_1 := Root_Project.Name;
1568 "{ is not a source of project %%",
1569 File.Location, Project);
1576 if Total_Errors_Detected > 0 then
1577 Fail_Program (Tree, "problems with main sources");
1581 -- Start of processing for Complete_Mains
1584 Complete_All (Root_Project, Project_Tree);
1586 if Mains.Count_Of_Mains_With_No_Tree > 0 then
1587 for J in Names.First .. Names.Last loop
1588 if Names.Table (J).Source = No_Source then
1590 (Project_Tree, '"' & Get_Name_String (Names.Table (J).File)
1591 & """ is not a source of any project");
1607 -----------------------
1608 -- Fill_From_Project --
1609 -----------------------
1611 procedure Fill_From_Project
1612 (Root_Project : Project_Id;
1613 Project_Tree : Project_Tree_Ref)
1615 procedure Add_Mains_From_Project
1616 (Project : Project_Id;
1617 Tree : Project_Tree_Ref);
1618 -- Add the main units from this project into Mains.
1619 -- This takes into account the aggregated projects
1621 ----------------------------
1622 -- Add_Mains_From_Project --
1623 ----------------------------
1625 procedure Add_Mains_From_Project
1626 (Project : Project_Id;
1627 Tree : Project_Tree_Ref)
1629 List : String_List_Id;
1630 Element : String_Element;
1633 if Number_Of_Mains (Tree) = 0
1634 and then Mains.Count_Of_Mains_With_No_Tree = 0
1636 Debug_Output ("Add_Mains_From_Project", Project.Name);
1637 List := Project.Mains;
1639 if List /= Prj.Nil_String then
1641 -- The attribute Main is not an empty list. Get the mains in
1644 while List /= Prj.Nil_String loop
1645 Element := Tree.Shared.String_Elements.Table (List);
1646 Debug_Output ("Add_Main", Element.Value);
1648 if Project.Library then
1651 "cannot specify a main program " &
1652 "for a library project file");
1655 Add_Main (Name => Get_Name_String (Element.Value),
1656 Index => Element.Index,
1657 Location => Element.Location,
1660 List := Element.Next;
1665 if Total_Errors_Detected > 0 then
1666 Fail_Program (Tree, "problems with main sources");
1668 end Add_Mains_From_Project;
1670 procedure Fill_All is new For_Project_And_Aggregated
1671 (Add_Mains_From_Project);
1673 -- Start of processing for Fill_From_Project
1676 Fill_All (Root_Project, Project_Tree);
1677 end Fill_From_Project;
1683 function Next_Main return String is
1684 Info : constant Main_Info := Next_Main;
1686 if Info = No_Main_Info then
1689 return Get_Name_String (Info.File);
1693 function Next_Main return Main_Info is
1695 if Current >= Names.Last then
1696 return No_Main_Info;
1698 Current := Current + 1;
1700 -- If not using projects, and in the gnatmake case, the main file
1701 -- may have not have the extension. Try ".adb" first then ".ads"
1703 if Names.Table (Current).Project = No_Project then
1705 Orig_Main : constant File_Name_Type :=
1706 Names.Table (Current).File;
1707 Current_Main : File_Name_Type;
1710 if Strip_Suffix (Orig_Main) = Orig_Main then
1711 Get_Name_String (Orig_Main);
1712 Add_Str_To_Name_Buffer (".adb");
1713 Current_Main := Name_Find;
1715 if Full_Source_Name (Current_Main) = No_File then
1716 Get_Name_String (Orig_Main);
1717 Add_Str_To_Name_Buffer (".ads");
1718 Current_Main := Name_Find;
1720 if Full_Source_Name (Current_Main) /= No_File then
1721 Names.Table (Current).File := Current_Main;
1725 Names.Table (Current).File := Current_Main;
1731 return Names.Table (Current);
1735 ---------------------
1736 -- Number_Of_Mains --
1737 ---------------------
1739 function Number_Of_Mains (Tree : Project_Tree_Ref) return Natural is
1744 return Builder_Data (Tree).Number_Of_Mains;
1746 end Number_Of_Mains;
1757 --------------------------
1758 -- Set_Multi_Unit_Index --
1759 --------------------------
1761 procedure Set_Multi_Unit_Index
1762 (Project_Tree : Project_Tree_Ref := null;
1767 if Names.Last = 0 then
1770 "cannot specify a multi-unit index but no main " &
1771 "on the command line");
1773 elsif Names.Last > 1 then
1776 "cannot specify several mains with a multi-unit index");
1779 Names.Table (Names.Last).Index := Index;
1782 end Set_Multi_Unit_Index;
1786 -----------------------
1787 -- Path_Or_File_Name --
1788 -----------------------
1790 function Path_Or_File_Name (Path : Path_Name_Type) return String is
1791 Path_Name : constant String := Get_Name_String (Path);
1793 if Debug.Debug_Flag_F then
1794 return File_Name (Path_Name);
1798 end Path_Or_File_Name;
1800 ---------------------------
1801 -- Test_If_Relative_Path --
1802 ---------------------------
1804 procedure Test_If_Relative_Path
1805 (Switch : in out String_Access;
1807 Do_Fail : Fail_Proc;
1808 Including_L_Switch : Boolean := True;
1809 Including_Non_Switch : Boolean := True;
1810 Including_RTS : Boolean := False)
1813 if Switch /= null then
1815 Sw : String (1 .. Switch'Length);
1821 if Sw (1) = '-' then
1823 and then (Sw (2) = 'A'
1824 or else Sw (2) = 'I'
1825 or else (Including_L_Switch and then Sw (2) = 'L'))
1833 elsif Sw'Length >= 4
1834 and then (Sw (2 .. 3) = "aL"
1835 or else Sw (2 .. 3) = "aO"
1836 or else Sw (2 .. 3) = "aI")
1841 and then Sw'Length >= 7
1842 and then Sw (2 .. 6) = "-RTS="
1850 -- Because relative path arguments to --RTS= may be relative to
1851 -- the search directory prefix, those relative path arguments
1852 -- are converted only when they include directory information.
1854 if not Is_Absolute_Path (Sw (Start .. Sw'Last)) then
1855 if Parent'Length = 0 then
1857 ("relative search path switches ("""
1859 & """) are not allowed");
1861 elsif Including_RTS then
1862 for J in Start .. Sw'Last loop
1863 if Sw (J) = Directory_Separator then
1866 (Sw (1 .. Start - 1) &
1868 Directory_Separator &
1869 Sw (Start .. Sw'Last));
1877 (Sw (1 .. Start - 1) &
1879 Directory_Separator &
1880 Sw (Start .. Sw'Last));
1884 elsif Including_Non_Switch then
1885 if not Is_Absolute_Path (Sw) then
1886 if Parent'Length = 0 then
1888 ("relative paths (""" & Sw & """) are not allowed");
1890 Switch := new String'(Parent & Directory_Separator & Sw);
1896 end Test_If_Relative_Path;
1902 function Unit_Index_Of (ALI_File : File_Name_Type) return Int is
1908 Get_Name_String (ALI_File);
1910 -- First, find the last dot
1914 while Finish >= 1 and then Name_Buffer (Finish) /= '.' loop
1915 Finish := Finish - 1;
1922 -- Now check that the dot is preceded by digits
1925 Finish := Finish - 1;
1927 while Start >= 1 and then Name_Buffer (Start - 1) in '0' .. '9' loop
1931 -- If there are no digits, or if the digits are not preceded by the
1932 -- character that precedes a unit index, this is not the ALI file of
1933 -- a unit in a multi-unit source.
1937 or else Name_Buffer (Start - 1) /= Multi_Unit_Index_Character
1942 -- Build the index from the digit(s)
1944 while Start <= Finish loop
1945 Result := Result * 10 +
1946 Character'Pos (Name_Buffer (Start)) - Character'Pos ('0');
1957 procedure Verbose_Msg
1960 N2 : Name_Id := No_Name;
1962 Prefix : String := " -> ";
1963 Minimum_Verbosity : Opt.Verbosity_Level_Type := Opt.Low)
1966 if not Opt.Verbose_Mode
1967 or else Minimum_Verbosity > Opt.Verbosity_Level
1978 if N2 /= No_Name then
1988 procedure Verbose_Msg
1989 (N1 : File_Name_Type;
1991 N2 : File_Name_Type := No_File;
1993 Prefix : String := " -> ";
1994 Minimum_Verbosity : Opt.Verbosity_Level_Type := Opt.Low)
1998 (Name_Id (N1), S1, Name_Id (N2), S2, Prefix, Minimum_Verbosity);
2005 package body Queue is
2007 type Q_Record is record
2009 Processed : Boolean;
2012 package Q is new Table.Table
2013 (Table_Component_Type => Q_Record,
2014 Table_Index_Type => Natural,
2015 Table_Low_Bound => 1,
2016 Table_Initial => 1000,
2017 Table_Increment => 100,
2018 Table_Name => "Makeutl.Queue.Q");
2019 -- This is the actual Queue
2021 package Busy_Obj_Dirs is new GNAT.HTable.Simple_HTable
2022 (Header_Num => Prj.Header_Num,
2024 No_Element => False,
2025 Key => Path_Name_Type,
2029 type Mark_Key is record
2030 File : File_Name_Type;
2033 -- Identify either a mono-unit source (when Index = 0) or a specific
2034 -- unit (index = 1's origin index of unit) in a multi-unit source.
2036 Max_Mask_Num : constant := 2048;
2037 subtype Mark_Num is Union_Id range 0 .. Max_Mask_Num - 1;
2039 function Hash (Key : Mark_Key) return Mark_Num;
2041 package Marks is new GNAT.HTable.Simple_HTable
2042 (Header_Num => Mark_Num,
2044 No_Element => False,
2048 -- A hash table to keep tracks of the marked units.
2049 -- These are the units that have already been processed, when using the
2050 -- gnatmake format. When using the gprbuild format, we can directly
2051 -- store in the source_id whether the file has already been processed.
2053 procedure Mark (Source_File : File_Name_Type; Index : Int := 0);
2054 -- Mark a unit, identified by its source file and, when Index is not 0,
2055 -- the index of the unit in the source file. Marking is used to signal
2056 -- that the unit has already been inserted in the Q.
2059 (Source_File : File_Name_Type;
2060 Index : Int := 0) return Boolean;
2061 -- Returns True if the unit was previously marked
2063 Q_Processed : Natural := 0;
2064 Q_Initialized : Boolean := False;
2066 Q_First : Natural := 1;
2067 -- Points to the first valid element in the queue
2069 One_Queue_Per_Obj_Dir : Boolean := False;
2070 -- See parameter to Initialize
2072 function Available_Obj_Dir (S : Source_Info) return Boolean;
2073 -- Whether the object directory for S is available for a build
2075 procedure Debug_Display (S : Source_Info);
2076 -- A debug display for S
2078 function Was_Processed (S : Source_Info) return Boolean;
2079 -- Whether S has already been processed. This marks the source as
2080 -- processed, if it hasn't already been processed.
2082 function Insert_No_Roots (Source : Source_Info) return Boolean;
2083 -- Insert Source, but do not look for its roots (see doc for Insert).
2089 function Was_Processed (S : Source_Info) return Boolean is
2092 when Format_Gprbuild =>
2093 if S.Id.In_The_Queue then
2097 S.Id.In_The_Queue := True;
2099 when Format_Gnatmake =>
2100 if Is_Marked (S.File, S.Index) then
2104 Mark (S.File, Index => S.Index);
2110 -----------------------
2111 -- Available_Obj_Dir --
2112 -----------------------
2114 function Available_Obj_Dir (S : Source_Info) return Boolean is
2117 when Format_Gprbuild =>
2118 return not Busy_Obj_Dirs.Get
2119 (S.Id.Project.Object_Directory.Name);
2121 when Format_Gnatmake =>
2122 return S.Project = No_Project
2124 not Busy_Obj_Dirs.Get (S.Project.Object_Directory.Name);
2126 end Available_Obj_Dir;
2132 procedure Debug_Display (S : Source_Info) is
2135 when Format_Gprbuild =>
2136 Write_Name (S.Id.File);
2138 if S.Id.Index /= 0 then
2140 Write_Int (S.Id.Index);
2143 when Format_Gnatmake =>
2144 Write_Name (S.File);
2146 if S.Index /= 0 then
2148 Write_Int (S.Index);
2157 function Hash (Key : Mark_Key) return Mark_Num is
2159 return Union_Id (Key.File) mod Max_Mask_Num;
2167 (Source_File : File_Name_Type;
2168 Index : Int := 0) return Boolean
2171 return Marks.Get (K => (File => Source_File, Index => Index));
2178 procedure Mark (Source_File : File_Name_Type; Index : Int := 0) is
2180 Marks.Set (K => (File => Source_File, Index => Index), E => True);
2188 (Found : out Boolean;
2189 Source : out Source_Info)
2194 if One_Queue_Per_Obj_Dir then
2195 for J in Q_First .. Q.Last loop
2196 if not Q.Table (J).Processed
2197 and then Available_Obj_Dir (Q.Table (J).Info)
2200 Source := Q.Table (J).Info;
2201 Q.Table (J).Processed := True;
2204 while Q_First <= Q.Last
2205 and then Q.Table (Q_First).Processed
2207 Q_First := Q_First + 1;
2215 elsif Q_First <= Q.Last then
2216 Source := Q.Table (Q_First).Info;
2217 Q.Table (Q_First).Processed := True;
2218 Q_First := Q_First + 1;
2223 Q_Processed := Q_Processed + 1;
2226 if Found and then Debug.Debug_Flag_Q then
2227 Write_Str (" Q := Q - [ ");
2228 Debug_Display (Source);
2232 Write_Str (" Q_First =");
2233 Write_Int (Int (Q_First));
2236 Write_Str (" Q.Last =");
2237 Write_Int (Int (Q.Last));
2246 function Processed return Natural is
2255 procedure Initialize
2256 (Queue_Per_Obj_Dir : Boolean;
2257 Force : Boolean := False)
2260 if Force or else not Q_Initialized then
2261 Q_Initialized := True;
2263 for J in 1 .. Q.Last loop
2264 case Q.Table (J).Info.Format is
2265 when Format_Gprbuild =>
2266 Q.Table (J).Info.Id.In_The_Queue := False;
2267 when Format_Gnatmake =>
2275 One_Queue_Per_Obj_Dir := Queue_Per_Obj_Dir;
2279 ---------------------
2280 -- Insert_No_Roots --
2281 ---------------------
2283 function Insert_No_Roots (Source : Source_Info) return Boolean is
2286 (Source.Format = Format_Gnatmake or else Source.Id /= No_Source);
2288 -- Only insert in the Q if it is not already done, to avoid
2289 -- simultaneous compilations if -jnnn is used.
2291 if Was_Processed (Source) then
2295 if Current_Verbosity = High then
2296 Write_Str ("Adding """);
2297 Debug_Display (Source);
2298 Write_Line (""" to the queue");
2301 Q.Append (New_Val => (Info => Source, Processed => False));
2303 if Debug.Debug_Flag_Q then
2304 Write_Str (" Q := Q + [ ");
2305 Debug_Display (Source);
2309 Write_Str (" Q_First =");
2310 Write_Int (Int (Q_First));
2313 Write_Str (" Q.Last =");
2314 Write_Int (Int (Q.Last));
2319 end Insert_No_Roots;
2326 (Source : Source_Info;
2327 With_Roots : Boolean := False) return Boolean
2329 Root_Arr : Array_Element_Id;
2330 Roots : Variable_Value;
2331 List : String_List_Id;
2332 Elem : String_Element;
2333 Unit_Name : Name_Id;
2335 Root_Pattern : Regexp;
2336 Root_Found : Boolean;
2337 Roots_Found : Boolean;
2338 Root_Source : Prj.Source_Id;
2339 Iter : Source_Iterator;
2342 pragma Unreferenced (Dummy);
2345 if not Insert_No_Roots (Source) then
2347 -- Was already in the queue
2352 if With_Roots and then Source.Format = Format_Gprbuild then
2353 Debug_Output ("looking for roots of", Name_Id (Source.Id.File));
2357 (Name => Name_Roots,
2358 In_Arrays => Source.Id.Project.Decl.Arrays,
2359 Shared => Source.Tree.Shared);
2363 (Index => Name_Id (Source.Id.File),
2365 In_Array => Root_Arr,
2366 Shared => Source.Tree.Shared);
2368 -- If there is no roots for the specific main, try the language
2370 if Roots = Nil_Variable_Value then
2373 (Index => Source.Id.Language.Name,
2375 In_Array => Root_Arr,
2376 Shared => Source.Tree.Shared,
2377 Force_Lower_Case_Index => True);
2382 if Roots = Nil_Variable_Value then
2384 Name_Buffer (1) := '*';
2388 (Index => Name_Find,
2390 In_Array => Root_Arr,
2391 Shared => Source.Tree.Shared,
2392 Force_Lower_Case_Index => True);
2395 if Roots = Nil_Variable_Value then
2396 Debug_Output (" -> no roots declared");
2398 List := Roots.Values;
2401 while List /= Nil_String loop
2402 Elem := Source.Tree.Shared.String_Elements.Table (List);
2403 Get_Name_String (Elem.Value);
2404 To_Lower (Name_Buffer (1 .. Name_Len));
2405 Unit_Name := Name_Find;
2407 -- Check if it is a unit name or a pattern
2411 for J in 1 .. Name_Len loop
2412 if Name_Buffer (J) not in 'a' .. 'z' and then
2413 Name_Buffer (J) not in '0' .. '9' and then
2414 Name_Buffer (J) /= '_' and then
2415 Name_Buffer (J) /= '.'
2426 (Pattern => Name_Buffer (1 .. Name_Len),
2430 when Error_In_Regexp =>
2431 Err_Vars.Error_Msg_Name_1 := Unit_Name;
2433 ("invalid pattern %", Roots.Location);
2438 Roots_Found := False;
2439 Iter := For_Each_Source (Source.Tree);
2443 Root_Source := Prj.Element (Iter);
2444 exit Source_Loop when Root_Source = No_Source;
2446 Root_Found := False;
2448 Root_Found := Root_Source.Unit /= No_Unit_Index
2450 (Get_Name_String (Root_Source.Unit.Name),
2455 Root_Source.Unit /= No_Unit_Index
2456 and then Root_Source.Unit.Name = Unit_Name;
2460 case Root_Source.Kind is
2465 Root_Found := Other_Part (Root_Source) = No_Source;
2468 Root_Found := False;
2473 Roots_Found := True;
2475 (" -> ", Name_Id (Root_Source.Display_File));
2476 Dummy := Queue.Insert_No_Roots
2477 (Source => (Format => Format_Gprbuild,
2478 Tree => Source.Tree,
2479 Id => Root_Source));
2481 Initialize_Source_Record (Root_Source);
2483 if Other_Part (Root_Source) /= No_Source then
2484 Initialize_Source_Record (Other_Part (Root_Source));
2487 -- Save the root for the binder.
2489 Source.Id.Roots := new Source_Roots'
2490 (Root => Root_Source,
2491 Next => Source.Id.Roots);
2493 exit Source_Loop when not Pat_Root;
2497 end loop Source_Loop;
2499 if not Roots_Found then
2501 if not Quiet_Output then
2502 Error_Msg_Name_1 := Unit_Name;
2504 ("?no unit matches pattern %", Roots.Location);
2509 ("Unit " & Get_Name_String (Unit_Name)
2510 & " does not exist", Roots.Location);
2515 end loop Pattern_Loop;
2527 (Source : Source_Info;
2528 With_Roots : Boolean := False)
2531 pragma Unreferenced (Discard);
2533 Discard := Insert (Source, With_Roots);
2540 function Is_Empty return Boolean is
2542 return Q_Processed >= Q.Last;
2545 ------------------------
2546 -- Is_Virtually_Empty --
2547 ------------------------
2549 function Is_Virtually_Empty return Boolean is
2551 if One_Queue_Per_Obj_Dir then
2552 for J in Q_First .. Q.Last loop
2553 if not Q.Table (J).Processed
2554 and then Available_Obj_Dir (Q.Table (J).Info)
2565 end Is_Virtually_Empty;
2567 ----------------------
2568 -- Set_Obj_Dir_Busy --
2569 ----------------------
2571 procedure Set_Obj_Dir_Busy (Obj_Dir : Path_Name_Type) is
2573 if One_Queue_Per_Obj_Dir then
2574 Busy_Obj_Dirs.Set (Obj_Dir, True);
2576 end Set_Obj_Dir_Busy;
2578 ----------------------
2579 -- Set_Obj_Dir_Free --
2580 ----------------------
2582 procedure Set_Obj_Dir_Free (Obj_Dir : Path_Name_Type) is
2584 if One_Queue_Per_Obj_Dir then
2585 Busy_Obj_Dirs.Set (Obj_Dir, False);
2587 end Set_Obj_Dir_Free;
2593 function Size return Natural is
2602 function Element (Rank : Positive) return File_Name_Type is
2604 if Rank <= Q.Last then
2605 case Q.Table (Rank).Info.Format is
2606 when Format_Gprbuild =>
2607 return Q.Table (Rank).Info.Id.File;
2608 when Format_Gnatmake =>
2609 return Q.Table (Rank).Info.File;
2620 procedure Remove_Marks is
2625 ----------------------------
2626 -- Insert_Project_Sources --
2627 ----------------------------
2629 procedure Insert_Project_Sources
2630 (Project : Project_Id;
2631 Project_Tree : Project_Tree_Ref;
2632 All_Projects : Boolean;
2633 Unique_Compile : Boolean)
2635 procedure Do_Insert (Project : Project_Id; Tree : Project_Tree_Ref);
2636 procedure Do_Insert (Project : Project_Id; Tree : Project_Tree_Ref) is
2637 Unit_Based : constant Boolean :=
2639 or else not Builder_Data (Tree).Closure_Needed;
2640 -- When Unit_Based is True, put in the queue all compilable
2641 -- sources including the unit based (Ada) one. When Unit_Based is
2642 -- False, put the Ada sources only when they are in a library
2645 Iter : Source_Iterator;
2646 Source : Prj.Source_Id;
2648 -- Nothing to do when "-u" was specified and some files were
2649 -- specified on the command line
2652 and then Mains.Number_Of_Mains (Tree) > 0
2657 Iter := For_Each_Source (Tree);
2659 Source := Prj.Element (Iter);
2660 exit when Source = No_Source;
2662 if Is_Compilable (Source)
2665 or else Is_Extending (Project, Source.Project))
2666 and then not Source.Locally_Removed
2667 and then Source.Replaced_By = No_Source
2669 (not Source.Project.Externally_Built
2671 (Is_Extending (Project, Source.Project)
2672 and then not Project.Externally_Built))
2673 and then Source.Kind /= Sep
2674 and then Source.Path /= No_Path_Information
2676 if Source.Kind = Impl
2677 or else (Source.Unit /= No_Unit_Index
2678 and then Source.Kind = Spec
2679 and then (Other_Part (Source) = No_Source
2681 Other_Part (Source).Locally_Removed))
2684 or else Source.Unit = No_Unit_Index
2685 or else Source.Project.Library)
2686 and then not Is_Subunit (Source)
2689 (Source => (Format => Format_Gprbuild,
2700 procedure Insert_All is new For_Project_And_Aggregated (Do_Insert);
2703 Insert_All (Project, Project_Tree);
2704 end Insert_Project_Sources;
2706 -------------------------------
2707 -- Insert_Withed_Sources_For --
2708 -------------------------------
2710 procedure Insert_Withed_Sources_For
2711 (The_ALI : ALI.ALI_Id;
2712 Project_Tree : Project_Tree_Ref;
2713 Excluding_Shared_SALs : Boolean := False)
2715 Sfile : File_Name_Type;
2716 Afile : File_Name_Type;
2717 Src_Id : Prj.Source_Id;
2720 -- Insert in the queue the unmarked source files (i.e. those which
2721 -- have never been inserted in the queue and hence never considered).
2723 for J in ALI.ALIs.Table (The_ALI).First_Unit ..
2724 ALI.ALIs.Table (The_ALI).Last_Unit
2726 for K in ALI.Units.Table (J).First_With ..
2727 ALI.Units.Table (J).Last_With
2729 Sfile := ALI.Withs.Table (K).Sfile;
2733 if Sfile /= No_File then
2734 Afile := ALI.Withs.Table (K).Afile;
2736 Src_Id := Source_Files_Htable.Get
2737 (Project_Tree.Source_Files_HT, Sfile);
2738 while Src_Id /= No_Source loop
2739 Initialize_Source_Record (Src_Id);
2741 if Is_Compilable (Src_Id)
2742 and then Src_Id.Dep_Name = Afile
2747 Bdy : constant Prj.Source_Id :=
2748 Other_Part (Src_Id);
2751 and then not Bdy.Locally_Removed
2753 Src_Id := Other_Part (Src_Id);
2758 if Is_Subunit (Src_Id) then
2759 Src_Id := No_Source;
2763 Src_Id := No_Source;
2769 Src_Id := Src_Id.Next_With_File_Name;
2772 -- If Excluding_Shared_SALs is True, do not insert in the
2773 -- queue the sources of a shared Stand-Alone Library.
2775 if Src_Id /= No_Source
2776 and then (not Excluding_Shared_SALs
2777 or else not Src_Id.Project.Standalone_Library
2778 or else Src_Id.Project.Library_Kind = Static)
2781 (Source => (Format => Format_Gprbuild,
2782 Tree => Project_Tree,
2788 end Insert_Withed_Sources_For;
2795 procedure Free (Data : in out Builder_Project_Tree_Data) is
2796 procedure Unchecked_Free is new Ada.Unchecked_Deallocation
2797 (Binding_Data_Record, Binding_Data);
2799 TmpB, Binding : Binding_Data := Data.Binding;
2802 while Binding /= null loop
2803 TmpB := Binding.Next;
2804 Unchecked_Free (Binding);
2813 function Builder_Data
2814 (Tree : Project_Tree_Ref) return Builder_Data_Access
2817 if Tree.Appdata = null then
2818 Tree.Appdata := new Builder_Project_Tree_Data;
2821 return Builder_Data_Access (Tree.Appdata);
2824 --------------------------------
2825 -- Compute_Compilation_Phases --
2826 --------------------------------
2828 procedure Compute_Compilation_Phases
2829 (Tree : Project_Tree_Ref;
2830 Root_Project : Project_Id;
2831 Option_Unique_Compile : Boolean := False; -- Was "-u" specified ?
2832 Option_Compile_Only : Boolean := False; -- Was "-c" specified ?
2833 Option_Bind_Only : Boolean := False;
2834 Option_Link_Only : Boolean := False)
2836 procedure Do_Compute (Project : Project_Id; Tree : Project_Tree_Ref);
2838 procedure Do_Compute (Project : Project_Id; Tree : Project_Tree_Ref) is
2839 Data : constant Builder_Data_Access := Builder_Data (Tree);
2840 All_Phases : constant Boolean :=
2841 not Option_Compile_Only
2842 and then not Option_Bind_Only
2843 and then not Option_Link_Only;
2844 -- Whether the command line asked for all three phases. Depending on
2845 -- the project settings, we might still disable some of the phases.
2847 Has_Mains : constant Boolean := Data.Number_Of_Mains > 0;
2848 -- Whether there are some main units defined for this project tree
2849 -- (either from one of the projects, or from the command line)
2852 if Option_Unique_Compile then
2854 -- If -u or -U is specified on the command line, disregard any -c,
2855 -- -b or -l switch: only perform compilation.
2857 Data.Closure_Needed := False;
2858 Data.Need_Compilation := True;
2859 Data.Need_Binding := False;
2860 Data.Need_Linking := False;
2863 Data.Closure_Needed := Has_Mains;
2864 Data.Need_Compilation := All_Phases or Option_Compile_Only;
2865 Data.Need_Binding := All_Phases or Option_Bind_Only;
2866 Data.Need_Linking := (All_Phases or Option_Link_Only)
2870 if Current_Verbosity = High then
2871 Debug_Output ("compilation phases: "
2872 & " compile=" & Data.Need_Compilation'Img
2873 & " bind=" & Data.Need_Binding'Img
2874 & " link=" & Data.Need_Linking'Img
2875 & " closure=" & Data.Closure_Needed'Img
2876 & " mains=" & Data.Number_Of_Mains'Img,
2881 procedure Compute_All is new For_Project_And_Aggregated (Do_Compute);
2884 Compute_All (Root_Project, Tree);
2885 end Compute_Compilation_Phases;