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;
43 with GNAT.Case_Util; use GNAT.Case_Util;
44 with GNAT.HTable; use GNAT.HTable;
46 package body Prj.Conf is
48 Auto_Cgpr : constant String := "auto.cgpr";
50 Default_Name : constant String := "default.cgpr";
51 -- Default configuration file that will be used if found
53 Config_Project_Env_Var : constant String := "GPR_CONFIG";
54 -- Name of the environment variable that provides the name of the
55 -- configuration file to use.
57 Gprconfig_Name : constant String := "gprconfig";
59 package RTS_Languages is new GNAT.HTable.Simple_HTable
60 (Header_Num => Prj.Header_Num,
62 No_Element => No_Name,
66 -- Stores the runtime names for the various languages. This is in general
67 -- set from a --RTS command line option.
69 procedure Add_Attributes
70 (Project_Tree : Project_Tree_Ref;
71 Conf_Decl : Declarations;
72 User_Decl : in out Declarations);
73 -- Process the attributes in the config declarations.
74 -- For single string values, if the attribute is not declared in the user
75 -- declarations, declare it with the value in the config declarations.
76 -- For string list values, prepend the value in the user declarations with
77 -- the value in the config declarations.
79 function Locate_Config_File (Name : String) return String_Access;
80 -- Search for Name in the config files directory. Return full path if
81 -- found, or null otherwise
84 (Config_File : Prj.Project_Id;
85 Autoconf_Specified : Boolean;
86 Project_Tree : Prj.Project_Tree_Ref;
87 Target : String := "") return Boolean;
88 -- Check that the config file's target matches Target.
89 -- Target should be set to the empty string when the user did not specify
90 -- a target. If the target in the configuration file is invalid, this
91 -- function will raise Invalid_Config with an appropriate message.
92 -- Autoconf_Specified should be set to True if the user has used --autoconf
98 procedure Add_Attributes
99 (Project_Tree : Project_Tree_Ref;
100 Conf_Decl : Declarations;
101 User_Decl : in out Declarations)
103 Conf_Attr_Id : Variable_Id;
104 Conf_Attr : Variable;
105 Conf_Array_Id : Array_Id;
106 Conf_Array : Array_Data;
107 Conf_Array_Elem_Id : Array_Element_Id;
108 Conf_Array_Elem : Array_Element;
109 Conf_List : String_List_Id;
110 Conf_List_Elem : String_Element;
112 User_Attr_Id : Variable_Id;
113 User_Attr : Variable;
114 User_Array_Id : Array_Id;
115 User_Array : Array_Data;
116 User_Array_Elem_Id : Array_Element_Id;
117 User_Array_Elem : Array_Element;
120 Conf_Attr_Id := Conf_Decl.Attributes;
121 User_Attr_Id := User_Decl.Attributes;
122 while Conf_Attr_Id /= No_Variable loop
124 Project_Tree.Variable_Elements.Table (Conf_Attr_Id);
126 Project_Tree.Variable_Elements.Table (User_Attr_Id);
128 if not Conf_Attr.Value.Default then
129 if User_Attr.Value.Default then
131 -- No attribute declared in user project file: just copy the
132 -- value of the configuration attribute.
134 User_Attr.Value := Conf_Attr.Value;
135 Project_Tree.Variable_Elements.Table (User_Attr_Id) :=
138 elsif User_Attr.Value.Kind = List
139 and then Conf_Attr.Value.Values /= Nil_String
141 -- List attribute declared in both the user project and the
142 -- configuration project: prepend the user list with the
143 -- configuration list.
146 Conf_List : String_List_Id := Conf_Attr.Value.Values;
147 Conf_Elem : String_Element;
148 User_List : constant String_List_Id :=
149 User_Attr.Value.Values;
150 New_List : String_List_Id;
151 New_Elem : String_Element;
156 String_Element_Table.Increment_Last
157 (Project_Tree.String_Elements);
158 New_List := String_Element_Table.Last
159 (Project_Tree.String_Elements);
161 -- Value of attribute is new list
163 User_Attr.Value.Values := New_List;
164 Project_Tree.Variable_Elements.Table (User_Attr_Id) :=
169 -- Get each element of configuration list
172 Project_Tree.String_Elements.Table (Conf_List);
173 New_Elem := Conf_Elem;
174 Conf_List := Conf_Elem.Next;
176 if Conf_List = Nil_String then
178 -- If it is the last element in the list, connect to
179 -- first element of user list, and we are done.
181 New_Elem.Next := User_List;
182 Project_Tree.String_Elements.Table
183 (New_List) := New_Elem;
187 -- If it is not the last element in the list, add to
190 String_Element_Table.Increment_Last
191 (Project_Tree.String_Elements);
193 String_Element_Table.Last
194 (Project_Tree.String_Elements);
195 Project_Tree.String_Elements.Table
196 (New_List) := New_Elem;
197 New_List := New_Elem.Next;
204 Conf_Attr_Id := Conf_Attr.Next;
205 User_Attr_Id := User_Attr.Next;
208 Conf_Array_Id := Conf_Decl.Arrays;
209 while Conf_Array_Id /= No_Array loop
210 Conf_Array := Project_Tree.Arrays.Table (Conf_Array_Id);
212 User_Array_Id := User_Decl.Arrays;
213 while User_Array_Id /= No_Array loop
214 User_Array := Project_Tree.Arrays.Table (User_Array_Id);
215 exit when User_Array.Name = Conf_Array.Name;
216 User_Array_Id := User_Array.Next;
219 -- If this associative array does not exist in the user project file,
220 -- do a shallow copy of the full associative array.
222 if User_Array_Id = No_Array then
223 Array_Table.Increment_Last (Project_Tree.Arrays);
224 User_Array := Conf_Array;
225 User_Array.Next := User_Decl.Arrays;
226 User_Decl.Arrays := Array_Table.Last (Project_Tree.Arrays);
227 Project_Tree.Arrays.Table (User_Decl.Arrays) := User_Array;
230 -- Otherwise, check each array element
232 Conf_Array_Elem_Id := Conf_Array.Value;
233 while Conf_Array_Elem_Id /= No_Array_Element loop
235 Project_Tree.Array_Elements.Table (Conf_Array_Elem_Id);
237 User_Array_Elem_Id := User_Array.Value;
238 while User_Array_Elem_Id /= No_Array_Element loop
240 Project_Tree.Array_Elements.Table (User_Array_Elem_Id);
241 exit when User_Array_Elem.Index = Conf_Array_Elem.Index;
242 User_Array_Elem_Id := User_Array_Elem.Next;
245 -- If the array element does not exist in the user array,
246 -- insert a shallow copy of the conf array element in the
249 if User_Array_Elem_Id = No_Array_Element then
250 Array_Element_Table.Increment_Last
251 (Project_Tree.Array_Elements);
252 User_Array_Elem := Conf_Array_Elem;
253 User_Array_Elem.Next := User_Array.Value;
255 Array_Element_Table.Last (Project_Tree.Array_Elements);
256 Project_Tree.Array_Elements.Table (User_Array.Value) :=
258 Project_Tree.Arrays.Table (User_Array_Id) := User_Array;
260 -- Otherwise, if the value is a string list, prepend the
261 -- user array element with the conf array element value.
263 elsif Conf_Array_Elem.Value.Kind = List then
264 Conf_List := Conf_Array_Elem.Value.Values;
266 if Conf_List /= Nil_String then
268 Link : constant String_List_Id :=
269 User_Array_Elem.Value.Values;
270 Previous : String_List_Id := Nil_String;
271 Next : String_List_Id;
276 Project_Tree.String_Elements.Table
278 String_Element_Table.Increment_Last
279 (Project_Tree.String_Elements);
281 String_Element_Table.Last
282 (Project_Tree.String_Elements);
283 Project_Tree.String_Elements.Table (Next) :=
286 if Previous = Nil_String then
287 User_Array_Elem.Value.Values := Next;
288 Project_Tree.Array_Elements.Table
289 (User_Array_Elem_Id) := User_Array_Elem;
292 Project_Tree.String_Elements.Table
293 (Previous).Next := Next;
298 Conf_List := Conf_List_Elem.Next;
300 if Conf_List = Nil_String then
301 Project_Tree.String_Elements.Table
302 (Previous).Next := Link;
310 Conf_Array_Elem_Id := Conf_Array_Elem.Next;
314 Conf_Array_Id := Conf_Array.Next;
318 ------------------------------------
319 -- Add_Default_GNAT_Naming_Scheme --
320 ------------------------------------
322 procedure Add_Default_GNAT_Naming_Scheme
323 (Config_File : in out Project_Node_Id;
324 Project_Tree : Project_Node_Tree_Ref)
326 procedure Create_Attribute
329 Index : String := "";
330 Pkg : Project_Node_Id := Empty_Node);
332 ----------------------
333 -- Create_Attribute --
334 ----------------------
336 procedure Create_Attribute
339 Index : String := "";
340 Pkg : Project_Node_Id := Empty_Node)
342 Attr : Project_Node_Id;
343 pragma Unreferenced (Attr);
345 Expr : Name_Id := No_Name;
346 Val : Name_Id := No_Name;
347 Parent : Project_Node_Id := Config_File;
350 Name_Len := Index'Length;
351 Name_Buffer (1 .. Name_Len) := Index;
355 if Pkg /= Empty_Node then
359 Name_Len := Value'Length;
360 Name_Buffer (1 .. Name_Len) := Value;
363 Attr := Create_Attribute
364 (Tree => Project_Tree,
365 Prj_Or_Pkg => Parent,
369 Value => Create_Literal_String (Expr, Project_Tree));
370 end Create_Attribute;
375 Naming : Project_Node_Id;
377 -- Start of processing for Add_Default_GNAT_Naming_Scheme
380 if Config_File = Empty_Node then
382 -- Create a dummy config file is none was found
384 Name_Len := Auto_Cgpr'Length;
385 Name_Buffer (1 .. Name_Len) := Auto_Cgpr;
388 -- An invalid project name to avoid conflicts with user-created ones
391 Name_Buffer (1 .. Name_Len) := "_auto";
395 (In_Tree => Project_Tree,
397 Full_Path => Path_Name_Type (Name),
398 Is_Config_File => True);
400 -- Setup library support
402 case MLib.Tgt.Support_For_Libraries is
407 Create_Attribute (Name_Library_Support, "static_only");
410 Create_Attribute (Name_Library_Support, "full");
413 if MLib.Tgt.Standalone_Library_Auto_Init_Is_Supported then
414 Create_Attribute (Name_Library_Auto_Init_Supported, "true");
416 Create_Attribute (Name_Library_Auto_Init_Supported, "false");
419 -- Setup Ada support (Ada is the default language here, since this
420 -- is only called when no config file existed initially, ie for
423 Create_Attribute (Name_Default_Language, "ada");
425 Naming := Create_Package (Project_Tree, Config_File, "naming");
426 Create_Attribute (Name_Spec_Suffix, ".ads", "ada", Pkg => Naming);
427 Create_Attribute (Name_Separate_Suffix, ".adb", "ada", Pkg => Naming);
428 Create_Attribute (Name_Body_Suffix, ".adb", "ada", Pkg => Naming);
429 Create_Attribute (Name_Dot_Replacement, "-", Pkg => Naming);
430 Create_Attribute (Name_Casing, "lowercase", Pkg => Naming);
432 if Current_Verbosity = High then
433 Write_Line ("Automatically generated (in-memory) config file");
435 (Project => Config_File,
436 In_Tree => Project_Tree,
437 Backward_Compatibility => False);
440 end Add_Default_GNAT_Naming_Scheme;
442 -----------------------
443 -- Apply_Config_File --
444 -----------------------
446 procedure Apply_Config_File
447 (Config_File : Prj.Project_Id;
448 Project_Tree : Prj.Project_Tree_Ref)
450 Conf_Decl : constant Declarations := Config_File.Decl;
451 Conf_Pack_Id : Package_Id;
452 Conf_Pack : Package_Element;
454 User_Decl : Declarations;
455 User_Pack_Id : Package_Id;
456 User_Pack : Package_Element;
460 Proj := Project_Tree.Projects;
461 while Proj /= null loop
462 if Proj.Project /= Config_File then
463 User_Decl := Proj.Project.Decl;
465 (Project_Tree => Project_Tree,
466 Conf_Decl => Conf_Decl,
467 User_Decl => User_Decl);
469 Conf_Pack_Id := Conf_Decl.Packages;
470 while Conf_Pack_Id /= No_Package loop
471 Conf_Pack := Project_Tree.Packages.Table (Conf_Pack_Id);
473 User_Pack_Id := User_Decl.Packages;
474 while User_Pack_Id /= No_Package loop
475 User_Pack := Project_Tree.Packages.Table (User_Pack_Id);
476 exit when User_Pack.Name = Conf_Pack.Name;
477 User_Pack_Id := User_Pack.Next;
480 if User_Pack_Id = No_Package then
481 Package_Table.Increment_Last (Project_Tree.Packages);
482 User_Pack := Conf_Pack;
483 User_Pack.Next := User_Decl.Packages;
484 User_Decl.Packages :=
485 Package_Table.Last (Project_Tree.Packages);
486 Project_Tree.Packages.Table (User_Decl.Packages) :=
491 (Project_Tree => Project_Tree,
492 Conf_Decl => Conf_Pack.Decl,
493 User_Decl => Project_Tree.Packages.Table
494 (User_Pack_Id).Decl);
497 Conf_Pack_Id := Conf_Pack.Next;
500 Proj.Project.Decl := User_Decl;
505 end Apply_Config_File;
511 function Check_Target
512 (Config_File : Project_Id;
513 Autoconf_Specified : Boolean;
514 Project_Tree : Prj.Project_Tree_Ref;
515 Target : String := "") return Boolean
517 Variable : constant Variable_Value :=
519 (Name_Target, Config_File.Decl.Attributes, Project_Tree);
520 Tgt_Name : Name_Id := No_Name;
524 if Variable /= Nil_Variable_Value and then not Variable.Default then
525 Tgt_Name := Variable.Value;
529 OK := not Autoconf_Specified or else Tgt_Name = No_Name;
531 OK := Tgt_Name /= No_Name
532 and then Target = Get_Name_String (Tgt_Name);
536 if Autoconf_Specified then
538 Write_Line ("inconsistent targets, performing autoconf");
544 if Tgt_Name /= No_Name then
546 with "invalid target name """
547 & Get_Name_String (Tgt_Name) & """ in configuration";
551 with "no target specified in configuration file";
559 --------------------------------------
560 -- Get_Or_Create_Configuration_File --
561 --------------------------------------
563 procedure Get_Or_Create_Configuration_File
564 (Project : Project_Id;
565 Project_Tree : Project_Tree_Ref;
566 Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
567 Allow_Automatic_Generation : Boolean;
568 Config_File_Name : String := "";
569 Autoconf_Specified : Boolean;
570 Target_Name : String := "";
571 Normalized_Hostname : String;
572 Packages_To_Check : String_List_Access := null;
573 Config : out Prj.Project_Id;
574 Config_File_Path : out String_Access;
575 Automatically_Generated : out Boolean;
576 Flags : Processing_Flags;
577 On_Load_Config : Config_File_Hook := null)
579 function Default_File_Name return String;
580 -- Return the name of the default config file that should be tested
582 procedure Do_Autoconf;
583 -- Generate a new config file through gprconfig.
584 -- In case of error, this raises the Invalid_Config exception with an
585 -- appropriate message
587 function Get_Config_Switches return Argument_List_Access;
588 -- Return the --config switches to use for gprconfig
590 function Might_Have_Sources (Project : Project_Id) return Boolean;
591 -- True if the specified project might have sources (ie the user has not
592 -- explicitly specified it. We haven't checked the file system, nor do
593 -- we need to at this stage.
595 -----------------------
596 -- Default_File_Name --
597 -----------------------
599 function Default_File_Name return String is
600 Ada_RTS : constant String := Runtime_Name_For (Name_Ada);
604 if Target_Name /= "" then
605 if Ada_RTS /= "" then
606 return Target_Name & '-' & Ada_RTS
607 & Config_Project_File_Extension;
609 return Target_Name & Config_Project_File_Extension;
612 elsif Ada_RTS /= "" then
613 return Ada_RTS & Config_Project_File_Extension;
616 Tmp := Getenv (Config_Project_Env_Var);
619 T : constant String := Tmp.all;
630 end Default_File_Name;
632 ------------------------
633 -- Might_Have_Sources --
634 ------------------------
636 function Might_Have_Sources (Project : Project_Id) return Boolean is
637 Variable : Variable_Value;
643 Project.Decl.Attributes,
646 if Variable = Nil_Variable_Value
647 or else Variable.Default
648 or else Variable.Values /= Nil_String
653 Project.Decl.Attributes,
655 return Variable = Nil_Variable_Value
656 or else Variable.Default
657 or else Variable.Values /= Nil_String;
662 end Might_Have_Sources;
664 -------------------------
665 -- Get_Config_Switches --
666 -------------------------
668 function Get_Config_Switches return Argument_List_Access is
669 package Language_Htable is new GNAT.HTable.Simple_HTable
670 (Header_Num => Prj.Header_Num,
672 No_Element => No_Name,
676 -- Hash table to keep the languages used in the project tree
678 IDE : constant Package_Id :=
681 Project.Decl.Packages,
684 Prj_Iter : Project_List;
685 List : String_List_Id;
686 Elem : String_Element;
688 Variable : Variable_Value;
691 Result : Argument_List_Access;
693 Check_Default : Boolean;
696 Prj_Iter := Project_Tree.Projects;
697 while Prj_Iter /= null loop
698 if Might_Have_Sources (Prj_Iter.Project) then
702 Prj_Iter.Project.Decl.Attributes,
705 if Variable = Nil_Variable_Value
706 or else Variable.Default
708 -- Languages is not declared. If it is not an extending
709 -- project, or if it extends a project with no Languages,
710 -- check for Default_Language.
712 Check_Default := Prj_Iter.Project.Extends = No_Project;
714 if not Check_Default then
718 Prj_Iter.Project.Extends.Decl.Attributes,
721 Variable /= Nil_Variable_Value
722 and then Variable.Values = Nil_String;
725 if Check_Default then
728 (Name_Default_Language,
729 Prj_Iter.Project.Decl.Attributes,
732 if Variable /= Nil_Variable_Value
733 and then not Variable.Default
735 Get_Name_String (Variable.Value);
736 To_Lower (Name_Buffer (1 .. Name_Len));
738 Language_Htable.Set (Lang, Lang);
741 -- If no default language is declared, default to Ada
743 Language_Htable.Set (Name_Ada, Name_Ada);
747 elsif Variable.Values /= Nil_String then
749 -- Attribute Languages is declared with a non empty
750 -- list: put all the languages in Language_HTable.
752 List := Variable.Values;
753 while List /= Nil_String loop
754 Elem := Project_Tree.String_Elements.Table (List);
756 Get_Name_String (Elem.Value);
757 To_Lower (Name_Buffer (1 .. Name_Len));
759 Language_Htable.Set (Lang, Lang);
766 Prj_Iter := Prj_Iter.Next;
769 Name := Language_Htable.Get_First;
771 while Name /= No_Name loop
773 Name := Language_Htable.Get_Next;
776 Result := new String_List (1 .. Count);
779 Name := Language_Htable.Get_First;
780 while Name /= No_Name loop
781 -- Check if IDE'Compiler_Command is declared for the language.
782 -- If it is, use its value to invoke gprconfig.
787 Attribute_Or_Array_Name => Name_Compiler_Command,
789 In_Tree => Project_Tree,
790 Force_Lower_Case_Index => True);
793 Config_Command : constant String :=
794 "--config=" & Get_Name_String (Name);
796 Runtime_Name : constant String :=
797 Runtime_Name_For (Name);
800 if Variable = Nil_Variable_Value
801 or else Length_Of_Name (Variable.Value) = 0
804 new String'(Config_Command & ",," & Runtime_Name);
808 Compiler_Command : constant String :=
809 Get_Name_String (Variable.Value);
812 if Is_Absolute_Path (Compiler_Command) then
815 (Config_Command & ",," & Runtime_Name & "," &
816 Containing_Directory (Compiler_Command) & "," &
817 Simple_Name (Compiler_Command));
821 (Config_Command & ",," & Runtime_Name & ",," &
829 Name := Language_Htable.Get_Next;
833 end Get_Config_Switches;
839 procedure Do_Autoconf is
840 Obj_Dir : constant Variable_Value :=
843 Project.Decl.Attributes,
846 Gprconfig_Path : String_Access;
850 Gprconfig_Path := Locate_Exec_On_Path (Gprconfig_Name);
852 if Gprconfig_Path = null then
854 with "could not locate gprconfig for auto-configuration";
857 -- First, find the object directory of the user's project
859 if Obj_Dir = Nil_Variable_Value or else Obj_Dir.Default then
860 Get_Name_String (Project.Directory.Display_Name);
863 if Is_Absolute_Path (Get_Name_String (Obj_Dir.Value)) then
864 Get_Name_String (Obj_Dir.Value);
868 Add_Str_To_Name_Buffer
869 (Get_Name_String (Project.Directory.Display_Name));
870 Add_Str_To_Name_Buffer (Get_Name_String (Obj_Dir.Value));
874 if Subdirs /= null then
875 Add_Char_To_Name_Buffer (Directory_Separator);
876 Add_Str_To_Name_Buffer (Subdirs.all);
879 for J in 1 .. Name_Len loop
880 if Name_Buffer (J) = '/' then
881 Name_Buffer (J) := Directory_Separator;
886 Obj_Dir : constant String := Name_Buffer (1 .. Name_Len);
887 Switches : Argument_List_Access := Get_Config_Switches;
888 Args : Argument_List (1 .. 5);
891 Obj_Dir_Exists : Boolean := True;
894 -- Check if the object directory exists. If Setup_Projects is True
895 -- (-p) and directory does not exist, attempt to create it.
896 -- Otherwise, if directory does not exist, fail without calling
899 if not Is_Directory (Obj_Dir)
900 and then (Setup_Projects or else Subdirs /= null)
903 Create_Path (Obj_Dir);
905 if not Quiet_Output then
906 Write_Str ("object directory """);
908 Write_Line (""" created");
914 with "could not create object directory " & Obj_Dir;
918 if not Is_Directory (Obj_Dir) then
919 case Flags.Require_Obj_Dirs is
922 with "object directory " & Obj_Dir & " does not exist";
926 "?object directory " & Obj_Dir & " does not exist");
927 Obj_Dir_Exists := False;
935 Args (1) := new String'("--batch");
936 Args (2) := new String'("-o");
938 -- If no config file was specified, set the auto.cgpr one
940 if Config_File_Name = "" then
941 if Obj_Dir_Exists then
943 new String'(Obj_Dir & Directory_Separator & Auto_Cgpr);
947 Path_FD : File_Descriptor;
948 Path_Name : Path_Name_Type;
951 Prj.Env.Create_Temp_File
952 (In_Tree => Project_Tree,
954 Path_Name => Path_Name,
955 File_Use => "configuration file");
957 if Path_FD /= Invalid_FD then
958 Args (3) := new String'(Get_Name_String (Path_Name));
959 GNAT.OS_Lib.Close (Path_FD);
962 -- We'll have an error message later on
966 (Obj_Dir & Directory_Separator & Auto_Cgpr);
971 Args (3) := new String'(Config_File_Name);
974 if Normalized_Hostname = "" then
977 if Target_Name = "" then
978 Args (4) := new String'("--target=" & Normalized_Hostname);
980 Args (4) := new String'("--target=" & Target_Name);
986 if not Verbose_Mode then
987 Arg_Last := Arg_Last + 1;
988 Args (Arg_Last) := new String'("-q");
992 Write_Str (Gprconfig_Name);
994 for J in 1 .. Arg_Last loop
996 Write_Str (Args (J).all);
999 for J in Switches'Range loop
1001 Write_Str (Switches (J).all);
1006 elsif not Quiet_Output then
1007 -- Display no message if we are creating auto.cgpr, unless in
1010 if Config_File_Name /= ""
1011 or else Verbose_Mode
1013 Write_Str ("creating ");
1014 Write_Str (Simple_Name (Args (3).all));
1019 Spawn (Gprconfig_Path.all, Args (1 .. Arg_Last) & Switches.all,
1024 Config_File_Path := Locate_Config_File (Args (3).all);
1026 if Config_File_Path = null then
1027 raise Invalid_Config
1028 with "could not create " & Args (3).all;
1031 for F in Args'Range loop
1038 Config_Project_Node : Project_Node_Id := Empty_Node;
1041 Free (Config_File_Path);
1042 Config := No_Project;
1044 if Config_File_Name /= "" then
1045 Config_File_Path := Locate_Config_File (Config_File_Name);
1047 Config_File_Path := Locate_Config_File (Default_File_Name);
1050 if Config_File_Path = null then
1051 if (not Allow_Automatic_Generation) and then
1052 Config_File_Name /= ""
1054 raise Invalid_Config
1055 with "could not locate main configuration project "
1060 Automatically_Generated :=
1061 Allow_Automatic_Generation and then Config_File_Path = null;
1063 <<Process_Config_File>>
1065 if Automatically_Generated then
1066 if Hostparm.OpenVMS then
1068 -- There is no gprconfig on VMS
1070 raise Invalid_Config
1071 with "could not locate any configuration project file";
1074 -- This might raise an Invalid_Config exception
1080 -- Parse the configuration file
1082 if Verbose_Mode and then Config_File_Path /= null then
1083 Write_Str ("Checking configuration ");
1084 Write_Line (Config_File_Path.all);
1087 if Config_File_Path /= null then
1089 (In_Tree => Project_Node_Tree,
1090 Project => Config_Project_Node,
1091 Project_File_Name => Config_File_Path.all,
1092 Always_Errout_Finalize => False,
1093 Packages_To_Check => Packages_To_Check,
1094 Current_Directory => Current_Directory,
1095 Is_Config_File => True,
1098 -- Maybe the user will want to create his own configuration file
1099 Config_Project_Node := Empty_Node;
1102 if On_Load_Config /= null then
1104 (Config_File => Config_Project_Node,
1105 Project_Node_Tree => Project_Node_Tree);
1108 if Config_Project_Node /= Empty_Node then
1109 Prj.Proc.Process_Project_Tree_Phase_1
1110 (In_Tree => Project_Tree,
1113 From_Project_Node => Config_Project_Node,
1114 From_Project_Node_Tree => Project_Node_Tree,
1116 Reset_Tree => False);
1119 if Config_Project_Node = Empty_Node
1120 or else Config = No_Project
1122 raise Invalid_Config
1123 with "processing of configuration project """
1124 & Config_File_Path.all & """ failed";
1127 -- Check that the target of the configuration file is the one the user
1128 -- specified on the command line. We do not need to check that when in
1129 -- auto-conf mode, since the appropriate target was passed to gprconfig.
1131 if not Automatically_Generated
1133 Check_Target (Config, Autoconf_Specified, Project_Tree, Target_Name)
1135 Automatically_Generated := True;
1136 goto Process_Config_File;
1138 end Get_Or_Create_Configuration_File;
1140 ------------------------
1141 -- Locate_Config_File --
1142 ------------------------
1144 function Locate_Config_File (Name : String) return String_Access is
1145 Prefix_Path : constant String := Executable_Prefix_Path;
1147 if Prefix_Path'Length /= 0 then
1148 return Locate_Regular_File
1150 "." & Path_Separator &
1151 Prefix_Path & "share" & Directory_Separator & "gpr");
1153 return Locate_Regular_File (Name, ".");
1155 end Locate_Config_File;
1157 ------------------------------------
1158 -- Parse_Project_And_Apply_Config --
1159 ------------------------------------
1161 procedure Parse_Project_And_Apply_Config
1162 (Main_Project : out Prj.Project_Id;
1163 User_Project_Node : out Prj.Tree.Project_Node_Id;
1164 Config_File_Name : String := "";
1165 Autoconf_Specified : Boolean;
1166 Project_File_Name : String;
1167 Project_Tree : Prj.Project_Tree_Ref;
1168 Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
1169 Packages_To_Check : String_List_Access;
1170 Allow_Automatic_Generation : Boolean := True;
1171 Automatically_Generated : out Boolean;
1172 Config_File_Path : out String_Access;
1173 Target_Name : String := "";
1174 Normalized_Hostname : String;
1175 Flags : Processing_Flags;
1176 On_Load_Config : Config_File_Hook := null)
1179 -- Parse the user project tree
1181 Prj.Initialize (Project_Tree);
1183 Main_Project := No_Project;
1184 Automatically_Generated := False;
1187 (In_Tree => Project_Node_Tree,
1188 Project => User_Project_Node,
1189 Project_File_Name => Project_File_Name,
1190 Always_Errout_Finalize => False,
1191 Packages_To_Check => Packages_To_Check,
1192 Current_Directory => Current_Directory,
1193 Is_Config_File => False,
1196 if User_Project_Node = Empty_Node then
1197 User_Project_Node := Empty_Node;
1201 Process_Project_And_Apply_Config
1202 (Main_Project => Main_Project,
1203 User_Project_Node => User_Project_Node,
1204 Config_File_Name => Config_File_Name,
1205 Autoconf_Specified => Autoconf_Specified,
1206 Project_Tree => Project_Tree,
1207 Project_Node_Tree => Project_Node_Tree,
1208 Packages_To_Check => Packages_To_Check,
1209 Allow_Automatic_Generation => Allow_Automatic_Generation,
1210 Automatically_Generated => Automatically_Generated,
1211 Config_File_Path => Config_File_Path,
1212 Target_Name => Target_Name,
1213 Normalized_Hostname => Normalized_Hostname,
1215 On_Load_Config => On_Load_Config);
1216 end Parse_Project_And_Apply_Config;
1218 --------------------------------------
1219 -- Process_Project_And_Apply_Config --
1220 --------------------------------------
1222 procedure Process_Project_And_Apply_Config
1223 (Main_Project : out Prj.Project_Id;
1224 User_Project_Node : Prj.Tree.Project_Node_Id;
1225 Config_File_Name : String := "";
1226 Autoconf_Specified : Boolean;
1227 Project_Tree : Prj.Project_Tree_Ref;
1228 Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
1229 Packages_To_Check : String_List_Access;
1230 Allow_Automatic_Generation : Boolean := True;
1231 Automatically_Generated : out Boolean;
1232 Config_File_Path : out String_Access;
1233 Target_Name : String := "";
1234 Normalized_Hostname : String;
1235 Flags : Processing_Flags;
1236 On_Load_Config : Config_File_Hook := null;
1237 Reset_Tree : Boolean := True)
1239 Main_Config_Project : Project_Id;
1243 Main_Project := No_Project;
1244 Automatically_Generated := False;
1246 Process_Project_Tree_Phase_1
1247 (In_Tree => Project_Tree,
1248 Project => Main_Project,
1250 From_Project_Node => User_Project_Node,
1251 From_Project_Node_Tree => Project_Node_Tree,
1253 Reset_Tree => Reset_Tree);
1256 Main_Project := No_Project;
1260 if Project_Tree.Source_Info_File_Name /= null then
1261 if not Is_Absolute_Path (Project_Tree.Source_Info_File_Name.all) then
1263 Obj_Dir : constant Variable_Value :=
1266 Main_Project.Decl.Attributes,
1270 if Obj_Dir = Nil_Variable_Value or else Obj_Dir.Default then
1271 Get_Name_String (Main_Project.Directory.Display_Name);
1274 if Is_Absolute_Path (Get_Name_String (Obj_Dir.Value)) then
1275 Get_Name_String (Obj_Dir.Value);
1279 Add_Str_To_Name_Buffer
1280 (Get_Name_String (Main_Project.Directory.Display_Name));
1281 Add_Str_To_Name_Buffer (Get_Name_String (Obj_Dir.Value));
1285 Add_Char_To_Name_Buffer (Directory_Separator);
1286 Add_Str_To_Name_Buffer (Project_Tree.Source_Info_File_Name.all);
1287 Free (Project_Tree.Source_Info_File_Name);
1288 Project_Tree.Source_Info_File_Name :=
1289 new String'(Name_Buffer (1 .. Name_Len));
1293 Read_Source_Info_File (Project_Tree);
1296 -- Find configuration file
1298 Get_Or_Create_Configuration_File
1299 (Config => Main_Config_Project,
1300 Project => Main_Project,
1301 Project_Tree => Project_Tree,
1302 Project_Node_Tree => Project_Node_Tree,
1303 Allow_Automatic_Generation => Allow_Automatic_Generation,
1304 Config_File_Name => Config_File_Name,
1305 Autoconf_Specified => Autoconf_Specified,
1306 Target_Name => Target_Name,
1307 Normalized_Hostname => Normalized_Hostname,
1308 Packages_To_Check => Packages_To_Check,
1309 Config_File_Path => Config_File_Path,
1310 Automatically_Generated => Automatically_Generated,
1312 On_Load_Config => On_Load_Config);
1314 Apply_Config_File (Main_Config_Project, Project_Tree);
1316 -- Finish processing the user's project
1318 Prj.Proc.Process_Project_Tree_Phase_2
1319 (In_Tree => Project_Tree,
1320 Project => Main_Project,
1322 From_Project_Node => User_Project_Node,
1323 From_Project_Node_Tree => Project_Node_Tree,
1327 if Project_Tree.Source_Info_File_Name /= null and then
1328 not Project_Tree.Source_Info_File_Exists
1330 Write_Source_Info_File (Project_Tree);
1334 Main_Project := No_Project;
1336 end Process_Project_And_Apply_Config;
1338 ----------------------
1339 -- Runtime_Name_For --
1340 ----------------------
1342 function Runtime_Name_For (Language : Name_Id) return String is
1344 if RTS_Languages.Get (Language) /= No_Name then
1345 return Get_Name_String (RTS_Languages.Get (Language));
1349 end Runtime_Name_For;
1351 ---------------------
1352 -- Set_Runtime_For --
1353 ---------------------
1355 procedure Set_Runtime_For (Language : Name_Id; RTS_Name : String) is
1357 Name_Len := RTS_Name'Length;
1358 Name_Buffer (1 .. Name_Len) := RTS_Name;
1359 RTS_Languages.Set (Language, Name_Find);
1360 end Set_Runtime_For;