annotate gcc/ada/make_util.ads @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- M A K E _ U T I L --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 2004-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
kono
parents:
diff changeset
17 -- for more details. You should have received a copy of the GNU General --
kono
parents:
diff changeset
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
kono
parents:
diff changeset
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
kono
parents:
diff changeset
20 -- --
kono
parents:
diff changeset
21 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
23 -- --
kono
parents:
diff changeset
24 ------------------------------------------------------------------------------
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 -- This package contains various subprograms used by the builders, in
kono
parents:
diff changeset
27 -- particular those subprograms related to build queue management.
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 with Namet; use Namet;
kono
parents:
diff changeset
30 with Opt;
kono
parents:
diff changeset
31 with Osint;
kono
parents:
diff changeset
32 with Types; use Types;
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 with GNAT.OS_Lib; use GNAT.OS_Lib;
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 package Make_Util is
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 type Fail_Proc is access procedure (S : String);
kono
parents:
diff changeset
39 -- Pointer to procedure which outputs a failure message
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 -- Root_Environment : Prj.Tree.Environment;
kono
parents:
diff changeset
42 -- The environment coming from environment variables and command line
kono
parents:
diff changeset
43 -- switches. When we do not have an aggregate project, this is used for
kono
parents:
diff changeset
44 -- parsing the project tree. When we have an aggregate project, this is
kono
parents:
diff changeset
45 -- used to parse the aggregate project; the latter then generates another
kono
parents:
diff changeset
46 -- environment (with additional external values and project path) to parse
kono
parents:
diff changeset
47 -- the aggregated projects.
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 -- Default_Config_Name : constant String := "default.cgpr";
kono
parents:
diff changeset
50 -- Name of the configuration file used by gprbuild and generated by
kono
parents:
diff changeset
51 -- gprconfig by default.
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 On_Windows : constant Boolean := Directory_Separator = '\';
kono
parents:
diff changeset
54 -- True when on Windows
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 Source_Info_Option : constant String := "--source-info=";
kono
parents:
diff changeset
57 -- Switch to indicate the source info file
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 Subdirs_Option : constant String := "--subdirs=";
kono
parents:
diff changeset
60 -- Switch used to indicate that the real directories (object, exec,
kono
parents:
diff changeset
61 -- library, ...) are subdirectories of those in the project file.
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 Relocate_Build_Tree_Option : constant String := "--relocate-build-tree";
kono
parents:
diff changeset
64 -- Switch to build out-of-tree. In this context the object, exec and
kono
parents:
diff changeset
65 -- library directories are relocated to the current working directory
kono
parents:
diff changeset
66 -- or the directory specified as parameter to this option.
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 Unchecked_Shared_Lib_Imports : constant String :=
kono
parents:
diff changeset
69 "--unchecked-shared-lib-imports";
kono
parents:
diff changeset
70 -- Command line switch to allow shared library projects to import projects
kono
parents:
diff changeset
71 -- that are not shared library projects.
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 Single_Compile_Per_Obj_Dir_Switch : constant String :=
kono
parents:
diff changeset
74 "--single-compile-per-obj-dir";
kono
parents:
diff changeset
75 -- Switch to forbid simultaneous compilations for the same object directory
kono
parents:
diff changeset
76 -- when project files are used.
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 Create_Map_File_Switch : constant String := "--create-map-file";
kono
parents:
diff changeset
79 -- Switch to create a map file when an executable is linked
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 No_Exit_Message_Option : constant String := "--no-exit-message";
kono
parents:
diff changeset
82 -- Switch to suppress exit error message when there are compilation
kono
parents:
diff changeset
83 -- failures. This is useful when a tool, such as gnatprove, silently calls
kono
parents:
diff changeset
84 -- the builder and does not want to pollute its output with error messages
kono
parents:
diff changeset
85 -- coming from the builder. This is an internal switch.
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 Keep_Temp_Files_Option : constant String := "--keep-temp-files";
kono
parents:
diff changeset
88 -- Switch to suppress deletion of temp files created by the builder.
kono
parents:
diff changeset
89 -- Note that debug switch -gnatdn also has this effect.
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 procedure Add
kono
parents:
diff changeset
92 (Option : String_Access;
kono
parents:
diff changeset
93 To : in out String_List_Access;
kono
parents:
diff changeset
94 Last : in out Natural);
kono
parents:
diff changeset
95 procedure Add
kono
parents:
diff changeset
96 (Option : String;
kono
parents:
diff changeset
97 To : in out String_List_Access;
kono
parents:
diff changeset
98 Last : in out Natural);
kono
parents:
diff changeset
99 -- Add a string to a list of strings
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 function Create_Name (Name : String) return File_Name_Type;
kono
parents:
diff changeset
102 function Create_Name (Name : String) return Name_Id;
kono
parents:
diff changeset
103 function Create_Name (Name : String) return Path_Name_Type;
kono
parents:
diff changeset
104 -- Get an id for a name
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 function Base_Name_Index_For
kono
parents:
diff changeset
107 (Main : String;
kono
parents:
diff changeset
108 Main_Index : Int;
kono
parents:
diff changeset
109 Index_Separator : Character) return File_Name_Type;
kono
parents:
diff changeset
110 -- Returns the base name of Main, without the extension, followed by the
kono
parents:
diff changeset
111 -- Index_Separator followed by the Main_Index if it is non-zero.
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 function Executable_Prefix_Path return String;
kono
parents:
diff changeset
114 -- Return the absolute path parent directory of the directory where the
kono
parents:
diff changeset
115 -- current executable resides, if its directory is named "bin", otherwise
kono
parents:
diff changeset
116 -- return an empty string. When a directory is returned, it is guaranteed
kono
parents:
diff changeset
117 -- to end with a directory separator.
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119 procedure Inform (N : Name_Id := No_Name; Msg : String);
kono
parents:
diff changeset
120 procedure Inform (N : File_Name_Type; Msg : String);
kono
parents:
diff changeset
121 -- Prints out the program name followed by a colon, N and S
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 procedure Ensure_Absolute_Path
kono
parents:
diff changeset
124 (Switch : in out String_Access;
kono
parents:
diff changeset
125 Parent : String;
kono
parents:
diff changeset
126 Do_Fail : Fail_Proc;
kono
parents:
diff changeset
127 For_Gnatbind : Boolean := False;
kono
parents:
diff changeset
128 Including_Non_Switch : Boolean := True;
kono
parents:
diff changeset
129 Including_RTS : Boolean := False);
kono
parents:
diff changeset
130 -- Do nothing if Switch is an absolute path switch. If relative, fail if
kono
parents:
diff changeset
131 -- Parent is the empty string, otherwise prepend the path with Parent. This
kono
parents:
diff changeset
132 -- subprogram is only used when using project files. If For_Gnatbind is
kono
parents:
diff changeset
133 -- True, consider gnatbind specific syntax for -L (not a path, left
kono
parents:
diff changeset
134 -- unchanged) and -A (path is optional, preceded with "=" if present).
kono
parents:
diff changeset
135 -- If Including_RTS is True, process also switches --RTS=. Do_Fail is
kono
parents:
diff changeset
136 -- called in case of error. Using Osint.Fail might be appropriate.
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 type Name_Ids is array (Positive range <>) of Name_Id;
kono
parents:
diff changeset
139 No_Names : constant Name_Ids := (1 .. 0 => No_Name);
kono
parents:
diff changeset
140 -- Name_Ids is used for list of language names in procedure Get_Directories
kono
parents:
diff changeset
141 -- below.
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 function Path_Or_File_Name (Path : Path_Name_Type) return String;
kono
parents:
diff changeset
144 -- Returns a file name if -df is used, otherwise return a path name
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 function Unit_Index_Of (ALI_File : File_Name_Type) return Int;
kono
parents:
diff changeset
147 -- Find the index of a unit in a source file. Return zero if the file is
kono
parents:
diff changeset
148 -- not a multi-unit source file.
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 procedure Verbose_Msg
kono
parents:
diff changeset
151 (N1 : Name_Id;
kono
parents:
diff changeset
152 S1 : String;
kono
parents:
diff changeset
153 N2 : Name_Id := No_Name;
kono
parents:
diff changeset
154 S2 : String := "";
kono
parents:
diff changeset
155 Prefix : String := " -> ";
kono
parents:
diff changeset
156 Minimum_Verbosity : Opt.Verbosity_Level_Type := Opt.Low);
kono
parents:
diff changeset
157 procedure Verbose_Msg
kono
parents:
diff changeset
158 (N1 : File_Name_Type;
kono
parents:
diff changeset
159 S1 : String;
kono
parents:
diff changeset
160 N2 : File_Name_Type := No_File;
kono
parents:
diff changeset
161 S2 : String := "";
kono
parents:
diff changeset
162 Prefix : String := " -> ";
kono
parents:
diff changeset
163 Minimum_Verbosity : Opt.Verbosity_Level_Type := Opt.Low);
kono
parents:
diff changeset
164 -- If the verbose flag (Verbose_Mode) is set and the verbosity level is at
kono
parents:
diff changeset
165 -- least equal to Minimum_Verbosity, then print Prefix to standard output
kono
parents:
diff changeset
166 -- followed by N1 and S1. If N2 /= No_Name then N2 is printed after S1. S2
kono
parents:
diff changeset
167 -- is printed last. Both N1 and N2 are printed in quotation marks. The two
kono
parents:
diff changeset
168 -- forms differ only in taking Name_Id or File_Name_Type arguments.
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 Max_Header_Num : constant := 6150;
kono
parents:
diff changeset
171 type Header_Num is range 0 .. Max_Header_Num;
kono
parents:
diff changeset
172 -- Size for hash table below. The upper bound is an arbitrary value, the
kono
parents:
diff changeset
173 -- value here was chosen after testing to determine a good compromise
kono
parents:
diff changeset
174 -- between speed of access and memory usage.
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 function Hash (Name : Name_Id) return Header_Num;
kono
parents:
diff changeset
177 function Hash (Name : File_Name_Type) return Header_Num;
kono
parents:
diff changeset
178 function Hash (Name : Path_Name_Type) return Header_Num;
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180 -------------------------
kono
parents:
diff changeset
181 -- Program termination --
kono
parents:
diff changeset
182 -------------------------
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 procedure Fail_Program
kono
parents:
diff changeset
185 (S : String;
kono
parents:
diff changeset
186 Flush_Messages : Boolean := True);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
187 pragma No_Return (Fail_Program);
111
kono
parents:
diff changeset
188 -- Terminate program with a message and a fatal status code
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 procedure Finish_Program
kono
parents:
diff changeset
191 (Exit_Code : Osint.Exit_Code_Type := Osint.E_Success;
kono
parents:
diff changeset
192 S : String := "");
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
193 pragma No_Return (Finish_Program);
111
kono
parents:
diff changeset
194 -- Terminate program, with or without a message, setting the status code
kono
parents:
diff changeset
195 -- according to Fatal. This properly removes all temporary files.
kono
parents:
diff changeset
196
kono
parents:
diff changeset
197 -----------
kono
parents:
diff changeset
198 -- Mains --
kono
parents:
diff changeset
199 -----------
kono
parents:
diff changeset
200
kono
parents:
diff changeset
201 -- Package Mains is used to store the mains specified on the command line
kono
parents:
diff changeset
202 -- and to retrieve them when a project file is used, to verify that the
kono
parents:
diff changeset
203 -- files exist and that they belong to a project file.
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 -- Mains are stored in a table. An index is used to retrieve the mains
kono
parents:
diff changeset
206 -- from the table.
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 type Main_Info is record
kono
parents:
diff changeset
209 File : File_Name_Type; -- Always canonical casing
kono
parents:
diff changeset
210 Index : Int := 0;
kono
parents:
diff changeset
211 end record;
kono
parents:
diff changeset
212
kono
parents:
diff changeset
213 No_Main_Info : constant Main_Info := (No_File, 0);
kono
parents:
diff changeset
214
kono
parents:
diff changeset
215 package Mains is
kono
parents:
diff changeset
216 procedure Add_Main (Name : String; Index : Int := 0);
kono
parents:
diff changeset
217 -- Add one main to the table. This is in general used to add the main
kono
parents:
diff changeset
218 -- files specified on the command line. Index is used for multi-unit
kono
parents:
diff changeset
219 -- source files, and indicates which unit in the source is concerned.
kono
parents:
diff changeset
220
kono
parents:
diff changeset
221 procedure Delete;
kono
parents:
diff changeset
222 -- Empty the table
kono
parents:
diff changeset
223
kono
parents:
diff changeset
224 procedure Reset;
kono
parents:
diff changeset
225 -- Reset the cursor to the beginning of the table
kono
parents:
diff changeset
226
kono
parents:
diff changeset
227 procedure Set_Multi_Unit_Index
kono
parents:
diff changeset
228 (Index : Int := 0);
kono
parents:
diff changeset
229 -- If a single main file was defined, this subprogram indicates which
kono
parents:
diff changeset
230 -- unit inside it is the main (case of a multi-unit source files).
kono
parents:
diff changeset
231 -- Errors are raised if zero or more than one main file was defined,
kono
parents:
diff changeset
232 -- and Index is non-zaero. This subprogram is used for the handling
kono
parents:
diff changeset
233 -- of the command line switch.
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 function Next_Main return String;
kono
parents:
diff changeset
236 function Next_Main return Main_Info;
kono
parents:
diff changeset
237 -- Moves the cursor forward and returns the new current entry. Returns
kono
parents:
diff changeset
238 -- No_Main_Info there are no more mains in the table.
kono
parents:
diff changeset
239
kono
parents:
diff changeset
240 function Number_Of_Mains return Natural;
kono
parents:
diff changeset
241 -- Returns the number of main.
kono
parents:
diff changeset
242
kono
parents:
diff changeset
243 end Mains;
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245 -----------
kono
parents:
diff changeset
246 -- Queue --
kono
parents:
diff changeset
247 -----------
kono
parents:
diff changeset
248
kono
parents:
diff changeset
249 package Queue is
kono
parents:
diff changeset
250
kono
parents:
diff changeset
251 -- The queue of sources to be checked for compilation. There can be a
kono
parents:
diff changeset
252 -- single such queue per application.
kono
parents:
diff changeset
253
kono
parents:
diff changeset
254 type Source_Info is
kono
parents:
diff changeset
255 record
kono
parents:
diff changeset
256 File : File_Name_Type := No_File;
kono
parents:
diff changeset
257 Unit : Unit_Name_Type := No_Unit_Name;
kono
parents:
diff changeset
258 Index : Int := 0;
kono
parents:
diff changeset
259 end record;
kono
parents:
diff changeset
260 -- Information about files stored in the queue.
kono
parents:
diff changeset
261
kono
parents:
diff changeset
262 No_Source_Info : constant Source_Info := (No_File, No_Unit_Name, 0);
kono
parents:
diff changeset
263
kono
parents:
diff changeset
264 procedure Initialize (Force : Boolean := False);
kono
parents:
diff changeset
265 -- Initialize the queue
kono
parents:
diff changeset
266
kono
parents:
diff changeset
267 procedure Remove_Marks;
kono
parents:
diff changeset
268 -- Remove all marks set for the files. This means that the files will be
kono
parents:
diff changeset
269 -- handed to the compiler if they are added to the queue, and is mostly
kono
parents:
diff changeset
270 -- useful when recompiling several executables as the switches may be
kono
parents:
diff changeset
271 -- different and -s may be in use.
kono
parents:
diff changeset
272
kono
parents:
diff changeset
273 function Is_Empty return Boolean;
kono
parents:
diff changeset
274 -- Returns True if the queue is empty
kono
parents:
diff changeset
275
kono
parents:
diff changeset
276 procedure Insert (Source : Source_Info);
kono
parents:
diff changeset
277 function Insert (Source : Source_Info) return Boolean;
kono
parents:
diff changeset
278 -- Insert source in the queue. The second version returns False if the
kono
parents:
diff changeset
279 -- Source was already marked in the queue.
kono
parents:
diff changeset
280
kono
parents:
diff changeset
281 procedure Extract
kono
parents:
diff changeset
282 (Found : out Boolean;
kono
parents:
diff changeset
283 Source : out Source_Info);
kono
parents:
diff changeset
284 -- Get the first source that can be compiled from the queue. If no
kono
parents:
diff changeset
285 -- source may be compiled, sets Found to False. In this case, the value
kono
parents:
diff changeset
286 -- for Source is undefined.
kono
parents:
diff changeset
287
kono
parents:
diff changeset
288 function Size return Natural;
kono
parents:
diff changeset
289 -- Return the total size of the queue, including the sources already
kono
parents:
diff changeset
290 -- extracted.
kono
parents:
diff changeset
291
kono
parents:
diff changeset
292 function Processed return Natural;
kono
parents:
diff changeset
293 -- Return the number of source in the queue that have aready been
kono
parents:
diff changeset
294 -- processed.
kono
parents:
diff changeset
295
kono
parents:
diff changeset
296 function Element (Rank : Positive) return File_Name_Type;
kono
parents:
diff changeset
297 -- Get the file name for element of index Rank in the queue
kono
parents:
diff changeset
298
kono
parents:
diff changeset
299 end Queue;
kono
parents:
diff changeset
300
kono
parents:
diff changeset
301 end Make_Util;