1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2006-2010, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
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
108 procedure Add_Attributes
109 (Project_Tree
: Project_Tree_Ref
;
110 Conf_Decl
: Declarations
;
111 User_Decl
: in out Declarations
)
113 Conf_Attr_Id
: Variable_Id
;
114 Conf_Attr
: Variable
;
115 Conf_Array_Id
: Array_Id
;
116 Conf_Array
: Array_Data
;
117 Conf_Array_Elem_Id
: Array_Element_Id
;
118 Conf_Array_Elem
: Array_Element
;
119 Conf_List
: String_List_Id
;
120 Conf_List_Elem
: String_Element
;
122 User_Attr_Id
: Variable_Id
;
123 User_Attr
: Variable
;
124 User_Array_Id
: Array_Id
;
125 User_Array
: Array_Data
;
126 User_Array_Elem_Id
: Array_Element_Id
;
127 User_Array_Elem
: Array_Element
;
130 Conf_Attr_Id
:= Conf_Decl
.Attributes
;
131 User_Attr_Id
:= User_Decl
.Attributes
;
132 while Conf_Attr_Id
/= No_Variable
loop
134 Project_Tree
.Variable_Elements
.Table
(Conf_Attr_Id
);
136 Project_Tree
.Variable_Elements
.Table
(User_Attr_Id
);
138 if not Conf_Attr
.Value
.Default
then
139 if User_Attr
.Value
.Default
then
141 -- No attribute declared in user project file: just copy the
142 -- value of the configuration attribute.
144 User_Attr
.Value
:= Conf_Attr
.Value
;
145 Project_Tree
.Variable_Elements
.Table
(User_Attr_Id
) :=
148 elsif User_Attr
.Value
.Kind
= List
149 and then Conf_Attr
.Value
.Values
/= Nil_String
151 -- List attribute declared in both the user project and the
152 -- configuration project: prepend the user list with the
153 -- configuration list.
156 Conf_List
: String_List_Id
:= Conf_Attr
.Value
.Values
;
157 Conf_Elem
: String_Element
;
158 User_List
: constant String_List_Id
:=
159 User_Attr
.Value
.Values
;
160 New_List
: String_List_Id
;
161 New_Elem
: String_Element
;
166 String_Element_Table
.Increment_Last
167 (Project_Tree
.String_Elements
);
168 New_List
:= String_Element_Table
.Last
169 (Project_Tree
.String_Elements
);
171 -- Value of attribute is new list
173 User_Attr
.Value
.Values
:= New_List
;
174 Project_Tree
.Variable_Elements
.Table
(User_Attr_Id
) :=
179 -- Get each element of configuration list
182 Project_Tree
.String_Elements
.Table
(Conf_List
);
183 New_Elem
:= Conf_Elem
;
184 Conf_List
:= Conf_Elem
.Next
;
186 if Conf_List
= Nil_String
then
188 -- If it is the last element in the list, connect to
189 -- first element of user list, and we are done.
191 New_Elem
.Next
:= User_List
;
192 Project_Tree
.String_Elements
.Table
193 (New_List
) := New_Elem
;
197 -- If it is not the last element in the list, add to
200 String_Element_Table
.Increment_Last
201 (Project_Tree
.String_Elements
);
203 String_Element_Table
.Last
204 (Project_Tree
.String_Elements
);
205 Project_Tree
.String_Elements
.Table
206 (New_List
) := New_Elem
;
207 New_List
:= New_Elem
.Next
;
214 Conf_Attr_Id
:= Conf_Attr
.Next
;
215 User_Attr_Id
:= User_Attr
.Next
;
218 Conf_Array_Id
:= Conf_Decl
.Arrays
;
219 while Conf_Array_Id
/= No_Array
loop
220 Conf_Array
:= Project_Tree
.Arrays
.Table
(Conf_Array_Id
);
222 User_Array_Id
:= User_Decl
.Arrays
;
223 while User_Array_Id
/= No_Array
loop
224 User_Array
:= Project_Tree
.Arrays
.Table
(User_Array_Id
);
225 exit when User_Array
.Name
= Conf_Array
.Name
;
226 User_Array_Id
:= User_Array
.Next
;
229 -- If this associative array does not exist in the user project file,
230 -- do a shallow copy of the full associative array.
232 if User_Array_Id
= No_Array
then
233 Array_Table
.Increment_Last
(Project_Tree
.Arrays
);
234 User_Array
:= Conf_Array
;
235 User_Array
.Next
:= User_Decl
.Arrays
;
236 User_Decl
.Arrays
:= Array_Table
.Last
(Project_Tree
.Arrays
);
237 Project_Tree
.Arrays
.Table
(User_Decl
.Arrays
) := User_Array
;
240 -- Otherwise, check each array element
242 Conf_Array_Elem_Id
:= Conf_Array
.Value
;
243 while Conf_Array_Elem_Id
/= No_Array_Element
loop
245 Project_Tree
.Array_Elements
.Table
(Conf_Array_Elem_Id
);
247 User_Array_Elem_Id
:= User_Array
.Value
;
248 while User_Array_Elem_Id
/= No_Array_Element
loop
250 Project_Tree
.Array_Elements
.Table
(User_Array_Elem_Id
);
251 exit when User_Array_Elem
.Index
= Conf_Array_Elem
.Index
;
252 User_Array_Elem_Id
:= User_Array_Elem
.Next
;
255 -- If the array element does not exist in the user array,
256 -- insert a shallow copy of the conf array element in the
259 if User_Array_Elem_Id
= No_Array_Element
then
260 Array_Element_Table
.Increment_Last
261 (Project_Tree
.Array_Elements
);
262 User_Array_Elem
:= Conf_Array_Elem
;
263 User_Array_Elem
.Next
:= User_Array
.Value
;
265 Array_Element_Table
.Last
(Project_Tree
.Array_Elements
);
266 Project_Tree
.Array_Elements
.Table
(User_Array
.Value
) :=
268 Project_Tree
.Arrays
.Table
(User_Array_Id
) := User_Array
;
270 -- Otherwise, if the value is a string list, prepend the
271 -- user array element with the conf array element value.
273 elsif Conf_Array_Elem
.Value
.Kind
= List
then
274 Conf_List
:= Conf_Array_Elem
.Value
.Values
;
276 if Conf_List
/= Nil_String
then
278 Link
: constant String_List_Id
:=
279 User_Array_Elem
.Value
.Values
;
280 Previous
: String_List_Id
:= Nil_String
;
281 Next
: String_List_Id
;
286 Project_Tree
.String_Elements
.Table
288 String_Element_Table
.Increment_Last
289 (Project_Tree
.String_Elements
);
291 String_Element_Table
.Last
292 (Project_Tree
.String_Elements
);
293 Project_Tree
.String_Elements
.Table
(Next
) :=
296 if Previous
= Nil_String
then
297 User_Array_Elem
.Value
.Values
:= Next
;
298 Project_Tree
.Array_Elements
.Table
299 (User_Array_Elem_Id
) := User_Array_Elem
;
302 Project_Tree
.String_Elements
.Table
303 (Previous
).Next
:= Next
;
308 Conf_List
:= Conf_List_Elem
.Next
;
310 if Conf_List
= Nil_String
then
311 Project_Tree
.String_Elements
.Table
312 (Previous
).Next
:= Link
;
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
;
360 Name_Len
:= Index
'Length;
361 Name_Buffer
(1 .. Name_Len
) := Index
;
365 if Pkg
/= Empty_Node
then
369 Name_Len
:= Value
'Length;
370 Name_Buffer
(1 .. Name_Len
) := Value
;
373 Attr
:= Create_Attribute
374 (Tree
=> Project_Tree
,
375 Prj_Or_Pkg
=> Parent
,
379 Value
=> Create_Literal_String
(Expr
, Project_Tree
));
380 end Create_Attribute
;
385 Naming
: Project_Node_Id
;
387 -- Start of processing for Add_Default_GNAT_Naming_Scheme
390 if Config_File
= Empty_Node
then
392 -- Create a dummy config file is none was found
394 Name_Len
:= Auto_Cgpr
'Length;
395 Name_Buffer
(1 .. Name_Len
) := Auto_Cgpr
;
398 -- An invalid project name to avoid conflicts with user-created ones
401 Name_Buffer
(1 .. Name_Len
) := "_auto";
405 (In_Tree
=> Project_Tree
,
407 Full_Path
=> Path_Name_Type
(Name
),
408 Is_Config_File
=> True);
410 -- Setup library support
412 case MLib
.Tgt
.Support_For_Libraries
is
417 Create_Attribute
(Name_Library_Support
, "static_only");
420 Create_Attribute
(Name_Library_Support
, "full");
423 if MLib
.Tgt
.Standalone_Library_Auto_Init_Is_Supported
then
424 Create_Attribute
(Name_Library_Auto_Init_Supported
, "true");
426 Create_Attribute
(Name_Library_Auto_Init_Supported
, "false");
429 -- Setup Ada support (Ada is the default language here, since this
430 -- is only called when no config file existed initially, ie for
433 Create_Attribute
(Name_Default_Language
, "ada");
435 Naming
:= Create_Package
(Project_Tree
, Config_File
, "naming");
436 Create_Attribute
(Name_Spec_Suffix
, ".ads", "ada", Pkg
=> Naming
);
437 Create_Attribute
(Name_Separate_Suffix
, ".adb", "ada", Pkg
=> Naming
);
438 Create_Attribute
(Name_Body_Suffix
, ".adb", "ada", Pkg
=> Naming
);
439 Create_Attribute
(Name_Dot_Replacement
, "-", Pkg
=> Naming
);
440 Create_Attribute
(Name_Casing
, "lowercase", Pkg
=> Naming
);
442 if Current_Verbosity
= High
then
443 Write_Line
("Automatically generated (in-memory) config file");
445 (Project
=> Config_File
,
446 In_Tree
=> Project_Tree
,
447 Backward_Compatibility
=> False);
450 end Add_Default_GNAT_Naming_Scheme
;
452 -----------------------
453 -- Apply_Config_File --
454 -----------------------
456 procedure Apply_Config_File
457 (Config_File
: Prj
.Project_Id
;
458 Project_Tree
: Prj
.Project_Tree_Ref
)
460 Conf_Decl
: constant Declarations
:= Config_File
.Decl
;
461 Conf_Pack_Id
: Package_Id
;
462 Conf_Pack
: Package_Element
;
464 User_Decl
: Declarations
;
465 User_Pack_Id
: Package_Id
;
466 User_Pack
: Package_Element
;
470 Proj
:= Project_Tree
.Projects
;
471 while Proj
/= null loop
472 if Proj
.Project
/= Config_File
then
473 User_Decl
:= Proj
.Project
.Decl
;
475 (Project_Tree
=> Project_Tree
,
476 Conf_Decl
=> Conf_Decl
,
477 User_Decl
=> User_Decl
);
479 Conf_Pack_Id
:= Conf_Decl
.Packages
;
480 while Conf_Pack_Id
/= No_Package
loop
481 Conf_Pack
:= Project_Tree
.Packages
.Table
(Conf_Pack_Id
);
483 User_Pack_Id
:= User_Decl
.Packages
;
484 while User_Pack_Id
/= No_Package
loop
485 User_Pack
:= Project_Tree
.Packages
.Table
(User_Pack_Id
);
486 exit when User_Pack
.Name
= Conf_Pack
.Name
;
487 User_Pack_Id
:= User_Pack
.Next
;
490 if User_Pack_Id
= No_Package
then
491 Package_Table
.Increment_Last
(Project_Tree
.Packages
);
492 User_Pack
:= Conf_Pack
;
493 User_Pack
.Next
:= User_Decl
.Packages
;
494 User_Decl
.Packages
:=
495 Package_Table
.Last
(Project_Tree
.Packages
);
496 Project_Tree
.Packages
.Table
(User_Decl
.Packages
) :=
501 (Project_Tree
=> Project_Tree
,
502 Conf_Decl
=> Conf_Pack
.Decl
,
503 User_Decl
=> Project_Tree
.Packages
.Table
504 (User_Pack_Id
).Decl
);
507 Conf_Pack_Id
:= Conf_Pack
.Next
;
510 Proj
.Project
.Decl
:= User_Decl
;
515 end Apply_Config_File
;
521 function Check_Target
522 (Config_File
: Project_Id
;
523 Autoconf_Specified
: Boolean;
524 Project_Tree
: Prj
.Project_Tree_Ref
;
525 Target
: String := "") return Boolean
527 Variable
: constant Variable_Value
:=
529 (Name_Target
, Config_File
.Decl
.Attributes
, Project_Tree
);
530 Tgt_Name
: Name_Id
:= No_Name
;
534 if Variable
/= Nil_Variable_Value
and then not Variable
.Default
then
535 Tgt_Name
:= Variable
.Value
;
539 OK
:= not Autoconf_Specified
or else Tgt_Name
= No_Name
;
541 OK
:= Tgt_Name
/= No_Name
542 and then Target
= Get_Name_String
(Tgt_Name
);
546 if Autoconf_Specified
then
548 Write_Line
("inconsistent targets, performing autoconf");
554 if Tgt_Name
/= No_Name
then
556 ("invalid target name """
557 & Get_Name_String
(Tgt_Name
) & """ in configuration");
560 ("no target specified in configuration file");
568 --------------------------------------
569 -- Get_Or_Create_Configuration_File --
570 --------------------------------------
572 procedure Get_Or_Create_Configuration_File
573 (Project
: Project_Id
;
574 Project_Tree
: Project_Tree_Ref
;
575 Project_Node_Tree
: Prj
.Tree
.Project_Node_Tree_Ref
;
576 Allow_Automatic_Generation
: Boolean;
577 Config_File_Name
: String := "";
578 Autoconf_Specified
: Boolean;
579 Target_Name
: String := "";
580 Normalized_Hostname
: String;
581 Packages_To_Check
: String_List_Access
:= null;
582 Config
: out Prj
.Project_Id
;
583 Config_File_Path
: out String_Access
;
584 Automatically_Generated
: out Boolean;
585 Flags
: Processing_Flags
;
586 On_Load_Config
: Config_File_Hook
:= null)
589 At_Least_One_Compiler_Command
: Boolean := False;
590 -- Set to True if at least one attribute Ide'Compiler_Command is
591 -- specified for one language of the system.
593 function Default_File_Name
return String;
594 -- Return the name of the default config file that should be tested
596 procedure Do_Autoconf
;
597 -- Generate a new config file through gprconfig. In case of error, this
598 -- raises the Invalid_Config exception with an appropriate message
600 function Get_Config_Switches
return Argument_List_Access
;
601 -- Return the --config switches to use for gprconfig
603 function Might_Have_Sources
(Project
: Project_Id
) return Boolean;
604 -- True if the specified project might have sources (ie the user has not
605 -- explicitly specified it. We haven't checked the file system, nor do
606 -- we need to at this stage.
608 -----------------------
609 -- Default_File_Name --
610 -----------------------
612 function Default_File_Name
return String is
613 Ada_RTS
: constant String := Runtime_Name_For
(Name_Ada
);
617 if Target_Name
/= "" then
618 if Ada_RTS
/= "" then
619 return Target_Name
& '-' & Ada_RTS
620 & Config_Project_File_Extension
;
622 return Target_Name
& Config_Project_File_Extension
;
625 elsif Ada_RTS
/= "" then
626 return Ada_RTS
& Config_Project_File_Extension
;
629 Tmp
:= Getenv
(Config_Project_Env_Var
);
632 T
: constant String := Tmp
.all;
644 end Default_File_Name
;
646 ------------------------
647 -- Might_Have_Sources --
648 ------------------------
650 function Might_Have_Sources
(Project
: Project_Id
) return Boolean is
651 Variable
: Variable_Value
;
657 Project
.Decl
.Attributes
,
660 if Variable
= Nil_Variable_Value
661 or else Variable
.Default
662 or else Variable
.Values
/= Nil_String
667 Project
.Decl
.Attributes
,
669 return Variable
= Nil_Variable_Value
670 or else Variable
.Default
671 or else Variable
.Values
/= Nil_String
;
676 end Might_Have_Sources
;
678 -------------------------
679 -- Get_Config_Switches --
680 -------------------------
682 function Get_Config_Switches
return Argument_List_Access
is
683 package Language_Htable
is new GNAT
.HTable
.Simple_HTable
684 (Header_Num
=> Prj
.Header_Num
,
686 No_Element
=> No_Name
,
690 -- Hash table to keep the languages used in the project tree
692 IDE
: constant Package_Id
:=
695 Project
.Decl
.Packages
,
698 Prj_Iter
: Project_List
;
699 List
: String_List_Id
;
700 Elem
: String_Element
;
702 Variable
: Variable_Value
;
705 Result
: Argument_List_Access
;
707 Check_Default
: Boolean;
710 Prj_Iter
:= Project_Tree
.Projects
;
711 while Prj_Iter
/= null loop
712 if Might_Have_Sources
(Prj_Iter
.Project
) then
716 Prj_Iter
.Project
.Decl
.Attributes
,
719 if Variable
= Nil_Variable_Value
720 or else Variable
.Default
722 -- Languages is not declared. If it is not an extending
723 -- project, or if it extends a project with no Languages,
724 -- check for Default_Language.
726 Check_Default
:= Prj_Iter
.Project
.Extends
= No_Project
;
728 if not Check_Default
then
732 Prj_Iter
.Project
.Extends
.Decl
.Attributes
,
735 Variable
/= Nil_Variable_Value
736 and then Variable
.Values
= Nil_String
;
739 if Check_Default
then
742 (Name_Default_Language
,
743 Prj_Iter
.Project
.Decl
.Attributes
,
746 if Variable
/= Nil_Variable_Value
747 and then not Variable
.Default
749 Get_Name_String
(Variable
.Value
);
750 To_Lower
(Name_Buffer
(1 .. Name_Len
));
752 Language_Htable
.Set
(Lang
, Lang
);
755 -- If no default language is declared, default to Ada
757 Language_Htable
.Set
(Name_Ada
, Name_Ada
);
761 elsif Variable
.Values
/= Nil_String
then
763 -- Attribute Languages is declared with a non empty
764 -- list: put all the languages in Language_HTable.
766 List
:= Variable
.Values
;
767 while List
/= Nil_String
loop
768 Elem
:= Project_Tree
.String_Elements
.Table
(List
);
770 Get_Name_String
(Elem
.Value
);
771 To_Lower
(Name_Buffer
(1 .. Name_Len
));
773 Language_Htable
.Set
(Lang
, Lang
);
780 Prj_Iter
:= Prj_Iter
.Next
;
783 Name
:= Language_Htable
.Get_First
;
785 while Name
/= No_Name
loop
787 Name
:= Language_Htable
.Get_Next
;
790 Result
:= new String_List
(1 .. Count
);
793 Name
:= Language_Htable
.Get_First
;
794 while Name
/= No_Name
loop
795 -- Check if IDE'Compiler_Command is declared for the language.
796 -- If it is, use its value to invoke gprconfig.
801 Attribute_Or_Array_Name
=> Name_Compiler_Command
,
803 In_Tree
=> Project_Tree
,
804 Force_Lower_Case_Index
=> True);
807 Config_Command
: constant String :=
808 "--config=" & Get_Name_String
(Name
);
810 Runtime_Name
: constant String :=
811 Runtime_Name_For
(Name
);
814 if Variable
= Nil_Variable_Value
815 or else Length_Of_Name
(Variable
.Value
) = 0
818 new String'(Config_Command & ",," & Runtime_Name);
821 At_Least_One_Compiler_Command := True;
824 Compiler_Command : constant String :=
825 Get_Name_String (Variable.Value);
828 if Is_Absolute_Path (Compiler_Command) then
831 (Config_Command
& ",," & Runtime_Name
& "," &
832 Containing_Directory
(Compiler_Command
) & "," &
833 Simple_Name
(Compiler_Command
));
837 (Config_Command & ",," & Runtime_Name & ",," &
845 Name := Language_Htable.Get_Next;
849 end Get_Config_Switches;
855 procedure Do_Autoconf is
856 Obj_Dir : constant Variable_Value :=
859 Project.Decl.Attributes,
862 Gprconfig_Path : String_Access;
866 Gprconfig_Path := Locate_Exec_On_Path (Gprconfig_Name);
868 if Gprconfig_Path = null then
870 ("could not locate gprconfig for auto-configuration");
873 -- First, find the object directory of the user's project
875 if Obj_Dir = Nil_Variable_Value or else Obj_Dir.Default then
876 Get_Name_String (Project.Directory.Display_Name);
879 if Is_Absolute_Path (Get_Name_String (Obj_Dir.Value)) then
880 Get_Name_String (Obj_Dir.Value);
884 Add_Str_To_Name_Buffer
885 (Get_Name_String (Project.Directory.Display_Name));
886 Add_Str_To_Name_Buffer (Get_Name_String (Obj_Dir.Value));
890 if Subdirs /= null then
891 Add_Char_To_Name_Buffer (Directory_Separator);
892 Add_Str_To_Name_Buffer (Subdirs.all);
895 for J in 1 .. Name_Len loop
896 if Name_Buffer (J) = '/' then
897 Name_Buffer (J) := Directory_Separator;
902 Obj_Dir : constant String := Name_Buffer (1 .. Name_Len);
903 Switches : Argument_List_Access := Get_Config_Switches;
904 Args : Argument_List (1 .. 5);
907 Obj_Dir_Exists : Boolean := True;
910 -- Check if the object directory exists. If Setup_Projects is True
911 -- (-p) and directory does not exist, attempt to create it.
912 -- Otherwise, if directory does not exist, fail without calling
915 if not Is_Directory (Obj_Dir)
916 and then (Setup_Projects or else Subdirs /= null)
919 Create_Path (Obj_Dir);
921 if not Quiet_Output then
922 Write_Str ("object directory """);
924 Write_Line (""" created");
930 ("could not create object directory " & Obj_Dir);
934 if not Is_Directory (Obj_Dir) then
935 case Flags.Require_Obj_Dirs is
938 ("object directory " & Obj_Dir & " does not exist");
942 "?object directory " & Obj_Dir & " does not exist");
943 Obj_Dir_Exists := False;
951 Args (1) := new String'("--batch");
952 Args
(2) := new String'("-o");
954 -- If no config file was specified, set the auto.cgpr one
956 if Config_File_Name = "" then
957 if Obj_Dir_Exists then
959 new String'(Obj_Dir
& Directory_Separator
& Auto_Cgpr
);
963 Path_FD
: File_Descriptor
;
964 Path_Name
: Path_Name_Type
;
967 Prj
.Env
.Create_Temp_File
968 (In_Tree
=> Project_Tree
,
970 Path_Name
=> Path_Name
,
971 File_Use
=> "configuration file");
973 if Path_FD
/= Invalid_FD
then
974 Args
(3) := new String'(Get_Name_String (Path_Name));
975 GNAT.OS_Lib.Close (Path_FD);
978 -- We'll have an error message later on
982 (Obj_Dir
& Directory_Separator
& Auto_Cgpr
);
987 Args
(3) := new String'(Config_File_Name);
990 if Normalized_Hostname = "" then
993 if Target_Name = "" then
994 if At_Least_One_Compiler_Command then
995 Args (4) := new String'("--target=all");
999 new String'("--target=" & Normalized_Hostname);
1003 Args (4) := new String'("--target=" & Target_Name
);
1009 if not Verbose_Mode
then
1010 Arg_Last
:= Arg_Last
+ 1;
1011 Args
(Arg_Last
) := new String'("-q");
1014 if Verbose_Mode then
1015 Write_Str (Gprconfig_Name);
1017 for J in 1 .. Arg_Last loop
1019 Write_Str (Args (J).all);
1022 for J in Switches'Range loop
1024 Write_Str (Switches (J).all);
1029 elsif not Quiet_Output then
1030 -- Display no message if we are creating auto.cgpr, unless in
1033 if Config_File_Name /= ""
1034 or else Verbose_Mode
1036 Write_Str ("creating ");
1037 Write_Str (Simple_Name (Args (3).all));
1042 Spawn (Gprconfig_Path.all, Args (1 .. Arg_Last) & Switches.all,
1047 Config_File_Path := Locate_Config_File (Args (3).all);
1049 if Config_File_Path = null then
1050 Raise_Invalid_Config
1051 ("could not create " & Args (3).all);
1054 for F in Args'Range loop
1061 Config_Project_Node : Project_Node_Id := Empty_Node;
1064 Free (Config_File_Path);
1065 Config := No_Project;
1067 if Config_File_Name /= "" then
1068 Config_File_Path := Locate_Config_File (Config_File_Name);
1070 Config_File_Path := Locate_Config_File (Default_File_Name);
1073 if Config_File_Path = null then
1074 if (not Allow_Automatic_Generation) and then
1075 Config_File_Name /= ""
1077 Raise_Invalid_Config
1078 ("could not locate main configuration project "
1079 & Config_File_Name);
1083 Automatically_Generated :=
1084 Allow_Automatic_Generation and then Config_File_Path = null;
1086 <<Process_Config_File>>
1088 if Automatically_Generated then
1089 if Hostparm.OpenVMS then
1091 -- There is no gprconfig on VMS
1093 Raise_Invalid_Config
1094 ("could not locate any configuration project file");
1097 -- This might raise an Invalid_Config exception
1103 -- Parse the configuration file
1105 if Verbose_Mode and then Config_File_Path /= null then
1106 Write_Str ("Checking configuration ");
1107 Write_Line (Config_File_Path.all);
1110 if Config_File_Path /= null then
1112 (In_Tree => Project_Node_Tree,
1113 Project => Config_Project_Node,
1114 Project_File_Name => Config_File_Path.all,
1115 Always_Errout_Finalize => False,
1116 Packages_To_Check => Packages_To_Check,
1117 Current_Directory => Current_Directory,
1118 Is_Config_File => True,
1121 -- Maybe the user will want to create his own configuration file
1122 Config_Project_Node := Empty_Node;
1125 if On_Load_Config /= null then
1127 (Config_File => Config_Project_Node,
1128 Project_Node_Tree => Project_Node_Tree);
1131 if Config_Project_Node /= Empty_Node then
1132 Prj.Proc.Process_Project_Tree_Phase_1
1133 (In_Tree => Project_Tree,
1136 From_Project_Node => Config_Project_Node,
1137 From_Project_Node_Tree => Project_Node_Tree,
1139 Reset_Tree => False);
1142 if Config_Project_Node = Empty_Node
1143 or else Config = No_Project
1145 Raise_Invalid_Config
1146 ("processing of configuration project """
1147 & Config_File_Path.all & """ failed");
1150 -- Check that the target of the configuration file is the one the user
1151 -- specified on the command line. We do not need to check that when in
1152 -- auto-conf mode, since the appropriate target was passed to gprconfig.
1154 if not Automatically_Generated
1156 Check_Target (Config, Autoconf_Specified, Project_Tree, Target_Name)
1158 Automatically_Generated := True;
1159 goto Process_Config_File;
1161 end Get_Or_Create_Configuration_File;
1163 ------------------------
1164 -- Locate_Config_File --
1165 ------------------------
1167 function Locate_Config_File (Name : String) return String_Access is
1168 Prefix_Path : constant String := Executable_Prefix_Path;
1170 if Prefix_Path'Length /= 0 then
1171 return Locate_Regular_File
1173 "." & Path_Separator &
1174 Prefix_Path & "share" & Directory_Separator & "gpr");
1176 return Locate_Regular_File (Name, ".");
1178 end Locate_Config_File;
1180 ------------------------------------
1181 -- Parse_Project_And_Apply_Config --
1182 ------------------------------------
1184 procedure Parse_Project_And_Apply_Config
1185 (Main_Project : out Prj.Project_Id;
1186 User_Project_Node : out Prj.Tree.Project_Node_Id;
1187 Config_File_Name : String := "";
1188 Autoconf_Specified : Boolean;
1189 Project_File_Name : String;
1190 Project_Tree : Prj.Project_Tree_Ref;
1191 Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
1192 Packages_To_Check : String_List_Access;
1193 Allow_Automatic_Generation : Boolean := True;
1194 Automatically_Generated : out Boolean;
1195 Config_File_Path : out String_Access;
1196 Target_Name : String := "";
1197 Normalized_Hostname : String;
1198 Flags : Processing_Flags;
1199 On_Load_Config : Config_File_Hook := null)
1202 -- Parse the user project tree
1204 Prj.Initialize (Project_Tree);
1206 Main_Project := No_Project;
1207 Automatically_Generated := False;
1210 (In_Tree => Project_Node_Tree,
1211 Project => User_Project_Node,
1212 Project_File_Name => Project_File_Name,
1213 Always_Errout_Finalize => False,
1214 Packages_To_Check => Packages_To_Check,
1215 Current_Directory => Current_Directory,
1216 Is_Config_File => False,
1219 if User_Project_Node = Empty_Node then
1220 User_Project_Node := Empty_Node;
1224 Process_Project_And_Apply_Config
1225 (Main_Project => Main_Project,
1226 User_Project_Node => User_Project_Node,
1227 Config_File_Name => Config_File_Name,
1228 Autoconf_Specified => Autoconf_Specified,
1229 Project_Tree => Project_Tree,
1230 Project_Node_Tree => Project_Node_Tree,
1231 Packages_To_Check => Packages_To_Check,
1232 Allow_Automatic_Generation => Allow_Automatic_Generation,
1233 Automatically_Generated => Automatically_Generated,
1234 Config_File_Path => Config_File_Path,
1235 Target_Name => Target_Name,
1236 Normalized_Hostname => Normalized_Hostname,
1238 On_Load_Config => On_Load_Config);
1239 end Parse_Project_And_Apply_Config;
1241 --------------------------------------
1242 -- Process_Project_And_Apply_Config --
1243 --------------------------------------
1245 procedure Process_Project_And_Apply_Config
1246 (Main_Project : out Prj.Project_Id;
1247 User_Project_Node : Prj.Tree.Project_Node_Id;
1248 Config_File_Name : String := "";
1249 Autoconf_Specified : Boolean;
1250 Project_Tree : Prj.Project_Tree_Ref;
1251 Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
1252 Packages_To_Check : String_List_Access;
1253 Allow_Automatic_Generation : Boolean := True;
1254 Automatically_Generated : out Boolean;
1255 Config_File_Path : out String_Access;
1256 Target_Name : String := "";
1257 Normalized_Hostname : String;
1258 Flags : Processing_Flags;
1259 On_Load_Config : Config_File_Hook := null;
1260 Reset_Tree : Boolean := True)
1262 Main_Config_Project : Project_Id;
1266 Main_Project := No_Project;
1267 Automatically_Generated := False;
1269 Process_Project_Tree_Phase_1
1270 (In_Tree => Project_Tree,
1271 Project => Main_Project,
1273 From_Project_Node => User_Project_Node,
1274 From_Project_Node_Tree => Project_Node_Tree,
1276 Reset_Tree => Reset_Tree);
1279 Main_Project := No_Project;
1283 if Project_Tree.Source_Info_File_Name /= null then
1284 if not Is_Absolute_Path (Project_Tree.Source_Info_File_Name.all) then
1286 Obj_Dir : constant Variable_Value :=
1289 Main_Project.Decl.Attributes,
1293 if Obj_Dir = Nil_Variable_Value or else Obj_Dir.Default then
1294 Get_Name_String (Main_Project.Directory.Display_Name);
1297 if Is_Absolute_Path (Get_Name_String (Obj_Dir.Value)) then
1298 Get_Name_String (Obj_Dir.Value);
1302 Add_Str_To_Name_Buffer
1303 (Get_Name_String (Main_Project.Directory.Display_Name));
1304 Add_Str_To_Name_Buffer (Get_Name_String (Obj_Dir.Value));
1308 Add_Char_To_Name_Buffer (Directory_Separator);
1309 Add_Str_To_Name_Buffer (Project_Tree.Source_Info_File_Name.all);
1310 Free (Project_Tree.Source_Info_File_Name);
1311 Project_Tree.Source_Info_File_Name :=
1312 new String'(Name_Buffer
(1 .. Name_Len
));
1316 Read_Source_Info_File
(Project_Tree
);
1319 -- Find configuration file
1321 Get_Or_Create_Configuration_File
1322 (Config
=> Main_Config_Project
,
1323 Project
=> Main_Project
,
1324 Project_Tree
=> Project_Tree
,
1325 Project_Node_Tree
=> Project_Node_Tree
,
1326 Allow_Automatic_Generation
=> Allow_Automatic_Generation
,
1327 Config_File_Name
=> Config_File_Name
,
1328 Autoconf_Specified
=> Autoconf_Specified
,
1329 Target_Name
=> Target_Name
,
1330 Normalized_Hostname
=> Normalized_Hostname
,
1331 Packages_To_Check
=> Packages_To_Check
,
1332 Config_File_Path
=> Config_File_Path
,
1333 Automatically_Generated
=> Automatically_Generated
,
1335 On_Load_Config
=> On_Load_Config
);
1337 Apply_Config_File
(Main_Config_Project
, Project_Tree
);
1339 -- Finish processing the user's project
1341 Prj
.Proc
.Process_Project_Tree_Phase_2
1342 (In_Tree
=> Project_Tree
,
1343 Project
=> Main_Project
,
1345 From_Project_Node
=> User_Project_Node
,
1346 From_Project_Node_Tree
=> Project_Node_Tree
,
1350 if Project_Tree
.Source_Info_File_Name
/= null and then
1351 not Project_Tree
.Source_Info_File_Exists
1353 Write_Source_Info_File
(Project_Tree
);
1357 Main_Project
:= No_Project
;
1359 end Process_Project_And_Apply_Config
;
1361 --------------------------
1362 -- Raise_Invalid_Config --
1363 --------------------------
1365 procedure Raise_Invalid_Config
(Msg
: String) is
1367 Raise_Exception
(Invalid_Config
'Identity, Msg
);
1368 end Raise_Invalid_Config
;
1370 ----------------------
1371 -- Runtime_Name_For --
1372 ----------------------
1374 function Runtime_Name_For
(Language
: Name_Id
) return String is
1376 if RTS_Languages
.Get
(Language
) /= No_Name
then
1377 return Get_Name_String
(RTS_Languages
.Get
(Language
));
1381 end Runtime_Name_For
;
1383 ---------------------
1384 -- Set_Runtime_For --
1385 ---------------------
1387 procedure Set_Runtime_For
(Language
: Name_Id
; RTS_Name
: String) is
1389 Name_Len
:= RTS_Name
'Length;
1390 Name_Buffer
(1 .. Name_Len
) := RTS_Name
;
1391 RTS_Languages
.Set
(Language
, Name_Find
);
1392 end Set_Runtime_For
;