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-2013, 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 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.          --
20--                                                                          --
21-- GNAT was originally developed  by the GNAT team at  New York University. --
22-- Extensive contributions were provided by Ada Core Technologies Inc.      --
23--                                                                          --
24------------------------------------------------------------------------------
25
26--  The following package manipulates the configuration files
27
28with Prj.Tree;
29
30package Prj.Conf is
31
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.
42
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      Env                        : in out Prj.Tree.Environment;
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      On_Load_Config             : Config_File_Hook := null);
59   --  Find the main configuration project and parse the project tree rooted at
60   --  this configuration project.
61   --
62   --  Project_Node_Tree must have been initialized first (and possibly the
63   --  value for external references and project path should also have been
64   --  set).
65   --
66   --  If the processing fails, Main_Project is set to No_Project. If the error
67   --  happened while parsing the project itself (i.e. creating the tree),
68   --  User_Project_Node is also set to Empty_Node.
69   --
70   --  Autoconf_Specified indicates whether the user has specified --autoconf.
71   --  If this is the case, the config file might be (re)generated, as
72   --  appropriate, to match languages and target if the one specified doesn't
73   --  already match.
74   --
75   --  Normalized_Hostname is the host on which gprbuild is returned,
76   --  normalized so that we can more easily compare it with what is stored in
77   --  configuration files. It is used when the target is unspecified, although
78   --  we need to know the target specified by the user (Target_Name) when
79   --  computing the name of the default config file that should be used.
80   --
81   --  If specified, On_Load_Config is called just after the config file has
82   --  been created/loaded. You can then modify it before it is later applied
83   --  to the project itself.
84   --
85   --  Any error in generating or parsing the config file is reported via the
86   --  Invalid_Config exception, with an appropriate message. Any error while
87   --  parsing the project file results in No_Project.
88
89   procedure Process_Project_And_Apply_Config
90     (Main_Project               : out Prj.Project_Id;
91      User_Project_Node          : Prj.Tree.Project_Node_Id;
92      Config_File_Name           : String := "";
93      Autoconf_Specified         : Boolean;
94      Project_Tree               : Prj.Project_Tree_Ref;
95      Project_Node_Tree          : Prj.Tree.Project_Node_Tree_Ref;
96      Env                        : in out Prj.Tree.Environment;
97      Packages_To_Check          : String_List_Access;
98      Allow_Automatic_Generation : Boolean := True;
99      Automatically_Generated    : out Boolean;
100      Config_File_Path           : out String_Access;
101      Target_Name                : String := "";
102      Normalized_Hostname        : String;
103      On_Load_Config             : Config_File_Hook := null;
104      Reset_Tree                 : Boolean := True);
105   --  Same as above, except the project must already have been parsed through
106   --  Prj.Part.Parse, and only the processing of the project and the
107   --  configuration is done at this level.
108   --
109   --  If Reset_Tree is true, all projects are first removed from the tree.
110   --  When_No_Sources indicates what should be done when no sources are found
111   --  for one of the languages of the project.
112   --
113   --  If Require_Sources_Other_Lang is true, then all languages must have at
114   --  least one source file, or an error is reported via When_No_Sources. If
115   --  it is false, this is only required for Ada (and only if it is a language
116   --  of the project).
117
118   Invalid_Config : exception;
119
120   procedure Get_Or_Create_Configuration_File
121     (Project                    : Prj.Project_Id;
122      Conf_Project               : Project_Id;
123      Project_Tree               : Prj.Project_Tree_Ref;
124      Project_Node_Tree          : Prj.Tree.Project_Node_Tree_Ref;
125      Env                        : in out Prj.Tree.Environment;
126      Allow_Automatic_Generation : Boolean;
127      Config_File_Name           : String := "";
128      Autoconf_Specified         : Boolean;
129      Target_Name                : String := "";
130      Normalized_Hostname        : String;
131      Packages_To_Check          : String_List_Access := null;
132      Config                     : out Prj.Project_Id;
133      Config_File_Path           : out String_Access;
134      Automatically_Generated    : out Boolean;
135      On_Load_Config             : Config_File_Hook := null);
136   --  Compute the name of the configuration file that should be used. If no
137   --  default configuration file is found, a new one will be automatically
138   --  generated if Allow_Automatic_Generation is true. This configuration
139   --  project file will be generated in the object directory of project
140   --  Conf_Project.
141   --
142   --  Any error in generating or parsing the config file is reported via the
143   --  Invalid_Config exception, with an appropriate message.
144   --
145   --  On exit, Configuration_Project_Path is never null (if none could be
146   --  found, Os.Fail was called and the program exited anyway).
147   --
148   --  The choice and generation of a configuration file depends on several
149   --  attributes of the user's project file (given by the Project argument),
150   --  e.g. list of languages that must be supported. Project must therefore
151   --  have been partially processed (phase one of the processing only).
152   --
153   --  Config_File_Name should be set to the name of the config file specified
154   --  by the user (either through gprbuild's --config or --autoconf switches).
155   --  In the latter case, Autoconf_Specified should be set to true to indicate
156   --  that the configuration file can be regenerated to match target and
157   --  languages. This name can either be an absolute path, or the base name
158   --  that will be searched in the default config file directories (which
159   --  depends on the installation path for the tools).
160   --
161   --  Target_Name is used to chose the configuration file that will be used
162   --  from among several possibilities.
163   --
164   --  If a project file could be found, it is automatically parsed and
165   --  processed (and Packages_To_Check is used to indicate which packages
166   --  should be processed).
167
168   procedure Add_Default_GNAT_Naming_Scheme
169     (Config_File  : in out Prj.Tree.Project_Node_Id;
170      Project_Tree : Prj.Tree.Project_Node_Tree_Ref);
171   --  A hook that will create a new config file (in memory), used for
172   --  Get_Or_Create_Configuration_File and Process_Project_And_Apply_Config
173   --  and add the default GNAT naming scheme to it. Nothing is done if the
174   --  config_file already exists, to avoid overriding what the user might
175   --  have put in there.
176
177   --------------
178   -- Runtimes --
179   --------------
180
181   procedure Set_Runtime_For (Language : Name_Id; RTS_Name : String);
182   --  Specifies the runtime to use for a specific language. Most of the time
183   --  this should be used for Ada, but other languages can also specify their
184   --  own runtime. This is in general specified via the --RTS command line
185   --  switch, and results in a specific component passed to gprconfig's
186   --  --config switch then automatically generating a configuration file.
187
188   function Runtime_Name_For (Language : Name_Id) return String;
189   --  Returns the runtime name for a language. Returns an empty string if no
190   --  runtime was specified for the language using option --RTS.
191
192   function Runtime_Name_Set_For (Language : Name_Id) return Boolean;
193   --  Returns True only if Set_Runtime_For has been called for the Language
194
195   procedure Locate_Runtime
196     (Language     : Name_Id;
197      Project_Tree : Prj.Project_Tree_Ref);
198   --  If RTS_Name is a base name (a name without path separator), then
199   --  do nothing. Otherwise, convert it to an absolute path (possibly by
200   --  searching it in the project path) and call Set_Runtime_For with the
201   --  absolute path. Fail the program if the path does not exist.
202
203end Prj.Conf;
204