1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2006-2009, 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 Ada.Directories; use Ada.Directories;
27 with GNAT.HTable; use GNAT.HTable;
28 with Makeutl; use Makeutl;
31 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;
40 with System.Case_Util; use System.Case_Util;
43 package body Prj.Conf is
45 Auto_Cgpr : constant String := "auto.cgpr";
47 Default_Name : constant String := "default.cgpr";
48 -- Default configuration file that will be used if found
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 procedure Add_Attributes
67 (Project_Tree : Project_Tree_Ref;
68 Conf_Decl : Declarations;
69 User_Decl : in out Declarations);
70 -- Process the attributes in the config declarations.
71 -- For single string values, if the attribute is not declared in the user
72 -- declarations, declare it with the value in the config declarations.
73 -- For string list values, prepend the value in the user declarations with
74 -- the value in the config declarations.
76 function Locate_Config_File (Name : String) return String_Access;
77 -- Search for Name in the config files directory. Return full path if
78 -- found, or null otherwise
81 (Config_File : Prj.Project_Id;
82 Autoconf_Specified : Boolean;
83 Project_Tree : Prj.Project_Tree_Ref;
84 Target : String := "") return Boolean;
85 -- Check that the config file's target matches Target.
86 -- Target should be set to the empty string when the user did not specify
87 -- a target. If the target in the configuration file is invalid, this
88 -- function will raise Invalid_Config with an appropriate message.
89 -- Autoconf_Specified should be set to True if the user has used --autoconf
95 procedure Add_Attributes
96 (Project_Tree : Project_Tree_Ref;
97 Conf_Decl : Declarations;
98 User_Decl : in out Declarations)
100 Conf_Attr_Id : Variable_Id;
101 Conf_Attr : Variable;
102 Conf_Array_Id : Array_Id;
103 Conf_Array : Array_Data;
104 Conf_Array_Elem_Id : Array_Element_Id;
105 Conf_Array_Elem : Array_Element;
106 Conf_List : String_List_Id;
107 Conf_List_Elem : String_Element;
109 User_Attr_Id : Variable_Id;
110 User_Attr : Variable;
111 User_Array_Id : Array_Id;
112 User_Array : Array_Data;
113 User_Array_Elem_Id : Array_Element_Id;
114 User_Array_Elem : Array_Element;
117 Conf_Attr_Id := Conf_Decl.Attributes;
118 User_Attr_Id := User_Decl.Attributes;
119 while Conf_Attr_Id /= No_Variable loop
121 Project_Tree.Variable_Elements.Table (Conf_Attr_Id);
123 Project_Tree.Variable_Elements.Table (User_Attr_Id);
125 if not Conf_Attr.Value.Default then
126 if User_Attr.Value.Default then
128 -- No attribute declared in user project file: just copy the
129 -- value of the configuration attribute.
131 User_Attr.Value := Conf_Attr.Value;
132 Project_Tree.Variable_Elements.Table (User_Attr_Id) :=
135 elsif User_Attr.Value.Kind = List
136 and then Conf_Attr.Value.Values /= Nil_String
138 -- List attribute declared in both the user project and the
139 -- configuration project: prepend the user list with the
140 -- configuration list.
143 Conf_List : String_List_Id := Conf_Attr.Value.Values;
144 Conf_Elem : String_Element;
145 User_List : constant String_List_Id :=
146 User_Attr.Value.Values;
147 New_List : String_List_Id;
148 New_Elem : String_Element;
153 String_Element_Table.Increment_Last
154 (Project_Tree.String_Elements);
155 New_List := String_Element_Table.Last
156 (Project_Tree.String_Elements);
158 -- Value of attribute is new list
160 User_Attr.Value.Values := New_List;
161 Project_Tree.Variable_Elements.Table (User_Attr_Id) :=
166 -- Get each element of configuration list
169 Project_Tree.String_Elements.Table (Conf_List);
170 New_Elem := Conf_Elem;
171 Conf_List := Conf_Elem.Next;
173 if Conf_List = Nil_String then
175 -- If it is the last element in the list, connect to
176 -- first element of user list, and we are done.
178 New_Elem.Next := User_List;
179 Project_Tree.String_Elements.Table
180 (New_List) := New_Elem;
184 -- If it is not the last element in the list, add to
187 String_Element_Table.Increment_Last
188 (Project_Tree.String_Elements);
190 String_Element_Table.Last
191 (Project_Tree.String_Elements);
192 Project_Tree.String_Elements.Table
193 (New_List) := New_Elem;
194 New_List := New_Elem.Next;
201 Conf_Attr_Id := Conf_Attr.Next;
202 User_Attr_Id := User_Attr.Next;
205 Conf_Array_Id := Conf_Decl.Arrays;
206 while Conf_Array_Id /= No_Array loop
207 Conf_Array := Project_Tree.Arrays.Table (Conf_Array_Id);
209 User_Array_Id := User_Decl.Arrays;
210 while User_Array_Id /= No_Array loop
211 User_Array := Project_Tree.Arrays.Table (User_Array_Id);
212 exit when User_Array.Name = Conf_Array.Name;
213 User_Array_Id := User_Array.Next;
216 -- If this associative array does not exist in the user project file,
217 -- do a shallow copy of the full associative array.
219 if User_Array_Id = No_Array then
220 Array_Table.Increment_Last (Project_Tree.Arrays);
221 User_Array := Conf_Array;
222 User_Array.Next := User_Decl.Arrays;
223 User_Decl.Arrays := Array_Table.Last (Project_Tree.Arrays);
224 Project_Tree.Arrays.Table (User_Decl.Arrays) := User_Array;
227 -- Otherwise, check each array element
229 Conf_Array_Elem_Id := Conf_Array.Value;
230 while Conf_Array_Elem_Id /= No_Array_Element loop
232 Project_Tree.Array_Elements.Table (Conf_Array_Elem_Id);
234 User_Array_Elem_Id := User_Array.Value;
235 while User_Array_Elem_Id /= No_Array_Element loop
237 Project_Tree.Array_Elements.Table (User_Array_Elem_Id);
238 exit when User_Array_Elem.Index = Conf_Array_Elem.Index;
239 User_Array_Elem_Id := User_Array_Elem.Next;
242 -- If the array element does not exist in the user array,
243 -- insert a shallow copy of the conf array element in the
246 if User_Array_Elem_Id = No_Array_Element then
247 Array_Element_Table.Increment_Last
248 (Project_Tree.Array_Elements);
249 User_Array_Elem := Conf_Array_Elem;
250 User_Array_Elem.Next := User_Array.Value;
252 Array_Element_Table.Last (Project_Tree.Array_Elements);
253 Project_Tree.Array_Elements.Table (User_Array.Value) :=
255 Project_Tree.Arrays.Table (User_Array_Id) := User_Array;
257 -- Otherwise, if the value is a string list, prepend the
258 -- user array element with the conf array element value.
260 elsif Conf_Array_Elem.Value.Kind = List then
261 Conf_List := Conf_Array_Elem.Value.Values;
263 if Conf_List /= Nil_String then
265 Link : constant String_List_Id :=
266 User_Array_Elem.Value.Values;
267 Previous : String_List_Id := Nil_String;
268 Next : String_List_Id;
273 Project_Tree.String_Elements.Table
275 String_Element_Table.Increment_Last
276 (Project_Tree.String_Elements);
278 String_Element_Table.Last
279 (Project_Tree.String_Elements);
280 Project_Tree.String_Elements.Table (Next) :=
283 if Previous = Nil_String then
284 User_Array_Elem.Value.Values := Next;
285 Project_Tree.Array_Elements.Table
286 (User_Array_Elem_Id) := User_Array_Elem;
289 Project_Tree.String_Elements.Table
290 (Previous).Next := Next;
295 Conf_List := Conf_List_Elem.Next;
297 if Conf_List = Nil_String then
298 Project_Tree.String_Elements.Table
299 (Previous).Next := Link;
307 Conf_Array_Elem_Id := Conf_Array_Elem.Next;
311 Conf_Array_Id := Conf_Array.Next;
315 ------------------------
316 -- Locate_Config_File --
317 ------------------------
319 function Locate_Config_File (Name : String) return String_Access is
320 Prefix_Path : constant String := Executable_Prefix_Path;
322 if Prefix_Path'Length /= 0 then
323 return Locate_Regular_File
325 "." & Path_Separator &
326 Prefix_Path & "share" & Directory_Separator & "gpr");
328 return Locate_Regular_File (Name, ".");
330 end Locate_Config_File;
336 function Check_Target
337 (Config_File : Project_Id;
338 Autoconf_Specified : Boolean;
339 Project_Tree : Prj.Project_Tree_Ref;
340 Target : String := "") return Boolean
342 Variable : constant Variable_Value :=
344 (Name_Target, Config_File.Decl.Attributes, Project_Tree);
345 Tgt_Name : Name_Id := No_Name;
349 if Variable /= Nil_Variable_Value and then not Variable.Default then
350 Tgt_Name := Variable.Value;
354 OK := not Autoconf_Specified or else Tgt_Name = No_Name;
356 OK := Tgt_Name /= No_Name
357 and then Target = Get_Name_String (Tgt_Name);
361 if Autoconf_Specified then
363 Write_Line ("inconsistent targets, performing autoconf");
369 if Tgt_Name /= No_Name then
371 with "invalid target name """
372 & Get_Name_String (Tgt_Name) & """ in configuration";
376 with "no target specified in configuration file";
384 --------------------------------------
385 -- Get_Or_Create_Configuration_File --
386 --------------------------------------
388 procedure Get_Or_Create_Configuration_File
389 (Project : Project_Id;
390 Project_Tree : Project_Tree_Ref;
391 Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
392 Allow_Automatic_Generation : Boolean;
393 Config_File_Name : String := "";
394 Autoconf_Specified : Boolean;
395 Target_Name : String := "";
396 Normalized_Hostname : String;
397 Packages_To_Check : String_List_Access := null;
398 Config : out Prj.Project_Id;
399 Config_File_Path : out String_Access;
400 Automatically_Generated : out Boolean;
401 Flags : Processing_Flags;
402 On_Load_Config : Config_File_Hook := null)
404 function Default_File_Name return String;
405 -- Return the name of the default config file that should be tested
407 procedure Do_Autoconf;
408 -- Generate a new config file through gprconfig.
409 -- In case of error, this raises the Invalid_Config exception with an
410 -- appropriate message
412 function Get_Config_Switches return Argument_List_Access;
413 -- Return the --config switches to use for gprconfig
415 function Might_Have_Sources (Project : Project_Id) return Boolean;
416 -- True if the specified project might have sources (ie the user has not
417 -- explicitly specified it. We haven't checked the file system, nor do
418 -- we need to at this stage.
420 -----------------------
421 -- Default_File_Name --
422 -----------------------
424 function Default_File_Name return String is
425 Ada_RTS : constant String := Runtime_Name_For (Name_Ada);
429 if Target_Name /= "" then
430 if Ada_RTS /= "" then
431 return Target_Name & '-' & Ada_RTS
432 & Config_Project_File_Extension;
434 return Target_Name & Config_Project_File_Extension;
437 elsif Ada_RTS /= "" then
438 return Ada_RTS & Config_Project_File_Extension;
441 Tmp := Getenv (Config_Project_Env_Var);
444 T : constant String := Tmp.all;
455 end Default_File_Name;
457 ------------------------
458 -- Might_Have_Sources --
459 ------------------------
461 function Might_Have_Sources (Project : Project_Id) return Boolean is
462 Variable : Variable_Value;
468 Project.Decl.Attributes,
471 if Variable = Nil_Variable_Value
472 or else Variable.Default
473 or else Variable.Values /= Nil_String
478 Project.Decl.Attributes,
480 return Variable = Nil_Variable_Value
481 or else Variable.Default
482 or else Variable.Values /= Nil_String;
487 end Might_Have_Sources;
489 -------------------------
490 -- Get_Config_Switches --
491 -------------------------
493 function Get_Config_Switches return Argument_List_Access is
494 package Language_Htable is new GNAT.HTable.Simple_HTable
495 (Header_Num => Prj.Header_Num,
497 No_Element => No_Name,
501 -- Hash table to keep the languages used in the project tree
503 IDE : constant Package_Id :=
506 Project.Decl.Packages,
509 Prj_Iter : Project_List;
510 List : String_List_Id;
511 Elem : String_Element;
513 Variable : Variable_Value;
516 Result : Argument_List_Access;
519 Prj_Iter := Project_Tree.Projects;
520 while Prj_Iter /= null loop
521 if Might_Have_Sources (Prj_Iter.Project) then
525 Prj_Iter.Project.Decl.Attributes,
528 if Variable = Nil_Variable_Value
529 or else Variable.Default
531 -- Languages is not declared. If it is not an extending
532 -- project, check for Default_Language
534 if Prj_Iter.Project.Extends = No_Project then
537 (Name_Default_Language,
538 Prj_Iter.Project.Decl.Attributes,
541 if Variable /= Nil_Variable_Value
542 and then not Variable.Default
544 Get_Name_String (Variable.Value);
545 To_Lower (Name_Buffer (1 .. Name_Len));
547 Language_Htable.Set (Lang, Lang);
550 -- If no language is declared, default to Ada
552 Language_Htable.Set (Name_Ada, Name_Ada);
556 elsif Variable.Values /= Nil_String then
558 -- Attribute Languages is declared with a non empty
559 -- list: put all the languages in Language_HTable.
561 List := Variable.Values;
562 while List /= Nil_String loop
563 Elem := Project_Tree.String_Elements.Table (List);
565 Get_Name_String (Elem.Value);
566 To_Lower (Name_Buffer (1 .. Name_Len));
568 Language_Htable.Set (Lang, Lang);
575 Prj_Iter := Prj_Iter.Next;
578 Name := Language_Htable.Get_First;
580 while Name /= No_Name loop
582 Name := Language_Htable.Get_Next;
585 Result := new String_List (1 .. Count);
588 Name := Language_Htable.Get_First;
589 while Name /= No_Name loop
590 -- Check if IDE'Compiler_Command is declared for the language.
591 -- If it is, use its value to invoke gprconfig.
596 Attribute_Or_Array_Name => Name_Compiler_Command,
598 In_Tree => Project_Tree,
599 Force_Lower_Case_Index => True);
602 Config_Command : constant String :=
603 "--config=" & Get_Name_String (Name);
605 Runtime_Name : constant String :=
606 Runtime_Name_For (Name);
609 if Variable = Nil_Variable_Value
610 or else Length_Of_Name (Variable.Value) = 0
613 new String'(Config_Command & ",," & Runtime_Name);
617 Compiler_Command : constant String :=
618 Get_Name_String (Variable.Value);
621 if Is_Absolute_Path (Compiler_Command) then
624 (Config_Command & ",," & Runtime_Name & "," &
625 Containing_Directory (Compiler_Command) & "," &
626 Simple_Name (Compiler_Command));
630 (Config_Command & ",," & Runtime_Name & ",," &
638 Name := Language_Htable.Get_Next;
642 end Get_Config_Switches;
648 procedure Do_Autoconf is
649 Obj_Dir : constant Variable_Value :=
652 Project.Decl.Attributes,
655 Gprconfig_Path : String_Access;
659 Gprconfig_Path := Locate_Exec_On_Path (Gprconfig_Name);
661 if Gprconfig_Path = null then
663 with "could not locate gprconfig for auto-configuration";
666 -- First, find the object directory of the user's project
668 if Obj_Dir = Nil_Variable_Value or else Obj_Dir.Default then
669 Get_Name_String (Project.Directory.Name);
672 if Is_Absolute_Path (Get_Name_String (Obj_Dir.Value)) then
673 Get_Name_String (Obj_Dir.Value);
677 Add_Str_To_Name_Buffer
678 (Get_Name_String (Project.Directory.Name));
679 Add_Str_To_Name_Buffer (Get_Name_String (Obj_Dir.Value));
683 if Subdirs /= null then
684 Add_Char_To_Name_Buffer (Directory_Separator);
685 Add_Str_To_Name_Buffer (Subdirs.all);
688 for J in 1 .. Name_Len loop
689 if Name_Buffer (J) = '/' then
690 Name_Buffer (J) := Directory_Separator;
695 Obj_Dir : constant String := Name_Buffer (1 .. Name_Len);
696 Switches : Argument_List_Access := Get_Config_Switches;
697 Args : Argument_List (1 .. 5);
701 -- Check if the object directory exists. If Setup_Projects is True
702 -- (-p) and directory does not exist, attempt to create it.
703 -- Otherwise, if directory does not exist, fail without calling
706 if not Is_Directory (Obj_Dir)
707 and then (Setup_Projects or else Subdirs /= null)
710 Create_Path (Obj_Dir);
712 if not Quiet_Output then
713 Write_Str ("object directory """);
715 Write_Line (""" created");
721 with "could not create object directory " & Obj_Dir;
725 if not Is_Directory (Obj_Dir) then
726 case Flags.Require_Obj_Dirs is
729 with "object directory " & Obj_Dir & " does not exist";
733 "?object directory " & Obj_Dir & " does not exist");
741 Args (1) := new String'("--batch");
742 Args (2) := new String'("-o");
744 -- If no config file was specified, set the auto.cgpr one
746 if Config_File_Name = "" then
747 Args (3) := new String'
748 (Obj_Dir & Directory_Separator & Auto_Cgpr);
750 Args (3) := new String'(Config_File_Name);
753 if Normalized_Hostname = "" then
756 if Target_Name = "" then
757 Args (4) := new String'("--target=" & Normalized_Hostname);
759 Args (4) := new String'("--target=" & Target_Name);
765 if not Verbose_Mode then
766 Arg_Last := Arg_Last + 1;
767 Args (Arg_Last) := new String'("-q");
771 Write_Str (Gprconfig_Name);
773 for J in 1 .. Arg_Last loop
775 Write_Str (Args (J).all);
778 for J in Switches'Range loop
780 Write_Str (Switches (J).all);
785 elsif not Quiet_Output then
786 Write_Str ("creating ");
787 Write_Str (Simple_Name (Args (3).all));
791 Spawn (Gprconfig_Path.all, Args (1 .. Arg_Last) & Switches.all,
796 Config_File_Path := Locate_Config_File (Args (3).all);
798 if Config_File_Path = null then
800 with "could not create " & Args (3).all;
803 for F in Args'Range loop
810 Config_Project_Node : Project_Node_Id := Empty_Node;
813 Free (Config_File_Path);
814 Config := No_Project;
816 if Config_File_Name /= "" then
817 Config_File_Path := Locate_Config_File (Config_File_Name);
819 Config_File_Path := Locate_Config_File (Default_File_Name);
822 if Config_File_Path = null then
823 if (not Allow_Automatic_Generation) and then
824 Config_File_Name /= ""
827 with "could not locate main configuration project "
832 Automatically_Generated :=
833 Allow_Automatic_Generation and then Config_File_Path = null;
835 <<Process_Config_File>>
837 if Automatically_Generated then
838 -- This might raise an Invalid_Config exception
842 -- Parse the configuration file
844 if Verbose_Mode and then Config_File_Path /= null then
845 Write_Str ("Checking configuration ");
846 Write_Line (Config_File_Path.all);
849 if Config_File_Path /= null then
851 (In_Tree => Project_Node_Tree,
852 Project => Config_Project_Node,
853 Project_File_Name => Config_File_Path.all,
854 Always_Errout_Finalize => False,
855 Packages_To_Check => Packages_To_Check,
856 Current_Directory => Current_Directory,
857 Is_Config_File => True,
860 -- Maybe the user will want to create his own configuration file
861 Config_Project_Node := Empty_Node;
864 if On_Load_Config /= null then
866 (Config_File => Config_Project_Node,
867 Project_Node_Tree => Project_Node_Tree);
870 if Config_Project_Node /= Empty_Node then
871 Prj.Proc.Process_Project_Tree_Phase_1
872 (In_Tree => Project_Tree,
875 From_Project_Node => Config_Project_Node,
876 From_Project_Node_Tree => Project_Node_Tree,
878 Reset_Tree => False);
881 if Config_Project_Node = Empty_Node
882 or else Config = No_Project
885 with "processing of configuration project """
886 & Config_File_Path.all & """ failed";
889 -- Check that the target of the configuration file is the one the user
890 -- specified on the command line. We do not need to check that when in
891 -- auto-conf mode, since the appropriate target was passed to gprconfig.
893 if not Automatically_Generated
895 Check_Target (Config, Autoconf_Specified, Project_Tree, Target_Name)
897 Automatically_Generated := True;
898 goto Process_Config_File;
900 end Get_Or_Create_Configuration_File;
902 --------------------------------------
903 -- Process_Project_And_Apply_Config --
904 --------------------------------------
906 procedure Process_Project_And_Apply_Config
907 (Main_Project : out Prj.Project_Id;
908 User_Project_Node : Prj.Tree.Project_Node_Id;
909 Config_File_Name : String := "";
910 Autoconf_Specified : Boolean;
911 Project_Tree : Prj.Project_Tree_Ref;
912 Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
913 Packages_To_Check : String_List_Access;
914 Allow_Automatic_Generation : Boolean := True;
915 Automatically_Generated : out Boolean;
916 Config_File_Path : out String_Access;
917 Target_Name : String := "";
918 Normalized_Hostname : String;
919 Flags : Processing_Flags;
920 On_Load_Config : Config_File_Hook := null;
921 Reset_Tree : Boolean := True)
923 Main_Config_Project : Project_Id;
927 Main_Project := No_Project;
928 Automatically_Generated := False;
930 Process_Project_Tree_Phase_1
931 (In_Tree => Project_Tree,
932 Project => Main_Project,
934 From_Project_Node => User_Project_Node,
935 From_Project_Node_Tree => Project_Node_Tree,
937 Reset_Tree => Reset_Tree);
940 Main_Project := No_Project;
944 -- Find configuration file
946 Get_Or_Create_Configuration_File
947 (Config => Main_Config_Project,
948 Project => Main_Project,
949 Project_Tree => Project_Tree,
950 Project_Node_Tree => Project_Node_Tree,
951 Allow_Automatic_Generation => Allow_Automatic_Generation,
952 Config_File_Name => Config_File_Name,
953 Autoconf_Specified => Autoconf_Specified,
954 Target_Name => Target_Name,
955 Normalized_Hostname => Normalized_Hostname,
956 Packages_To_Check => Packages_To_Check,
957 Config_File_Path => Config_File_Path,
958 Automatically_Generated => Automatically_Generated,
960 On_Load_Config => On_Load_Config);
962 Apply_Config_File (Main_Config_Project, Project_Tree);
964 -- Finish processing the user's project
966 Prj.Proc.Process_Project_Tree_Phase_2
967 (In_Tree => Project_Tree,
968 Project => Main_Project,
970 From_Project_Node => User_Project_Node,
971 From_Project_Node_Tree => Project_Node_Tree,
975 Main_Project := No_Project;
977 end Process_Project_And_Apply_Config;
979 ------------------------------------
980 -- Parse_Project_And_Apply_Config --
981 ------------------------------------
983 procedure Parse_Project_And_Apply_Config
984 (Main_Project : out Prj.Project_Id;
985 User_Project_Node : out Prj.Tree.Project_Node_Id;
986 Config_File_Name : String := "";
987 Autoconf_Specified : Boolean;
988 Project_File_Name : String;
989 Project_Tree : Prj.Project_Tree_Ref;
990 Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
991 Packages_To_Check : String_List_Access;
992 Allow_Automatic_Generation : Boolean := True;
993 Automatically_Generated : out Boolean;
994 Config_File_Path : out String_Access;
995 Target_Name : String := "";
996 Normalized_Hostname : String;
997 Flags : Processing_Flags;
998 On_Load_Config : Config_File_Hook := null)
1001 -- Parse the user project tree
1003 Prj.Initialize (Project_Tree);
1005 Main_Project := No_Project;
1006 Automatically_Generated := False;
1009 (In_Tree => Project_Node_Tree,
1010 Project => User_Project_Node,
1011 Project_File_Name => Project_File_Name,
1012 Always_Errout_Finalize => False,
1013 Packages_To_Check => Packages_To_Check,
1014 Current_Directory => Current_Directory,
1015 Is_Config_File => False,
1018 if User_Project_Node = Empty_Node then
1019 User_Project_Node := Empty_Node;
1023 Process_Project_And_Apply_Config
1024 (Main_Project => Main_Project,
1025 User_Project_Node => User_Project_Node,
1026 Config_File_Name => Config_File_Name,
1027 Autoconf_Specified => Autoconf_Specified,
1028 Project_Tree => Project_Tree,
1029 Project_Node_Tree => Project_Node_Tree,
1030 Packages_To_Check => Packages_To_Check,
1031 Allow_Automatic_Generation => Allow_Automatic_Generation,
1032 Automatically_Generated => Automatically_Generated,
1033 Config_File_Path => Config_File_Path,
1034 Target_Name => Target_Name,
1035 Normalized_Hostname => Normalized_Hostname,
1037 On_Load_Config => On_Load_Config);
1038 end Parse_Project_And_Apply_Config;
1040 -----------------------
1041 -- Apply_Config_File --
1042 -----------------------
1044 procedure Apply_Config_File
1045 (Config_File : Prj.Project_Id;
1046 Project_Tree : Prj.Project_Tree_Ref)
1048 Conf_Decl : constant Declarations := Config_File.Decl;
1049 Conf_Pack_Id : Package_Id;
1050 Conf_Pack : Package_Element;
1052 User_Decl : Declarations;
1053 User_Pack_Id : Package_Id;
1054 User_Pack : Package_Element;
1055 Proj : Project_List;
1058 Proj := Project_Tree.Projects;
1059 while Proj /= null loop
1060 if Proj.Project /= Config_File then
1061 User_Decl := Proj.Project.Decl;
1063 (Project_Tree => Project_Tree,
1064 Conf_Decl => Conf_Decl,
1065 User_Decl => User_Decl);
1067 Conf_Pack_Id := Conf_Decl.Packages;
1068 while Conf_Pack_Id /= No_Package loop
1069 Conf_Pack := Project_Tree.Packages.Table (Conf_Pack_Id);
1071 User_Pack_Id := User_Decl.Packages;
1072 while User_Pack_Id /= No_Package loop
1073 User_Pack := Project_Tree.Packages.Table (User_Pack_Id);
1074 exit when User_Pack.Name = Conf_Pack.Name;
1075 User_Pack_Id := User_Pack.Next;
1078 if User_Pack_Id = No_Package then
1079 Package_Table.Increment_Last (Project_Tree.Packages);
1080 User_Pack := Conf_Pack;
1081 User_Pack.Next := User_Decl.Packages;
1082 User_Decl.Packages :=
1083 Package_Table.Last (Project_Tree.Packages);
1084 Project_Tree.Packages.Table (User_Decl.Packages) :=
1089 (Project_Tree => Project_Tree,
1090 Conf_Decl => Conf_Pack.Decl,
1091 User_Decl => Project_Tree.Packages.Table
1092 (User_Pack_Id).Decl);
1095 Conf_Pack_Id := Conf_Pack.Next;
1098 Proj.Project.Decl := User_Decl;
1103 end Apply_Config_File;
1105 ---------------------
1106 -- Set_Runtime_For --
1107 ---------------------
1109 procedure Set_Runtime_For (Language : Name_Id; RTS_Name : String) is
1111 Name_Len := RTS_Name'Length;
1112 Name_Buffer (1 .. Name_Len) := RTS_Name;
1113 RTS_Languages.Set (Language, Name_Find);
1114 end Set_Runtime_For;
1116 ----------------------
1117 -- Runtime_Name_For --
1118 ----------------------
1120 function Runtime_Name_For (Language : Name_Id) return String is
1122 if RTS_Languages.Get (Language) /= No_Name then
1123 return Get_Name_String (RTS_Languages.Get (Language));
1127 end Runtime_Name_For;
1129 ------------------------------------
1130 -- Add_Default_GNAT_Naming_Scheme --
1131 ------------------------------------
1133 procedure Add_Default_GNAT_Naming_Scheme
1134 (Config_File : in out Project_Node_Id;
1135 Project_Tree : Project_Node_Tree_Ref)
1137 procedure Create_Attribute
1140 Index : String := "";
1141 Pkg : Project_Node_Id := Empty_Node);
1143 ----------------------
1144 -- Create_Attribute --
1145 ----------------------
1147 procedure Create_Attribute
1150 Index : String := "";
1151 Pkg : Project_Node_Id := Empty_Node)
1153 Attr : Project_Node_Id;
1154 Val : Name_Id := No_Name;
1155 Parent : Project_Node_Id := Config_File;
1158 Name_Len := Index'Length;
1159 Name_Buffer (1 .. Name_Len) := Index;
1163 if Pkg /= Empty_Node then
1167 Attr := Create_Attribute
1168 (Tree => Project_Tree,
1169 Prj_Or_Pkg => Parent,
1172 Kind => Prj.Single);
1174 Name_Len := Value'Length;
1175 Name_Buffer (1 .. Name_Len) := Value;
1179 (Attr, Project_Tree,
1180 Enclose_In_Expression
1181 (Create_Literal_String (Val, Project_Tree),
1183 end Create_Attribute;
1186 Naming : Project_Node_Id;
1188 -- Start of processing for Add_Default_GNAT_Naming_Scheme
1191 if Config_File = Empty_Node then
1193 -- Create a dummy config file is none was found
1195 Name_Len := Auto_Cgpr'Length;
1196 Name_Buffer (1 .. Name_Len) := Auto_Cgpr;
1199 -- An invalid project name to avoid conflicts with user-created ones
1202 Name_Buffer (1 .. Name_Len) := "_auto";
1206 (In_Tree => Project_Tree,
1208 Full_Path => Path_Name_Type (Name),
1209 Is_Config_File => True);
1211 -- Setup library support
1213 case MLib.Tgt.Support_For_Libraries is
1218 Create_Attribute (Name_Library_Support, "static_only");
1221 Create_Attribute (Name_Library_Support, "full");
1224 if MLib.Tgt.Standalone_Library_Auto_Init_Is_Supported then
1225 Create_Attribute (Name_Library_Auto_Init_Supported, "true");
1227 Create_Attribute (Name_Library_Auto_Init_Supported, "false");
1230 -- Setup Ada support (Ada is the default language here, since this
1231 -- is only called when no config file existed initially, ie for
1234 Create_Attribute (Name_Default_Language, "ada");
1236 Naming := Create_Package (Project_Tree, Config_File, "naming");
1237 Create_Attribute (Name_Spec_Suffix, ".ads", "ada", Pkg => Naming);
1238 Create_Attribute (Name_Separate_Suffix, ".adb", "ada", Pkg => Naming);
1239 Create_Attribute (Name_Body_Suffix, ".adb", "ada", Pkg => Naming);
1240 Create_Attribute (Name_Dot_Replacement, "-", Pkg => Naming);
1241 Create_Attribute (Name_Casing, "lowercase", Pkg => Naming);
1243 if Current_Verbosity = High then
1244 Write_Line ("Automatically generated (in-memory) config file");
1246 (Project => Config_File,
1247 In_Tree => Project_Tree,
1248 Backward_Compatibility => False);
1251 end Add_Default_GNAT_Naming_Scheme;