1------------------------------------------------------------------------------ 2-- -- 3-- ASIS UTILITY LIBRARY COMPONENTS -- 4-- -- 5-- A S I S _ U L . C O M M O N -- 6-- -- 7-- S p e c -- 8-- -- 9-- Copyright (C) 2004-2016, AdaCore -- 10-- -- 11-- Asis Utility Library (ASIS UL) is free software; you can redistribute it -- 12-- and/or modify it under terms of the GNU General Public License as -- 13-- published by the Free Software Foundation; either version 3, or (at your -- 14-- option) any later version. ASIS UL is distributed in the hope that it -- 15-- will be useful, but WITHOUT ANY WARRANTY; without even the implied -- 16-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- 17-- GNU General Public License for more details. You should have received a -- 18-- copy of the GNU General Public License distributed with GNAT; see file -- 19-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy -- 20-- of the license. -- 21-- -- 22-- GNATCHECK is maintained by AdaCore (http://www.adacore.com). -- 23-- -- 24------------------------------------------------------------------------------ 25 26-- This package defines entities that are of general interest and can be used 27-- in more than one component of the tool 28 29-- When using this package, keep in mind that it computes the name of the 30-- tool as a part of its elaboration, and if the tool name contains a path 31-- information, the full absolute name of the directory the tool is located in 32-- is added to the beginning of the PATH environment variable. This is done 33-- to make it possible to use a tool belonging (or related)) to a particular 34-- version GNAT compiler in case when more than one GNAT version is 35-- installed - the idea is that when a tool calls a compiler to create a tree 36-- file, this compiler should be from the same GNAT version as the tool 37-- itself. See the body (Set_Tool_Name_And_Path routine) for all details. 38-- 39-- Note, that on Windows the system implicitly adds a full path to a command 40-- name even if the real tool invocation does not contain any path information 41-- for the tool name, so in case Windows the directory where the tool 42-- executable is located will allways be prepended to the path. 43 44with GNAT.OS_Lib; use GNAT.OS_Lib; 45 46with Asis; 47 48package ASIS_UL.Common is 49 50 pragma Elaborate_Body (ASIS_UL.Common); 51 52 Tool_Name : String_Access; 53 -- Used to generate error messages and to define the compiler to be used 54 -- to create the trees. Is set as the name of the tool that is actually 55 -- called (that is, as the result of Ada.Command_Line.Command_Name). This 56 -- name is used in the diagnostic messages generated by the tool 57 -- (preserving the casing of the result returned by 58 -- Ada.Command_Line.Command_Name). 59 -- 60 -- The tool name given in the command line should satisfy the following 61 -- rules: 62 -- 63 -- - if the name contains the minus sign ('-'), the part of the name before 64 -- the rightmost '-' should be the name of the cross platform the tool 65 -- is supposed to be used for 66 -- 67 -- - if the name starts from "gnaamp", it is treated as the name of the 68 -- tool to be used for AAMP compiler, in this case if the name contains 69 -- a '-' sign, this minus is treated as a part of the tool name with 70 -- no possible relation to the name of the cross platform. 71 -- 72 -- This variable is initialized during the elaboration of this package, a 73 -- tool may change it afterwards. If the tool is invoked with directory 74 -- information, this directory information is stripped away when setting 75 -- the value for Tool_Name, but the directory where the tool is invoked is 76 -- added in front of the path. Here we are using the same approach as 77 -- gnatmake. See E709-001. Note that the tool name is always converted to 78 -- lower case. 79 80 Target_From_Command_Line : String_Access; 81 -- Target as it is specified by the command-line '--target=...' option. 82 -- Remains equal to null if no '--target=...' option is specified. 83 84 Target_From_Project : String_Access; 85 -- Target as it is specified by the 'Target attribute in the argument 86 -- project file. Remains equal to null if there is no 'Target attribute 87 -- in the project file. 88 89 Gcc_To_Call : String_Access; 90 -- This variable is supposed to contain the full path to gcc to be used to 91 -- create trees, it is initialized during the elaboration of this package, 92 -- a tool may change it afterwards. If this is set to null, the standard 93 -- gcc installation is used (if any). 94 -- The value of this variable is detected during elaboration, just after 95 -- detecting Tool_Name. 96 97 Gnatmake_To_Call : String_Access; 98 -- This variable is supposed to contain the full path to gnatmake to be 99 -- used namely as gnatmake, but not the tree creator for ASIS Context. 100 -- This is needed by gnatelim and is probably needed by some other tools. 101 -- The value of this variable is detected during elaboration, just after 102 -- detecting Tool_Name. 103 104 Use_Gnatmake_To_Compile : Boolean := False; 105 -- This flag indicates that gnatmake (as 'gnatmake -c -u -f ...') should be 106 -- used to create the tree instead of gcc. 107 108 Gprbuild_To_Call : String_Access; 109 -- Full pathname of the executable for gprbuild, which is called in 110 -- --incremental mode. 111 112 Fatal_Error : exception; 113 -- This exception should be raised when there is no sense any more to do 114 -- any work in the tool. When raising this exception, one has to generate 115 -- the "fatal" diagnostic message. 116 117 Parameter_Error : exception; 118 -- Is raised when an error is detected for the parameters supplied for the 119 -- tool (includes both wrong parameters and wrong combinations of correct 120 -- parameters). 121 122 Non_Implemented_Error : exception; 123 -- This exception is raised if the execution comes to some part of the tool 124 -- that has not been completely implemented yet. 125 126 Tool_Failures : Natural := 0; 127 -- Counter for tool failures a tool has recovered from 128 129 Illegal_File_Detected : Boolean := False; 130 -- Flag indicating if there was at least one non-successful compilation 131 -- during the tool invocation. 132 133 The_Context : Asis.Context; 134 -- The Context for all the ASIS processing made by the tools. May be 135 -- associated, opened, closed and dissociated several times during one 136 -- tool run. 137 138 The_CU : Asis.Compilation_Unit; 139 -- The ASIS Compilation Unit corresponding to the unit represented by the 140 -- source being processed. 141 142 Arg_File : String_Access; 143 -- The name of the source to process. May be set in different ways, but 144 -- if it is non-null, it should contain the name of an existing file with 145 -- full directory information in normalized absolute form. 146 147 Tree_File : String_Access; 148 -- The name of the tree file created in the temporary directory 149 150 Project_File_Obsolete : String_Access; 151 -- The name of the project file used to locate sources and to compile 152 -- for the tree. It is supposed that after reading and checking the tool 153 -- parameters this variable is either null (in case if no project file is 154 -- used) or it points to the full name of the existing project file with 155 -- path information in absolute form. 156 -- 157 -- ???This is obsolete (see Use_Project_File_Obsolete below). 158 159 Multiple_File_Mode : Boolean := True; 160 -- This flag may be used by tools that use Source file table to check if 161 -- they have several or only one file to process. The tool should itself 162 -- set this file if it wants to use it. If this file is OFF, no source 163 -- trace is generated in non-verbise mode. 164 165 function Detect_Target return String; 166 -- Detects if this is a cross version of the tool by analyzing its name. 167 -- In case if it is a cross version, returns the prefix of the name 168 -- detecting the specific cross version, otherwise returns an empty 169 -- string (in case if the tool name starts with "gnaamp", returns "AAMP") 170 171 function Get_Global_Report_Dir return String; 172 -- Returns the path to the directory to place the global results into (the 173 -- path is ended with a directory separator). Returns null string if 174 -- No_Object_Dir is ON. 175 176 procedure Set_Global_Report_Dir (Dir : String); 177 -- Stores S as the path to the directory to place the global results into. 178 179 Ada_Version_Changed : Boolean := False; 180 -- Indicates if the language version is changed by tool parameters. We 181 -- need this flag because we may need to restore the default that is 182 -- changed in project analysis environment 183 184 Preprocessing_Allowed : Boolean := True; 185 -- Indicates if a tool can use preprcessor-related GNAT options when 186 -- compiling a source for the tree. If needed, this flag should be changed 187 -- before parsing tool arguments, because we can get prepeocessor-specific 188 -- options from a project file. 189 190 ----------------------------------- 191 -- Project support in ASIS tools -- 192 ----------------------------------- 193 194 -- The basic idea of providing the project support for ASIS tools is to 195 -- use not GCC, but GNATMAKE to create the tree for the ASIS part of the 196 -- tool and by means of this to use the project support embedded in 197 -- GNATMAKE. That is, if the tool has a parameter -Pproject_file, then 198 -- to create the tree we use: 199 -- 200 -- $gnatmake -c -f -u -Pproject_file_1 -gnatct ... 201 -- 202 -- The main problem with this approach is that the tree file is placed in 203 -- the directory that is defined as an object directory in the project 204 -- file, so we have to do something to get the tree created in the 205 -- temporarry directory the tool creates for all its compilations. There 206 -- are two solutions for this problem: 207 208 -- (1) to add '-cargs -o .' to the gnatmake arguments to redirect the 209 -- gnatmake output into the current dir (gnatmake is called from the 210 -- temporary dir created by the tool). 211 212 -- (2) to create in the temporary dir a new project file with the following 213 -- content: 214 -- 215 -- project Temp extends "full_name_of_project_file" is 216 -- for Object_Dir use "."; 217 -- end Temp; 218 -- 219 -- and to use this new project file as the argument of the gnatmake 220 -- call 221 222 -- The main problem with the first approach is that in case if the argument 223 -- file has not been compiled before (with generating the corresponding 224 -- ALI file, that call ends up with the diagnostic messages like: 225 -- 226 -- gnatmake: "p.ali" WARNING: ALI or object file not found after compile 227 -- gnatmake: "c:\atre-tests\projects\p.ads" compilation error 228 -- 229 -- and no tree file is generated. 230 231 -- At the moment we implement both approaches. The tool can select the 232 -- needed approach of the project support by setting the 233 -- Project_Support_Type variable below 234 235 type Project_Support_Types is (No_Tmp_Project_File, Use_Tmp_Project_File); 236 237 Project_Support_Type : Project_Support_Types := Use_Tmp_Project_File; 238 239 procedure Process_Project_File (Project_File_Name : String); 240 pragma Obsolescent (Process_Project_File); 241 -- This procedure analyzes the parameter of -P tool option. First, it 242 -- checks that Project_File_Name really exists, and if it is, stores 243 -- the full normalized name of this file as the value of 244 -- ASIS_UL.Common.Project_File, otherwise Parameter_Error is raised. 245 -- If No_Tmp_Project_File project support mode is set, this procedure 246 -- adds '-P<full_proj_file_name> option to the set of compiler/gnatmake 247 -- options used to create the tree. This procedure also tries to locate 248 -- gnatmake and raises Parameter_Error if this attempt fails. 249 -- If all the checks are successful, Use_Project_File_Obsolete is set ON. 250 251 Use_Project_File_Obsolete : Boolean := False; 252 -- Flag indicating if a project file is used when compiling sources for 253 -- the trees. With a project file, we should not try to check from a 254 -- short file name if the file exists and we should not use full file 255 -- names. 256 -- 257 -- ???This flag and related code is obsolete, but we can't remove it, 258 -- because it is still used by ada2java. 259 260end ASIS_UL.Common; 261