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 -- The following package manipulates the configuration files
32 type Config_File_Hook is access procedure
33 (Config_File : in out Prj.Tree.Project_Node_Id;
34 Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref);
35 -- Hook called after the config file has been parsed. This lets the
36 -- application do last minute changes to it (GPS uses this to add the
37 -- default naming schemes for instance). At that point, the config file
38 -- has not been applied to the project yet. When no config file was found,
39 -- and automatic generation is disabled, it is possible that Config_File
40 -- is set to Empty_Node when this procedure is called. You can then decide
41 -- to create a new config file if you need.
43 procedure Parse_Project_And_Apply_Config
44 (Main_Project : out Prj.Project_Id;
45 User_Project_Node : out Prj.Tree.Project_Node_Id;
46 Config_File_Name : String := "";
47 Autoconf_Specified : Boolean;
48 Project_File_Name : String;
49 Project_Tree : Prj.Project_Tree_Ref;
50 Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
51 Packages_To_Check : String_List_Access;
52 Allow_Automatic_Generation : Boolean := True;
53 Automatically_Generated : out Boolean;
54 Config_File_Path : out String_Access;
55 Target_Name : String := "";
56 Normalized_Hostname : String;
57 Flags : Processing_Flags;
58 On_Load_Config : Config_File_Hook := null);
59 -- Find the main configuration project and parse the project tree rooted at
60 -- this configuration project.
62 -- If the processing fails, Main_Project is set to No_Project. If the error
63 -- happend while parsing the project itself (ie creating the tree),
64 -- User_Project_Node is also set to Empty_Node.
66 -- Autoconf_Specified indicates whether the user has specified --autoconf.
67 -- If this is the case, the config file might be (re)generated, as
68 -- appropriate, to match languages and target if the one specified doesn't
71 -- Normalized_Hostname is the host on which gprbuild is returned,
72 -- normalized so that we can more easily compare it with what is stored in
73 -- configuration files. It is used when the target is unspecified, although
74 -- we need to know the target specified by the user (Target_Name) when
75 -- computing the name of the default config file that should be used.
77 -- If specified, On_Load_Config is called just after the config file has
78 -- been created/loaded. You can then modify it before it is later applied
79 -- to the project itself.
81 -- Any error in generating or parsing the config file is reported via the
82 -- Invalid_Config exception, with an appropriate message. Any error while
83 -- parsing the project file results in No_Project.
85 procedure Process_Project_And_Apply_Config
86 (Main_Project : out Prj.Project_Id;
87 User_Project_Node : Prj.Tree.Project_Node_Id;
88 Config_File_Name : String := "";
89 Autoconf_Specified : Boolean;
90 Project_Tree : Prj.Project_Tree_Ref;
91 Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
92 Packages_To_Check : String_List_Access;
93 Allow_Automatic_Generation : Boolean := True;
94 Automatically_Generated : out Boolean;
95 Config_File_Path : out String_Access;
96 Target_Name : String := "";
97 Normalized_Hostname : String;
98 Flags : Processing_Flags;
99 On_Load_Config : Config_File_Hook := null;
100 Reset_Tree : Boolean := True);
101 -- Same as above, except the project must already have been parsed through
102 -- Prj.Part.Parse, and only the processing of the project and the
103 -- configuration is done at this level.
105 -- If Reset_Tree is true, all projects are first removed from the tree.
106 -- When_No_Sources indicates what should be done when no sources are found
107 -- for one of the languages of the project.
109 -- If Require_Sources_Other_Lang is true, then all languages must have at
110 -- least one source file, or an error is reported via When_No_Sources. If
111 -- it is false, this is only required for Ada (and only if it is a language
114 Invalid_Config : exception;
116 procedure Get_Or_Create_Configuration_File
117 (Project : Prj.Project_Id;
118 Project_Tree : Prj.Project_Tree_Ref;
119 Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref;
120 Allow_Automatic_Generation : Boolean;
121 Config_File_Name : String := "";
122 Autoconf_Specified : Boolean;
123 Target_Name : String := "";
124 Normalized_Hostname : String;
125 Packages_To_Check : String_List_Access := null;
126 Config : out Prj.Project_Id;
127 Config_File_Path : out String_Access;
128 Automatically_Generated : out Boolean;
129 Flags : Processing_Flags;
130 On_Load_Config : Config_File_Hook := null);
131 -- Compute the name of the configuration file that should be used. If no
132 -- default configuration file is found, a new one will be automatically
133 -- generated if Allow_Automatic_Generation is true.
135 -- Any error in generating or parsing the config file is reported via the
136 -- Invalid_Config exception, with an appropriate message.
138 -- On exit, Configuration_Project_Path is never null (if none could be
139 -- found, Os.Fail was called and the program exited anyway).
141 -- The choice and generation of a configuration file depends on several
142 -- attributes of the user's project file (given by the Project argument),
143 -- e.g. list of languages that must be supported. Project must therefore
144 -- have been partially processed (phase one of the processing only).
146 -- Config_File_Name should be set to the name of the config file specified
147 -- by the user (either through gprbuild's --config or --autoconf switches).
148 -- In the latter case, Autoconf_Specified should be set to true to indicate
149 -- that the configuration file can be regenerated to match target and
150 -- languages. This name can either be an absolute path, or the a base name
151 -- that will be searched in the default config file directories (which
152 -- depends on the installation path for the tools).
154 -- Target_Name is used to chose the configuration file that will be used
155 -- from among several possibilities.
157 -- If a project file could be found, it is automatically parsed and
158 -- processed (and Packages_To_Check is used to indicate which packages
159 -- should be processed)
161 procedure Apply_Config_File
162 (Config_File : Prj.Project_Id;
163 Project_Tree : Prj.Project_Tree_Ref);
164 -- Apply the configuration file settings to all the projects in the
165 -- project tree. The Project_Tree must have been parsed first, and
166 -- processed through the first phase so that all its projects are known.
168 -- Currently, this will add new attributes and packages in the various
169 -- projects, so that when the second phase of the processing is performed
170 -- these attributes are automatically taken into account.
172 procedure Add_Default_GNAT_Naming_Scheme
173 (Config_File : in out Prj.Tree.Project_Node_Id;
174 Project_Tree : Prj.Tree.Project_Node_Tree_Ref);
175 -- A hook that will create a new config file (in memory), used for
176 -- Get_Or_Create_Configuration_File and Process_Project_And_Apply_Config
177 -- and add the default GNAT naming scheme to it. Nothing is done if the
178 -- config_file already exists, to avoid overriding what the user might
179 -- have put in there.
185 procedure Set_Runtime_For (Language : Name_Id; RTS_Name : String);
186 -- Specifies the runtime to use for a specific language. Most of the time
187 -- this should be used for Ada, but other languages can also specify their
188 -- own runtime. This is in general specified via the --RTS command line
189 -- switch, and results in a specific component passed to gprconfig's
190 -- --config switch then automatically generating a configuration file.
192 function Runtime_Name_For (Language : Name_Id) return String;
193 -- Returns the runtime name for a language. Returns an empty string if no
194 -- runtime was specified for the language using option --RTS.