1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2006-2014, 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 Makeutl
; use Makeutl
;
29 with Output
; use Output
;
34 with Prj
.Proc
; use Prj
.Proc
;
35 with Prj
.Tree
; use Prj
.Tree
;
36 with Prj
.Util
; use Prj
.Util
;
38 with Snames
; use Snames
;
40 with Ada
.Directories
; use Ada
.Directories
;
41 with Ada
.Exceptions
; use Ada
.Exceptions
;
43 with GNAT
.Case_Util
; use GNAT
.Case_Util
;
44 with GNAT
.HTable
; use GNAT
.HTable
;
46 package body Prj
.Conf
is
48 Auto_Cgpr
: constant String := "auto.cgpr";
50 Config_Project_Env_Var
: constant String := "GPR_CONFIG";
51 -- Name of the environment variable that provides the name of the
52 -- configuration file to use.
54 Gprconfig_Name
: constant String := "gprconfig";
56 package RTS_Languages
is new GNAT
.HTable
.Simple_HTable
57 (Header_Num
=> Prj
.Header_Num
,
59 No_Element
=> No_Name
,
63 -- Stores the runtime names for the various languages. This is in general
64 -- set from a --RTS command line option.
66 -----------------------
67 -- Local_Subprograms --
68 -----------------------
71 (Config_File
: Prj
.Project_Id
;
72 Autoconf_Specified
: Boolean;
73 Project_Tree
: Prj
.Project_Tree_Ref
;
74 Target
: String := "") return Boolean;
75 -- Check that the config file's target matches Target.
76 -- Target should be set to the empty string when the user did not specify
77 -- a target. If the target in the configuration file is invalid, this
78 -- function will raise Invalid_Config with an appropriate message.
79 -- Autoconf_Specified should be set to True if the user has used
82 function Locate_Config_File
(Name
: String) return String_Access
;
83 -- Search for Name in the config files directory. Return full path if
84 -- found, or null otherwise.
86 procedure Raise_Invalid_Config
(Msg
: String);
87 pragma No_Return
(Raise_Invalid_Config
);
88 -- Raises exception Invalid_Config with given message
90 procedure Apply_Config_File
91 (Config_File
: Prj
.Project_Id
;
92 Project_Tree
: Prj
.Project_Tree_Ref
);
93 -- Apply the configuration file settings to all the projects in the
94 -- project tree. The Project_Tree must have been parsed first, and
95 -- processed through the first phase so that all its projects are known.
97 -- Currently, this will add new attributes and packages in the various
98 -- projects, so that when the second phase of the processing is performed
99 -- these attributes are automatically taken into account.
101 ------------------------------------
102 -- Add_Default_GNAT_Naming_Scheme --
103 ------------------------------------
105 procedure Add_Default_GNAT_Naming_Scheme
106 (Config_File
: in out Project_Node_Id
;
107 Project_Tree
: Project_Node_Tree_Ref
)
109 procedure Create_Attribute
112 Index
: String := "";
113 Pkg
: Project_Node_Id
:= Empty_Node
);
115 ----------------------
116 -- Create_Attribute --
117 ----------------------
119 procedure Create_Attribute
122 Index
: String := "";
123 Pkg
: Project_Node_Id
:= Empty_Node
)
125 Attr
: Project_Node_Id
;
126 pragma Unreferenced
(Attr
);
128 Expr
: Name_Id
:= No_Name
;
129 Val
: Name_Id
:= No_Name
;
130 Parent
: Project_Node_Id
:= Config_File
;
134 Name_Len
:= Index
'Length;
135 Name_Buffer
(1 .. Name_Len
) := Index
;
139 if Pkg
/= Empty_Node
then
143 Name_Len
:= Value
'Length;
144 Name_Buffer
(1 .. Name_Len
) := Value
;
147 Attr
:= Create_Attribute
148 (Tree
=> Project_Tree
,
149 Prj_Or_Pkg
=> Parent
,
153 Value
=> Create_Literal_String
(Expr
, Project_Tree
));
154 end Create_Attribute
;
159 Naming
: Project_Node_Id
;
160 Compiler
: Project_Node_Id
;
162 -- Start of processing for Add_Default_GNAT_Naming_Scheme
165 if Config_File
= Empty_Node
then
167 -- Create a dummy config file if none was found
169 Name_Len
:= Auto_Cgpr
'Length;
170 Name_Buffer
(1 .. Name_Len
) := Auto_Cgpr
;
173 -- An invalid project name to avoid conflicts with user-created ones
176 Name_Buffer
(1 .. Name_Len
) := "_auto";
180 (In_Tree
=> Project_Tree
,
182 Full_Path
=> Path_Name_Type
(Name
),
183 Is_Config_File
=> True);
185 -- Setup library support
187 case MLib
.Tgt
.Support_For_Libraries
is
192 Create_Attribute
(Name_Library_Support
, "static_only");
195 Create_Attribute
(Name_Library_Support
, "full");
198 if MLib
.Tgt
.Standalone_Library_Auto_Init_Is_Supported
then
199 Create_Attribute
(Name_Library_Auto_Init_Supported
, "true");
201 Create_Attribute
(Name_Library_Auto_Init_Supported
, "false");
204 -- Declare an empty target
206 Create_Attribute
(Name_Target
, "");
208 -- Setup Ada support (Ada is the default language here, since this
209 -- is only called when no config file existed initially, ie for
212 Create_Attribute
(Name_Default_Language
, "ada");
214 Compiler
:= Create_Package
(Project_Tree
, Config_File
, "compiler");
216 (Name_Driver
, "gcc", "ada", Pkg
=> Compiler
);
218 (Name_Language_Kind
, "unit_based", "ada", Pkg
=> Compiler
);
220 (Name_Dependency_Kind
, "ALI_File", "ada", Pkg
=> Compiler
);
222 Naming
:= Create_Package
(Project_Tree
, Config_File
, "naming");
223 Create_Attribute
(Name_Spec_Suffix
, ".ads", "ada", Pkg
=> Naming
);
224 Create_Attribute
(Name_Separate_Suffix
, ".adb", "ada", Pkg
=> Naming
);
225 Create_Attribute
(Name_Body_Suffix
, ".adb", "ada", Pkg
=> Naming
);
226 Create_Attribute
(Name_Dot_Replacement
, "-", Pkg
=> Naming
);
227 Create_Attribute
(Name_Casing
, "lowercase", Pkg
=> Naming
);
229 if Current_Verbosity
= High
then
230 Write_Line
("Automatically generated (in-memory) config file");
232 (Project
=> Config_File
,
233 In_Tree
=> Project_Tree
,
234 Backward_Compatibility
=> False);
237 end Add_Default_GNAT_Naming_Scheme
;
239 -----------------------
240 -- Apply_Config_File --
241 -----------------------
243 procedure Apply_Config_File
244 (Config_File
: Prj
.Project_Id
;
245 Project_Tree
: Prj
.Project_Tree_Ref
)
247 procedure Add_Attributes
248 (Project_Tree
: Project_Tree_Ref
;
249 Conf_Decl
: Declarations
;
250 User_Decl
: in out Declarations
);
251 -- Process the attributes in the config declarations. For
252 -- single string values, if the attribute is not declared in
253 -- the user declarations, declare it with the value in the
254 -- config declarations. For string list values, prepend the
255 -- value in the user declarations with the value in the config
262 procedure Add_Attributes
263 (Project_Tree
: Project_Tree_Ref
;
264 Conf_Decl
: Declarations
;
265 User_Decl
: in out Declarations
)
267 Shared
: constant Shared_Project_Tree_Data_Access
:=
269 Conf_Attr_Id
: Variable_Id
;
270 Conf_Attr
: Variable
;
271 Conf_Array_Id
: Array_Id
;
272 Conf_Array
: Array_Data
;
273 Conf_Array_Elem_Id
: Array_Element_Id
;
274 Conf_Array_Elem
: Array_Element
;
275 Conf_List
: String_List_Id
;
276 Conf_List_Elem
: String_Element
;
278 User_Attr_Id
: Variable_Id
;
279 User_Attr
: Variable
;
280 User_Array_Id
: Array_Id
;
281 User_Array
: Array_Data
;
282 User_Array_Elem_Id
: Array_Element_Id
;
283 User_Array_Elem
: Array_Element
;
286 Conf_Attr_Id
:= Conf_Decl
.Attributes
;
287 User_Attr_Id
:= User_Decl
.Attributes
;
289 while Conf_Attr_Id
/= No_Variable
loop
290 Conf_Attr
:= Shared
.Variable_Elements
.Table
(Conf_Attr_Id
);
291 User_Attr
:= Shared
.Variable_Elements
.Table
(User_Attr_Id
);
293 if not Conf_Attr
.Value
.Default
then
294 if User_Attr
.Value
.Default
then
296 -- No attribute declared in user project file: just copy
297 -- the value of the configuration attribute.
299 User_Attr
.Value
:= Conf_Attr
.Value
;
300 Shared
.Variable_Elements
.Table
(User_Attr_Id
) := User_Attr
;
302 elsif User_Attr
.Value
.Kind
= List
303 and then Conf_Attr
.Value
.Values
/= Nil_String
305 -- List attribute declared in both the user project and the
306 -- configuration project: prepend the user list with the
307 -- configuration list.
310 User_List
: constant String_List_Id
:=
311 User_Attr
.Value
.Values
;
312 Conf_List
: String_List_Id
:= Conf_Attr
.Value
.Values
;
313 Conf_Elem
: String_Element
;
314 New_List
: String_List_Id
;
315 New_Elem
: String_Element
;
320 String_Element_Table
.Increment_Last
321 (Shared
.String_Elements
);
323 String_Element_Table
.Last
(Shared
.String_Elements
);
325 -- Value of attribute is new list
327 User_Attr
.Value
.Values
:= New_List
;
328 Shared
.Variable_Elements
.Table
(User_Attr_Id
) :=
332 -- Get each element of configuration list
334 Conf_Elem
:= Shared
.String_Elements
.Table
(Conf_List
);
335 New_Elem
:= Conf_Elem
;
336 Conf_List
:= Conf_Elem
.Next
;
338 if Conf_List
= Nil_String
then
340 -- If it is the last element in the list, connect
341 -- to first element of user list, and we are done.
343 New_Elem
.Next
:= User_List
;
344 Shared
.String_Elements
.Table
(New_List
) := New_Elem
;
348 -- If it is not the last element in the list, add
351 String_Element_Table
.Increment_Last
352 (Shared
.String_Elements
);
353 New_Elem
.Next
:= String_Element_Table
.Last
354 (Shared
.String_Elements
);
355 Shared
.String_Elements
.Table
(New_List
) := New_Elem
;
356 New_List
:= New_Elem
.Next
;
363 Conf_Attr_Id
:= Conf_Attr
.Next
;
364 User_Attr_Id
:= User_Attr
.Next
;
367 Conf_Array_Id
:= Conf_Decl
.Arrays
;
368 while Conf_Array_Id
/= No_Array
loop
369 Conf_Array
:= Shared
.Arrays
.Table
(Conf_Array_Id
);
371 User_Array_Id
:= User_Decl
.Arrays
;
372 while User_Array_Id
/= No_Array
loop
373 User_Array
:= Shared
.Arrays
.Table
(User_Array_Id
);
374 exit when User_Array
.Name
= Conf_Array
.Name
;
375 User_Array_Id
:= User_Array
.Next
;
378 -- If this associative array does not exist in the user project
379 -- file, do a shallow copy of the full associative array.
381 if User_Array_Id
= No_Array
then
382 Array_Table
.Increment_Last
(Shared
.Arrays
);
383 User_Array
:= Conf_Array
;
384 User_Array
.Next
:= User_Decl
.Arrays
;
385 User_Decl
.Arrays
:= Array_Table
.Last
(Shared
.Arrays
);
386 Shared
.Arrays
.Table
(User_Decl
.Arrays
) := User_Array
;
388 -- Otherwise, check each array element
391 Conf_Array_Elem_Id
:= Conf_Array
.Value
;
392 while Conf_Array_Elem_Id
/= No_Array_Element
loop
394 Shared
.Array_Elements
.Table
(Conf_Array_Elem_Id
);
396 User_Array_Elem_Id
:= User_Array
.Value
;
397 while User_Array_Elem_Id
/= No_Array_Element
loop
399 Shared
.Array_Elements
.Table
(User_Array_Elem_Id
);
400 exit when User_Array_Elem
.Index
= Conf_Array_Elem
.Index
;
401 User_Array_Elem_Id
:= User_Array_Elem
.Next
;
404 -- If the array element doesn't exist in the user array,
405 -- insert a shallow copy of the conf array element in the
408 if User_Array_Elem_Id
= No_Array_Element
then
409 Array_Element_Table
.Increment_Last
410 (Shared
.Array_Elements
);
411 User_Array_Elem
:= Conf_Array_Elem
;
412 User_Array_Elem
.Next
:= User_Array
.Value
;
414 Array_Element_Table
.Last
(Shared
.Array_Elements
);
415 Shared
.Array_Elements
.Table
(User_Array
.Value
) :=
417 Shared
.Arrays
.Table
(User_Array_Id
) := User_Array
;
419 -- Otherwise, if the value is a string list, prepend the
420 -- conf array element value to the array element.
422 elsif Conf_Array_Elem
.Value
.Kind
= List
then
423 Conf_List
:= Conf_Array_Elem
.Value
.Values
;
425 if Conf_List
/= Nil_String
then
427 Link
: constant String_List_Id
:=
428 User_Array_Elem
.Value
.Values
;
429 Previous
: String_List_Id
:= Nil_String
;
430 Next
: String_List_Id
;
435 Shared
.String_Elements
.Table
(Conf_List
);
436 String_Element_Table
.Increment_Last
437 (Shared
.String_Elements
);
439 String_Element_Table
.Last
440 (Shared
.String_Elements
);
441 Shared
.String_Elements
.Table
(Next
) :=
444 if Previous
= Nil_String
then
445 User_Array_Elem
.Value
.Values
:= Next
;
446 Shared
.Array_Elements
.Table
447 (User_Array_Elem_Id
) := User_Array_Elem
;
450 Shared
.String_Elements
.Table
451 (Previous
).Next
:= Next
;
456 Conf_List
:= Conf_List_Elem
.Next
;
458 if Conf_List
= Nil_String
then
459 Shared
.String_Elements
.Table
460 (Previous
).Next
:= Link
;
468 Conf_Array_Elem_Id
:= Conf_Array_Elem
.Next
;
472 Conf_Array_Id
:= Conf_Array
.Next
;
476 Shared
: constant Shared_Project_Tree_Data_Access
:= Project_Tree
.Shared
;
478 Conf_Decl
: constant Declarations
:= Config_File
.Decl
;
479 Conf_Pack_Id
: Package_Id
;
480 Conf_Pack
: Package_Element
;
482 User_Decl
: Declarations
;
483 User_Pack_Id
: Package_Id
;
484 User_Pack
: Package_Element
;
488 Debug_Output
("Applying config file to a project tree");
490 Proj
:= Project_Tree
.Projects
;
491 while Proj
/= null loop
492 if Proj
.Project
/= Config_File
then
493 User_Decl
:= Proj
.Project
.Decl
;
495 (Project_Tree
=> Project_Tree
,
496 Conf_Decl
=> Conf_Decl
,
497 User_Decl
=> User_Decl
);
499 Conf_Pack_Id
:= Conf_Decl
.Packages
;
500 while Conf_Pack_Id
/= No_Package
loop
501 Conf_Pack
:= Shared
.Packages
.Table
(Conf_Pack_Id
);
503 User_Pack_Id
:= User_Decl
.Packages
;
504 while User_Pack_Id
/= No_Package
loop
505 User_Pack
:= Shared
.Packages
.Table
(User_Pack_Id
);
506 exit when User_Pack
.Name
= Conf_Pack
.Name
;
507 User_Pack_Id
:= User_Pack
.Next
;
510 if User_Pack_Id
= No_Package
then
511 Package_Table
.Increment_Last
(Shared
.Packages
);
512 User_Pack
:= Conf_Pack
;
513 User_Pack
.Next
:= User_Decl
.Packages
;
514 User_Decl
.Packages
:= Package_Table
.Last
(Shared
.Packages
);
515 Shared
.Packages
.Table
(User_Decl
.Packages
) := User_Pack
;
519 (Project_Tree
=> Project_Tree
,
520 Conf_Decl
=> Conf_Pack
.Decl
,
521 User_Decl
=> Shared
.Packages
.Table
522 (User_Pack_Id
).Decl
);
525 Conf_Pack_Id
:= Conf_Pack
.Next
;
528 Proj
.Project
.Decl
:= User_Decl
;
530 -- For aggregate projects, we need to apply the config to all
531 -- their aggregated trees as well.
533 if Proj
.Project
.Qualifier
in Aggregate_Project
then
535 List
: Aggregated_Project_List
;
537 List
:= Proj
.Project
.Aggregated_Projects
;
538 while List
/= null loop
540 ("Recursively apply config to aggregated tree",
543 (Config_File
, Project_Tree
=> List
.Tree
);
552 end Apply_Config_File
;
558 function Check_Target
559 (Config_File
: Project_Id
;
560 Autoconf_Specified
: Boolean;
561 Project_Tree
: Prj
.Project_Tree_Ref
;
562 Target
: String := "") return Boolean
564 Shared
: constant Shared_Project_Tree_Data_Access
:=
566 Variable
: constant Variable_Value
:=
568 (Name_Target
, Config_File
.Decl
.Attributes
, Shared
);
569 Tgt_Name
: Name_Id
:= No_Name
;
573 if Variable
/= Nil_Variable_Value
and then not Variable
.Default
then
574 Tgt_Name
:= Variable
.Value
;
581 and then (Length_Of_Name
(Tgt_Name
) = 0
582 or else Target
= Get_Name_String
(Tgt_Name
)));
585 if Autoconf_Specified
then
587 Write_Line
("inconsistent targets, performing autoconf");
593 if Tgt_Name
/= No_Name
then
595 ("invalid target name """
596 & Get_Name_String
(Tgt_Name
) & """ in configuration");
599 ("no target specified in configuration file");
607 --------------------------------------
608 -- Get_Or_Create_Configuration_File --
609 --------------------------------------
611 procedure Get_Or_Create_Configuration_File
612 (Project
: Project_Id
;
613 Conf_Project
: Project_Id
;
614 Project_Tree
: Project_Tree_Ref
;
615 Project_Node_Tree
: Prj
.Tree
.Project_Node_Tree_Ref
;
616 Env
: in out Prj
.Tree
.Environment
;
617 Allow_Automatic_Generation
: Boolean;
618 Config_File_Name
: String := "";
619 Autoconf_Specified
: Boolean;
620 Target_Name
: String := "";
621 Normalized_Hostname
: String;
622 Packages_To_Check
: String_List_Access
:= null;
623 Config
: out Prj
.Project_Id
;
624 Config_File_Path
: out String_Access
;
625 Automatically_Generated
: out Boolean;
626 On_Load_Config
: Config_File_Hook
:= null)
628 Shared
: constant Shared_Project_Tree_Data_Access
:= Project_Tree
.Shared
;
630 At_Least_One_Compiler_Command
: Boolean := False;
631 -- Set to True if at least one attribute Ide'Compiler_Command is
632 -- specified for one language of the system.
634 Conf_File_Name
: String_Access
:= new String'(Config_File_Name);
635 -- The configuration project file name. May be modified if there are
636 -- switches --config= in the Builder package of the main project.
638 Selected_Target : String_Access := new String'(Target_Name
);
640 function Default_File_Name
return String;
641 -- Return the name of the default config file that should be tested
643 procedure Do_Autoconf
;
644 -- Generate a new config file through gprconfig. In case of error, this
645 -- raises the Invalid_Config exception with an appropriate message
647 procedure Check_Builder_Switches
;
648 -- Check for switches --config and --RTS in package Builder
650 procedure Get_Project_Target
;
651 -- If Target_Name is empty, get the specified target in the project
654 procedure Get_Project_Runtimes
;
655 -- Get the various Runtime (<lang>) in the project file or any project
656 -- it extends, if any are specified.
658 function Get_Config_Switches
return Argument_List_Access
;
659 -- Return the --config switches to use for gprconfig
661 function Get_Db_Switches
return Argument_List_Access
;
662 -- Return the --db switches to use for gprconfig
664 function Might_Have_Sources
(Project
: Project_Id
) return Boolean;
665 -- True if the specified project might have sources (ie the user has not
666 -- explicitly specified it. We haven't checked the file system, nor do
667 -- we need to at this stage.
669 ----------------------------
670 -- Check_Builder_Switches --
671 ----------------------------
673 procedure Check_Builder_Switches
is
674 Get_RTS_Switches
: constant Boolean :=
675 RTS_Languages
.Get_First
= No_Name
;
676 -- If no switch --RTS have been specified on the command line, look
677 -- for --RTS switches in the Builder switches.
679 Builder
: constant Package_Id
:=
680 Value_Of
(Name_Builder
, Project
.Decl
.Packages
, Shared
);
682 Switch_Array_Id
: Array_Element_Id
;
683 -- The Switches to be checked
685 procedure Check_Switches
;
686 -- Check the switches in Switch_Array_Id
692 procedure Check_Switches
is
693 Switch_Array
: Array_Element
;
694 Switch_List
: String_List_Id
:= Nil_String
;
695 Switch
: String_Element
;
697 Lang_Last
: Positive;
700 while Switch_Array_Id
/= No_Array_Element
loop
702 Shared
.Array_Elements
.Table
(Switch_Array_Id
);
704 Switch_List
:= Switch_Array
.Value
.Values
;
705 List_Loop
: while Switch_List
/= Nil_String
loop
706 Switch
:= Shared
.String_Elements
.Table
(Switch_List
);
708 if Switch
.Value
/= No_Name
then
709 Get_Name_String
(Switch
.Value
);
711 if Conf_File_Name
'Length = 0
712 and then Name_Len
> 9
713 and then Name_Buffer
(1 .. 9) = "--config="
716 new String'(Name_Buffer (10 .. Name_Len));
718 elsif Get_RTS_Switches
719 and then Name_Len >= 7
720 and then Name_Buffer (1 .. 5) = "--RTS"
722 if Name_Buffer (6) = '=' then
723 if not Runtime_Name_Set_For (Name_Ada) then
726 Name_Buffer (7 .. Name_Len));
730 and then Name_Buffer (6) = ':'
731 and then Name_Buffer (7) /= '='
734 while Lang_Last < Name_Len
735 and then Name_Buffer (Lang_Last + 1) /= '='
737 Lang_Last := Lang_Last + 1;
740 if Name_Buffer (Lang_Last + 1) = '=' then
742 RTS : constant String :=
743 Name_Buffer (Lang_Last + 2 .. Name_Len);
745 Name_Buffer (1 .. Lang_Last - 6) :=
746 Name_Buffer (7 .. Lang_Last);
747 Name_Len := Lang_Last - 6;
748 To_Lower (Name_Buffer (1 .. Name_Len));
751 if not Runtime_Name_Set_For (Lang) then
752 Set_Runtime_For (Lang, RTS);
760 Switch_List := Switch.Next;
763 Switch_Array_Id := Switch_Array.Next;
767 -- Start of processing for Check_Builder_Switches
770 if Builder /= No_Package then
773 (Name => Name_Switches,
774 In_Arrays => Shared.Packages.Table (Builder).Decl.Arrays,
780 (Name => Name_Default_Switches,
781 In_Arrays => Shared.Packages.Table (Builder).Decl.Arrays,
785 end Check_Builder_Switches;
787 ------------------------
788 -- Get_Project_Target --
789 ------------------------
791 procedure Get_Project_Target is
793 if Selected_Target'Length = 0 then
795 -- Check if attribute Target is specified in the main
796 -- project, or in a project it extends. If it is, use this
797 -- target to invoke gprconfig.
800 Variable : Variable_Value;
802 Tgt_Name : Name_Id := No_Name;
807 while Proj /= No_Project loop
809 Value_Of (Name_Target, Proj.Decl.Attributes, Shared);
811 if Variable /= Nil_Variable_Value
812 and then not Variable.Default
813 and then Variable.Value /= No_Name
815 Tgt_Name := Variable.Value;
819 Proj := Proj.Extends;
820 end loop Project_Loop;
822 if Tgt_Name /= No_Name then
823 Selected_Target := new String'(Get_Name_String
(Tgt_Name
));
827 end Get_Project_Target
;
829 --------------------------
830 -- Get_Project_Runtimes --
831 --------------------------
833 procedure Get_Project_Runtimes
is
834 Element
: Array_Element
;
835 Id
: Array_Element_Id
;
841 while Proj
/= No_Project
loop
842 Id
:= Value_Of
(Name_Runtime
, Proj
.Decl
.Arrays
, Shared
);
843 while Id
/= No_Array_Element
loop
844 Element
:= Shared
.Array_Elements
.Table
(Id
);
845 Lang
:= Element
.Index
;
847 if not Runtime_Name_Set_For
(Lang
) then
849 (Lang
, RTS_Name
=> Get_Name_String
(Element
.Value
.Value
));
855 Proj
:= Proj
.Extends
;
857 end Get_Project_Runtimes
;
859 -----------------------
860 -- Default_File_Name --
861 -----------------------
863 function Default_File_Name
return String is
864 Ada_RTS
: constant String := Runtime_Name_For
(Name_Ada
);
868 if Selected_Target
'Length /= 0 then
869 if Ada_RTS
/= "" then
871 Selected_Target
.all & '-' &
872 Ada_RTS
& Config_Project_File_Extension
;
875 Selected_Target
.all & Config_Project_File_Extension
;
878 elsif Ada_RTS
/= "" then
879 return Ada_RTS
& Config_Project_File_Extension
;
882 Tmp
:= Getenv
(Config_Project_Env_Var
);
885 T
: constant String := Tmp
.all;
891 return Default_Config_Name
;
897 end Default_File_Name
;
903 procedure Do_Autoconf
is
904 Obj_Dir
: constant Variable_Value
:=
907 Conf_Project
.Decl
.Attributes
,
910 Gprconfig_Path
: String_Access
;
914 Gprconfig_Path
:= Locate_Exec_On_Path
(Gprconfig_Name
);
916 if Gprconfig_Path
= null then
918 ("could not locate gprconfig for auto-configuration");
921 -- First, find the object directory of the Conf_Project
923 if Obj_Dir
= Nil_Variable_Value
or else Obj_Dir
.Default
then
924 Get_Name_String
(Conf_Project
.Directory
.Display_Name
);
927 if Is_Absolute_Path
(Get_Name_String
(Obj_Dir
.Value
)) then
928 Get_Name_String
(Obj_Dir
.Value
);
932 Add_Str_To_Name_Buffer
933 (Get_Name_String
(Conf_Project
.Directory
.Display_Name
));
934 Add_Str_To_Name_Buffer
(Get_Name_String
(Obj_Dir
.Value
));
938 if Subdirs
/= null then
939 Add_Char_To_Name_Buffer
(Directory_Separator
);
940 Add_Str_To_Name_Buffer
(Subdirs
.all);
943 for J
in 1 .. Name_Len
loop
944 if Name_Buffer
(J
) = '/' then
945 Name_Buffer
(J
) := Directory_Separator
;
949 -- Make sure that Obj_Dir ends with a directory separator
951 if Name_Buffer
(Name_Len
) /= Directory_Separator
then
952 Name_Len
:= Name_Len
+ 1;
953 Name_Buffer
(Name_Len
) := Directory_Separator
;
957 Obj_Dir
: constant String := Name_Buffer
(1 .. Name_Len
);
958 Config_Switches
: Argument_List_Access
;
959 Db_Switches
: Argument_List_Access
;
960 Args
: Argument_List
(1 .. 5);
962 Obj_Dir_Exists
: Boolean := True;
965 -- Check if the object directory exists. If Setup_Projects is True
966 -- (-p) and directory does not exist, attempt to create it.
967 -- Otherwise, if directory does not exist, fail without calling
970 if not Is_Directory
(Obj_Dir
)
971 and then (Setup_Projects
or else Subdirs
/= null)
974 Create_Path
(Obj_Dir
);
976 if not Quiet_Output
then
977 Write_Str
("object directory """);
979 Write_Line
(""" created");
985 ("could not create object directory " & Obj_Dir
);
989 if not Is_Directory
(Obj_Dir
) then
990 case Env
.Flags
.Require_Obj_Dirs
is
993 ("object directory " & Obj_Dir
& " does not exist");
998 "?object directory " & Obj_Dir
& " does not exist");
999 Obj_Dir_Exists
:= False;
1006 -- Get the config switches. This should be done only now, as some
1007 -- runtimes may have been found in the Builder switches.
1009 Config_Switches
:= Get_Config_Switches
;
1011 -- Get eventual --db switches
1013 Db_Switches
:= Get_Db_Switches
;
1017 Args
(1) := new String'("--batch");
1018 Args (2) := new String'("-o");
1020 -- If no config file was specified, set the auto.cgpr one
1022 if Conf_File_Name
'Length = 0 then
1023 if Obj_Dir_Exists
then
1024 Args
(3) := new String'(Obj_Dir & Auto_Cgpr);
1028 Path_FD : File_Descriptor;
1029 Path_Name : Path_Name_Type;
1032 Prj.Env.Create_Temp_File
1033 (Shared => Project_Tree.Shared,
1035 Path_Name => Path_Name,
1036 File_Use => "configuration file");
1038 if Path_FD /= Invalid_FD then
1040 Temp_Dir : constant String :=
1041 Containing_Directory
1042 (Get_Name_String (Path_Name));
1044 GNAT.OS_Lib.Close (Path_FD);
1046 new String'(Temp_Dir
&
1047 Directory_Separator
&
1049 Delete_File
(Get_Name_String
(Path_Name
));
1053 -- We'll have an error message later on
1055 Args
(3) := new String'(Obj_Dir & Auto_Cgpr);
1060 Args (3) := Conf_File_Name;
1063 if Normalized_Hostname = "" then
1066 if Selected_Target'Length = 0 then
1067 if At_Least_One_Compiler_Command then
1069 new String'("--target=all");
1072 new String'("--target=" & Normalized_Hostname);
1077 new String'("--target=" & Selected_Target
.all);
1083 if not Verbose_Mode
then
1084 Arg_Last
:= Arg_Last
+ 1;
1085 Args
(Arg_Last
) := new String'("-q");
1088 if Verbose_Mode then
1089 Write_Str (Gprconfig_Name);
1091 for J in 1 .. Arg_Last loop
1093 Write_Str (Args (J).all);
1096 for J in Config_Switches'Range loop
1098 Write_Str (Config_Switches (J).all);
1101 for J in Db_Switches'Range loop
1103 Write_Str (Db_Switches (J).all);
1108 elsif not Quiet_Output then
1110 -- Display no message if we are creating auto.cgpr, unless in
1113 if Config_File_Name'Length > 0 or else Verbose_Mode then
1114 Write_Str ("creating ");
1115 Write_Str (Simple_Name (Args (3).all));
1120 Spawn (Gprconfig_Path.all, Args (1 .. Arg_Last) &
1121 Config_Switches.all & Db_Switches.all,
1124 Free (Config_Switches);
1126 Config_File_Path := Locate_Config_File (Args (3).all);
1128 if Config_File_Path = null then
1129 Raise_Invalid_Config
1130 ("could not create " & Args (3).all);
1133 for F in Args'Range loop
1139 ---------------------
1140 -- Get_Db_Switches --
1141 ---------------------
1143 function Get_Db_Switches return Argument_List_Access is
1144 Result : Argument_List_Access;
1148 (2 * Db_Switch_Args.Last) + Boolean'Pos (not Load_Standard_Base);
1149 Result := new Argument_List (1 .. Nmb_Arg);
1151 if Nmb_Arg /= 0 then
1152 for J in 1 .. Db_Switch_Args.Last loop
1153 Result (2 * J - 1) :=
1154 new String'("--db");
1156 new String'(Get_Name_String (Db_Switch_Args.Table (J)));
1159 if not Load_Standard_Base then
1160 Result (Result'Last) := new String'("--db-");
1165 end Get_Db_Switches
;
1167 -------------------------
1168 -- Get_Config_Switches --
1169 -------------------------
1171 function Get_Config_Switches
return Argument_List_Access
is
1173 package Language_Htable
is new GNAT
.HTable
.Simple_HTable
1174 (Header_Num
=> Prj
.Header_Num
,
1176 No_Element
=> No_Name
,
1180 -- Hash table to keep the languages used in the project tree
1182 IDE
: constant Package_Id
:=
1183 Value_Of
(Name_Ide
, Project
.Decl
.Packages
, Shared
);
1185 procedure Add_Config_Switches_For_Project
1186 (Project
: Project_Id
;
1187 Tree
: Project_Tree_Ref
;
1188 With_State
: in out Integer);
1189 -- Add all --config switches for this project. This is also called
1190 -- for aggregate projects.
1192 -------------------------------------
1193 -- Add_Config_Switches_For_Project --
1194 -------------------------------------
1196 procedure Add_Config_Switches_For_Project
1197 (Project
: Project_Id
;
1198 Tree
: Project_Tree_Ref
;
1199 With_State
: in out Integer)
1201 pragma Unreferenced
(With_State
);
1203 Shared
: constant Shared_Project_Tree_Data_Access
:= Tree
.Shared
;
1205 Variable
: Variable_Value
;
1206 Check_Default
: Boolean;
1208 List
: String_List_Id
;
1209 Elem
: String_Element
;
1212 if Might_Have_Sources
(Project
) then
1214 Value_Of
(Name_Languages
, Project
.Decl
.Attributes
, Shared
);
1216 if Variable
= Nil_Variable_Value
or else Variable
.Default
then
1218 -- Languages is not declared. If it is not an extending
1219 -- project, or if it extends a project with no Languages,
1220 -- check for Default_Language.
1222 Check_Default
:= Project
.Extends
= No_Project
;
1224 if not Check_Default
then
1228 Project
.Extends
.Decl
.Attributes
,
1231 Variable
/= Nil_Variable_Value
1232 and then Variable
.Values
= Nil_String
;
1235 if Check_Default
then
1238 (Name_Default_Language
,
1239 Project
.Decl
.Attributes
,
1242 if Variable
/= Nil_Variable_Value
1243 and then not Variable
.Default
1245 Get_Name_String
(Variable
.Value
);
1246 To_Lower
(Name_Buffer
(1 .. Name_Len
));
1248 Language_Htable
.Set
(Lang
, Lang
);
1250 -- If no default language is declared, default to Ada
1253 Language_Htable
.Set
(Name_Ada
, Name_Ada
);
1257 elsif Variable
.Values
/= Nil_String
then
1259 -- Attribute Languages is declared with a non empty list:
1260 -- put all the languages in Language_HTable.
1262 List
:= Variable
.Values
;
1263 while List
/= Nil_String
loop
1264 Elem
:= Shared
.String_Elements
.Table
(List
);
1266 Get_Name_String
(Elem
.Value
);
1267 To_Lower
(Name_Buffer
(1 .. Name_Len
));
1269 Language_Htable
.Set
(Lang
, Lang
);
1275 end Add_Config_Switches_For_Project
;
1277 procedure For_Every_Imported_Project
is new For_Every_Project_Imported
1278 (State
=> Integer, Action
=> Add_Config_Switches_For_Project
);
1279 -- Document this procedure ???
1285 Result
: Argument_List_Access
;
1286 Variable
: Variable_Value
;
1287 Dummy
: Integer := 0;
1289 -- Start of processing for Get_Config_Switches
1292 For_Every_Imported_Project
1294 Tree
=> Project_Tree
,
1295 With_State
=> Dummy
,
1296 Include_Aggregated
=> True);
1298 Name
:= Language_Htable
.Get_First
;
1300 while Name
/= No_Name
loop
1302 Name
:= Language_Htable
.Get_Next
;
1305 Result
:= new String_List
(1 .. Count
);
1308 Name
:= Language_Htable
.Get_First
;
1309 while Name
/= No_Name
loop
1311 -- Check if IDE'Compiler_Command is declared for the language.
1312 -- If it is, use its value to invoke gprconfig.
1317 Attribute_Or_Array_Name
=> Name_Compiler_Command
,
1320 Force_Lower_Case_Index
=> True);
1323 Config_Command
: constant String :=
1324 "--config=" & Get_Name_String
(Name
);
1326 Runtime_Name
: constant String := Runtime_Name_For
(Name
);
1329 -- In CodePeer mode, we do not take into account any compiler
1330 -- command from the package IDE.
1333 or else Variable
= Nil_Variable_Value
1334 or else Length_Of_Name
(Variable
.Value
) = 0
1337 new String'(Config_Command & ",," & Runtime_Name);
1340 At_Least_One_Compiler_Command := True;
1343 Compiler_Command : constant String :=
1344 Get_Name_String (Variable.Value);
1347 if Is_Absolute_Path (Compiler_Command) then
1350 (Config_Command
& ",," & Runtime_Name
& ","
1351 & Containing_Directory
(Compiler_Command
) & ","
1352 & Simple_Name
(Compiler_Command
));
1356 (Config_Command & ",," & Runtime_Name & ",,"
1357 & Compiler_Command);
1364 Name := Language_Htable.Get_Next;
1368 end Get_Config_Switches;
1370 ------------------------
1371 -- Might_Have_Sources --
1372 ------------------------
1374 function Might_Have_Sources (Project : Project_Id) return Boolean is
1375 Variable : Variable_Value;
1379 Value_Of (Name_Source_Dirs, Project.Decl.Attributes, Shared);
1381 if Variable = Nil_Variable_Value
1382 or else Variable.Default
1383 or else Variable.Values /= Nil_String
1386 Value_Of (Name_Source_Files, Project.Decl.Attributes, Shared);
1387 return Variable = Nil_Variable_Value
1388 or else Variable.Default
1389 or else Variable.Values /= Nil_String;
1394 end Might_Have_Sources;
1399 Config_Project_Node : Project_Node_Id := Empty_Node;
1401 -- Start of processing for Get_Or_Create_Configuration_File
1404 pragma Assert (Prj.Env.Is_Initialized (Env.Project_Path));
1406 Free (Config_File_Path);
1407 Config := No_Project;
1410 Get_Project_Runtimes;
1411 Check_Builder_Switches;
1413 -- Do not attempt to find a configuration project file when
1414 -- Config_File_Name is No_Configuration_File.
1416 if Config_File_Name = No_Configuration_File then
1417 Config_File_Path := null;
1420 if Conf_File_Name'Length > 0 then
1421 Config_File_Path := Locate_Config_File (Conf_File_Name.all);
1423 Config_File_Path := Locate_Config_File (Default_File_Name);
1426 if Config_File_Path = null then
1427 if not Allow_Automatic_Generation
1428 and then Conf_File_Name'Length > 0
1430 Raise_Invalid_Config
1431 ("could not locate main configuration project "
1432 & Conf_File_Name.all);
1437 Automatically_Generated :=
1438 Allow_Automatic_Generation and then Config_File_Path = null;
1440 <<Process_Config_File>>
1442 if Automatically_Generated then
1444 -- This might raise an Invalid_Config exception
1448 -- If the config file is not auto-generated, warn if there is any --RTS
1449 -- switch, but not when the config file is generated in memory.
1451 elsif RTS_Languages.Get_First /= No_Name
1452 and then Opt.Warning_Mode /= Opt.Suppress
1453 and then On_Load_Config = null
1457 "--RTS is taken into account only in auto-configuration");
1460 -- Parse the configuration file
1462 if Verbose_Mode and then Config_File_Path /= null then
1463 Write_Str ("Checking configuration ");
1464 Write_Line (Config_File_Path.all);
1467 if Config_File_Path /= null then
1469 (In_Tree => Project_Node_Tree,
1470 Project => Config_Project_Node,
1471 Project_File_Name => Config_File_Path.all,
1472 Errout_Handling => Prj.Part.Finalize_If_Error,
1473 Packages_To_Check => Packages_To_Check,
1474 Current_Directory => Current_Directory,
1475 Is_Config_File => True,
1478 Config_Project_Node := Empty_Node;
1481 if On_Load_Config /= null then
1483 (Config_File => Config_Project_Node,
1484 Project_Node_Tree => Project_Node_Tree);
1487 if Config_Project_Node /= Empty_Node then
1488 Prj.Proc.Process_Project_Tree_Phase_1
1489 (In_Tree => Project_Tree,
1491 Packages_To_Check => Packages_To_Check,
1493 From_Project_Node => Config_Project_Node,
1494 From_Project_Node_Tree => Project_Node_Tree,
1496 Reset_Tree => False,
1497 On_New_Tree_Loaded => null);
1500 if Config_Project_Node = Empty_Node or else Config = No_Project then
1501 Raise_Invalid_Config
1502 ("processing of configuration project """
1503 & Config_File_Path.all & """ failed");
1506 -- Check that the target of the configuration file is the one the user
1507 -- specified on the command line. We do not need to check that when in
1508 -- auto-conf mode, since the appropriate target was passed to gprconfig.
1510 if not Automatically_Generated
1513 (Config, Autoconf_Specified, Project_Tree, Selected_Target.all)
1515 Automatically_Generated := True;
1516 goto Process_Config_File;
1518 end Get_Or_Create_Configuration_File;
1520 ------------------------
1521 -- Locate_Config_File --
1522 ------------------------
1524 function Locate_Config_File (Name : String) return String_Access is
1525 Prefix_Path : constant String := Executable_Prefix_Path;
1527 if Prefix_Path'Length /= 0 then
1528 return Locate_Regular_File
1530 "." & Path_Separator &
1531 Prefix_Path & "share" & Directory_Separator & "gpr");
1533 return Locate_Regular_File (Name, ".");
1535 end Locate_Config_File;
1537 ------------------------------------
1538 -- Parse_Project_And_Apply_Config --
1539 ------------------------------------
1541 procedure Parse_Project_And_Apply_Config
1542 (Main_Project : out Prj.Project_Id;
1543 User_Project_Node : out Prj.Tree.Project_Node_Id;
1544 Config_File_Name : String := "";
1545 Autoconf_Specified : Boolean;
1546 Project_File_Name : String;
1547 Project_Tree : Prj.Project_Tree_Ref;
1548 Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
1549 Env : in out Prj.Tree.Environment;
1550 Packages_To_Check : String_List_Access;
1551 Allow_Automatic_Generation : Boolean := True;
1552 Automatically_Generated : out Boolean;
1553 Config_File_Path : out String_Access;
1554 Target_Name : String := "";
1555 Normalized_Hostname : String;
1556 On_Load_Config : Config_File_Hook := null;
1557 Implicit_Project : Boolean := False;
1558 On_New_Tree_Loaded : Prj.Proc.Tree_Loaded_Callback := null)
1560 Success : Boolean := False;
1561 Try_Again : Boolean := True;
1564 pragma Assert (Prj.Env.Is_Initialized (Env.Project_Path));
1566 -- Record Target_Value and Target_Origin.
1568 if Target_Name = "" then
1569 Opt.Target_Value := new String'(Normalized_Hostname
);
1570 Opt
.Target_Origin
:= Default
;
1572 Opt
.Target_Value
:= new String'(Target_Name);
1573 Opt.Target_Origin := Specified;
1578 -- Parse the user project tree
1580 Prj.Initialize (Project_Tree);
1582 Main_Project := No_Project;
1583 Automatically_Generated := False;
1586 (In_Tree => Project_Node_Tree,
1587 Project => User_Project_Node,
1588 Project_File_Name => Project_File_Name,
1589 Errout_Handling => Prj.Part.Finalize_If_Error,
1590 Packages_To_Check => Packages_To_Check,
1591 Current_Directory => Current_Directory,
1592 Is_Config_File => False,
1594 Implicit_Project => Implicit_Project);
1596 if User_Project_Node = Empty_Node then
1600 -- If --target was not specified on the command line, then do Phase 1 to
1601 -- check if attribute Target is declared in the main project.
1603 if Opt.Target_Origin /= Specified then
1604 Main_Project := No_Project;
1605 Process_Project_Tree_Phase_1
1606 (In_Tree => Project_Tree,
1607 Project => Main_Project,
1608 Packages_To_Check => Packages_To_Check,
1610 From_Project_Node => User_Project_Node,
1611 From_Project_Node_Tree => Project_Node_Tree,
1614 On_New_Tree_Loaded => On_New_Tree_Loaded);
1617 Main_Project := No_Project;
1622 Variable : constant Variable_Value :=
1625 Main_Project.Decl.Attributes,
1626 Project_Tree.Shared);
1628 if Variable /= Nil_Variable_Value
1629 and then not Variable.Default
1631 Get_Name_String (Variable.Value) /= Opt.Target_Value.all
1635 new String'(Get_Name_String
(Variable
.Value
));
1642 "inconsistent value of attribute Target");
1649 Process_Project_And_Apply_Config
1650 (Main_Project
=> Main_Project
,
1651 User_Project_Node
=> User_Project_Node
,
1652 Config_File_Name
=> Config_File_Name
,
1653 Autoconf_Specified
=> Autoconf_Specified
,
1654 Project_Tree
=> Project_Tree
,
1655 Project_Node_Tree
=> Project_Node_Tree
,
1657 Packages_To_Check
=> Packages_To_Check
,
1658 Allow_Automatic_Generation
=> Allow_Automatic_Generation
,
1659 Automatically_Generated
=> Automatically_Generated
,
1660 Config_File_Path
=> Config_File_Path
,
1661 Target_Name
=> Target_Name
,
1662 Normalized_Hostname
=> Normalized_Hostname
,
1663 On_Load_Config
=> On_Load_Config
,
1664 On_New_Tree_Loaded
=> On_New_Tree_Loaded
,
1665 Do_Phase_1
=> Opt
.Target_Origin
= Specified
);
1666 end Parse_Project_And_Apply_Config
;
1668 --------------------------------------
1669 -- Process_Project_And_Apply_Config --
1670 --------------------------------------
1672 procedure Process_Project_And_Apply_Config
1673 (Main_Project
: out Prj
.Project_Id
;
1674 User_Project_Node
: Prj
.Tree
.Project_Node_Id
;
1675 Config_File_Name
: String := "";
1676 Autoconf_Specified
: Boolean;
1677 Project_Tree
: Prj
.Project_Tree_Ref
;
1678 Project_Node_Tree
: Prj
.Tree
.Project_Node_Tree_Ref
;
1679 Env
: in out Prj
.Tree
.Environment
;
1680 Packages_To_Check
: String_List_Access
;
1681 Allow_Automatic_Generation
: Boolean := True;
1682 Automatically_Generated
: out Boolean;
1683 Config_File_Path
: out String_Access
;
1684 Target_Name
: String := "";
1685 Normalized_Hostname
: String;
1686 On_Load_Config
: Config_File_Hook
:= null;
1687 Reset_Tree
: Boolean := True;
1688 On_New_Tree_Loaded
: Prj
.Proc
.Tree_Loaded_Callback
:= null;
1689 Do_Phase_1
: Boolean := True)
1691 Shared
: constant Shared_Project_Tree_Data_Access
:=
1692 Project_Tree
.Shared
;
1693 Main_Config_Project
: Project_Id
;
1696 Conf_Project
: Project_Id
:= No_Project
;
1697 -- The object directory of this project is used to store the config
1698 -- project file in auto-configuration. Set by Check_Project below.
1700 procedure Check_Project
(Project
: Project_Id
);
1701 -- Look for a non aggregate project. If one is found, put its project Id
1708 procedure Check_Project
(Project
: Project_Id
) is
1710 if Project
.Qualifier
= Aggregate
1712 Project
.Qualifier
= Aggregate_Library
1715 List
: Aggregated_Project_List
:= Project
.Aggregated_Projects
;
1718 -- Look for a non aggregate project until one is found
1720 while Conf_Project
= No_Project
and then List
/= null loop
1721 Check_Project
(List
.Project
);
1727 Conf_Project
:= Project
;
1731 -- Start of processing for Process_Project_And_Apply_Config
1734 Automatically_Generated
:= False;
1737 Main_Project
:= No_Project
;
1738 Process_Project_Tree_Phase_1
1739 (In_Tree
=> Project_Tree
,
1740 Project
=> Main_Project
,
1741 Packages_To_Check
=> Packages_To_Check
,
1743 From_Project_Node
=> User_Project_Node
,
1744 From_Project_Node_Tree
=> Project_Node_Tree
,
1746 Reset_Tree
=> Reset_Tree
,
1747 On_New_Tree_Loaded
=> On_New_Tree_Loaded
);
1750 Main_Project
:= No_Project
;
1755 if Project_Tree
.Source_Info_File_Name
/= null then
1756 if not Is_Absolute_Path
(Project_Tree
.Source_Info_File_Name
.all) then
1758 Obj_Dir
: constant Variable_Value
:=
1761 Main_Project
.Decl
.Attributes
,
1765 if Obj_Dir
= Nil_Variable_Value
or else Obj_Dir
.Default
then
1766 Get_Name_String
(Main_Project
.Directory
.Display_Name
);
1769 if Is_Absolute_Path
(Get_Name_String
(Obj_Dir
.Value
)) then
1770 Get_Name_String
(Obj_Dir
.Value
);
1774 Add_Str_To_Name_Buffer
1775 (Get_Name_String
(Main_Project
.Directory
.Display_Name
));
1776 Add_Str_To_Name_Buffer
(Get_Name_String
(Obj_Dir
.Value
));
1780 Add_Char_To_Name_Buffer
(Directory_Separator
);
1781 Add_Str_To_Name_Buffer
(Project_Tree
.Source_Info_File_Name
.all);
1782 Free
(Project_Tree
.Source_Info_File_Name
);
1783 Project_Tree
.Source_Info_File_Name
:=
1784 new String'(Name_Buffer (1 .. Name_Len));
1788 Read_Source_Info_File (Project_Tree);
1791 -- Get the first project that is not an aggregate project or an
1792 -- aggregate library project. The object directory of this project will
1793 -- be used to store the config project file in auto-configuration.
1795 Check_Project (Main_Project);
1797 -- Fail if there is only aggregate projects and aggregate library
1798 -- projects in the project tree.
1800 if Conf_Project = No_Project then
1801 Raise_Invalid_Config ("there are no non-aggregate projects");
1804 -- Find configuration file
1806 Get_Or_Create_Configuration_File
1807 (Config => Main_Config_Project,
1808 Project => Main_Project,
1809 Conf_Project => Conf_Project,
1810 Project_Tree => Project_Tree,
1811 Project_Node_Tree => Project_Node_Tree,
1813 Allow_Automatic_Generation => Allow_Automatic_Generation,
1814 Config_File_Name => Config_File_Name,
1815 Autoconf_Specified => Autoconf_Specified,
1816 Target_Name => Target_Name,
1817 Normalized_Hostname => Normalized_Hostname,
1818 Packages_To_Check => Packages_To_Check,
1819 Config_File_Path => Config_File_Path,
1820 Automatically_Generated => Automatically_Generated,
1821 On_Load_Config => On_Load_Config);
1823 Apply_Config_File (Main_Config_Project, Project_Tree);
1825 -- Finish processing the user's project
1827 Prj.Proc.Process_Project_Tree_Phase_2
1828 (In_Tree => Project_Tree,
1829 Project => Main_Project,
1831 From_Project_Node => User_Project_Node,
1832 From_Project_Node_Tree => Project_Node_Tree,
1836 if Project_Tree.Source_Info_File_Name /= null
1837 and then not Project_Tree.Source_Info_File_Exists
1839 Write_Source_Info_File (Project_Tree);
1843 Main_Project := No_Project;
1845 end Process_Project_And_Apply_Config;
1847 --------------------------
1848 -- Raise_Invalid_Config --
1849 --------------------------
1851 procedure Raise_Invalid_Config (Msg : String) is
1853 Raise_Exception (Invalid_Config'Identity, Msg);
1854 end Raise_Invalid_Config;
1856 ----------------------
1857 -- Runtime_Name_For --
1858 ----------------------
1860 function Runtime_Name_For (Language : Name_Id) return String is
1862 if RTS_Languages.Get (Language) /= No_Name then
1863 return Get_Name_String (RTS_Languages.Get (Language));
1867 end Runtime_Name_For;
1869 --------------------------
1870 -- Runtime_Name_Set_For --
1871 --------------------------
1873 function Runtime_Name_Set_For (Language : Name_Id) return Boolean is
1875 return RTS_Languages.Get (Language) /= No_Name;
1876 end Runtime_Name_Set_For;
1878 ---------------------
1879 -- Set_Runtime_For --
1880 ---------------------
1882 procedure Set_Runtime_For (Language : Name_Id; RTS_Name : String) is
1884 Name_Len := RTS_Name'Length;
1885 Name_Buffer (1 .. Name_Len) := RTS_Name;
1886 RTS_Languages.Set (Language, Name_Find);
1887 end Set_Runtime_For;