1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2006-2012, 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 ------------------------------------------------------------------------------
27 with Makeutl
; use Makeutl
;
30 with Output
; use Output
;
35 with Prj
.Proc
; use Prj
.Proc
;
36 with Prj
.Tree
; use Prj
.Tree
;
37 with Prj
.Util
; use Prj
.Util
;
39 with Snames
; use Snames
;
41 with Ada
.Directories
; use Ada
.Directories
;
42 with Ada
.Exceptions
; use Ada
.Exceptions
;
44 with GNAT
.Case_Util
; use GNAT
.Case_Util
;
45 with GNAT
.HTable
; use GNAT
.HTable
;
47 package body Prj
.Conf
is
49 Auto_Cgpr
: constant String := "auto.cgpr";
51 Default_Name
: constant String := "default.cgpr";
52 -- Default configuration file that will be used if found
54 Config_Project_Env_Var
: constant String := "GPR_CONFIG";
55 -- Name of the environment variable that provides the name of the
56 -- configuration file to use.
58 Gprconfig_Name
: constant String := "gprconfig";
60 package RTS_Languages
is new GNAT
.HTable
.Simple_HTable
61 (Header_Num
=> Prj
.Header_Num
,
63 No_Element
=> No_Name
,
67 -- Stores the runtime names for the various languages. This is in general
68 -- set from a --RTS command line option.
70 -----------------------
71 -- Local_Subprograms --
72 -----------------------
74 procedure Add_Attributes
75 (Project_Tree
: Project_Tree_Ref
;
76 Conf_Decl
: Declarations
;
77 User_Decl
: in out Declarations
);
78 -- Process the attributes in the config declarations.
79 -- For single string values, if the attribute is not declared in the user
80 -- declarations, declare it with the value in the config declarations.
81 -- For string list values, prepend the value in the user declarations with
82 -- the value in the config declarations.
85 (Config_File
: Prj
.Project_Id
;
86 Autoconf_Specified
: Boolean;
87 Project_Tree
: Prj
.Project_Tree_Ref
;
88 Target
: String := "") return Boolean;
89 -- Check that the config file's target matches Target.
90 -- Target should be set to the empty string when the user did not specify
91 -- a target. If the target in the configuration file is invalid, this
92 -- function will raise Invalid_Config with an appropriate message.
93 -- Autoconf_Specified should be set to True if the user has used
96 function Locate_Config_File
(Name
: String) return String_Access
;
97 -- Search for Name in the config files directory. Return full path if
98 -- found, or null otherwise.
100 procedure Raise_Invalid_Config
(Msg
: String);
101 pragma No_Return
(Raise_Invalid_Config
);
102 -- Raises exception Invalid_Config with given message
104 procedure Apply_Config_File
105 (Config_File
: Prj
.Project_Id
;
106 Project_Tree
: Prj
.Project_Tree_Ref
);
107 -- Apply the configuration file settings to all the projects in the
108 -- project tree. The Project_Tree must have been parsed first, and
109 -- processed through the first phase so that all its projects are known.
111 -- Currently, this will add new attributes and packages in the various
112 -- projects, so that when the second phase of the processing is performed
113 -- these attributes are automatically taken into account.
119 procedure Add_Attributes
120 (Project_Tree
: Project_Tree_Ref
;
121 Conf_Decl
: Declarations
;
122 User_Decl
: in out Declarations
)
124 Shared
: constant Shared_Project_Tree_Data_Access
:= Project_Tree
.Shared
;
125 Conf_Attr_Id
: Variable_Id
;
126 Conf_Attr
: Variable
;
127 Conf_Array_Id
: Array_Id
;
128 Conf_Array
: Array_Data
;
129 Conf_Array_Elem_Id
: Array_Element_Id
;
130 Conf_Array_Elem
: Array_Element
;
131 Conf_List
: String_List_Id
;
132 Conf_List_Elem
: String_Element
;
134 User_Attr_Id
: Variable_Id
;
135 User_Attr
: Variable
;
136 User_Array_Id
: Array_Id
;
137 User_Array
: Array_Data
;
138 User_Array_Elem_Id
: Array_Element_Id
;
139 User_Array_Elem
: Array_Element
;
142 Conf_Attr_Id
:= Conf_Decl
.Attributes
;
143 User_Attr_Id
:= User_Decl
.Attributes
;
144 while Conf_Attr_Id
/= No_Variable
loop
145 Conf_Attr
:= Shared
.Variable_Elements
.Table
(Conf_Attr_Id
);
146 User_Attr
:= Shared
.Variable_Elements
.Table
(User_Attr_Id
);
148 if not Conf_Attr
.Value
.Default
then
149 if User_Attr
.Value
.Default
then
151 -- No attribute declared in user project file: just copy the
152 -- value of the configuration attribute.
154 User_Attr
.Value
:= Conf_Attr
.Value
;
155 Shared
.Variable_Elements
.Table
(User_Attr_Id
) := User_Attr
;
157 elsif User_Attr
.Value
.Kind
= List
158 and then Conf_Attr
.Value
.Values
/= Nil_String
160 -- List attribute declared in both the user project and the
161 -- configuration project: prepend the user list with the
162 -- configuration list.
165 User_List
: constant String_List_Id
:=
166 User_Attr
.Value
.Values
;
167 Conf_List
: String_List_Id
:= Conf_Attr
.Value
.Values
;
168 Conf_Elem
: String_Element
;
169 New_List
: String_List_Id
;
170 New_Elem
: String_Element
;
175 String_Element_Table
.Increment_Last
176 (Shared
.String_Elements
);
178 String_Element_Table
.Last
(Shared
.String_Elements
);
180 -- Value of attribute is new list
182 User_Attr
.Value
.Values
:= New_List
;
183 Shared
.Variable_Elements
.Table
(User_Attr_Id
) := User_Attr
;
186 -- Get each element of configuration list
188 Conf_Elem
:= Shared
.String_Elements
.Table
(Conf_List
);
189 New_Elem
:= Conf_Elem
;
190 Conf_List
:= Conf_Elem
.Next
;
192 if Conf_List
= Nil_String
then
194 -- If it is the last element in the list, connect to
195 -- first element of user list, and we are done.
197 New_Elem
.Next
:= User_List
;
198 Shared
.String_Elements
.Table
(New_List
) := New_Elem
;
202 -- If it is not the last element in the list, add to
205 String_Element_Table
.Increment_Last
206 (Shared
.String_Elements
);
208 String_Element_Table
.Last
(Shared
.String_Elements
);
209 Shared
.String_Elements
.Table
(New_List
) := New_Elem
;
210 New_List
:= New_Elem
.Next
;
217 Conf_Attr_Id
:= Conf_Attr
.Next
;
218 User_Attr_Id
:= User_Attr
.Next
;
221 Conf_Array_Id
:= Conf_Decl
.Arrays
;
222 while Conf_Array_Id
/= No_Array
loop
223 Conf_Array
:= Shared
.Arrays
.Table
(Conf_Array_Id
);
225 User_Array_Id
:= User_Decl
.Arrays
;
226 while User_Array_Id
/= No_Array
loop
227 User_Array
:= Shared
.Arrays
.Table
(User_Array_Id
);
228 exit when User_Array
.Name
= Conf_Array
.Name
;
229 User_Array_Id
:= User_Array
.Next
;
232 -- If this associative array does not exist in the user project file,
233 -- do a shallow copy of the full associative array.
235 if User_Array_Id
= No_Array
then
236 Array_Table
.Increment_Last
(Shared
.Arrays
);
237 User_Array
:= Conf_Array
;
238 User_Array
.Next
:= User_Decl
.Arrays
;
239 User_Decl
.Arrays
:= Array_Table
.Last
(Shared
.Arrays
);
240 Shared
.Arrays
.Table
(User_Decl
.Arrays
) := User_Array
;
242 -- Otherwise, check each array element
245 Conf_Array_Elem_Id
:= Conf_Array
.Value
;
246 while Conf_Array_Elem_Id
/= No_Array_Element
loop
248 Shared
.Array_Elements
.Table
(Conf_Array_Elem_Id
);
250 User_Array_Elem_Id
:= User_Array
.Value
;
251 while User_Array_Elem_Id
/= No_Array_Element
loop
253 Shared
.Array_Elements
.Table
(User_Array_Elem_Id
);
254 exit when User_Array_Elem
.Index
= Conf_Array_Elem
.Index
;
255 User_Array_Elem_Id
:= User_Array_Elem
.Next
;
258 -- If the array element doesn't exist in the user array, insert
259 -- a shallow copy of the conf array element in the user array.
261 if User_Array_Elem_Id
= No_Array_Element
then
262 Array_Element_Table
.Increment_Last
(Shared
.Array_Elements
);
263 User_Array_Elem
:= Conf_Array_Elem
;
264 User_Array_Elem
.Next
:= User_Array
.Value
;
266 Array_Element_Table
.Last
(Shared
.Array_Elements
);
267 Shared
.Array_Elements
.Table
(User_Array
.Value
) :=
269 Shared
.Arrays
.Table
(User_Array_Id
) := User_Array
;
271 -- Otherwise, if the value is a string list, prepend the conf
272 -- array element value to the array element.
274 elsif Conf_Array_Elem
.Value
.Kind
= List
then
275 Conf_List
:= Conf_Array_Elem
.Value
.Values
;
277 if Conf_List
/= Nil_String
then
279 Link
: constant String_List_Id
:=
280 User_Array_Elem
.Value
.Values
;
281 Previous
: String_List_Id
:= Nil_String
;
282 Next
: String_List_Id
;
287 Shared
.String_Elements
.Table
(Conf_List
);
288 String_Element_Table
.Increment_Last
289 (Shared
.String_Elements
);
291 String_Element_Table
.Last
292 (Shared
.String_Elements
);
293 Shared
.String_Elements
.Table
(Next
) :=
296 if Previous
= Nil_String
then
297 User_Array_Elem
.Value
.Values
:= Next
;
298 Shared
.Array_Elements
.Table
299 (User_Array_Elem_Id
) := User_Array_Elem
;
302 Shared
.String_Elements
.Table
303 (Previous
).Next
:= Next
;
308 Conf_List
:= Conf_List_Elem
.Next
;
310 if Conf_List
= Nil_String
then
311 Shared
.String_Elements
.Table
(Previous
).Next
:=
320 Conf_Array_Elem_Id
:= Conf_Array_Elem
.Next
;
324 Conf_Array_Id
:= Conf_Array
.Next
;
328 ------------------------------------
329 -- Add_Default_GNAT_Naming_Scheme --
330 ------------------------------------
332 procedure Add_Default_GNAT_Naming_Scheme
333 (Config_File
: in out Project_Node_Id
;
334 Project_Tree
: Project_Node_Tree_Ref
)
336 procedure Create_Attribute
339 Index
: String := "";
340 Pkg
: Project_Node_Id
:= Empty_Node
);
342 ----------------------
343 -- Create_Attribute --
344 ----------------------
346 procedure Create_Attribute
349 Index
: String := "";
350 Pkg
: Project_Node_Id
:= Empty_Node
)
352 Attr
: Project_Node_Id
;
353 pragma Unreferenced
(Attr
);
355 Expr
: Name_Id
:= No_Name
;
356 Val
: Name_Id
:= No_Name
;
357 Parent
: Project_Node_Id
:= Config_File
;
361 Name_Len
:= Index
'Length;
362 Name_Buffer
(1 .. Name_Len
) := Index
;
366 if Pkg
/= Empty_Node
then
370 Name_Len
:= Value
'Length;
371 Name_Buffer
(1 .. Name_Len
) := Value
;
374 Attr
:= Create_Attribute
375 (Tree
=> Project_Tree
,
376 Prj_Or_Pkg
=> Parent
,
380 Value
=> Create_Literal_String
(Expr
, Project_Tree
));
381 end Create_Attribute
;
386 Naming
: Project_Node_Id
;
387 Compiler
: Project_Node_Id
;
389 -- Start of processing for Add_Default_GNAT_Naming_Scheme
392 if Config_File
= Empty_Node
then
394 -- Create a dummy config file is none was found
396 Name_Len
:= Auto_Cgpr
'Length;
397 Name_Buffer
(1 .. Name_Len
) := Auto_Cgpr
;
400 -- An invalid project name to avoid conflicts with user-created ones
403 Name_Buffer
(1 .. Name_Len
) := "_auto";
407 (In_Tree
=> Project_Tree
,
409 Full_Path
=> Path_Name_Type
(Name
),
410 Is_Config_File
=> True);
412 -- Setup library support
414 case MLib
.Tgt
.Support_For_Libraries
is
419 Create_Attribute
(Name_Library_Support
, "static_only");
422 Create_Attribute
(Name_Library_Support
, "full");
425 if MLib
.Tgt
.Standalone_Library_Auto_Init_Is_Supported
then
426 Create_Attribute
(Name_Library_Auto_Init_Supported
, "true");
428 Create_Attribute
(Name_Library_Auto_Init_Supported
, "false");
431 -- Setup Ada support (Ada is the default language here, since this
432 -- is only called when no config file existed initially, ie for
435 Create_Attribute
(Name_Default_Language
, "ada");
437 Compiler
:= Create_Package
(Project_Tree
, Config_File
, "compiler");
439 (Name_Driver
, "gcc", "ada", Pkg
=> Compiler
);
441 (Name_Language_Kind
, "unit_based", "ada", Pkg
=> Compiler
);
443 (Name_Dependency_Kind
, "ALI_File", "ada", Pkg
=> Compiler
);
445 Naming
:= Create_Package
(Project_Tree
, Config_File
, "naming");
446 Create_Attribute
(Name_Spec_Suffix
, ".ads", "ada", Pkg
=> Naming
);
447 Create_Attribute
(Name_Separate_Suffix
, ".adb", "ada", Pkg
=> Naming
);
448 Create_Attribute
(Name_Body_Suffix
, ".adb", "ada", Pkg
=> Naming
);
449 Create_Attribute
(Name_Dot_Replacement
, "-", Pkg
=> Naming
);
450 Create_Attribute
(Name_Casing
, "lowercase", Pkg
=> Naming
);
452 if Current_Verbosity
= High
then
453 Write_Line
("Automatically generated (in-memory) config file");
455 (Project
=> Config_File
,
456 In_Tree
=> Project_Tree
,
457 Backward_Compatibility
=> False);
460 end Add_Default_GNAT_Naming_Scheme
;
462 -----------------------
463 -- Apply_Config_File --
464 -----------------------
466 procedure Apply_Config_File
467 (Config_File
: Prj
.Project_Id
;
468 Project_Tree
: Prj
.Project_Tree_Ref
)
470 Shared
: constant Shared_Project_Tree_Data_Access
:= Project_Tree
.Shared
;
472 Conf_Decl
: constant Declarations
:= Config_File
.Decl
;
473 Conf_Pack_Id
: Package_Id
;
474 Conf_Pack
: Package_Element
;
476 User_Decl
: Declarations
;
477 User_Pack_Id
: Package_Id
;
478 User_Pack
: Package_Element
;
482 Debug_Output
("Applying config file to a project tree");
484 Proj
:= Project_Tree
.Projects
;
485 while Proj
/= null loop
486 if Proj
.Project
/= Config_File
then
487 User_Decl
:= Proj
.Project
.Decl
;
489 (Project_Tree
=> Project_Tree
,
490 Conf_Decl
=> Conf_Decl
,
491 User_Decl
=> User_Decl
);
493 Conf_Pack_Id
:= Conf_Decl
.Packages
;
494 while Conf_Pack_Id
/= No_Package
loop
495 Conf_Pack
:= Shared
.Packages
.Table
(Conf_Pack_Id
);
497 User_Pack_Id
:= User_Decl
.Packages
;
498 while User_Pack_Id
/= No_Package
loop
499 User_Pack
:= Shared
.Packages
.Table
(User_Pack_Id
);
500 exit when User_Pack
.Name
= Conf_Pack
.Name
;
501 User_Pack_Id
:= User_Pack
.Next
;
504 if User_Pack_Id
= No_Package
then
505 Package_Table
.Increment_Last
(Shared
.Packages
);
506 User_Pack
:= Conf_Pack
;
507 User_Pack
.Next
:= User_Decl
.Packages
;
508 User_Decl
.Packages
:= Package_Table
.Last
(Shared
.Packages
);
509 Shared
.Packages
.Table
(User_Decl
.Packages
) := User_Pack
;
513 (Project_Tree
=> Project_Tree
,
514 Conf_Decl
=> Conf_Pack
.Decl
,
515 User_Decl
=> Shared
.Packages
.Table
516 (User_Pack_Id
).Decl
);
519 Conf_Pack_Id
:= Conf_Pack
.Next
;
522 Proj
.Project
.Decl
:= User_Decl
;
524 -- For aggregate projects, we need to apply the config to all
525 -- their aggregated trees as well.
527 if Proj
.Project
.Qualifier
in Aggregate_Project
then
529 List
: Aggregated_Project_List
;
531 List
:= Proj
.Project
.Aggregated_Projects
;
532 while List
/= null loop
534 ("Recursively apply config to aggregated tree",
537 (Config_File
, Project_Tree
=> List
.Tree
);
546 end Apply_Config_File
;
552 function Check_Target
553 (Config_File
: Project_Id
;
554 Autoconf_Specified
: Boolean;
555 Project_Tree
: Prj
.Project_Tree_Ref
;
556 Target
: String := "") return Boolean
558 Shared
: constant Shared_Project_Tree_Data_Access
:=
560 Variable
: constant Variable_Value
:=
562 (Name_Target
, Config_File
.Decl
.Attributes
, Shared
);
563 Tgt_Name
: Name_Id
:= No_Name
;
567 if Variable
/= Nil_Variable_Value
and then not Variable
.Default
then
568 Tgt_Name
:= Variable
.Value
;
572 OK
:= not Autoconf_Specified
or else Tgt_Name
= No_Name
;
574 OK
:= Tgt_Name
/= No_Name
575 and then Target
= Get_Name_String
(Tgt_Name
);
579 if Autoconf_Specified
then
581 Write_Line
("inconsistent targets, performing autoconf");
587 if Tgt_Name
/= No_Name
then
589 ("invalid target name """
590 & Get_Name_String
(Tgt_Name
) & """ in configuration");
593 ("no target specified in configuration file");
601 --------------------------------------
602 -- Get_Or_Create_Configuration_File --
603 --------------------------------------
605 procedure Get_Or_Create_Configuration_File
606 (Project
: Project_Id
;
607 Project_Tree
: Project_Tree_Ref
;
608 Project_Node_Tree
: Prj
.Tree
.Project_Node_Tree_Ref
;
609 Env
: in out Prj
.Tree
.Environment
;
610 Allow_Automatic_Generation
: Boolean;
611 Config_File_Name
: String := "";
612 Autoconf_Specified
: Boolean;
613 Target_Name
: String := "";
614 Normalized_Hostname
: String;
615 Packages_To_Check
: String_List_Access
:= null;
616 Config
: out Prj
.Project_Id
;
617 Config_File_Path
: out String_Access
;
618 Automatically_Generated
: out Boolean;
619 On_Load_Config
: Config_File_Hook
:= null)
621 Shared
: constant Shared_Project_Tree_Data_Access
:= Project_Tree
.Shared
;
623 At_Least_One_Compiler_Command
: Boolean := False;
624 -- Set to True if at least one attribute Ide'Compiler_Command is
625 -- specified for one language of the system.
627 function Default_File_Name
return String;
628 -- Return the name of the default config file that should be tested
630 procedure Do_Autoconf
;
631 -- Generate a new config file through gprconfig. In case of error, this
632 -- raises the Invalid_Config exception with an appropriate message
634 function Get_Config_Switches
return Argument_List_Access
;
635 -- Return the --config switches to use for gprconfig
637 function Might_Have_Sources
(Project
: Project_Id
) return Boolean;
638 -- True if the specified project might have sources (ie the user has not
639 -- explicitly specified it. We haven't checked the file system, nor do
640 -- we need to at this stage.
642 -----------------------
643 -- Default_File_Name --
644 -----------------------
646 function Default_File_Name
return String is
647 Ada_RTS
: constant String := Runtime_Name_For
(Name_Ada
);
651 if Target_Name
/= "" then
652 if Ada_RTS
/= "" then
653 return Target_Name
& '-' & Ada_RTS
654 & Config_Project_File_Extension
;
656 return Target_Name
& Config_Project_File_Extension
;
659 elsif Ada_RTS
/= "" then
660 return Ada_RTS
& Config_Project_File_Extension
;
663 Tmp
:= Getenv
(Config_Project_Env_Var
);
666 T
: constant String := Tmp
.all;
678 end Default_File_Name
;
680 ------------------------
681 -- Might_Have_Sources --
682 ------------------------
684 function Might_Have_Sources
(Project
: Project_Id
) return Boolean is
685 Variable
: Variable_Value
;
691 Project
.Decl
.Attributes
,
694 if Variable
= Nil_Variable_Value
695 or else Variable
.Default
696 or else Variable
.Values
/= Nil_String
701 Project
.Decl
.Attributes
,
703 return Variable
= Nil_Variable_Value
704 or else Variable
.Default
705 or else Variable
.Values
/= Nil_String
;
710 end Might_Have_Sources
;
712 -------------------------
713 -- Get_Config_Switches --
714 -------------------------
716 function Get_Config_Switches
return Argument_List_Access
is
718 package Language_Htable
is new GNAT
.HTable
.Simple_HTable
719 (Header_Num
=> Prj
.Header_Num
,
721 No_Element
=> No_Name
,
725 -- Hash table to keep the languages used in the project tree
727 IDE
: constant Package_Id
:=
728 Value_Of
(Name_Ide
, Project
.Decl
.Packages
, Shared
);
730 procedure Add_Config_Switches_For_Project
731 (Project
: Project_Id
;
732 Tree
: Project_Tree_Ref
;
733 With_State
: in out Integer);
734 -- Add all --config switches for this project. This is also called
735 -- for aggregate projects.
737 -------------------------------------
738 -- Add_Config_Switches_For_Project --
739 -------------------------------------
741 procedure Add_Config_Switches_For_Project
742 (Project
: Project_Id
;
743 Tree
: Project_Tree_Ref
;
744 With_State
: in out Integer)
746 pragma Unreferenced
(With_State
);
748 Shared
: constant Shared_Project_Tree_Data_Access
:= Tree
.Shared
;
750 Variable
: Variable_Value
;
751 Check_Default
: Boolean;
753 List
: String_List_Id
;
754 Elem
: String_Element
;
757 if Might_Have_Sources
(Project
) then
759 Value_Of
(Name_Languages
, Project
.Decl
.Attributes
, Shared
);
761 if Variable
= Nil_Variable_Value
or else Variable
.Default
then
763 -- Languages is not declared. If it is not an extending
764 -- project, or if it extends a project with no Languages,
765 -- check for Default_Language.
767 Check_Default
:= Project
.Extends
= No_Project
;
769 if not Check_Default
then
773 Project
.Extends
.Decl
.Attributes
,
776 Variable
/= Nil_Variable_Value
777 and then Variable
.Values
= Nil_String
;
780 if Check_Default
then
783 (Name_Default_Language
,
784 Project
.Decl
.Attributes
,
787 if Variable
/= Nil_Variable_Value
788 and then not Variable
.Default
790 Get_Name_String
(Variable
.Value
);
791 To_Lower
(Name_Buffer
(1 .. Name_Len
));
793 Language_Htable
.Set
(Lang
, Lang
);
795 -- If no default language is declared, default to Ada
798 Language_Htable
.Set
(Name_Ada
, Name_Ada
);
802 elsif Variable
.Values
/= Nil_String
then
804 -- Attribute Languages is declared with a non empty list:
805 -- put all the languages in Language_HTable.
807 List
:= Variable
.Values
;
808 while List
/= Nil_String
loop
809 Elem
:= Shared
.String_Elements
.Table
(List
);
811 Get_Name_String
(Elem
.Value
);
812 To_Lower
(Name_Buffer
(1 .. Name_Len
));
814 Language_Htable
.Set
(Lang
, Lang
);
820 end Add_Config_Switches_For_Project
;
822 procedure For_Every_Imported_Project
is new For_Every_Project_Imported
823 (State
=> Integer, Action
=> Add_Config_Switches_For_Project
);
824 -- Document this procedure ???
830 Result
: Argument_List_Access
;
831 Variable
: Variable_Value
;
832 Dummy
: Integer := 0;
834 -- Start of processing for Get_Config_Switches
837 For_Every_Imported_Project
839 Tree
=> Project_Tree
,
841 Include_Aggregated
=> True);
843 Name
:= Language_Htable
.Get_First
;
845 while Name
/= No_Name
loop
847 Name
:= Language_Htable
.Get_Next
;
850 Result
:= new String_List
(1 .. Count
);
853 Name
:= Language_Htable
.Get_First
;
854 while Name
/= No_Name
loop
856 -- Check if IDE'Compiler_Command is declared for the language.
857 -- If it is, use its value to invoke gprconfig.
862 Attribute_Or_Array_Name
=> Name_Compiler_Command
,
865 Force_Lower_Case_Index
=> True);
868 Config_Command
: constant String :=
869 "--config=" & Get_Name_String
(Name
);
871 Runtime_Name
: constant String :=
872 Runtime_Name_For
(Name
);
875 if Variable
= Nil_Variable_Value
876 or else Length_Of_Name
(Variable
.Value
) = 0
879 new String'(Config_Command & ",," & Runtime_Name);
882 At_Least_One_Compiler_Command := True;
885 Compiler_Command : constant String :=
886 Get_Name_String (Variable.Value);
889 if Is_Absolute_Path (Compiler_Command) then
892 (Config_Command
& ",," & Runtime_Name
& "," &
893 Containing_Directory
(Compiler_Command
) & "," &
894 Simple_Name
(Compiler_Command
));
898 (Config_Command & ",," & Runtime_Name & ",," &
906 Name := Language_Htable.Get_Next;
910 end Get_Config_Switches;
916 procedure Do_Autoconf is
917 Obj_Dir : constant Variable_Value :=
920 Project.Decl.Attributes,
923 Gprconfig_Path : String_Access;
927 Gprconfig_Path := Locate_Exec_On_Path (Gprconfig_Name);
929 if Gprconfig_Path = null then
931 ("could not locate gprconfig for auto-configuration");
934 -- First, find the object directory of the user's project
936 if Obj_Dir = Nil_Variable_Value or else Obj_Dir.Default then
937 Get_Name_String (Project.Directory.Display_Name);
940 if Is_Absolute_Path (Get_Name_String (Obj_Dir.Value)) then
941 Get_Name_String (Obj_Dir.Value);
945 Add_Str_To_Name_Buffer
946 (Get_Name_String (Project.Directory.Display_Name));
947 Add_Str_To_Name_Buffer (Get_Name_String (Obj_Dir.Value));
951 if Subdirs /= null then
952 Add_Char_To_Name_Buffer (Directory_Separator);
953 Add_Str_To_Name_Buffer (Subdirs.all);
956 for J in 1 .. Name_Len loop
957 if Name_Buffer (J) = '/' then
958 Name_Buffer (J) := Directory_Separator;
962 -- Make sure that Obj_Dir ends with a directory separator
964 if Name_Buffer (Name_Len) /= Directory_Separator then
965 Name_Len := Name_Len + 1;
966 Name_Buffer (Name_Len) := Directory_Separator;
970 Obj_Dir : constant String := Name_Buffer (1 .. Name_Len);
971 Config_Switches : Argument_List_Access;
972 Args : Argument_List (1 .. 5);
974 Obj_Dir_Exists : Boolean := True;
977 -- Check if the object directory exists. If Setup_Projects is True
978 -- (-p) and directory does not exist, attempt to create it.
979 -- Otherwise, if directory does not exist, fail without calling
982 if not Is_Directory (Obj_Dir)
983 and then (Setup_Projects or else Subdirs /= null)
986 Create_Path (Obj_Dir);
988 if not Quiet_Output then
989 Write_Str ("object directory """);
991 Write_Line (""" created");
997 ("could not create object directory " & Obj_Dir);
1001 if not Is_Directory (Obj_Dir) then
1002 case Env.Flags.Require_Obj_Dirs is
1004 Raise_Invalid_Config
1005 ("object directory " & Obj_Dir & " does not exist");
1010 "?object directory " & Obj_Dir & " does not exist");
1011 Obj_Dir_Exists := False;
1018 -- If no switch --RTS have been specified on the command line,
1019 -- look for --RTS switches in the Builder switches.
1021 if RTS_Languages.Get_First = No_Name then
1023 Builder : constant Package_Id :=
1025 (Name_Builder, Project.Decl.Packages, Shared);
1026 Switch_Array_Id : Array_Element_Id;
1028 procedure Check_RTS_Switches;
1029 -- Take into account eventual switches --RTS in
1032 ------------------------
1033 -- Check_RTS_SWitches --
1034 ------------------------
1036 procedure Check_RTS_Switches is
1037 Switch_Array : Array_Element;
1038 Switch_List : String_List_Id := Nil_String;
1039 Switch : String_Element;
1041 Lang_Last : Positive;
1044 while Switch_Array_Id /= No_Array_Element loop
1046 Shared.Array_Elements.Table (Switch_Array_Id);
1048 Switch_List := Switch_Array.Value.Values;
1049 while Switch_List /= Nil_String loop
1051 Shared.String_Elements.Table (Switch_List);
1053 if Switch.Value /= No_Name then
1054 Get_Name_String (Switch.Value);
1056 if Name_Len >= 7 and then
1057 Name_Buffer (1 .. 5) = "--RTS"
1059 if Name_Buffer (6) = '=' then
1060 if not Runtime_Name_Set_For (Name_Ada) then
1063 Name_Buffer (7 .. Name_Len));
1066 elsif Name_Len > 7 and then
1067 Name_Buffer (6) = ':' and then
1068 Name_Buffer (7) /= '='
1071 while Lang_Last < Name_Len and then
1072 Name_Buffer (Lang_Last + 1) /= '='
1074 Lang_Last := Lang_Last + 1;
1077 if Name_Buffer (Lang_Last + 1) = '=' then
1079 RTS : constant String :=
1080 Name_Buffer (Lang_Last + 2 ..
1083 Name_Buffer (1 .. Lang_Last - 6) :=
1084 Name_Buffer (7 .. Lang_Last);
1085 Name_Len := Lang_Last - 6;
1087 (Name_Buffer (1 .. Name_Len));
1091 Runtime_Name_Set_For (Lang)
1093 Set_Runtime_For (Lang, RTS);
1101 Switch_List := Switch.Next;
1104 Switch_Array_Id := Switch_Array.Next;
1106 end Check_RTS_Switches;
1109 if Builder /= No_Package then
1112 (Name => Name_Switches,
1114 Shared.Packages.Table (Builder).Decl.Arrays,
1120 (Name => Name_Default_Switches,
1122 Shared.Packages.Table (Builder).Decl.Arrays,
1129 -- Get the config switches. This should be done only now, as some
1130 -- runtimes may have been found if the Builder switches.
1132 Config_Switches := Get_Config_Switches;
1136 Args (1) := new String'("--batch");
1137 Args
(2) := new String'("-o");
1139 -- If no config file was specified, set the auto.cgpr one
1141 if Config_File_Name = "" then
1142 if Obj_Dir_Exists then
1143 Args (3) := new String'(Obj_Dir
& Auto_Cgpr
);
1147 Path_FD
: File_Descriptor
;
1148 Path_Name
: Path_Name_Type
;
1151 Prj
.Env
.Create_Temp_File
1152 (Shared
=> Project_Tree
.Shared
,
1154 Path_Name
=> Path_Name
,
1155 File_Use
=> "configuration file");
1157 if Path_FD
/= Invalid_FD
then
1159 Temp_Dir
: constant String :=
1160 Containing_Directory
1161 (Get_Name_String
(Path_Name
));
1163 GNAT
.OS_Lib
.Close
(Path_FD
);
1165 new String'(Temp_Dir &
1166 Directory_Separator &
1168 Delete_File (Get_Name_String (Path_Name));
1172 -- We'll have an error message later on
1174 Args (3) := new String'(Obj_Dir
& Auto_Cgpr
);
1179 Args
(3) := new String'(Config_File_Name);
1182 if Normalized_Hostname = "" then
1185 if Target_Name = "" then
1186 if At_Least_One_Compiler_Command then
1187 Args (4) := new String'("--target=all");
1191 new String'("--target=" & Normalized_Hostname);
1195 Args (4) := new String'("--target=" & Target_Name
);
1201 if not Verbose_Mode
then
1202 Arg_Last
:= Arg_Last
+ 1;
1203 Args
(Arg_Last
) := new String'("-q");
1206 if Verbose_Mode then
1207 Write_Str (Gprconfig_Name);
1209 for J in 1 .. Arg_Last loop
1211 Write_Str (Args (J).all);
1214 for J in Config_Switches'Range loop
1216 Write_Str (Config_Switches (J).all);
1221 elsif not Quiet_Output then
1222 -- Display no message if we are creating auto.cgpr, unless in
1225 if Config_File_Name /= ""
1226 or else Verbose_Mode
1228 Write_Str ("creating ");
1229 Write_Str (Simple_Name (Args (3).all));
1234 Spawn (Gprconfig_Path.all, Args (1 .. Arg_Last) &
1235 Config_Switches.all,
1238 Free (Config_Switches);
1240 Config_File_Path := Locate_Config_File (Args (3).all);
1242 if Config_File_Path = null then
1243 Raise_Invalid_Config
1244 ("could not create " & Args (3).all);
1247 for F in Args'Range loop
1254 Config_Project_Node : Project_Node_Id := Empty_Node;
1257 pragma Assert (Prj.Env.Is_Initialized (Env.Project_Path));
1259 Free (Config_File_Path);
1260 Config := No_Project;
1262 if Config_File_Name /= "" then
1263 Config_File_Path := Locate_Config_File (Config_File_Name);
1265 Config_File_Path := Locate_Config_File (Default_File_Name);
1268 if Config_File_Path = null then
1269 if (not Allow_Automatic_Generation)
1270 and then Config_File_Name /= ""
1272 Raise_Invalid_Config
1273 ("could not locate main configuration project "
1274 & Config_File_Name);
1278 Automatically_Generated :=
1279 Allow_Automatic_Generation and then Config_File_Path = null;
1281 <<Process_Config_File>>
1283 if Automatically_Generated then
1284 if Hostparm.OpenVMS then
1286 -- There is no gprconfig on VMS
1288 Raise_Invalid_Config
1289 ("could not locate any configuration project file");
1292 -- This might raise an Invalid_Config exception
1297 -- If the config file is not auto-generated, warn if there is any --RTS
1298 -- switch on the command line.
1300 elsif RTS_Languages.Get_First /= No_Name
1301 and then Opt.Warning_Mode /= Opt.Suppress
1304 ("warning: --RTS is taken into account only in auto-configuration");
1307 -- Parse the configuration file
1309 if Verbose_Mode and then Config_File_Path /= null then
1310 Write_Str ("Checking configuration ");
1311 Write_Line (Config_File_Path.all);
1314 if On_Load_Config /= null then
1316 (Config_File => Config_Project_Node,
1317 Project_Node_Tree => Project_Node_Tree);
1319 elsif Config_File_Path /= null then
1321 (In_Tree => Project_Node_Tree,
1322 Project => Config_Project_Node,
1323 Project_File_Name => Config_File_Path.all,
1324 Errout_Handling => Prj.Part.Finalize_If_Error,
1325 Packages_To_Check => Packages_To_Check,
1326 Current_Directory => Current_Directory,
1327 Is_Config_File => True,
1330 Config_Project_Node := Empty_Node;
1333 if Config_Project_Node /= Empty_Node then
1334 Prj.Proc.Process_Project_Tree_Phase_1
1335 (In_Tree => Project_Tree,
1337 Packages_To_Check => Packages_To_Check,
1339 From_Project_Node => Config_Project_Node,
1340 From_Project_Node_Tree => Project_Node_Tree,
1342 Reset_Tree => False);
1345 if Config_Project_Node = Empty_Node
1346 or else Config = No_Project
1348 Raise_Invalid_Config
1349 ("processing of configuration project """
1350 & Config_File_Path.all & """ failed");
1353 -- Check that the target of the configuration file is the one the user
1354 -- specified on the command line. We do not need to check that when in
1355 -- auto-conf mode, since the appropriate target was passed to gprconfig.
1357 if not Automatically_Generated
1359 Check_Target (Config, Autoconf_Specified, Project_Tree, Target_Name)
1361 Automatically_Generated := True;
1362 goto Process_Config_File;
1364 end Get_Or_Create_Configuration_File;
1366 ------------------------
1367 -- Locate_Config_File --
1368 ------------------------
1370 function Locate_Config_File (Name : String) return String_Access is
1371 Prefix_Path : constant String := Executable_Prefix_Path;
1373 if Prefix_Path'Length /= 0 then
1374 return Locate_Regular_File
1376 "." & Path_Separator &
1377 Prefix_Path & "share" & Directory_Separator & "gpr");
1379 return Locate_Regular_File (Name, ".");
1381 end Locate_Config_File;
1383 ------------------------------------
1384 -- Parse_Project_And_Apply_Config --
1385 ------------------------------------
1387 procedure Parse_Project_And_Apply_Config
1388 (Main_Project : out Prj.Project_Id;
1389 User_Project_Node : out Prj.Tree.Project_Node_Id;
1390 Config_File_Name : String := "";
1391 Autoconf_Specified : Boolean;
1392 Project_File_Name : String;
1393 Project_Tree : Prj.Project_Tree_Ref;
1394 Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
1395 Env : in out Prj.Tree.Environment;
1396 Packages_To_Check : String_List_Access;
1397 Allow_Automatic_Generation : Boolean := True;
1398 Automatically_Generated : out Boolean;
1399 Config_File_Path : out String_Access;
1400 Target_Name : String := "";
1401 Normalized_Hostname : String;
1402 On_Load_Config : Config_File_Hook := null)
1405 pragma Assert (Prj.Env.Is_Initialized (Env.Project_Path));
1407 -- Parse the user project tree
1409 Prj.Initialize (Project_Tree);
1411 Main_Project := No_Project;
1412 Automatically_Generated := False;
1415 (In_Tree => Project_Node_Tree,
1416 Project => User_Project_Node,
1417 Project_File_Name => Project_File_Name,
1418 Errout_Handling => Prj.Part.Finalize_If_Error,
1419 Packages_To_Check => Packages_To_Check,
1420 Current_Directory => Current_Directory,
1421 Is_Config_File => False,
1424 if User_Project_Node = Empty_Node then
1425 User_Project_Node := Empty_Node;
1429 Process_Project_And_Apply_Config
1430 (Main_Project => Main_Project,
1431 User_Project_Node => User_Project_Node,
1432 Config_File_Name => Config_File_Name,
1433 Autoconf_Specified => Autoconf_Specified,
1434 Project_Tree => Project_Tree,
1435 Project_Node_Tree => Project_Node_Tree,
1437 Packages_To_Check => Packages_To_Check,
1438 Allow_Automatic_Generation => Allow_Automatic_Generation,
1439 Automatically_Generated => Automatically_Generated,
1440 Config_File_Path => Config_File_Path,
1441 Target_Name => Target_Name,
1442 Normalized_Hostname => Normalized_Hostname,
1443 On_Load_Config => On_Load_Config);
1444 end Parse_Project_And_Apply_Config;
1446 --------------------------------------
1447 -- Process_Project_And_Apply_Config --
1448 --------------------------------------
1450 procedure Process_Project_And_Apply_Config
1451 (Main_Project : out Prj.Project_Id;
1452 User_Project_Node : Prj.Tree.Project_Node_Id;
1453 Config_File_Name : String := "";
1454 Autoconf_Specified : Boolean;
1455 Project_Tree : Prj.Project_Tree_Ref;
1456 Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
1457 Env : in out Prj.Tree.Environment;
1458 Packages_To_Check : String_List_Access;
1459 Allow_Automatic_Generation : Boolean := True;
1460 Automatically_Generated : out Boolean;
1461 Config_File_Path : out String_Access;
1462 Target_Name : String := "";
1463 Normalized_Hostname : String;
1464 On_Load_Config : Config_File_Hook := null;
1465 Reset_Tree : Boolean := True)
1467 Shared : constant Shared_Project_Tree_Data_Access :=
1468 Project_Tree.Shared;
1469 Main_Config_Project : Project_Id;
1473 Main_Project := No_Project;
1474 Automatically_Generated := False;
1476 Process_Project_Tree_Phase_1
1477 (In_Tree => Project_Tree,
1478 Project => Main_Project,
1479 Packages_To_Check => Packages_To_Check,
1481 From_Project_Node => User_Project_Node,
1482 From_Project_Node_Tree => Project_Node_Tree,
1484 Reset_Tree => Reset_Tree);
1487 Main_Project := No_Project;
1491 if Project_Tree.Source_Info_File_Name /= null then
1492 if not Is_Absolute_Path (Project_Tree.Source_Info_File_Name.all) then
1494 Obj_Dir : constant Variable_Value :=
1497 Main_Project.Decl.Attributes,
1501 if Obj_Dir = Nil_Variable_Value or else Obj_Dir.Default then
1502 Get_Name_String (Main_Project.Directory.Display_Name);
1505 if Is_Absolute_Path (Get_Name_String (Obj_Dir.Value)) then
1506 Get_Name_String (Obj_Dir.Value);
1510 Add_Str_To_Name_Buffer
1511 (Get_Name_String (Main_Project.Directory.Display_Name));
1512 Add_Str_To_Name_Buffer (Get_Name_String (Obj_Dir.Value));
1516 Add_Char_To_Name_Buffer (Directory_Separator);
1517 Add_Str_To_Name_Buffer (Project_Tree.Source_Info_File_Name.all);
1518 Free (Project_Tree.Source_Info_File_Name);
1519 Project_Tree.Source_Info_File_Name :=
1520 new String'(Name_Buffer
(1 .. Name_Len
));
1524 Read_Source_Info_File
(Project_Tree
);
1527 -- Find configuration file
1529 Get_Or_Create_Configuration_File
1530 (Config
=> Main_Config_Project
,
1531 Project
=> Main_Project
,
1532 Project_Tree
=> Project_Tree
,
1533 Project_Node_Tree
=> Project_Node_Tree
,
1535 Allow_Automatic_Generation
=> Allow_Automatic_Generation
,
1536 Config_File_Name
=> Config_File_Name
,
1537 Autoconf_Specified
=> Autoconf_Specified
,
1538 Target_Name
=> Target_Name
,
1539 Normalized_Hostname
=> Normalized_Hostname
,
1540 Packages_To_Check
=> Packages_To_Check
,
1541 Config_File_Path
=> Config_File_Path
,
1542 Automatically_Generated
=> Automatically_Generated
,
1543 On_Load_Config
=> On_Load_Config
);
1545 Apply_Config_File
(Main_Config_Project
, Project_Tree
);
1547 -- Finish processing the user's project
1549 Prj
.Proc
.Process_Project_Tree_Phase_2
1550 (In_Tree
=> Project_Tree
,
1551 Project
=> Main_Project
,
1553 From_Project_Node
=> User_Project_Node
,
1554 From_Project_Node_Tree
=> Project_Node_Tree
,
1558 if Project_Tree
.Source_Info_File_Name
/= null
1559 and then not Project_Tree
.Source_Info_File_Exists
1561 Write_Source_Info_File
(Project_Tree
);
1565 Main_Project
:= No_Project
;
1567 end Process_Project_And_Apply_Config
;
1569 --------------------------
1570 -- Raise_Invalid_Config --
1571 --------------------------
1573 procedure Raise_Invalid_Config
(Msg
: String) is
1575 Raise_Exception
(Invalid_Config
'Identity, Msg
);
1576 end Raise_Invalid_Config
;
1578 ----------------------
1579 -- Runtime_Name_For --
1580 ----------------------
1582 function Runtime_Name_For
(Language
: Name_Id
) return String is
1584 if RTS_Languages
.Get
(Language
) /= No_Name
then
1585 return Get_Name_String
(RTS_Languages
.Get
(Language
));
1589 end Runtime_Name_For
;
1591 --------------------------
1592 -- Runtime_Name_Set_For --
1593 --------------------------
1595 function Runtime_Name_Set_For
(Language
: Name_Id
) return Boolean is
1597 return RTS_Languages
.Get
(Language
) /= No_Name
;
1598 end Runtime_Name_Set_For
;
1600 ---------------------
1601 -- Set_Runtime_For --
1602 ---------------------
1604 procedure Set_Runtime_For
(Language
: Name_Id
; RTS_Name
: String) is
1606 Name_Len
:= RTS_Name
'Length;
1607 Name_Buffer
(1 .. Name_Len
) := RTS_Name
;
1608 RTS_Languages
.Set
(Language
, Name_Find
);
1609 end Set_Runtime_For
;