OSDN Git Service

2009-06-23 Ed Schonberg <schonberg@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / prj-conf.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                              P R J . C O N F                             --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --            Copyright (C) 2006-2009, Free Software Foundation, Inc.       --
10 --                                                                          --
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 2,  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 COPYING.  If not, write --
19 -- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
20 -- Boston, MA 02110-1301, USA.                                              --
21 --                                                                          --
22 -- GNAT was originally developed  by the GNAT team at  New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
24 --                                                                          --
25 ------------------------------------------------------------------------------
26
27 --  The following package manipulates the configuration files
28
29 with Prj.Tree;
30
31 package Prj.Conf is
32
33    type Config_File_Hook is access procedure
34      (Config_File       : in out Prj.Tree.Project_Node_Id;
35       Project_Node_Tree : Prj.Tree.Project_Node_Tree_Ref);
36    --  Hook called after the config file has been parsed. This lets the
37    --  application do last minute changes to it (GPS uses this to add the
38    --  default naming schemes for instance). At that point, the config file
39    --  has not been applied to the project yet. When no config file was found,
40    --  and automatic generation is disabled, it is possible that Config_File
41    --  is set to Empty_Node when this procedure is called. You can then decide
42    --  to create a new config file if you need.
43
44    procedure Parse_Project_And_Apply_Config
45      (Main_Project               : out Prj.Project_Id;
46       User_Project_Node          : out Prj.Tree.Project_Node_Id;
47       Config_File_Name           : String := "";
48       Autoconf_Specified         : Boolean;
49       Project_File_Name          : String;
50       Project_Tree               : Prj.Project_Tree_Ref;
51       Project_Node_Tree          : Prj.Tree.Project_Node_Tree_Ref;
52       Packages_To_Check          : String_List_Access;
53       Allow_Automatic_Generation : Boolean := True;
54       Automatically_Generated    : out Boolean;
55       Config_File_Path           : out String_Access;
56       Target_Name                : String := "";
57       Normalized_Hostname        : String;
58       Report_Error               : Put_Line_Access := null;
59       On_Load_Config             : Config_File_Hook := null);
60    --  Find the main configuration project and parse the project tree rooted at
61    --  this configuration project.
62    --
63    --  If the processing fails, Main_Project is set to No_Project. If the error
64    --  happend while parsing the project itself (ie creating the tree),
65    --  User_Project_Node is also set to Empty_Node.
66    --
67    --  Autoconf_Specified indicates whether the user has specified --autoconf.
68    --  If this is the case, the config file might be (re)generated, as
69    --  appropriate, to match languages and target if the one specified doesn't
70    --  already match.
71    --
72    --  Normalized_Hostname is the host on which gprbuild is returned,
73    --  normalized so that we can more easily compare it with what is stored in
74    --  configuration files. It is used when the target is unspecified, although
75    --  we need to know the target specified by the user (Target_Name) when
76    --  computing the name of the default config file that should be used.
77    --
78    --  If specified, On_Load_Config is called just after the config file has
79    --  been created/loaded. You can then modify it before it is later applied
80    --  to the project itself.
81    --
82    --  Any error in generating or parsing the config file is reported via the
83    --  Invalid_Config exception, with an appropriate message. Any error while
84    --  parsing the project file results in No_Project.
85
86    procedure Process_Project_And_Apply_Config
87      (Main_Project               : out Prj.Project_Id;
88       User_Project_Node          : Prj.Tree.Project_Node_Id;
89       Config_File_Name           : String := "";
90       Autoconf_Specified         : Boolean;
91       Project_Tree               : Prj.Project_Tree_Ref;
92       Project_Node_Tree          : Prj.Tree.Project_Node_Tree_Ref;
93       Packages_To_Check          : String_List_Access;
94       Allow_Automatic_Generation : Boolean := True;
95       Automatically_Generated    : out Boolean;
96       Config_File_Path           : out String_Access;
97       Target_Name                : String := "";
98       Normalized_Hostname        : String;
99       Report_Error               : Put_Line_Access := null;
100       On_Load_Config             : Config_File_Hook := null;
101       Compiler_Driver_Mandatory  : Boolean := True);
102    --  Same as above, except the project must already have been parsed through
103    --  Prj.Part.Parse, and only the processing of the project and the
104    --  configuration is done at this level.
105
106    Invalid_Config : exception;
107
108    procedure Get_Or_Create_Configuration_File
109      (Project                    : Prj.Project_Id;
110       Project_Tree               : Prj.Project_Tree_Ref;
111       Project_Node_Tree          : Prj.Tree.Project_Node_Tree_Ref;
112       Allow_Automatic_Generation : Boolean;
113       Config_File_Name           : String := "";
114       Autoconf_Specified         : Boolean;
115       Target_Name                : String := "";
116       Normalized_Hostname        : String;
117       Packages_To_Check          : String_List_Access := null;
118       Config                     : out Prj.Project_Id;
119       Config_File_Path           : out String_Access;
120       Automatically_Generated    : out Boolean;
121       On_Load_Config             : Config_File_Hook := null);
122    --  Compute the name of the configuration file that should be used. If no
123    --  default configuration file is found, a new one will be automatically
124    --  generated if Allow_Automatic_Generation is true.
125    --
126    --  Any error in generating or parsing the config file is reported via the
127    --  Invalid_Config exception, with an appropriate message.
128    --
129    --  On exit, Configuration_Project_Path is never null (if none could be
130    --  found, Os.Fail was called and the program exited anyway).
131    --
132    --  The choice and generation of a configuration file depends on several
133    --  attributes of the user's project file (given by the Project argument),
134    --  like the list of languages that must be supported. Project must
135    --  therefore have been partially processed (phase one of the processing
136    --  only).
137    --
138    --  Config_File_Name should be set to the name of the config file specified
139    --  by the user (either through gprbuild's --config or --autoconf switches).
140    --  In the latter case, Autoconf_Specified should be set to true, to
141    --  indicate that the configuration file can be regenerated to match target
142    --  and languages. This name can either be an absolute path, or the a base
143    --  name that will be searched in the default config file directories (which
144    --  depends on the installation path for the tools).
145    --
146    --  Target_Name is used to chose among several possibilities
147    --  the configuration file that will be used.
148    --
149    --  If a project file could be found, it is automatically parsed and
150    --  processed (and Packages_To_Check is used to indicate which packages
151    --  should be processed)
152
153    procedure Apply_Config_File
154      (Config_File  : Prj.Project_Id;
155       Project_Tree : Prj.Project_Tree_Ref);
156    --  Apply the configuration file settings to all the projects in the
157    --  project tree. The Project_Tree must have been parsed first, and
158    --  processed through the first phase so that all its projects are known.
159    --
160    --  Currently, this will add new attributes and packages in the various
161    --  projects, so that when the second phase of the processing is performed
162    --  these attributes are automatically taken into account.
163
164    --------------
165    -- Runtimes --
166    --------------
167
168    procedure Set_Runtime_For (Language : Name_Id; RTS_Name : String);
169    --  Specifies the runtime to use for a specific language. Most of the time
170    --  this should be used for Ada, but other languages can also specify their
171    --  own runtime. This is in general specified via the --RTS command line
172    --  switch, and results in a specific component passed to gprconfig's
173    --  --config switch then automatically generating a configuration file.
174
175    function Runtime_Name_For (Language : Name_Id) return String;
176    --  Returns the runtime name for a language. Returns an empty string if
177    --  no runtime was specified for the language using option --RTS.
178
179 end Prj.Conf;