-- --
-- B o d y --
-- --
--- Copyright (C) 1992-2008, Free Software Foundation, Inc. --
+-- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
with Hostparm; use Hostparm;
with Makeusg;
with Makeutl; use Makeutl;
+with MLib;
with MLib.Prj;
with MLib.Tgt; use MLib.Tgt;
with MLib.Utl;
with Prj.Com;
with Prj.Env;
with Prj.Pars;
+with Prj.Tree; use Prj.Tree;
with Prj.Util;
with SFN_Scan;
with Sinput.P;
with Snames; use Snames;
+
+pragma Warnings (Off);
+with System.HTable;
+pragma Warnings (On);
+
with Switch; use Switch;
with Switch.M; use Switch.M;
with Targparm; use Targparm;
with Ada.Command_Line; use Ada.Command_Line;
with GNAT.Directory_Operations; use GNAT.Directory_Operations;
+with GNAT.Dynamic_HTables; use GNAT.Dynamic_HTables;
with GNAT.Case_Util; use GNAT.Case_Util;
with GNAT.OS_Lib; use GNAT.OS_Lib;
-with System.HTable;
-
package body Make is
use ASCII;
Full_Source_File : File_Name_Type;
Lib_File : File_Name_Type;
Source_Unit : Unit_Name_Type;
+ Full_Lib_File : File_Name_Type;
+ Lib_File_Attr : aliased File_Attributes;
Mapping_File : Natural := No_Mapping_File;
Project : Project_Id := No_Project;
- Syntax_Only : Boolean := False;
- Output_Is_Object : Boolean := True;
end record;
-- Data recorded for each compilation process spawned
+ No_Compilation_Data : constant Compilation_Data :=
+ (Invalid_Pid, No_File, No_File, No_Unit_Name, No_File, Unknown_Attributes,
+ No_Mapping_File, No_Project);
+
type Comp_Data_Arr is array (Positive range <>) of Compilation_Data;
type Comp_Data_Ptr is access Comp_Data_Arr;
Running_Compile : Comp_Data_Ptr;
-- Q | | ........ | | | | ....... | |
-- +---+--------------+---+---+---+-----------+---+--------
-- ^ ^ ^
- -- Q.First Q_Front Q.Last - 1
+ -- Q.First Q_Front Q.Last-1
--
- -- The elements comprised between Q.First and Q_Front - 1 are the elements
+ -- The elements comprised between Q.First and Q_Front-1 are the elements
-- that have been enqueued and then dequeued, while the elements between
- -- Q_Front and Q.Last - 1 are the elements currently in the Q. When the Q
+ -- Q_Front and Q.Last-1 are the elements currently in the Q. When the Q
-- is initialized Q_Front = Q.First = Q.Last. After Compile_Sources has
-- terminated its execution, Q_Front = Q.Last and the elements contained
- -- between Q.Front and Q.Last-1 are those that were explored and thus
+ -- between Q.First and Q.Last-1 are those that were explored and thus
-- marked by Compile_Sources. Whenever the Q is reinitialized, the elements
- -- between Q.First and Q.Last - 1 are unmarked.
+ -- between Q.First and Q.Last-1 are unmarked.
procedure Init_Q;
-- Must be called to (re)initialize the Q
RTS_Specified : String_Access := null;
-- Used to detect multiple --RTS= switches
+ N_M_Switch : Natural := 0;
+ -- Used to count -mxxx switches that can affect multilib
+
type Q_Record is record
File : File_Name_Type;
Unit : Unit_Name_Type;
Current_Verbosity : Prj.Verbosity := Prj.Default;
-- Verbosity to parse the project files
- Project_Tree : constant Project_Tree_Ref := new Project_Tree_Data;
-
Main_Project : Prj.Project_Id := No_Project;
-- The project id of the main project file, if any
Project_Of_Current_Object_Directory : Project_Id := No_Project;
-- The object directory of the project for the last compilation. Avoid
-- calling Change_Dir if the current working directory is already this
- -- directory
+ -- directory.
-- Packages of project files where unknown attributes are errors
Last_Argument : Natural := 0;
-- Last index of arguments in Arguments above
- Arguments_Collected : Boolean := False;
- -- Set to True when the arguments for the next invocation of the compiler
- -- have been collected.
-
Arguments_Project : Project_Id;
-- Project id, if any, of the source to be compiled
procedure List_Bad_Compilations;
-- Prints out the list of all files for which the compilation failed
- procedure Verbose_Msg
- (N1 : Name_Id;
- S1 : String;
- N2 : Name_Id := No_Name;
- S2 : String := "";
- Prefix : String := " -> ";
- Minimum_Verbosity : Verbosity_Level_Type := Opt.Low);
- procedure Verbose_Msg
- (N1 : File_Name_Type;
- S1 : String;
- N2 : File_Name_Type := No_File;
- S2 : String := "";
- Prefix : String := " -> ";
- Minimum_Verbosity : Verbosity_Level_Type := Opt.Low);
- -- If the verbose flag (Verbose_Mode) is set and the verbosity level is
- -- at least equal to Minimum_Verbosity, then print Prefix to standard
- -- output followed by N1 and S1. If N2 /= No_Name then N2 is printed after
- -- S1. S2 is printed last. Both N1 and N2 are printed in quotation marks.
-
Usage_Needed : Boolean := True;
-- Flag used to make sure Makeusg is call at most once
procedure Debug_Msg (S : String; N : Unit_Name_Type);
-- If Debug.Debug_Flag_W is set outputs string S followed by name N
- procedure Recursive_Compute_Depth
- (Project : Project_Id;
- Depth : Natural);
+ procedure Recursive_Compute_Depth (Project : Project_Id);
-- Compute depth of Project and of the projects it depends on
- procedure Compute_All_Imported_Projects (Project : Project_Id);
- -- Compute, the list of the projects imported directly or indirectly by
- -- project Project.
-
-----------------------
-- Gnatmake Routines --
-----------------------
(Source_File : File_Name_Type;
Source_File_Name : String;
Source_Index : Int;
- Naming : Naming_Data;
+ Project : Project_Id;
In_Package : Package_Id;
Allow_ALI : Boolean) return Variable_Value;
-- Return the switches for the source file in the specified package of a
-- directory of the ultimate extending project. If it is not, we ignore
-- the fact that this ALI file is read-only.
+ procedure Process_Multilib (Project_Node_Tree : Project_Node_Tree_Ref);
+ -- Add appropriate --RTS argument to handle multilib
+
----------------------------------------------------
-- Compiler, Binder & Linker Data and Subprograms --
----------------------------------------------------
File_Name : String;
Index : Int;
Program : Make_Program_Type;
- Unknown_Switches_To_The_Compiler : Boolean := True);
+ Unknown_Switches_To_The_Compiler : Boolean := True;
+ Project_Node_Tree : Project_Node_Tree_Ref);
procedure Add_Switch
(S : String_Access;
Program : Make_Program_Type;
Is_Main_Source : Boolean;
The_Args : Argument_List;
Lib_File : File_Name_Type;
+ Full_Lib_File : File_Name_Type;
+ Lib_File_Attr : access File_Attributes;
Read_Only : Boolean;
ALI : out ALI_Id;
O_File : out File_Name_Type;
-- ALI is the ALI_Id corresponding to Lib_File. If Lib_File in not
-- up-to-date, then the corresponding source file needs to be recompiled.
-- In this case ALI = No_ALI_Id.
+ -- Full_Lib_File must be the result of calling Osint.Full_Lib_File_Name on
+ -- Lib_File. Precomputing it saves system calls. Lib_File_Attr is the
+ -- initialized attributes of that file, which is also used to save on
+ -- system calls (it can safely be initialized to Unknown_Attributes).
procedure Check_Linker_Options
(E_Stamp : Time_Stamp_Type;
-- Mapping files
-----------------
- type Temp_Path_Names is
- array (Project_Id range <>, Positive range <>) of Path_Name_Type;
-
+ type Temp_Path_Names is array (Positive range <>) of Path_Name_Type;
type Temp_Path_Ptr is access Temp_Path_Names;
- type Indices is array (Project_Id range <>) of Natural;
+ type Free_File_Indices is array (Positive range <>) of Positive;
+ type Free_Indices_Ptr is access Free_File_Indices;
- type Indices_Ptr is access Indices;
+ type Project_Compilation_Data is record
+ Mapping_File_Names : Temp_Path_Ptr;
+ -- The name ids of the temporary mapping files used. This is indexed
+ -- on the maximum number of compilation processes we will be spawning
+ -- (-j parameter)
- type Free_File_Indices is array
- (Project_Id range <>, Positive range <>) of Positive;
+ Last_Mapping_File_Names : Natural;
+ -- Index of the last mapping file created for this project
- type Free_Indices_Ptr is access Free_File_Indices;
+ Free_Mapping_File_Indices : Free_Indices_Ptr;
+ -- Indices in Mapping_File_Names of the mapping file names that can be
+ -- reused for subsequent compilations.
- The_Mapping_File_Names : Temp_Path_Ptr;
- -- For each project, the name ids of the temporary mapping files used
+ Last_Free_Indices : Natural;
+ -- Number of mapping files that can be reused
+ end record;
+ -- Information necessary when compiling a project
- Last_Mapping_File_Names : Indices_Ptr;
- -- For each project, the index of the last mapping file created
+ type Project_Compilation_Access is access Project_Compilation_Data;
- The_Free_Mapping_File_Indices : Free_Indices_Ptr;
- -- For each project, the indices in The_Mapping_File_Names of the mapping
- -- file names that can be reused for subsequent compilations.
+ package Project_Compilation_Htable is new Simple_HTable
+ (Header_Num => Prj.Header_Num,
+ Element => Project_Compilation_Access,
+ No_Element => null,
+ Key => Project_Id,
+ Hash => Prj.Hash,
+ Equal => "=");
- Last_Free_Indices : Indices_Ptr;
- -- For each project, the number of mapping files that can be reused
+ Project_Compilation : Project_Compilation_Htable.Instance;
Gnatmake_Mapping_File : String_Access := null;
-- The path name of a mapping file specified by switch -C=
- procedure Delete_Mapping_Files;
- -- Delete all temporary mapping files. Called only in Delete_All_Temp_Files
- -- which ensures that Debug_Flag_N is False.
-
procedure Init_Mapping_File
- (Project : Project_Id;
+ (Project : Project_Id;
+ Data : in out Project_Compilation_Data;
File_Index : in out Natural);
-- Create a new temporary mapping file, and fill it with the project file
-- mappings, when using project file(s). The out parameter File_Index is
-- during a compilation are also transitively included in the W section
-- of the originally compiled file.
- procedure Initialize;
+ procedure Initialize (Project_Node_Tree : out Project_Node_Tree_Ref);
-- Performs default and package initialization. Therefore,
-- Compile_Sources can be called by an external unit.
-- Args must have a lower bound of 1. Success indicates if the link
-- succeeded or not.
- procedure Scan_Make_Arg (Argv : String; And_Save : Boolean);
- -- Scan make arguments. Argv is a single argument to be processed
+ procedure Scan_Make_Arg
+ (Project_Node_Tree : Project_Node_Tree_Ref;
+ Argv : String;
+ And_Save : Boolean);
+ -- Scan make arguments. Argv is a single argument to be processed.
+ -- Project_Node_Tree will be used to initialize external references. It
+ -- must have been initialized.
-------------------
-- Add_Arguments --
Add_Lib_Search_Dir (Normalize_Pathname (Path));
else
- Get_Name_String
- (Project_Tree.Projects.Table (Main_Project).Directory.Display_Name);
+ Get_Name_String (Main_Project.Directory.Display_Name);
Add_Lib_Search_Dir
(Normalize_Pathname (Path, Name_Buffer (1 .. Name_Len)));
end if;
Add_Src_Search_Dir (Normalize_Pathname (Path));
else
- Get_Name_String
- (Project_Tree.Projects.Table (Main_Project).Directory.Display_Name);
+ Get_Name_String (Main_Project.Directory.Display_Name);
Add_Src_Search_Dir
(Normalize_Pathname (Path, Name_Buffer (1 .. Name_Len)));
end if;
File_Name : String;
Index : Int;
Program : Make_Program_Type;
- Unknown_Switches_To_The_Compiler : Boolean := True)
+ Unknown_Switches_To_The_Compiler : Boolean := True;
+ Project_Node_Tree : Project_Node_Tree_Ref)
is
Switches : Variable_Value;
Switch_List : String_List_Id;
Unknown_Switches_To_The_Compiler;
if File_Name'Length > 0 then
- Name_Len := File_Name'Length;
- Name_Buffer (1 .. Name_Len) := File_Name;
+ Name_Len := 0;
+ Add_Str_To_Name_Buffer (File_Name);
Switches :=
Switches_Of
(Source_File => Name_Find,
Source_File_Name => File_Name,
Source_Index => Index,
- Naming => Project_Tree.Projects.Table
- (Main_Project).Naming,
+ Project => Main_Project,
In_Package => The_Package,
Allow_ALI => Program = Binder or else Program = Linker);
Write_Line (Argv);
end if;
- Scan_Make_Arg (Argv, And_Save => False);
+ Scan_Make_Arg
+ (Project_Node_Tree, Argv, And_Save => False);
if not Gnatmake_Switch_Found
and then not Switch_May_Be_Passed_To_The_Compiler
--------------------------------
procedure Change_To_Object_Directory (Project : Project_Id) is
- Actual_Project : Project_Id;
Object_Directory : Path_Name_Type;
begin
- -- For sources outside of any project, compilation occurs in the object
- -- directory of the main project, otherwise we use the project given.
-
- if Project = No_Project then
- Actual_Project := Main_Project;
- else
- Actual_Project := Project;
- end if;
+ pragma Assert (Project /= No_Project);
-- Nothing to do if the current working directory is already the correct
-- object directory.
- if Project_Of_Current_Object_Directory /= Actual_Project then
- Project_Of_Current_Object_Directory := Actual_Project;
- Object_Directory :=
- Project_Tree.Projects.Table (Actual_Project).Object_Directory.Name;
+ if Project_Of_Current_Object_Directory /= Project then
+ Project_Of_Current_Object_Directory := Project;
+ Object_Directory := Project.Object_Directory.Name;
-- Set the working directory to the object directory of the actual
-- project.
if Verbose_Mode then
Write_Str ("Changing to object directory of """);
- Write_Name
- (Project_Tree.Projects.Table (Actual_Project).Display_Name);
+ Write_Name (Project.Display_Name);
Write_Str (""": """);
Write_Name (Object_Directory);
Write_Line ("""");
when Directory_Error =>
Make_Failed ("unable to change to object directory """ &
Path_Or_File_Name
- (Project_Tree.Projects.Table
- (Actual_Project).Object_Directory.Name) &
+ (Project.Object_Directory.Name) &
""" of project " &
- Get_Name_String (Project_Tree.Projects.Table
- (Actual_Project).Display_Name));
+ Get_Name_String (Project.Display_Name));
end Change_To_Object_Directory;
-----------
Is_Main_Source : Boolean;
The_Args : Argument_List;
Lib_File : File_Name_Type;
+ Full_Lib_File : File_Name_Type;
+ Lib_File_Attr : access File_Attributes;
Read_Only : Boolean;
ALI : out ALI_Id;
O_File : out File_Name_Type;
O_Stamp : out Time_Stamp_Type)
is
- function File_Not_A_Source_Of
- (Uname : Name_Id;
- Sfile : File_Name_Type) return Boolean;
-
function First_New_Spec (A : ALI_Id) return File_Name_Type;
-- Looks in the with table entries of A and returns the spec file name
-- of the first withed unit (subprogram) for which no spec existed when
-- services, but this causes the whole compiler to be dragged along
-- for gnatbind and gnatmake.
- --------------------------
- -- File_Not_A_Source_Of --
- --------------------------
-
- function File_Not_A_Source_Of
- (Uname : Name_Id;
- Sfile : File_Name_Type) return Boolean
- is
- UID : Prj.Unit_Index;
- U_Data : Unit_Data;
-
- begin
- UID := Units_Htable.Get (Project_Tree.Units_HT, Uname);
-
- if UID /= Prj.No_Unit_Index then
- U_Data := Project_Tree.Units.Table (UID);
-
- if U_Data.File_Names (Body_Part).Name /= Sfile
- and then U_Data.File_Names (Specification).Name /= Sfile
- then
- Verbose_Msg (Uname, "sources do not include ", Name_Id (Sfile));
- return True;
- end if;
- end if;
-
- return False;
- end File_Not_A_Source_Of;
-
--------------------
-- First_New_Spec --
--------------------
-- Data declarations for Check --
---------------------------------
- Full_Lib_File : File_Name_Type;
- -- Full name of current library file
-
Full_Obj_File : File_Name_Type;
-- Full name of the object file corresponding to Lib_File
Check_Object_Consistency;
begin
Check_Object_Consistency := False;
- Text := Read_Library_Info (Lib_File);
+ Text := Read_Library_Info_From_Full (Full_Lib_File, Lib_File_Attr);
Check_Object_Consistency := Saved_Check_Object_Consistency;
end;
else
- Text := Read_Library_Info (Lib_File);
+ Text := Read_Library_Info_From_Full (Full_Lib_File, Lib_File_Attr);
end if;
- Full_Lib_File := Full_Library_Info_Name;
Full_Obj_File := Full_Object_File_Name;
Lib_Stamp := Current_Library_File_Stamp;
Obj_Stamp := Current_Object_File_Stamp;
elsif not Read_Only and then Main_Project /= No_Project then
- -- Check if a file name does not correspond to the mapping of
- -- units to file names.
-
- declare
- SD : Sdep_Record;
- WR : With_Record;
- Unit_Name : Name_Id;
-
- begin
- U_Chk :
- for U in ALIs.Table (ALI).First_Unit ..
- ALIs.Table (ALI).Last_Unit
- loop
- -- Check if the file name is one of the source of the
- -- unit.
-
- Get_Name_String (Units.Table (U).Uname);
- Name_Len := Name_Len - 2;
- Unit_Name := Name_Find;
-
- if File_Not_A_Source_Of
- (Unit_Name, Units.Table (U).Sfile)
- then
- ALI := No_ALI_Id;
- return;
- end if;
-
- -- Do the same check for each of the withed units
-
- W_Check :
- for W in Units.Table (U).First_With
- ..
- Units.Table (U).Last_With
- loop
- WR := Withs.Table (W);
-
- if WR.Sfile /= No_File then
- Get_Name_String (WR.Uname);
- Name_Len := Name_Len - 2;
- Unit_Name := Name_Find;
-
- if File_Not_A_Source_Of (Unit_Name, WR.Sfile) then
- ALI := No_ALI_Id;
- return;
- end if;
- end if;
- end loop W_Check;
- end loop U_Chk;
-
- -- Check also the subunits
-
- D_Check :
- for D in ALIs.Table (ALI).First_Sdep ..
- ALIs.Table (ALI).Last_Sdep
- loop
- SD := Sdep.Table (D);
- Unit_Name := SD.Subunit_Name;
-
- if Unit_Name /= No_Name then
- if File_Not_A_Source_Of (Unit_Name, SD.Sfile) then
- ALI := No_ALI_Id;
- return;
- end if;
- end if;
- end loop D_Check;
- end;
+ if not Check_Source_Info_In_ALI (ALI) then
+ ALI := No_ALI_Id;
+ return;
+ end if;
-- Check that the ALI file is in the correct object directory.
-- If it is in the object directory of a project that is
ALI_Project := No_Project;
declare
- Udata : Prj.Unit_Data;
+ Udata : Prj.Unit_Index;
begin
- for U in 1 .. Unit_Table.Last (Project_Tree.Units) loop
- Udata := Project_Tree.Units.Table (U);
-
- if Udata.File_Names (Body_Part).Name = Source_File then
- ALI_Project := Udata.File_Names (Body_Part).Project;
+ Udata := Units_Htable.Get_First (Project_Tree.Units_HT);
+ while Udata /= No_Unit_Index loop
+ if Udata.File_Names (Impl) /= null
+ and then Udata.File_Names (Impl).File = Source_File
+ then
+ ALI_Project := Udata.File_Names (Impl).Project;
exit;
- elsif
- Udata.File_Names (Specification).Name = Source_File
+ elsif Udata.File_Names (Spec) /= null
+ and then Udata.File_Names (Spec).File = Source_File
then
- ALI_Project :=
- Udata.File_Names (Specification).Project;
+ ALI_Project := Udata.File_Names (Spec).Project;
exit;
end if;
+
+ Udata := Units_Htable.Get_Next (Project_Tree.Units_HT);
end loop;
end;
Normalize_Pathname
(Dir_Name
(Get_Name_String (Full_Lib_File)),
- Resolve_Links => True,
+ Resolve_Links =>
+ Opt.Follow_Links_For_Dirs,
Case_Sensitive => False);
begin
Name_Len := 0;
Add_Str_To_Name_Buffer (Res_Obj_Dir);
- if Name_Len > 1 and then
- (Name_Buffer (Name_Len) = '/'
- or else
- Name_Buffer (Name_Len) = Directory_Separator)
- then
- Name_Len := Name_Len - 1;
+ if not Is_Directory_Separator (Name_Buffer (Name_Len)) then
+ Add_Char_To_Name_Buffer (Directory_Separator);
end if;
Obj_Dir := Name_Find;
- while ALI_Project /= No_Project and then
- Obj_Dir /=
- Project_Tree.Projects.Table
- (ALI_Project).Object_Directory.Name
+ while ALI_Project /= No_Project
+ and then Obj_Dir /= ALI_Project.Object_Directory.Name
loop
- ALI_Project :=
- Project_Tree.Projects.Table (ALI_Project).Extended_By;
+ ALI_Project := ALI_Project.Extended_By;
end loop;
end;
-- If the ALI project is not extended, then it must be in
-- the correct object directory.
- if Project_Tree.Projects.Table (ALI_Project).Extended_By =
- No_Project
- then
+ if ALI_Project.Extended_By = No_Project then
return;
end if;
Num_Ext := 0;
Proj := ALI_Project;
loop
- Proj := Project_Tree.Projects.Table (Proj).Extended_By;
+ Proj := Proj.Extended_By;
exit when Proj = No_Project;
Num_Ext := Num_Ext + 1;
end loop;
Projects : array (1 .. Num_Ext) of Project_Id;
Dep : Sdep_Record;
OK : Boolean := True;
+ UID : Unit_Index;
begin
Proj := ALI_Project;
for J in Projects'Range loop
- Proj := Project_Tree.Projects.Table (Proj).Extended_By;
+ Proj := Proj.Extended_By;
Projects (J) := Proj;
end loop;
ALIs.Table (ALI).Last_Sdep
loop
Dep := Sdep.Table (D);
-
+ UID := Units_Htable.Get_First (Project_Tree.Units_HT);
Proj := No_Project;
Unit_Loop :
- for
- UID in 1 .. Unit_Table.Last (Project_Tree.Units)
- loop
- if Project_Tree.Units.Table (UID).
- File_Names (Body_Part).Name = Dep.Sfile
+ while UID /= null loop
+ if UID.File_Names (Impl) /= null
+ and then UID.File_Names (Impl).File = Dep.Sfile
then
- Proj := Project_Tree.Units.Table (UID).
- File_Names (Body_Part).Project;
+ Proj := UID.File_Names (Impl).Project;
- elsif Project_Tree.Units.Table (UID).
- File_Names (Specification).Name = Dep.Sfile
+ elsif UID.File_Names (Spec) /= null
+ and then UID.File_Names (Spec).File = Dep.Sfile
then
- Proj := Project_Tree.Units.Table (UID).
- File_Names (Specification).Project;
+ Proj := UID.File_Names (Spec).Project;
end if;
-- If a source is in a project, check if it is one
exit Unit_Loop;
end if;
+
+ UID :=
+ Units_Htable.Get_Next (Project_Tree.Units_HT);
end loop Unit_Loop;
end loop D_Chk;
Args : Argument_List)
is
begin
- Arguments_Collected := True;
Arguments_Project := No_Project;
Last_Argument := 0;
Add_Arguments (Args);
Get_Name_String (Source_File);
Compiler_Package : Prj.Package_Id;
Switches : Prj.Variable_Value;
- Data : Project_Data;
begin
Prj.Env.
if Arguments_Project = No_Project then
Add_Arguments (The_Saved_Gcc_Switches.all);
- elsif not Project_Tree.Projects.Table
- (Arguments_Project).Externally_Built
- then
+ elsif not Arguments_Project.Externally_Built then
-- We get the project directory for the relative path
-- switches and arguments.
- Data := Project_Tree.Projects.Table (Arguments_Project);
-
- -- If the source is in an extended project, we go to
- -- the ultimate extending project.
-
- while Data.Extended_By /= No_Project loop
- Arguments_Project := Data.Extended_By;
- Data := Project_Tree.Projects.Table (Arguments_Project);
- end loop;
+ Arguments_Project := Ultimate_Extending_Project_Of
+ (Arguments_Project);
-- If building a dynamic or relocatable library, compile with
-- PIC option, if it exists.
- if Data.Library and then Data.Library_Kind /= Static then
+ if Arguments_Project.Library
+ and then Arguments_Project.Library_Kind /= Static
+ then
declare
PIC : constant String := MLib.Tgt.PIC_Option;
end;
end if;
- if Data.Dir_Path = null then
- Data.Dir_Path :=
- new String'(Get_Name_String (Data.Directory.Display_Name));
- Project_Tree.Projects.Table (Arguments_Project) :=
- Data;
- end if;
-
-- We now look for package Compiler and get the switches from
-- this package.
Compiler_Package :=
Prj.Util.Value_Of
(Name => Name_Compiler,
- In_Packages => Data.Decl.Packages,
+ In_Packages => Arguments_Project.Decl.Packages,
In_Tree => Project_Tree);
if Compiler_Package /= No_Package then
(Source_File => Source_File,
Source_File_Name => Source_File_Name,
Source_Index => Source_Index,
- Naming => Data.Naming,
+ Project => Arguments_Project,
In_Package => Compiler_Package,
Allow_ALI => False);
declare
New_Args : Argument_List (1 .. Number);
Last_New : Natural := 0;
+ Dir_Path : constant String := Get_Name_String
+ (Arguments_Project.Directory.Name);
begin
Current := Switches.Values;
new String'(Name_Buffer (1 .. Name_Len));
Test_If_Relative_Path
(New_Args (Last_New),
- Parent => Data.Dir_Path,
+ Parent => Dir_Path,
Including_Non_Switch => False);
end if;
New_Args : Argument_List :=
(1 => new String'
(Name_Buffer (1 .. Name_Len)));
+ Dir_Path : constant String :=
+ Get_Name_String
+ (Arguments_Project.Directory.Name);
begin
Test_If_Relative_Path
(New_Args (1),
- Parent => Data.Dir_Path,
+ Parent => Dir_Path,
Including_Non_Switch => False);
Add_Arguments
(Configuration_Pragmas_Switch (Arguments_Project) &
Initialize_ALI_Data : Boolean := True;
Max_Process : Positive := 1)
is
- Source_Unit : Unit_Name_Type;
- -- Current source unit
-
- Source_File : File_Name_Type;
- -- Current source file
-
- Full_Source_File : File_Name_Type;
- -- Full name of the current source file
-
- Lib_File : File_Name_Type;
- -- Current library file
-
- Full_Lib_File : File_Name_Type;
- -- Full name of the current library file
-
- Obj_File : File_Name_Type;
- -- Full name of the object file corresponding to Lib_File
-
- Obj_Stamp : Time_Stamp_Type;
- -- Time stamp of the current object file
-
- Sfile : File_Name_Type;
- -- Contains the source file of the units withed by Source_File
-
- Uname : Unit_Name_Type;
- -- Contains the unit name of the units withed by Source_File
-
- ALI : ALI_Id;
- -- ALI Id of the current ALI file
-
- -- Comment following declarations ???
-
- Read_Only : Boolean := False;
-
- Compilation_OK : Boolean;
- Need_To_Compile : Boolean;
-
- Pid : Process_Id;
- Text : Text_Buffer_Ptr;
-
- Mfile : Natural := No_Mapping_File;
+ Mfile : Natural := No_Mapping_File;
+ Mapping_File_Arg : String_Access;
+ -- Info on the mapping file
Need_To_Check_Standard_Library : Boolean :=
Check_Readonly_Files
and not Unique_Compile;
- Mapping_File_Arg : String_Access;
-
- Process_Created : Boolean := False;
-
procedure Add_Process
- (Pid : Process_Id;
- Sfile : File_Name_Type;
- Afile : File_Name_Type;
- Uname : Unit_Name_Type;
- Mfile : Natural := No_Mapping_File);
+ (Pid : Process_Id;
+ Sfile : File_Name_Type;
+ Afile : File_Name_Type;
+ Uname : Unit_Name_Type;
+ Full_Lib_File : File_Name_Type;
+ Lib_File_Attr : File_Attributes;
+ Mfile : Natural := No_Mapping_File);
-- Adds process Pid to the current list of outstanding compilation
-- processes and record the full name of the source file Sfile that
-- we are compiling, the name of its library file Afile and the
-- array The_Mapping_File_Names.
procedure Await_Compile
- (Sfile : out File_Name_Type;
- Afile : out File_Name_Type;
- Uname : out Unit_Name_Type;
+ (Data : out Compilation_Data;
OK : out Boolean);
- -- Awaits that an outstanding compilation process terminates. When
- -- it does set Sfile to the name of the source file that was compiled
- -- Afile to the name of its library file and Uname to the name of its
- -- unit. Note that this time stamp can be used to check whether the
- -- compilation did generate an object file. OK is set to True if the
- -- compilation succeeded. Note that Sfile, Afile and Uname could be
- -- resp. No_File, No_File and No_Name if there were no compilations
- -- to wait for.
+ -- Awaits that an outstanding compilation process terminates. When it
+ -- does set Data to the information registered for the corresponding
+ -- call to Add_Process. Note that this time stamp can be used to check
+ -- whether the compilation did generate an object file. OK is set to
+ -- True if the compilation succeeded. Data could be No_Compilation_Data
+ -- if there was no compilation to wait for.
function Bad_Compilation_Count return Natural;
-- Returns the number of compilation failures
-- Check if s-stalib.adb needs to be compiled
procedure Collect_Arguments_And_Compile
- (Source_File : File_Name_Type;
- Source_Index : Int);
- -- Collect arguments from project file (if any) and compile
+ (Full_Source_File : File_Name_Type;
+ Lib_File : File_Name_Type;
+ Source_Index : Int;
+ Pid : out Process_Id;
+ Process_Created : out Boolean);
+ -- Collect arguments from project file (if any) and compile. If no
+ -- compilation was attempted, Processed_Created is set to False, and the
+ -- value of Pid is unknown.
function Compile
- (S : File_Name_Type;
+ (Project : Project_Id;
+ S : File_Name_Type;
L : File_Name_Type;
Source_Index : Int;
Args : Argument_List) return Process_Id;
procedure Record_Good_ALI (A : ALI_Id);
-- Records in the previous set the Id of an ALI file
+ function Must_Exit_Because_Of_Error return Boolean;
+ -- Return True if there were errors and the user decided to exit in such
+ -- a case. This waits for any outstanding compilation.
+
+ function Start_Compile_If_Possible (Args : Argument_List) return Boolean;
+ -- Check if there is more work that we can do (i.e. the Queue is non
+ -- empty). If there is, do it only if we have not yet used up all the
+ -- available processes.
+ -- Returns True if we should exit the main loop
+
+ procedure Wait_For_Available_Slot;
+ -- Check if we should wait for a compilation to finish. This is the case
+ -- if all the available processes are busy compiling sources or there is
+ -- nothing else to do (that is the Q is empty and there are no good ALIs
+ -- to process).
+
+ procedure Fill_Queue_From_ALI_Files;
+ -- Check if we recorded good ALI files. If yes process them now in the
+ -- order in which they have been recorded. There are two occasions in
+ -- which we record good ali files. The first is in phase 1 when, after
+ -- scanning an existing ALI file we realize it is up-to-date, the second
+ -- instance is after a successful compilation.
+
-----------------
-- Add_Process --
-----------------
procedure Add_Process
- (Pid : Process_Id;
- Sfile : File_Name_Type;
- Afile : File_Name_Type;
- Uname : Unit_Name_Type;
- Mfile : Natural := No_Mapping_File)
+ (Pid : Process_Id;
+ Sfile : File_Name_Type;
+ Afile : File_Name_Type;
+ Uname : Unit_Name_Type;
+ Full_Lib_File : File_Name_Type;
+ Lib_File_Attr : File_Attributes;
+ Mfile : Natural := No_Mapping_File)
is
OC1 : constant Positive := Outstanding_Compiles + 1;
pragma Assert (OC1 <= Max_Process);
pragma Assert (Pid /= Invalid_Pid);
- Running_Compile (OC1).Pid := Pid;
- Running_Compile (OC1).Full_Source_File := Sfile;
- Running_Compile (OC1).Lib_File := Afile;
- Running_Compile (OC1).Source_Unit := Uname;
- Running_Compile (OC1).Mapping_File := Mfile;
- Running_Compile (OC1).Project := Arguments_Project;
- Running_Compile (OC1).Syntax_Only := Syntax_Only;
- Running_Compile (OC1).Output_Is_Object := Output_Is_Object;
+ Running_Compile (OC1) :=
+ (Pid => Pid,
+ Full_Source_File => Sfile,
+ Lib_File => Afile,
+ Full_Lib_File => Full_Lib_File,
+ Lib_File_Attr => Lib_File_Attr,
+ Source_Unit => Uname,
+ Mapping_File => Mfile,
+ Project => Arguments_Project);
Outstanding_Compiles := OC1;
end Add_Process;
-------------------
procedure Await_Compile
- (Sfile : out File_Name_Type;
- Afile : out File_Name_Type;
- Uname : out Unit_Name_Type;
- OK : out Boolean)
+ (Data : out Compilation_Data;
+ OK : out Boolean)
is
- Pid : Process_Id;
- Project : Project_Id;
+ Pid : Process_Id;
+ Project : Project_Id;
+ Comp_Data : Project_Compilation_Access;
begin
pragma Assert (Outstanding_Compiles > 0);
- Sfile := No_File;
- Afile := No_File;
- Uname := No_Unit_Name;
- OK := False;
+ Data := No_Compilation_Data;
+ OK := False;
-- The loop here is a work-around for a problem on VMS; in some
-- circumstances (shared library and several executables, for
for J in Running_Compile'First .. Outstanding_Compiles loop
if Pid = Running_Compile (J).Pid then
- Sfile := Running_Compile (J).Full_Source_File;
- Afile := Running_Compile (J).Lib_File;
- Uname := Running_Compile (J).Source_Unit;
- Syntax_Only := Running_Compile (J).Syntax_Only;
- Output_Is_Object := Running_Compile (J).Output_Is_Object;
+ Data := Running_Compile (J);
Project := Running_Compile (J).Project;
- -- If a mapping file was used by this compilation,
- -- get its file name for reuse by a subsequent compilation
+ -- If a mapping file was used by this compilation, get its
+ -- file name for reuse by a subsequent compilation.
if Running_Compile (J).Mapping_File /= No_Mapping_File then
- Last_Free_Indices (Project) :=
- Last_Free_Indices (Project) + 1;
- The_Free_Mapping_File_Indices
- (Project, Last_Free_Indices (Project)) :=
- Running_Compile (J).Mapping_File;
+ Comp_Data :=
+ Project_Compilation_Htable.Get
+ (Project_Compilation, Project);
+ Comp_Data.Last_Free_Indices :=
+ Comp_Data.Last_Free_Indices + 1;
+ Comp_Data.Free_Mapping_File_Indices
+ (Comp_Data.Last_Free_Indices) :=
+ Running_Compile (J).Mapping_File;
end if;
-- To actually remove this Pid and related info from
if J = Outstanding_Compiles then
null;
-
else
Running_Compile (J) :=
Running_Compile (Outstanding_Compiles);
-- This child process was not one of our compilation processes;
-- just ignore it for now.
+ -- Why is this commented out code sitting here???
+
-- raise Program_Error;
end loop;
end Await_Compile;
Add_It : Boolean := True;
begin
- Name_Len := Standard_Library_Package_Body_Name'Length;
- Name_Buffer (1 .. Name_Len) :=
- Standard_Library_Package_Body_Name;
+ Name_Len := 0;
+ Add_Str_To_Name_Buffer (Standard_Library_Package_Body_Name);
Sfile := Name_Enter;
-- If we have a special runtime, we add the standard
-- library only if we can find it.
if RTS_Switch then
- Add_It :=
- Find_File (Sfile, Osint.Source) /= No_File;
+ Add_It := Full_Source_Name (Sfile) /= No_File;
end if;
if Add_It then
-----------------------------------
procedure Collect_Arguments_And_Compile
- (Source_File : File_Name_Type;
- Source_Index : Int)
- is
+ (Full_Source_File : File_Name_Type;
+ Lib_File : File_Name_Type;
+ Source_Index : Int;
+ Pid : out Process_Id;
+ Process_Created : out Boolean) is
begin
- -- Process_Created will be set True if an attempt is made to compile
- -- the source, that is if it is not in an externally built project.
-
Process_Created := False;
- -- If arguments not yet collected (in Check), collect them now
-
- if not Arguments_Collected then
- Collect_Arguments
- (Source_File, Source_Index, Source_File = Main_Source, Args);
- end if;
-
-- If we use mapping file (-P or -C switches), then get one
if Create_Mapping_File then
-- check for an eventual library project, and use the full path.
if Arguments_Project /= No_Project then
- if not Project_Tree.Projects.Table
- (Arguments_Project).Externally_Built
- then
- Prj.Env.Set_Ada_Paths (Arguments_Project, Project_Tree, True);
+ if not Arguments_Project.Externally_Built then
+ Prj.Env.Set_Ada_Paths
+ (Arguments_Project,
+ Project_Tree,
+ Including_Libraries => True);
if not Unique_Compile
and then MLib.Tgt.Support_For_Libraries /= Prj.None
then
declare
- The_Data : Project_Data :=
- Project_Tree.Projects.Table
- (Arguments_Project);
-
- Prj : Project_Id := Arguments_Project;
+ Prj : constant Project_Id :=
+ Ultimate_Extending_Project_Of (Arguments_Project);
begin
- while The_Data.Extended_By /= No_Project loop
- Prj := The_Data.Extended_By;
- The_Data := Project_Tree.Projects.Table (Prj);
- end loop;
-
- if The_Data.Library
- and then not The_Data.Externally_Built
- and then not The_Data.Need_To_Build_Lib
+ if Prj.Library
+ and then not Prj.Externally_Built
+ and then not Prj.Need_To_Build_Lib
then
- -- Add to the Q all sources of the project that
- -- have not been marked
+ -- Add to the Q all sources of the project that have
+ -- not been marked.
Insert_Project_Sources
(The_Project => Prj,
-- Now mark the project as processed
- Project_Tree.Projects.Table
- (Prj).Need_To_Build_Lib := True;
+ Prj.Need_To_Build_Lib := True;
end if;
end;
end if;
- -- Change to the object directory of the project file,
- -- if necessary.
-
- Change_To_Object_Directory (Arguments_Project);
-
Pid :=
Compile
- (File_Name_Type (Arguments_Path_Name),
- Lib_File,
- Source_Index,
- Arguments (1 .. Last_Argument));
+ (Project => Arguments_Project,
+ S => File_Name_Type (Arguments_Path_Name),
+ L => Lib_File,
+ Source_Index => Source_Index,
+ Args => Arguments (1 .. Last_Argument));
Process_Created := True;
end if;
-- If this is a source outside of any project file, make sure it
-- will be compiled in object directory of the main project file.
- if Main_Project /= No_Project then
- Change_To_Object_Directory (Arguments_Project);
- end if;
-
- Pid := Compile (Full_Source_File, Lib_File, Source_Index,
- Arguments (1 .. Last_Argument));
+ Pid :=
+ Compile
+ (Project => Main_Project,
+ S => Full_Source_File,
+ L => Lib_File,
+ Source_Index => Source_Index,
+ Args => Arguments (1 .. Last_Argument));
Process_Created := True;
end if;
end Collect_Arguments_And_Compile;
-------------
function Compile
- (S : File_Name_Type;
+ (Project : Project_Id;
+ S : File_Name_Type;
L : File_Name_Type;
Source_Index : Int;
Args : Argument_List) return Process_Id
Comp_Next := Comp_Next + 1;
-- Optimize the simple case where the gcc command line looks like
- -- gcc -c -I. ... -I- file.adb --into-> gcc -c ... file.adb
+ -- gcc -c -I. ... -I- file.adb
+ -- into
+ -- gcc -c ... file.adb
if Args (Args'First).all = "-I" & Normalized_CWD
and then Args (Args'Last).all = "-I-"
end if;
end if;
- if Create_Mapping_File then
+ if Create_Mapping_File and then Mapping_File_Arg /= null then
Comp_Last := Comp_Last + 1;
- Comp_Args (Comp_Last) := Mapping_File_Arg;
+ Comp_Args (Comp_Last) := new String'(Mapping_File_Arg.all);
end if;
Get_Name_String (S);
Comp_Last := Comp_Last + 1;
Comp_Args (Comp_Last) := new String'(Name_Buffer (1 .. Name_Len));
+ -- Change to object directory of the project file, if necessary
+
+ if Project /= No_Project then
+ Change_To_Object_Directory (Project);
+ end if;
+
GNAT.OS_Lib.Normalize_Arguments (Comp_Args (Args'First .. Comp_Last));
Comp_Last := Comp_Last + 1;
(Gcc_Path.all, Comp_Args (Args'First .. Comp_Last));
end Compile;
+ -------------------------------
+ -- Fill_Queue_From_ALI_Files --
+ -------------------------------
+
+ procedure Fill_Queue_From_ALI_Files is
+ ALI : ALI_Id;
+ Source_Index : Int;
+ Sfile : File_Name_Type;
+ Uname : Unit_Name_Type;
+ Unit_Name : Name_Id;
+ Uid : Prj.Unit_Index;
+
+ begin
+ while Good_ALI_Present loop
+ ALI := Get_Next_Good_ALI;
+ Source_Index := Unit_Index_Of (ALIs.Table (ALI).Afile);
+
+ -- If we are processing the library file corresponding to the
+ -- main source file check if this source can be a main unit.
+
+ if ALIs.Table (ALI).Sfile = Main_Source
+ and then Source_Index = Main_Index
+ then
+ Main_Unit := ALIs.Table (ALI).Main_Program /= None;
+ end if;
+
+ -- The following adds the standard library (s-stalib) to the list
+ -- of files to be handled by gnatmake: this file and any files it
+ -- depends on are always included in every bind, even if they are
+ -- not in the explicit dependency list. Of course, it is not added
+ -- if Suppress_Standard_Library is True.
+
+ -- However, to avoid annoying output about s-stalib.ali being read
+ -- only, when "-v" is used, we add the standard library only when
+ -- "-a" is used.
+
+ if Need_To_Check_Standard_Library then
+ Check_Standard_Library;
+ end if;
+
+ -- Now insert in the Q the unmarked source files (i.e. those which
+ -- have never been inserted in the Q and hence never considered).
+ -- Only do that if Unique_Compile is False.
+
+ if not Unique_Compile then
+ for J in
+ ALIs.Table (ALI).First_Unit .. ALIs.Table (ALI).Last_Unit
+ loop
+ for K in
+ Units.Table (J).First_With .. Units.Table (J).Last_With
+ loop
+ Sfile := Withs.Table (K).Sfile;
+ Uname := Withs.Table (K).Uname;
+
+ -- If project files are used, find the proper source to
+ -- compile in case Sfile is the spec but there is a body.
+
+ if Main_Project /= No_Project then
+ Get_Name_String (Uname);
+ Name_Len := Name_Len - 2;
+ Unit_Name := Name_Find;
+ Uid :=
+ Units_Htable.Get (Project_Tree.Units_HT, Unit_Name);
+
+ if Uid /= Prj.No_Unit_Index then
+ if Uid.File_Names (Impl) /= null
+ and then not Uid.File_Names (Impl).Locally_Removed
+ then
+ Sfile := Uid.File_Names (Impl).File;
+ Source_Index := Uid.File_Names (Impl).Index;
+
+ elsif Uid.File_Names (Spec) /= null
+ and then not Uid.File_Names (Spec).Locally_Removed
+ then
+ Sfile := Uid.File_Names (Spec).File;
+ Source_Index := Uid.File_Names (Spec).Index;
+ end if;
+ end if;
+ end if;
+
+ Dependencies.Append ((ALIs.Table (ALI).Sfile, Sfile));
+
+ if Is_In_Obsoleted (Sfile) then
+ Executable_Obsolete := True;
+ end if;
+
+ if Sfile = No_File then
+ Debug_Msg ("Skipping generic:", Withs.Table (K).Uname);
+
+ else
+ Source_Index := Unit_Index_Of (Withs.Table (K).Afile);
+
+ if Is_Marked (Sfile, Source_Index) then
+ Debug_Msg ("Skipping marked file:", Sfile);
+
+ elsif not Check_Readonly_Files
+ and then Is_Internal_File_Name (Sfile, False)
+ then
+ Debug_Msg ("Skipping internal file:", Sfile);
+
+ else
+ Insert_Q
+ (Sfile, Withs.Table (K).Uname, Source_Index);
+ Mark (Sfile, Source_Index);
+ end if;
+ end if;
+ end loop;
+ end loop;
+ end if;
+ end loop;
+ end Fill_Queue_From_ALI_Files;
+
----------------------
-- Get_Mapping_File --
----------------------
procedure Get_Mapping_File (Project : Project_Id) is
+ Data : Project_Compilation_Access;
+
begin
+ Data := Project_Compilation_Htable.Get (Project_Compilation, Project);
+
-- If there is a mapping file ready to be reused, reuse it
- if Last_Free_Indices (Project) > 0 then
- Mfile := The_Free_Mapping_File_Indices
- (Project, Last_Free_Indices (Project));
- Last_Free_Indices (Project) := Last_Free_Indices (Project) - 1;
+ if Data.Last_Free_Indices > 0 then
+ Mfile := Data.Free_Mapping_File_Indices (Data.Last_Free_Indices);
+ Data.Last_Free_Indices := Data.Last_Free_Indices - 1;
-- Otherwise, create and initialize a new one
else
- Init_Mapping_File (Project => Project, File_Index => Mfile);
+ Init_Mapping_File
+ (Project => Project, Data => Data.all, File_Index => Mfile);
end if;
-- Put the name in the mapping file argument for the invocation
Free (Mapping_File_Arg);
Mapping_File_Arg :=
new String'("-gnatem=" &
- Get_Name_String
- (The_Mapping_File_Names (Project, Mfile)));
-
+ Get_Name_String (Data.Mapping_File_Names (Mfile)));
end Get_Mapping_File;
-----------------------
return Good_ALI.First <= Good_ALI.Last;
end Good_ALI_Present;
+ --------------------------------
+ -- Must_Exit_Because_Of_Error --
+ --------------------------------
+
+ function Must_Exit_Because_Of_Error return Boolean is
+ Data : Compilation_Data;
+ Success : Boolean;
+
+ begin
+ if Bad_Compilation_Count > 0 and then not Keep_Going then
+ while Outstanding_Compiles > 0 loop
+ Await_Compile (Data, Success);
+
+ if not Success then
+ Record_Failure (Data.Full_Source_File, Data.Source_Unit);
+ end if;
+ end loop;
+
+ return True;
+ end if;
+
+ return False;
+ end Must_Exit_Because_Of_Error;
+
--------------------
-- Record_Failure --
--------------------
Good_ALI.Table (Good_ALI.Last) := A;
end Record_Good_ALI;
- -- Start of processing for Compile_Sources
+ -------------------------------
+ -- Start_Compile_If_Possible --
+ -------------------------------
- begin
- pragma Assert (Args'First = 1);
+ function Start_Compile_If_Possible
+ (Args : Argument_List) return Boolean
+ is
+ In_Lib_Dir : Boolean;
+ Need_To_Compile : Boolean;
+ Pid : Process_Id;
+ Process_Created : Boolean;
- Outstanding_Compiles := 0;
- Running_Compile := new Comp_Data_Arr (1 .. Max_Process);
+ Source_File : File_Name_Type;
+ Full_Source_File : File_Name_Type;
+ Source_File_Attr : aliased File_Attributes;
+ -- The full name of the source file and its attributes (size, ...)
- -- Package and Queue initializations
+ Source_Unit : Unit_Name_Type;
+ Source_Index : Int;
+ -- Index of the current unit in the current source file
- Good_ALI.Init;
+ Lib_File : File_Name_Type;
+ Full_Lib_File : File_Name_Type;
+ Lib_File_Attr : aliased File_Attributes;
+ Read_Only : Boolean := False;
+ ALI : ALI_Id;
+ -- The ALI file and its attributes (size, stamp, ...)
- if First_Q_Initialization then
- Init_Q;
- end if;
+ Obj_File : File_Name_Type;
+ Obj_Stamp : Time_Stamp_Type;
+ -- The object file
- if Initialize_ALI_Data then
- Initialize_ALI;
- Initialize_ALI_Source;
- end if;
+ begin
+ if not Empty_Q and then Outstanding_Compiles < Max_Process then
+ Extract_From_Q (Source_File, Source_Unit, Source_Index);
- -- The following two flags affect the behavior of ALI.Set_Source_Table.
- -- We set Check_Source_Files to True to ensure that source file
- -- time stamps are checked, and we set All_Sources to False to
- -- avoid checking the presence of the source files listed in the
- -- source dependency section of an ali file (which would be a mistake
- -- since the ali file may be obsolete).
+ Osint.Full_Source_Name
+ (Source_File,
+ Full_File => Full_Source_File,
+ Attr => Source_File_Attr'Access);
- Check_Source_Files := True;
- All_Sources := False;
+ Lib_File := Osint.Lib_File_Name (Source_File, Source_Index);
- -- Only insert in the Q if it is not already done, to avoid simultaneous
- -- compilations if -jnnn is used.
+ -- ??? This call could be avoided when using projects, since we
+ -- know where the ALI file is supposed to be. That would avoid
+ -- searches in the object directories, including in the runtime
+ -- dir. However, that would require getting access to the
+ -- Source_Id.
- if not Is_Marked (Main_Source, Main_Index) then
- Insert_Q (Main_Source, Index => Main_Index);
- Mark (Main_Source, Main_Index);
- end if;
+ Osint.Full_Lib_File_Name
+ (Lib_File,
+ Lib_File => Full_Lib_File,
+ Attr => Lib_File_Attr);
- First_Compiled_File := No_File;
- Most_Recent_Obj_File := No_File;
- Most_Recent_Obj_Stamp := Empty_Time_Stamp;
- Main_Unit := False;
+ -- If source has already been compiled, executable is obsolete
- -- Keep looping until there is no more work to do (the Q is empty)
- -- and all the outstanding compilations have terminated
-
- Make_Loop : while not Empty_Q or else Outstanding_Compiles > 0 loop
+ if Is_In_Obsoleted (Source_File) then
+ Executable_Obsolete := True;
+ end if;
- -- If the user does not want to keep going in case of errors then
- -- wait for the remaining outstanding compiles and then exit.
+ In_Lib_Dir := Full_Lib_File /= No_File
+ and then In_Ada_Lib_Dir (Full_Lib_File);
- if Bad_Compilation_Count > 0 and then not Keep_Going then
- while Outstanding_Compiles > 0 loop
- Await_Compile
- (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
+ -- Since the following requires a system call, we precompute it
+ -- when needed.
- if not Compilation_OK then
- Record_Failure (Full_Source_File, Source_Unit);
+ if not In_Lib_Dir then
+ if Full_Lib_File /= No_File
+ and then not Check_Readonly_Files
+ then
+ Get_Name_String (Full_Lib_File);
+ Name_Buffer (Name_Len + 1) := ASCII.NUL;
+ Read_Only := not Is_Writable_File
+ (Name_Buffer'Address, Lib_File_Attr'Access);
+ else
+ Read_Only := False;
end if;
- end loop;
+ end if;
- exit Make_Loop;
- end if;
+ -- If the library file is an Ada library skip it
- -- PHASE 1: Check if there is more work that we can do (i.e. the Q
- -- is non empty). If there is, do it only if we have not yet used
- -- up all the available processes.
+ if In_Lib_Dir then
+ Verbose_Msg
+ (Lib_File,
+ "is in an Ada library",
+ Prefix => " ",
+ Minimum_Verbosity => Opt.High);
- if not Empty_Q and then Outstanding_Compiles < Max_Process then
- declare
- Source_Index : Int;
- -- Index of the current unit in the current source file
+ -- If the library file is a read-only library skip it, but only
+ -- if, when using project files, this library file is in the
+ -- right object directory (a read-only ALI file in the object
+ -- directory of a project being extended must not be skipped).
- begin
- Extract_From_Q (Source_File, Source_Unit, Source_Index);
- Full_Source_File := Osint.Full_Source_Name (Source_File);
- Lib_File := Osint.Lib_File_Name
- (Source_File, Source_Index);
- Full_Lib_File := Osint.Full_Lib_File_Name (Lib_File);
+ elsif Read_Only
+ and then Is_In_Object_Directory (Source_File, Full_Lib_File)
+ then
+ Verbose_Msg
+ (Lib_File,
+ "is a read-only library",
+ Prefix => " ",
+ Minimum_Verbosity => Opt.High);
- -- If this source has already been compiled, the executable is
- -- obsolete.
+ -- The source file that we are checking cannot be located
- if Is_In_Obsoleted (Source_File) then
- Executable_Obsolete := True;
- end if;
+ elsif Full_Source_File = No_File then
+ Record_Failure (Source_File, Source_Unit, False);
- -- If the library file is an Ada library skip it
+ -- Source and library files can be located but are internal
+ -- files.
- if Full_Lib_File /= No_File
- and then In_Ada_Lib_Dir (Full_Lib_File)
- then
- Verbose_Msg
- (Lib_File,
- "is in an Ada library",
- Prefix => " ",
- Minimum_Verbosity => Opt.High);
-
- -- If the library file is a read-only library skip it, but
- -- only if, when using project files, this library file is
- -- in the right object directory (a read-only ALI file
- -- in the object directory of a project being extended
- -- should not be skipped).
-
- elsif Full_Lib_File /= No_File
- and then not Check_Readonly_Files
- and then Is_Readonly_Library (Full_Lib_File)
- and then Is_In_Object_Directory (Source_File, Full_Lib_File)
- then
- Verbose_Msg
- (Lib_File,
- "is a read-only library",
- Prefix => " ",
- Minimum_Verbosity => Opt.High);
+ elsif not Check_Readonly_Files
+ and then Full_Lib_File /= No_File
+ and then Is_Internal_File_Name (Source_File, False)
+ then
+ if Force_Compilations then
+ Fail
+ ("not allowed to compile """ &
+ Get_Name_String (Source_File) &
+ """; use -a switch, or compile file with " &
+ """-gnatg"" switch");
+ end if;
+
+ Verbose_Msg
+ (Lib_File,
+ "is an internal library",
+ Prefix => " ",
+ Minimum_Verbosity => Opt.High);
- -- The source file that we are checking cannot be located
+ -- The source file that we are checking can be located
- elsif Full_Source_File = No_File then
- Record_Failure (Source_File, Source_Unit, False);
+ else
+ Collect_Arguments (Source_File, Source_Index,
+ Source_File = Main_Source, Args);
- -- Source and library files can be located but are internal
- -- files
+ -- Do nothing if project of source is externally built
- elsif not Check_Readonly_Files
- and then Full_Lib_File /= No_File
- and then Is_Internal_File_Name (Source_File, False)
+ if Arguments_Project = No_Project
+ or else not Arguments_Project.Externally_Built
then
- if Force_Compilations then
- Fail
- ("not allowed to compile """ &
- Get_Name_String (Source_File) &
- """; use -a switch, or compile file with " &
- """-gnatg"" switch");
+ -- Don't waste any time if we have to recompile anyway
+
+ Obj_Stamp := Empty_Time_Stamp;
+ Need_To_Compile := Force_Compilations;
+
+ if not Force_Compilations then
+ Check (Source_File => Source_File,
+ Source_Index => Source_Index,
+ Is_Main_Source => Source_File = Main_Source,
+ The_Args => Args,
+ Lib_File => Lib_File,
+ Full_Lib_File => Full_Lib_File,
+ Lib_File_Attr => Lib_File_Attr'Access,
+ Read_Only => Read_Only,
+ ALI => ALI,
+ O_File => Obj_File,
+ O_Stamp => Obj_Stamp);
+ Need_To_Compile := (ALI = No_ALI_Id);
end if;
- Verbose_Msg
- (Lib_File,
- "is an internal library",
- Prefix => " ",
- Minimum_Verbosity => Opt.High);
+ if not Need_To_Compile then
- -- The source file that we are checking can be located
+ -- The ALI file is up-to-date; record its Id
- else
- Arguments_Collected := False;
-
- Collect_Arguments (Source_File, Source_Index,
- Source_File = Main_Source, Args);
+ Record_Good_ALI (ALI);
- -- Do nothing if project of source is externally built
+ -- Record the time stamp of the most recent object
+ -- file as long as no (re)compilations are needed.
- if Arguments_Project = No_Project
- or else not Project_Tree.Projects.Table
- (Arguments_Project).Externally_Built
- then
- -- Don't waste any time if we have to recompile anyway
-
- Obj_Stamp := Empty_Time_Stamp;
- Need_To_Compile := Force_Compilations;
-
- if not Force_Compilations then
- Read_Only :=
- Full_Lib_File /= No_File
- and then not Check_Readonly_Files
- and then Is_Readonly_Library (Full_Lib_File);
- Check (Source_File, Source_Index,
- Source_File = Main_Source, Args, Lib_File,
- Read_Only, ALI, Obj_File, Obj_Stamp);
- Need_To_Compile := (ALI = No_ALI_Id);
+ if First_Compiled_File = No_File
+ and then (Most_Recent_Obj_File = No_File
+ or else Obj_Stamp > Most_Recent_Obj_Stamp)
+ then
+ Most_Recent_Obj_File := Obj_File;
+ Most_Recent_Obj_Stamp := Obj_Stamp;
end if;
- if not Need_To_Compile then
- -- The ALI file is up-to-date. Record its Id
-
- Record_Good_ALI (ALI);
-
- -- Record the time stamp of the most recent object
- -- file as long as no (re)compilations are needed.
+ else
+ -- Check that switch -x has been used if a source outside
+ -- of project files need to be compiled.
- if First_Compiled_File = No_File
- and then (Most_Recent_Obj_File = No_File
- or else Obj_Stamp > Most_Recent_Obj_Stamp)
- then
- Most_Recent_Obj_File := Obj_File;
- Most_Recent_Obj_Stamp := Obj_Stamp;
- end if;
+ if Main_Project /= No_Project
+ and then Arguments_Project = No_Project
+ and then not External_Unit_Compilation_Allowed
+ then
+ Make_Failed ("external source ("
+ & Get_Name_String (Source_File)
+ & ") is not part of any project;"
+ & " cannot be compiled without"
+ & " gnatmake switch -x");
+ end if;
- else
- -- Check that switch -x has been used if a source
- -- outside of project files need to be compiled.
+ -- Is this the first file we have to compile?
- if Main_Project /= No_Project
- and then Arguments_Project = No_Project
- and then not External_Unit_Compilation_Allowed
- then
- Make_Failed ("external source ("
- & Get_Name_String (Source_File)
- & ") is not part of any project;"
- & " cannot be compiled without"
- & " gnatmake switch -x");
- end if;
+ if First_Compiled_File = No_File then
+ First_Compiled_File := Full_Source_File;
+ Most_Recent_Obj_File := No_File;
- -- Is this the first file we have to compile?
+ if Do_Not_Execute then
- if First_Compiled_File = No_File then
- First_Compiled_File := Full_Source_File;
- Most_Recent_Obj_File := No_File;
+ -- Exit the main loop
- if Do_Not_Execute then
- exit Make_Loop;
- end if;
+ return True;
end if;
+ end if;
- if In_Place_Mode then
+ -- Compute where the ALI file must be generated in
+ -- In_Place_Mode (this does not require to know the
+ -- location of the object directory).
+
+ if In_Place_Mode then
+ if Full_Lib_File = No_File then
-- If the library file was not found, then save
-- the library file near the source file.
- if Full_Lib_File = No_File then
- Lib_File := Osint.Lib_File_Name
- (Full_Source_File, Source_Index);
+ Lib_File :=
+ Osint.Lib_File_Name
+ (Full_Source_File, Source_Index);
+ Full_Lib_File := Lib_File;
- -- If the library file was found, then save the
- -- library file in the same place.
+ else
+ -- If the library file was found, then save the
+ -- library file in the same place.
+
+ Lib_File := Full_Lib_File;
+ end if;
+ end if;
+
+ -- Start the compilation and record it. We can do this
+ -- because there is at least one free process. This might
+ -- change the current directory.
+
+ Collect_Arguments_And_Compile
+ (Full_Source_File => Full_Source_File,
+ Lib_File => Lib_File,
+ Source_Index => Source_Index,
+ Pid => Pid,
+ Process_Created => Process_Created);
+
+ -- Compute where the ALI file will be generated (for
+ -- cases that might require to know the current
+ -- directory). The current directory might be changed
+ -- when compiling other files so we cannot rely on it
+ -- being the same to find the resulting ALI file.
+
+ if not In_Place_Mode then
+
+ -- Compute the expected location of the ALI file. This
+ -- can be from several places:
+ -- -i => in place mode. In such a case,
+ -- Full_Lib_File has already been set above
+ -- -D => if specified
+ -- or defaults in current dir
+ -- We could simply use a call similar to
+ -- Osint.Full_Lib_File_Name (Lib_File)
+ -- but that involves system calls and is thus slower
+
+ if Object_Directory_Path /= null then
+ Name_Len := 0;
+ Add_Str_To_Name_Buffer (Object_Directory_Path.all);
+ Add_Str_To_Name_Buffer (Get_Name_String (Lib_File));
+ Full_Lib_File := Name_Find;
+
+ else
+ if Project_Of_Current_Object_Directory /=
+ No_Project
+ then
+ Get_Name_String
+ (Project_Of_Current_Object_Directory
+ .Object_Directory.Name);
+ Add_Str_To_Name_Buffer
+ (Get_Name_String (Lib_File));
+ Full_Lib_File := Name_Find;
else
- Lib_File := Full_Lib_File;
+ Full_Lib_File := Lib_File;
end if;
-
end if;
- -- Start the compilation and record it. We can do
- -- this because there is at least one free process.
+ end if;
- Collect_Arguments_And_Compile
- (Source_File, Source_Index);
+ Lib_File_Attr := Unknown_Attributes;
- -- Make sure we could successfully start
- -- the Compilation.
+ -- Make sure we could successfully start the compilation
- if Process_Created then
- if Pid = Invalid_Pid then
- Record_Failure (Full_Source_File, Source_Unit);
- else
- Add_Process
- (Pid,
- Full_Source_File,
- Lib_File,
- Source_Unit,
- Mfile);
- end if;
+ if Process_Created then
+ if Pid = Invalid_Pid then
+ Record_Failure (Full_Source_File, Source_Unit);
+ else
+ Add_Process
+ (Pid => Pid,
+ Sfile => Full_Source_File,
+ Afile => Lib_File,
+ Uname => Source_Unit,
+ Mfile => Mfile,
+ Full_Lib_File => Full_Lib_File,
+ Lib_File_Attr => Lib_File_Attr);
end if;
end if;
end if;
end if;
- end;
+ end if;
end if;
+ return False;
+ end Start_Compile_If_Possible;
+
+ -----------------------------
+ -- Wait_For_Available_Slot --
+ -----------------------------
- -- PHASE 2: Now check if we should wait for a compilation to
- -- finish. This is the case if all the available processes are
- -- busy compiling sources or there is nothing else to do
- -- (that is the Q is empty and there are no good ALIs to process).
+ procedure Wait_For_Available_Slot is
+ Compilation_OK : Boolean;
+ Text : Text_Buffer_Ptr;
+ ALI : ALI_Id;
+ Data : Compilation_Data;
+ begin
if Outstanding_Compiles = Max_Process
or else (Empty_Q
and then not Good_ALI_Present
and then Outstanding_Compiles > 0)
then
- Await_Compile
- (Full_Source_File, Lib_File, Source_Unit, Compilation_OK);
+ Await_Compile (Data, Compilation_OK);
if not Compilation_OK then
- Record_Failure (Full_Source_File, Source_Unit);
+ Record_Failure (Data.Full_Source_File, Data.Source_Unit);
end if;
if Compilation_OK or else Keep_Going then
Check_Object_Consistency;
begin
- -- If compilation was not OK, or if output is not an
- -- object file and we don't do the bind step, don't check
- -- for object consistency.
+ -- If compilation was not OK, or if output is not an object
+ -- file and we don't do the bind step, don't check for
+ -- object consistency.
Check_Object_Consistency :=
Check_Object_Consistency
- and Compilation_OK
- and (Output_Is_Object or Do_Bind_Step);
- Text := Read_Library_Info (Lib_File);
+ and Compilation_OK
+ and (Output_Is_Object or Do_Bind_Step);
+
+ Text :=
+ Read_Library_Info_From_Full
+ (Data.Full_Lib_File, Data.Lib_File_Attr'Access);
-- Restore Check_Object_Consistency to its initial value
Check_Object_Consistency := Saved_Object_Consistency;
end;
- -- If an ALI file was generated by this compilation, scan
- -- the ALI file and record it.
+ -- If an ALI file was generated by this compilation, scan the
+ -- ALI file and record it.
-- If the scan fails, a previous ali file is inconsistent with
-- the unit just compiled.
if Text /= null then
ALI :=
- Scan_ALI (Lib_File, Text, Ignore_ED => False, Err => True);
+ Scan_ALI
+ (Data.Lib_File, Text, Ignore_ED => False, Err => True);
if ALI = No_ALI_Id then
if Compilation_OK then
Inform
- (Lib_File,
+ (Data.Lib_File,
"incompatible ALI file, please recompile");
- Record_Failure (Full_Source_File, Source_Unit);
+ Record_Failure
+ (Data.Full_Source_File, Data.Source_Unit);
end if;
+
else
- Free (Text);
Record_Good_ALI (ALI);
end if;
+ Free (Text);
+
-- If we could not read the ALI file that was just generated
-- then there could be a problem reading either the ALI or the
-- corresponding object file (if Check_Object_Consistency is
else
if Compilation_OK and not Syntax_Only then
Inform
- (Lib_File,
+ (Data.Lib_File,
"WARNING: ALI or object file not found after compile");
- Record_Failure (Full_Source_File, Source_Unit);
+ Record_Failure (Data.Full_Source_File, Data.Source_Unit);
end if;
end if;
end if;
end if;
+ end Wait_For_Available_Slot;
- -- PHASE 3: Check if we recorded good ALI files. If yes process
- -- them now in the order in which they have been recorded. There
- -- are two occasions in which we record good ali files. The first is
- -- in phase 1 when, after scanning an existing ALI file we realize
- -- it is up-to-date, the second instance is after a successful
- -- compilation.
-
- while Good_ALI_Present loop
- ALI := Get_Next_Good_ALI;
-
- declare
- Source_Index : Int := Unit_Index_Of (ALIs.Table (ALI).Afile);
-
- begin
- -- If we are processing the library file corresponding to the
- -- main source file check if this source can be a main unit.
+ -- Start of processing for Compile_Sources
- if ALIs.Table (ALI).Sfile = Main_Source and then
- Source_Index = Main_Index
- then
- Main_Unit := ALIs.Table (ALI).Main_Program /= None;
- end if;
+ begin
+ pragma Assert (Args'First = 1);
- -- The following adds the standard library (s-stalib) to the
- -- list of files to be handled by gnatmake: this file and any
- -- files it depends on are always included in every bind,
- -- even if they are not in the explicit dependency list.
- -- Of course, it is not added if Suppress_Standard_Library
- -- is True.
+ Outstanding_Compiles := 0;
+ Running_Compile := new Comp_Data_Arr (1 .. Max_Process);
- -- However, to avoid annoying output about s-stalib.ali being
- -- read only, when "-v" is used, we add the standard library
- -- only when "-a" is used.
+ -- Package and Queue initializations
- if Need_To_Check_Standard_Library then
- Check_Standard_Library;
- end if;
+ Good_ALI.Init;
- -- Now insert in the Q the unmarked source files (i.e. those
- -- which have never been inserted in the Q and hence never
- -- considered). Only do that if Unique_Compile is False.
+ if First_Q_Initialization then
+ Init_Q;
+ end if;
- if not Unique_Compile then
- for J in
- ALIs.Table (ALI).First_Unit .. ALIs.Table (ALI).Last_Unit
- loop
- for K in
- Units.Table (J).First_With .. Units.Table (J).Last_With
- loop
- Sfile := Withs.Table (K).Sfile;
- Uname := Withs.Table (K).Uname;
+ if Initialize_ALI_Data then
+ Initialize_ALI;
+ Initialize_ALI_Source;
+ end if;
- -- If project files are used, find the proper source
- -- to compile, in case Sfile is the spec, but there
- -- is a body.
+ -- The following two flags affect the behavior of ALI.Set_Source_Table.
+ -- We set Check_Source_Files to True to ensure that source file time
+ -- stamps are checked, and we set All_Sources to False to avoid checking
+ -- the presence of the source files listed in the source dependency
+ -- section of an ali file (which would be a mistake since the ali file
+ -- may be obsolete).
- if Main_Project /= No_Project then
- declare
- Unit_Name : Name_Id;
- Uid : Prj.Unit_Index;
- Udata : Unit_Data;
+ Check_Source_Files := True;
+ All_Sources := False;
- begin
- Get_Name_String (Uname);
- Name_Len := Name_Len - 2;
- Unit_Name := Name_Find;
- Uid :=
- Units_Htable.Get
- (Project_Tree.Units_HT, Unit_Name);
-
- if Uid /= Prj.No_Unit_Index then
- Udata := Project_Tree.Units.Table (Uid);
-
- if
- Udata.File_Names (Body_Part).Name /=
- No_File
- and then
- Udata.File_Names (Body_Part).Path.Name /=
- Slash
- then
- Sfile := Udata.File_Names (Body_Part).Name;
- Source_Index :=
- Udata.File_Names (Body_Part).Index;
-
- elsif
- Udata.File_Names (Specification).Name /=
- No_File
- and then
- Udata.File_Names
- (Specification).Path.Name /= Slash
- then
- Sfile :=
- Udata.File_Names (Specification).Name;
- Source_Index :=
- Udata.File_Names (Specification).Index;
- end if;
- end if;
- end;
- end if;
+ -- Only insert in the Q if it is not already done, to avoid simultaneous
+ -- compilations if -jnnn is used.
- Dependencies.Append ((ALIs.Table (ALI).Sfile, Sfile));
+ if not Is_Marked (Main_Source, Main_Index) then
+ Insert_Q (Main_Source, Index => Main_Index);
+ Mark (Main_Source, Main_Index);
+ end if;
- if Is_In_Obsoleted (Sfile) then
- Executable_Obsolete := True;
- end if;
+ First_Compiled_File := No_File;
+ Most_Recent_Obj_File := No_File;
+ Most_Recent_Obj_Stamp := Empty_Time_Stamp;
+ Main_Unit := False;
- if Sfile = No_File then
- Debug_Msg
- ("Skipping generic:", Withs.Table (K).Uname);
+ -- Keep looping until there is no more work to do (the Q is empty)
+ -- and all the outstanding compilations have terminated.
- else
- Source_Index :=
- Unit_Index_Of (Withs.Table (K).Afile);
+ Make_Loop : while not Empty_Q or else Outstanding_Compiles > 0 loop
+ exit Make_Loop when Must_Exit_Because_Of_Error;
+ exit Make_Loop when Start_Compile_If_Possible (Args);
- if Is_Marked (Sfile, Source_Index) then
- Debug_Msg ("Skipping marked file:", Sfile);
+ Wait_For_Available_Slot;
- elsif not Check_Readonly_Files
- and then Is_Internal_File_Name (Sfile, False)
- then
- Debug_Msg ("Skipping internal file:", Sfile);
+ -- ??? Should be done as soon as we add a Good_ALI, wouldn't it avoid
+ -- the need for a list of good ALI?
- else
- Insert_Q
- (Sfile, Withs.Table (K).Uname, Source_Index);
- Mark (Sfile, Source_Index);
- end if;
- end if;
- end loop;
- end loop;
- end if;
- end;
- end loop;
+ Fill_Queue_From_ALI_Files;
if Display_Compilation_Progress then
Write_Str ("completed ");
end if;
end Compile_Sources;
- -----------------------------------
- -- Compute_All_Imported_Projects --
- -----------------------------------
-
- procedure Compute_All_Imported_Projects (Project : Project_Id) is
- procedure Add_To_List (Prj : Project_Id);
- -- Add a project to the list All_Imported_Projects of project Project
-
- procedure Recursive_Add_Imported (Project : Project_Id);
- -- Recursively add the projects imported by project Project, but not
- -- those that are extended.
-
- -----------------
- -- Add_To_List --
- -----------------
-
- procedure Add_To_List (Prj : Project_Id) is
- Element : constant Project_Element :=
- (Prj, Project_Tree.Projects.Table (Project).All_Imported_Projects);
- List : Project_List;
- begin
- Project_List_Table.Increment_Last (Project_Tree.Project_Lists);
- List := Project_List_Table.Last (Project_Tree.Project_Lists);
- Project_Tree.Project_Lists.Table (List) := Element;
- Project_Tree.Projects.Table (Project).All_Imported_Projects := List;
- end Add_To_List;
-
- ----------------------------
- -- Recursive_Add_Imported --
- ----------------------------
-
- procedure Recursive_Add_Imported (Project : Project_Id) is
- List : Project_List;
- Element : Project_Element;
- Prj : Project_Id;
-
- begin
- if Project /= No_Project then
-
- -- For all the imported projects
-
- List := Project_Tree.Projects.Table (Project).Imported_Projects;
- while List /= Empty_Project_List loop
- Element := Project_Tree.Project_Lists.Table (List);
- Prj := Element.Project;
-
- -- Get the ultimate extending project
-
- while
- Project_Tree.Projects.Table (Prj).Extended_By /= No_Project
- loop
- Prj := Project_Tree.Projects.Table (Prj).Extended_By;
- end loop;
-
- -- If project has not yet been visited, add to list and recurse
-
- if not Project_Tree.Projects.Table (Prj).Seen then
- Project_Tree.Projects.Table (Prj).Seen := True;
- Add_To_List (Prj);
- Recursive_Add_Imported (Prj);
- end if;
-
- List := Element.Next;
- end loop;
-
- -- Recurse on projects being imported, if any
-
- Recursive_Add_Imported
- (Project_Tree.Projects.Table (Project).Extends);
- end if;
- end Recursive_Add_Imported;
-
- begin
- -- Reset the Seen flag for all projects
-
- for Index in 1 .. Project_Table.Last (Project_Tree.Projects) loop
- Project_Tree.Projects.Table (Index).Seen := False;
- end loop;
-
- -- Make sure the list is empty
-
- Project_Tree.Projects.Table (Project).All_Imported_Projects :=
- Empty_Project_List;
-
- -- Add to the list all projects imported directly or indirectly
-
- Recursive_Add_Imported (Project);
- end Compute_All_Imported_Projects;
-
----------------------------------
-- Configuration_Pragmas_Switch --
----------------------------------
else
declare
Parent_Directory : constant String :=
- Get_Name_String
- (Project_Tree.Projects.Table
- (Project).Directory.Display_Name);
+ Get_Name_String (Project.Directory.Display_Name);
begin
if Parent_Directory (Parent_Directory'Last) =
begin
Prj.Env.Create_Config_Pragmas_File
- (For_Project, Main_Project, Project_Tree);
+ (For_Project, Project_Tree);
- if Project_Tree.Projects.Table
- (For_Project).Config_File_Name /= No_Path
- then
- Temporary_Config_File :=
- Project_Tree.Projects.Table (For_Project).Config_File_Temp;
+ if For_Project.Config_File_Name /= No_Path then
+ Temporary_Config_File := For_Project.Config_File_Temp;
Last := 1;
Result (1) :=
new String'
- ("-gnatec=" &
- Get_Name_String
- (Project_Tree.Projects.Table
- (For_Project).Config_File_Name));
+ ("-gnatec=" & Get_Name_String (For_Project.Config_File_Name));
else
Temporary_Config_File := False;
-- Check for attribute Builder'Global_Configuration_Pragmas
- The_Packages := Project_Tree.Projects.Table
- (Main_Project).Decl.Packages;
+ The_Packages := Main_Project.Decl.Packages;
Gnatmake :=
Prj.Util.Value_Of
(Name => Name_Builder,
-- Check for attribute Compiler'Local_Configuration_Pragmas
- The_Packages :=
- Project_Tree.Projects.Table (For_Project).Decl.Packages;
+ The_Packages := For_Project.Decl.Packages;
Compiler :=
Prj.Util.Value_Of
(Name => Name_Compiler,
procedure Delete_All_Temp_Files is
begin
if not Debug.Debug_Flag_N then
- Delete_Mapping_Files;
Delete_Temp_Config_Files;
- Prj.Env.Delete_All_Path_Files (Project_Tree);
+ Prj.Delete_All_Temp_Files (Project_Tree);
end if;
end Delete_All_Temp_Files;
- --------------------------
- -- Delete_Mapping_Files --
- --------------------------
-
- procedure Delete_Mapping_Files is
- Success : Boolean;
- pragma Warnings (Off, Success);
-
- begin
- -- The caller is responsible for ensuring that Debug_Flag_N is False
-
- pragma Assert (not Debug.Debug_Flag_N);
-
- if The_Mapping_File_Names /= null then
- for Project in The_Mapping_File_Names'Range (1) loop
- for Index in 1 .. Last_Mapping_File_Names (Project) loop
- Delete_File
- (Name => Get_Name_String
- (The_Mapping_File_Names (Project, Index)),
- Success => Success);
- end loop;
- end loop;
- end if;
- end Delete_Mapping_Files;
-
------------------------------
-- Delete_Temp_Config_Files --
------------------------------
procedure Delete_Temp_Config_Files is
Success : Boolean;
+ Proj : Project_List;
pragma Warnings (Off, Success);
begin
pragma Assert (not Debug.Debug_Flag_N);
if Main_Project /= No_Project then
- for Project in Project_Table.First ..
- Project_Table.Last (Project_Tree.Projects)
- loop
- if
- Project_Tree.Projects.Table (Project).Config_File_Temp
- then
- if Verbose_Mode then
- Write_Str ("Deleting temp configuration file """);
- Write_Str (Get_Name_String
- (Project_Tree.Projects.Table
- (Project).Config_File_Name));
- Write_Line ("""");
- end if;
-
- Delete_File
- (Name => Get_Name_String
- (Project_Tree.Projects.Table
- (Project).Config_File_Name),
- Success => Success);
+ Proj := Project_Tree.Projects;
+ while Proj /= null loop
+ if Proj.Project.Config_File_Temp then
+ Delete_Temporary_File
+ (Project_Tree, Proj.Project.Config_File_Name);
-- Make sure that we don't have a config file for this project,
-- in case there are several mains. In this case, we will
-- recreate another config file: we cannot reuse the one that
-- we just deleted!
- Project_Tree.Projects.Table (Project).
- Config_Checked := False;
- Project_Tree.Projects.Table (Project).
- Config_File_Name := No_Path;
- Project_Tree.Projects.Table (Project).
- Config_File_Temp := False;
+ Proj.Project.Config_Checked := False;
+ Proj.Project.Config_File_Name := No_Path;
+ Proj.Project.Config_File_Temp := False;
end if;
+ Proj := Proj.Next;
end loop;
end if;
end Delete_Temp_Config_Files;
-- Never display -gnatea nor -gnatez
- if Args (J).all /= "-gnatea" and then
- Args (J).all /= "-gnatez"
+ if Args (J).all /= "-gnatea"
+ and then
+ Args (J).all /= "-gnatez"
then
-
-- Do not display the mapping file argument automatically
-- created when using a project file.
then
Temporary_Config_File := False;
- -- Do not display the -F=mapping_file switch for
- -- gnatbind, if -dn is not specified.
+ -- Do not display the -F=mapping_file switch for gnatbind
+ -- if -dn is not specified.
elsif Debug.Debug_Flag_N
or else Args (J)'Length < 4
Total_Compilation_Failures : Natural := 0;
Is_Main_Unit : Boolean;
- -- Set to True by Compile_Sources if the Main_Source_File can be a
- -- main unit.
+ -- Set True by Compile_Sources if Main_Source_File can be a main unit
Main_ALI_File : File_Name_Type;
-- The ali file corresponding to Main_Source_File
-- The file name of an executable
Non_Std_Executable : Boolean := False;
- -- Non_Std_Executable is set to True when there is a possibility
- -- that the linker will not choose the correct executable file name.
+ -- Non_Std_Executable is set to True when there is a possibility that
+ -- the linker will not choose the correct executable file name.
Current_Work_Dir : constant String_Access :=
new String'(Get_Current_Dir);
Current_Main_Index : Int := 0;
-- If not zero, the index of the current main unit in its source file
- There_Are_Stand_Alone_Libraries : Boolean := False;
+ Stand_Alone_Libraries : Boolean := False;
-- Set to True when there are Stand-Alone Libraries, so that gnatbind
-- is invoked with the -F switch to force checking of elaboration flags.
Mapping_Path : Path_Name_Type := No_Path;
-- The path name of the mapping file
+ Project_Node_Tree : Project_Node_Tree_Ref;
+
Discard : Boolean;
pragma Warnings (Off, Discard);
Proj : Project_Id := No_Project;
-- The project of the current main
- Data : Project_Data;
-
Real_Path : String_Access;
begin
loop
declare
Main : constant String := Mains.Next_Main;
- -- The name specified on the command line may include
- -- directory information.
+ -- The name specified on the command line may include directory
+ -- information.
File_Name : constant String := Base_Name (Main);
-- The simple file name of the current main
+ Lang : Language_Ptr;
+
begin
exit when Main = "";
Proj := Prj.Env.Project_Of
(File_Name, Main_Project, Project_Tree);
- -- Fail if the current main is not a source of a
- -- project.
+ -- Fail if the current main is not a source of a project
if Proj = No_Project then
Make_Failed
("""" & Main & """ is not a source of any project");
else
- -- If there is directory information, check that
- -- the source exists and, if it does, that the path
- -- is the actual path of a source of a project.
+ -- If there is directory information, check that the source
+ -- exists and, if it does, that the path is the actual path
+ -- of a source of a project.
if Main /= File_Name then
- Data :=
- Project_Tree.Projects.Table (Main_Project);
+ Lang := Get_Language_From_Name (Main_Project, "ada");
Real_Path :=
Locate_Regular_File
- (Main &
- Body_Suffix_Of (Project_Tree, "ada", Data.Naming),
+ (Main & Get_Name_String
+ (Lang.Config.Naming_Data.Body_Suffix),
"");
if Real_Path = null then
Real_Path :=
Locate_Regular_File
- (Main &
- Spec_Suffix_Of (Project_Tree, "ada", Data.Naming),
+ (Main & Get_Name_String
+ (Lang.Config.Naming_Data.Spec_Suffix),
"");
end if;
if Real_Path = null then
- Real_Path :=
- Locate_Regular_File (Main, "");
+ Real_Path := Locate_Regular_File (Main, "");
end if;
-- Fail if the file cannot be found
elsif Proj /= Real_Main_Project then
- -- Fail, as the current main is not a source
- -- of the same project as the first main.
+ -- Fail, as the current main is not a source of the
+ -- same project as the first main.
Make_Failed
("""" & Main &
""" is not a source of project " &
- Get_Name_String
- (Project_Tree.Projects.Table
- (Real_Main_Project).Name));
+ Get_Name_String (Real_Main_Project.Name));
end if;
end if;
end if;
- -- If -u and -U are not used, we may have mains that
- -- are sources of a project that is not the one
- -- specified with switch -P.
+ -- If -u and -U are not used, we may have mains that are
+ -- sources of a project that is not the one specified with
+ -- switch -P.
if not Unique_Compile then
Main_Project := Real_Main_Project;
Bytes : Integer;
OK : Boolean := True;
+ Unit : Unit_Index;
Status : Boolean;
-- For call to Close
begin
Tempdir.Create_Temp_File (Mapping_FD, Mapping_Path);
- Record_Temp_File (Mapping_Path);
+ Record_Temp_File (Project_Tree, Mapping_Path);
if Mapping_FD /= Invalid_FD then
-- Traverse all units
- for J in Unit_Table.First ..
- Unit_Table.Last (Project_Tree.Units)
- loop
- declare
- Unit : constant Unit_Data := Project_Tree.Units.Table (J);
- begin
- if Unit.Name /= No_Name then
+ Unit := Units_Htable.Get_First (Project_Tree.Units_HT);
- -- If there is a body, put it in the mapping
+ while Unit /= No_Unit_Index loop
+ if Unit.Name /= No_Name then
- if Unit.File_Names (Body_Part).Name /= No_File
- and then Unit.File_Names (Body_Part).Project /=
- No_Project
- then
- Get_Name_String (Unit.Name);
- Name_Buffer (Name_Len + 1 .. Name_Len + 2) := "%b";
- Name_Len := Name_Len + 2;
- ALI_Unit := Name_Find;
- ALI_Name :=
- Lib_File_Name
- (Unit.File_Names (Body_Part).Display_Name);
- ALI_Project :=
- Unit.File_Names (Body_Part).Project;
-
- -- Otherwise, if there is a spec, put it
- -- in the mapping.
-
- elsif Unit.File_Names (Specification).Name /= No_File
- and then Unit.File_Names (Specification).Project /=
- No_Project
- then
- Get_Name_String (Unit.Name);
- Name_Buffer (Name_Len + 1 .. Name_Len + 2) := "%s";
- Name_Len := Name_Len + 2;
- ALI_Unit := Name_Find;
- ALI_Name :=
- Lib_File_Name
- (Unit.File_Names (Specification).Display_Name);
- ALI_Project :=
- Unit.File_Names (Specification).Project;
+ -- If there is a body, put it in the mapping
- else
- ALI_Name := No_File;
- end if;
+ if Unit.File_Names (Impl) /= No_Source
+ and then Unit.File_Names (Impl).Project /=
+ No_Project
+ then
+ Get_Name_String (Unit.Name);
+ Add_Str_To_Name_Buffer ("%b");
+ ALI_Unit := Name_Find;
+ ALI_Name :=
+ Lib_File_Name
+ (Unit.File_Names (Impl).Display_File);
+ ALI_Project := Unit.File_Names (Impl).Project;
+
+ -- Otherwise, if there is a spec, put it in the mapping
+
+ elsif Unit.File_Names (Spec) /= No_Source
+ and then Unit.File_Names (Spec).Project /= No_Project
+ then
+ Get_Name_String (Unit.Name);
+ Add_Str_To_Name_Buffer ("%s");
+ ALI_Unit := Name_Find;
+ ALI_Name :=
+ Lib_File_Name
+ (Unit.File_Names (Spec).Display_File);
+ ALI_Project := Unit.File_Names (Spec).Project;
- -- If we have something to put in the mapping
- -- then we do it now. However, if the project
- -- is extended, we don't put anything in the
- -- mapping file, because we do not know where
- -- the ALI file is: it might be in the ext-
- -- ended project obj dir as well as in the
- -- extending project obj dir.
-
- if ALI_Name /= No_File
- and then
- Project_Tree.Projects.Table
- (ALI_Project).Extended_By = No_Project
- and then
- Project_Tree.Projects.Table
- (ALI_Project).Extends = No_Project
- then
- -- First check if the ALI file exists. If it does not,
- -- do not put the unit in the mapping file.
+ else
+ ALI_Name := No_File;
+ end if;
- declare
- ALI : constant String :=
- Get_Name_String (ALI_Name);
- PD : Project_Data renames
- Project_Tree.Projects.Table (ALI_Project);
+ -- If we have something to put in the mapping then do it
+ -- now. However, if the project is extended, we don't put
+ -- anything in the mapping file, because we don't know where
+ -- the ALI file is: it might be in the extended project
+ -- object directory as well as in the extending project
+ -- object directory.
- begin
- -- For library projects, use the library directory,
- -- for other projects, use the object directory.
+ if ALI_Name /= No_File
+ and then ALI_Project.Extended_By = No_Project
+ and then ALI_Project.Extends = No_Project
+ then
+ -- First check if the ALI file exists. If it does not,
+ -- do not put the unit in the mapping file.
- if PD.Library then
- Get_Name_String (PD.Library_Dir.Name);
- else
- Get_Name_String (PD.Object_Directory.Name);
- end if;
+ declare
+ ALI : constant String := Get_Name_String (ALI_Name);
- if Name_Buffer (Name_Len) /=
- Directory_Separator
- then
- Name_Len := Name_Len + 1;
- Name_Buffer (Name_Len) :=
- Directory_Separator;
- end if;
+ begin
+ -- For library projects, use the library directory,
+ -- for other projects, use the object directory.
+
+ if ALI_Project.Library then
+ Get_Name_String (ALI_Project.Library_Dir.Name);
+ else
+ Get_Name_String
+ (ALI_Project.Object_Directory.Name);
+ end if;
+
+ if not
+ Is_Directory_Separator (Name_Buffer (Name_Len))
+ then
+ Add_Char_To_Name_Buffer (Directory_Separator);
+ end if;
- Name_Buffer
- (Name_Len + 1 ..
- Name_Len + ALI'Length) := ALI;
- Name_Len :=
- Name_Len + ALI'Length + 1;
- Name_Buffer (Name_Len) := ASCII.LF;
+ Add_Str_To_Name_Buffer (ALI);
+ Add_Char_To_Name_Buffer (ASCII.LF);
- declare
- ALI_Path_Name : constant String :=
- Name_Buffer (1 .. Name_Len);
+ declare
+ ALI_Path_Name : constant String :=
+ Name_Buffer (1 .. Name_Len);
- begin
- if Is_Regular_File
+ begin
+ if Is_Regular_File
(ALI_Path_Name (1 .. ALI_Path_Name'Last - 1))
- then
-
- -- First line is the unit name
-
- Get_Name_String (ALI_Unit);
- Name_Len := Name_Len + 1;
- Name_Buffer (Name_Len) := ASCII.LF;
- Bytes :=
- Write
- (Mapping_FD,
- Name_Buffer (1)'Address,
- Name_Len);
- OK := Bytes = Name_Len;
-
- exit when not OK;
-
- -- Second line it the ALI file name
-
- Get_Name_String (ALI_Name);
- Name_Len := Name_Len + 1;
- Name_Buffer (Name_Len) := ASCII.LF;
- Bytes :=
- Write
- (Mapping_FD,
- Name_Buffer (1)'Address,
- Name_Len);
- OK := Bytes = Name_Len;
-
- exit when not OK;
-
- -- Third line it the ALI path name
-
- Bytes :=
- Write
- (Mapping_FD,
- ALI_Path_Name (1)'Address,
- ALI_Path_Name'Length);
- OK := Bytes = ALI_Path_Name'Length;
-
- -- If OK is False, it means we were unable
- -- to write a line. No point in continuing
- -- with the other units.
-
- exit when not OK;
- end if;
- end;
+ then
+ -- First line is the unit name
+
+ Get_Name_String (ALI_Unit);
+ Add_Char_To_Name_Buffer (ASCII.LF);
+ Bytes :=
+ Write
+ (Mapping_FD,
+ Name_Buffer (1)'Address,
+ Name_Len);
+ OK := Bytes = Name_Len;
+
+ exit when not OK;
+
+ -- Second line it the ALI file name
+
+ Get_Name_String (ALI_Name);
+ Add_Char_To_Name_Buffer (ASCII.LF);
+ Bytes :=
+ Write
+ (Mapping_FD,
+ Name_Buffer (1)'Address,
+ Name_Len);
+ OK := (Bytes = Name_Len);
+
+ exit when not OK;
+
+ -- Third line it the ALI path name
+
+ Bytes :=
+ Write
+ (Mapping_FD,
+ ALI_Path_Name (1)'Address,
+ ALI_Path_Name'Length);
+ OK := (Bytes = ALI_Path_Name'Length);
+
+ -- If OK is False, it means we were unable to
+ -- write a line. No point in continuing with the
+ -- other units.
+
+ exit when not OK;
+ end if;
end;
- end if;
+ end;
end if;
- end;
+ end if;
+
+ Unit := Units_Htable.Get_Next (Project_Tree.Units_HT);
end loop;
Close (Mapping_FD, Status);
OK := OK and Status;
- -- If the creation of the mapping file was successful,
- -- we add the switch to the arguments of gnatbind.
+ -- If the creation of the mapping file was successful, we add the
+ -- switch to the arguments of gnatbind.
if OK then
Last_Arg := Last_Arg + 1;
-- Start of processing for Gnatmake
- -- This body is very long, should be broken down ???
+ -- This body is very long, should be broken down???
begin
Install_Int_Handler (Sigint_Intercepted'Access);
Obsoleted.Reset;
- Make.Initialize;
+ Make.Initialize (Project_Node_Tree);
Bind_Shared := No_Shared_Switch'Access;
Link_With_Shared_Libgcc := No_Shared_Libgcc_Switch'Access;
-- And the project file cannot be a library project file
- elsif Project_Tree.Projects.Table (Main_Project).Library then
+ elsif Main_Project.Library then
Make_Failed ("-B cannot be used for a library project file");
else
end if;
-- Specify -n for gnatbind and add the ALI files of all the
- -- sources, except the one which is a fake main subprogram:
- -- this is the one for the binder generated file and it will be
- -- transmitted to gnatlink. These sources are those that are
- -- in the queue.
+ -- sources, except the one which is a fake main subprogram: this
+ -- is the one for the binder generated file and it will be
+ -- transmitted to gnatlink. These sources are those that are in
+ -- the queue.
Add_Switch ("-n", Binder, And_Save => True);
elsif Main_Project /= No_Project then
- -- If the main project file is a library project file, main(s)
- -- cannot be specified on the command line.
+ -- If the main project file is a library project file, main(s) cannot
+ -- be specified on the command line.
if Osint.Number_Of_Files /= 0 then
- if Project_Tree.Projects.Table (Main_Project).Library
+ if Main_Project.Library
and then not Unique_Compile
and then ((not Make_Steps) or else Bind_Only or else Link_Only)
then
Check_Mains;
end if;
- -- If no mains have been specified on the command line,
- -- and we are using a project file, we either find the main(s)
- -- in the attribute Main of the main project, or we put all
- -- the sources of the project file as mains.
+ -- If no mains have been specified on the command line, and we are
+ -- using a project file, we either find the main(s) in attribute Main
+ -- of the main project, or we put all the sources of the project file
+ -- as mains.
else
if Main_Index /= 0 then
end if;
declare
- Value : String_List_Id :=
- Project_Tree.Projects.Table (Main_Project).Mains;
+ Value : String_List_Id := Main_Project.Mains;
begin
- -- The attribute Main is an empty list or not specified,
- -- or else gnatmake was invoked with the switch "-u".
+ -- The attribute Main is an empty list or not specified, or
+ -- else gnatmake was invoked with the switch "-u".
if Value = Prj.Nil_String or else Unique_Compile then
if (not Make_Steps) or else Compile_Only
- or else not Project_Tree.Projects.Table
- (Main_Project).Library
+ or else not Main_Project.Library
then
- -- First make sure that the binder and the linker
- -- will not be invoked.
+ -- First make sure that the binder and the linker will
+ -- not be invoked.
Do_Bind_Step := False;
Do_Link_Step := False;
end if;
else
- -- The attribute Main is not an empty list.
- -- Put all the main subprograms in the list as if there
- -- were specified on the command line. However, if attribute
- -- Languages includes a language other than Ada, only
- -- include the Ada mains; if there is no Ada main, compile
- -- all the sources of the project.
+ -- The attribute Main is not an empty list. Put all the main
+ -- subprograms in the list as if they were specified on the
+ -- command line. However, if attribute Languages includes a
+ -- language other than Ada, only include the Ada mains; if
+ -- there is no Ada main, compile all sources of the project.
declare
- Data : constant Project_Data :=
- Project_Tree.Projects.Table (Main_Project);
-
Languages : constant Variable_Value :=
Prj.Util.Value_Of
- (Name_Languages,
- Data.Decl.Attributes,
- Project_Tree);
+ (Name_Languages,
+ Main_Project.Decl.Attributes,
+ Project_Tree);
Current : String_List_Id;
Element : String_Element;
if not Languages.Default then
Current := Languages.Values;
-
Look_For_Foreign :
while Current /= Nil_String loop
Element := Project_Tree.String_Elements.
while Value /= Prj.Nil_String loop
Get_Name_String
- (Project_Tree.String_Elements.Table
- (Value).Value);
+ (Project_Tree.String_Elements.Table (Value).Value);
-- To know if a main is an Ada main, get its project.
-- It should be the project specified on the command
end if;
if Main_Project /= No_Project
- and then Project_Tree.Projects.Table
- (Main_Project).Externally_Built
+ and then Main_Project.Externally_Built
then
Make_Failed
("nothing to do for a main project that is externally built");
if Osint.Number_Of_Files = 0 then
if Main_Project /= No_Project
- and then Project_Tree.Projects.Table (Main_Project).Library
+ and then Main_Project.Library
then
if Do_Bind_Step
- and then not Project_Tree.Projects.Table
- (Main_Project).Standalone_Library
+ and then not Main_Project.Standalone_Library
then
Make_Failed ("only stand-alone libraries may be bound");
end if;
Exit_Program (E_Success);
else
+ -- Call Get_Target_Parameters to ensure that VM_Target and
+ -- AAMP_On_Target get set before calling Usage.
+
+ Targparm.Get_Target_Parameters;
+
-- Output usage information if no files to compile
Usage;
if Main_Project /= No_Project then
- if Project_Tree.Projects.Table
- (Main_Project).Object_Directory /= No_Path_Information
- then
+ if Main_Project.Object_Directory /= No_Path_Information then
-- Change current directory to object directory of main project
Project_Of_Current_Object_Directory := No_Project;
not Unique_Compile);
The_Packages : constant Package_Id :=
- Project_Tree.Projects.Table
- (Main_Project).Decl.Packages;
+ Main_Project.Decl.Packages;
Builder_Package : constant Prj.Package_Id :=
Prj.Util.Value_Of
& """ is not a unit of project "
& Project_File_Name.all & ".");
else
- -- Remove any directory information from the main
- -- source file name.
+ -- Remove any directory information from the main source file
+ -- file name.
declare
Pos : Natural := Main_Unit_File_Name'Last;
end if;
Add_Switches
- (File_Name => Main_Unit_File_Name,
+ (Project_Node_Tree => Project_Node_Tree,
+ File_Name => Main_Unit_File_Name,
Index => Main_Index,
The_Package => Builder_Package,
Program => None,
end if;
Add_Switches
- (File_Name => " ",
+ (Project_Node_Tree => Project_Node_Tree,
+ File_Name => " ",
Index => 0,
The_Package => Builder_Package,
Program => None,
end if;
Add_Switches
- (File_Name => " ",
+ (Project_Node_Tree => Project_Node_Tree,
+ File_Name => " ",
Index => 0,
The_Package => Builder_Package,
Program => None);
-- Add binder switches from the project file for the first main
- if Do_Bind_Step and Binder_Package /= No_Package then
+ if Do_Bind_Step and then Binder_Package /= No_Package then
if Verbose_Mode then
Write_Str ("Adding binder switches for """);
Write_Str (Main_Unit_File_Name);
end if;
Add_Switches
- (File_Name => Main_Unit_File_Name,
- Index => Main_Index,
- The_Package => Binder_Package,
- Program => Binder);
+ (Project_Node_Tree => Project_Node_Tree,
+ File_Name => Main_Unit_File_Name,
+ Index => Main_Index,
+ The_Package => Binder_Package,
+ Program => Binder);
end if;
-- Add linker switches from the project file for the first main
- if Do_Link_Step and Linker_Package /= No_Package then
+ if Do_Link_Step and then Linker_Package /= No_Package then
if Verbose_Mode then
Write_Str ("Adding linker switches for""");
Write_Str (Main_Unit_File_Name);
end if;
Add_Switches
- (File_Name => Main_Unit_File_Name,
- Index => Main_Index,
- The_Package => Linker_Package,
- Program => Linker);
+ (Project_Node_Tree => Project_Node_Tree,
+ File_Name => Main_Unit_File_Name,
+ Index => Main_Index,
+ The_Package => Linker_Package,
+ Program => Linker);
end if;
end;
end if;
-- Get the target parameters, which are only needed for a couple of
- -- cases in gnatmake. Protect against an exception, such as the case
- -- of system.ads missing from the library, and fail gracefully.
+ -- cases in gnatmake. Protect against an exception, such as the case of
+ -- system.ads missing from the library, and fail gracefully.
begin
Targparm.Get_Target_Parameters;
-- JVM machine since ".class" files are generated instead.
Check_Object_Consistency := False;
-
- Gcc := new String'("jgnat");
- Gnatbind := new String'("jgnatbind");
- Gnatlink := new String'("jgnatlink");
+ Gcc := new String'("jvm-gnatcompile");
when Targparm.CLI_Target =>
Gcc := new String'("dotnet-gnatcompile");
if not Unique_Compile
and then MLib.Tgt.Support_For_Libraries /= Prj.None
then
- for Proj in Project_Table.First ..
- Project_Table.Last (Project_Tree.Projects)
- loop
- if Project_Tree.Projects.Table (Proj).Library then
- Project_Tree.Projects.Table
- (Proj).Need_To_Build_Lib :=
- (not MLib.Tgt.Library_Exists_For (Proj, Project_Tree))
- and then (not Project_Tree.Projects.Table
- (Proj).Externally_Built);
-
- if Project_Tree.Projects.Table (Proj).Need_To_Build_Lib then
+ declare
+ Proj : Project_List;
- -- If there is no object directory, then it will be
- -- impossible to build the library. So fail immediately.
+ begin
+ Proj := Project_Tree.Projects;
+ while Proj /= null loop
+ if Proj.Project.Library then
+ Proj.Project.Need_To_Build_Lib :=
+ not MLib.Tgt.Library_Exists_For
+ (Proj.Project, Project_Tree)
+ and then not Proj.Project.Externally_Built;
+
+ if Proj.Project.Need_To_Build_Lib then
+
+ -- If there is no object directory, then it will be
+ -- impossible to build the library. So fail
+ -- immediately.
+
+ if
+ Proj.Project.Object_Directory = No_Path_Information
+ then
+ Make_Failed
+ ("no object files to build library for project """
+ & Get_Name_String (Proj.Project.Name)
+ & """");
+ Proj.Project.Need_To_Build_Lib := False;
- if Project_Tree.Projects.Table (Proj).Object_Directory =
- No_Path_Information
- then
- Make_Failed
- ("no object files to build library for project """
- & Get_Name_String
- (Project_Tree.Projects.Table (Proj).Name)
- & """");
- Project_Tree.Projects.Table
- (Proj).Need_To_Build_Lib := False;
+ else
+ if Verbose_Mode then
+ Write_Str
+ ("Library file does not exist for project """);
+ Write_Str (Get_Name_String (Proj.Project.Name));
+ Write_Line ("""");
+ end if;
- else
- if Verbose_Mode then
- Write_Str
- ("Library file does not exist for project """);
- Write_Str
- (Get_Name_String
- (Project_Tree.Projects.Table
- (Proj).Name));
- Write_Line ("""");
+ Insert_Project_Sources
+ (The_Project => Proj.Project,
+ All_Projects => False,
+ Into_Q => True);
end if;
-
- Insert_Project_Sources
- (The_Project => Proj,
- All_Projects => False,
- Into_Q => True);
end if;
end if;
- end if;
- end loop;
+
+ Proj := Proj.Next;
+ end loop;
+ end;
end if;
- -- If a relative path output file has been specified, we add
- -- the exec directory.
+ -- If a relative path output file has been specified, we add the
+ -- exec directory.
for J in reverse 1 .. Saved_Linker_Switches.Last - 1 loop
if Saved_Linker_Switches.Table (J).all = Output_Flag.all then
begin
if not Is_Absolute_Path (Exec_File_Name) then
- Get_Name_String
- (Project_Tree.Projects.Table
- (Main_Project).Exec_Directory.Name);
+ Get_Name_String (Main_Project.Exec_Directory.Name);
- if Name_Buffer (Name_Len) /= Directory_Separator then
- Name_Len := Name_Len + 1;
- Name_Buffer (Name_Len) := Directory_Separator;
+ if not
+ Is_Directory_Separator (Name_Buffer (Name_Len))
+ then
+ Add_Char_To_Name_Buffer (Directory_Separator);
end if;
- Name_Buffer (Name_Len + 1 ..
- Name_Len + Exec_File_Name'Length) :=
- Exec_File_Name;
- Name_Len := Name_Len + Exec_File_Name'Length;
+ Add_Str_To_Name_Buffer (Exec_File_Name);
Saved_Linker_Switches.Table (J + 1) :=
new String'(Name_Buffer (1 .. Name_Len));
end if;
-- project file.
declare
- Dir_Path : constant String_Access :=
- new String'(Get_Name_String
- (Project_Tree.Projects.Table
- (Main_Project).Directory.Name));
+ Dir_Path : constant String :=
+ Get_Name_String (Main_Project.Directory.Name);
begin
for J in 1 .. Binder_Switches.Last loop
Test_If_Relative_Path
for J in 1 .. Saved_Binder_Switches.Last loop
Test_If_Relative_Path
(Saved_Binder_Switches.Table (J),
- Parent => Current_Work_Dir, Including_L_Switch => False);
+ Parent => Current_Work_Dir.all, Including_L_Switch => False);
end loop;
for J in 1 .. Linker_Switches.Last loop
for J in 1 .. Saved_Linker_Switches.Last loop
Test_If_Relative_Path
- (Saved_Linker_Switches.Table (J), Parent => Current_Work_Dir);
+ (Saved_Linker_Switches.Table (J),
+ Parent => Current_Work_Dir.all);
end loop;
for J in 1 .. Gcc_Switches.Last loop
Test_If_Relative_Path
(Gcc_Switches.Table (J),
- Parent => Dir_Path,
+ Parent => Dir_Path,
Including_Non_Switch => False);
end loop;
for J in 1 .. Saved_Gcc_Switches.Last loop
Test_If_Relative_Path
(Saved_Gcc_Switches.Table (J),
- Parent => Current_Work_Dir,
+ Parent => Current_Work_Dir.all,
Including_Non_Switch => False);
end loop;
end;
if Main_Project = No_Project then
for J in 1 .. Saved_Gcc_Switches.Last loop
Add_Switch
- (Saved_Gcc_Switches.Table (J),
- Compiler,
- And_Save => False);
+ (Saved_Gcc_Switches.Table (J), Compiler, And_Save => False);
end loop;
else
-- We never use gnat.adc when a project file is used
- The_Saved_Gcc_Switches (The_Saved_Gcc_Switches'Last) :=
- No_gnat_adc;
+ The_Saved_Gcc_Switches (The_Saved_Gcc_Switches'Last) := No_gnat_adc;
end if;
- -- If there was a --GCC, --GNATBIND or --GNATLINK switch on
- -- the command line, then we have to use it, even if there was
- -- another switch in the project file.
+ -- If there was a --GCC, --GNATBIND or --GNATLINK switch on the command
+ -- line, then we have to use it, even if there was another switch in
+ -- the project file.
if Saved_Gcc /= null then
Gcc := Saved_Gcc;
Saved_Maximum_Processes := Maximum_Processes;
end if;
- -- Allocate as many temporary mapping file names as the maximum
- -- number of compilation processed, for each possible project.
-
- The_Mapping_File_Names :=
- new Temp_Path_Names
- (No_Project .. Project_Table.Last (Project_Tree.Projects),
- 1 .. Saved_Maximum_Processes);
- Last_Mapping_File_Names :=
- new Indices'
- (No_Project .. Project_Table.Last (Project_Tree.Projects)
- => 0);
-
- The_Free_Mapping_File_Indices :=
- new Free_File_Indices
- (No_Project .. Project_Table.Last (Project_Tree.Projects),
- 1 .. Saved_Maximum_Processes);
- Last_Free_Indices :=
- new Indices'(No_Project .. Project_Table.Last
- (Project_Tree.Projects) => 0);
+ -- Allocate as many temporary mapping file names as the maximum number
+ -- of compilations processed, for each possible project.
+
+ declare
+ Data : Project_Compilation_Access;
+ Proj : Project_List := Project_Tree.Projects;
+ begin
+ while Proj /= null loop
+ Data := new Project_Compilation_Data'
+ (Mapping_File_Names => new Temp_Path_Names
+ (1 .. Saved_Maximum_Processes),
+ Last_Mapping_File_Names => 0,
+ Free_Mapping_File_Indices => new Free_File_Indices
+ (1 .. Saved_Maximum_Processes),
+ Last_Free_Indices => 0);
+
+ Project_Compilation_Htable.Set
+ (Project_Compilation, Proj.Project, Data);
+ Proj := Proj.Next;
+ end loop;
+
+ Data := new Project_Compilation_Data'
+ (Mapping_File_Names => new Temp_Path_Names
+ (1 .. Saved_Maximum_Processes),
+ Last_Mapping_File_Names => 0,
+ Free_Mapping_File_Indices => new Free_File_Indices
+ (1 .. Saved_Maximum_Processes),
+ Last_Free_Indices => 0);
+
+ Project_Compilation_Htable.Set
+ (Project_Compilation, No_Project, Data);
+ end;
Bad_Compilation.Init;
- -- If project files are used, create the mapping of all the sources,
- -- so that the correct paths will be found. Otherwise, if there is
- -- a file which is not a source with the same name in a source directory
- -- this file may be incorrectly found.
+ -- If project files are used, create the mapping of all the sources, so
+ -- that the correct paths will be found. Otherwise, if there is a file
+ -- which is not a source with the same name in a source directory this
+ -- file may be incorrectly found.
if Main_Project /= No_Project then
Prj.Env.Create_Mapping (Project_Tree);
-- Look inside the linker switches to see if the name of the final
-- executable program was specified.
- for
- J in reverse Linker_Switches.First .. Linker_Switches.Last
- loop
+ for J in reverse Linker_Switches.First .. Linker_Switches.Last loop
if Linker_Switches.Table (J).all = Output_Flag.all then
pragma Assert (J < Linker_Switches.Last);
- -- We cannot specify a single executable for several
- -- main subprograms!
+ -- We cannot specify a single executable for several main
+ -- subprograms
if Osint.Number_Of_Files > 1 then
Fail
- ("cannot specify a single executable " &
- "for several mains");
+ ("cannot specify a single executable for several mains");
end if;
- Name_Len := Linker_Switches.Table (J + 1)'Length;
- Name_Buffer (1 .. Name_Len) :=
- Linker_Switches.Table (J + 1).all;
+ Name_Len := 0;
+ Add_Str_To_Name_Buffer (Linker_Switches.Table (J + 1).all);
Executable := Name_Enter;
Verbose_Msg (Executable, "final executable");
end if;
end loop;
- -- If the name of the final executable program was not specified
- -- then construct it from the main input file.
+ -- If the name of the final executable program was not specified then
+ -- construct it from the main input file.
if Executable = No_File then
if Main_Project = No_Project then
- Executable :=
- Executable_Name (Strip_Suffix (Main_Source_File));
+ Executable := Executable_Name (Strip_Suffix (Main_Source_File));
else
-- If we are using a project file, we attempt to remove the
end if;
end if;
- if Main_Project /= No_Project then
+ if Main_Project /= No_Project
+ and then Main_Project.Exec_Directory /= No_Path_Information
+ then
declare
Exec_File_Name : constant String :=
Get_Name_String (Executable);
begin
if not Is_Absolute_Path (Exec_File_Name) then
- Get_Name_String
- (Project_Tree.Projects.Table
- (Main_Project).Exec_Directory.Display_Name);
+ Get_Name_String (Main_Project.Exec_Directory.Display_Name);
if Name_Buffer (Name_Len) /= Directory_Separator then
- Name_Len := Name_Len + 1;
- Name_Buffer (Name_Len) := Directory_Separator;
+ Add_Char_To_Name_Buffer (Directory_Separator);
end if;
- Name_Buffer (Name_Len + 1 ..
- Name_Len + Exec_File_Name'Length) :=
- Exec_File_Name;
-
- Name_Len := Name_Len + Exec_File_Name'Length;
+ Add_Str_To_Name_Buffer (Exec_File_Name);
Executable := Name_Find;
end if;
Executable_Stamp : Time_Stamp_Type;
-- Executable is the final executable program
+ -- ??? comment seems unrelated to declaration
Library_Rebuilt : Boolean := False;
if Total_Compilation_Failures /= 0 then
if Keep_Going then
goto Next_Main;
+
else
List_Bad_Compilations;
Report_Compilation_Failed;
and then (Do_Bind_Step
or Unique_Compile_All_Projects
or not Compile_Only)
- and then (Do_Link_Step or N_File = Osint.Number_Of_Files)
+ and then (Do_Link_Step or else N_File = Osint.Number_Of_Files)
then
Library_Projs.Init;
declare
Depth : Natural;
Current : Natural;
+ Proj1 : Project_List;
procedure Add_To_Library_Projs (Proj : Project_Id);
-- Add project Project to table Library_Projs in
begin
Library_Projs.Increment_Last;
- Depth := Project_Tree.Projects.Table (Proj).Depth;
+ Depth := Proj.Depth;
-- Put the projects in decreasing depth order, so that
-- if libA depends on libB, libB is first in order.
Current := Library_Projs.Last;
while Current > 1 loop
Prj := Library_Projs.Table (Current - 1);
- exit when Project_Tree.Projects.Table
- (Prj).Depth >= Depth;
+ exit when Prj.Depth >= Depth;
Library_Projs.Table (Current) := Prj;
Current := Current - 1;
end loop;
-- or probably better, break this out as a nested proc).
begin
- -- Put in Library_Projs table all library project
- -- file ids when the library need to be rebuilt.
+ -- Put in Library_Projs table all library project file
+ -- ids when the library need to be rebuilt.
- for Proj1 in Project_Table.First ..
- Project_Table.Last (Project_Tree.Projects)
- loop
- if Project_Tree.Projects.Table
- (Proj1).Standalone_Library
- then
- There_Are_Stand_Alone_Libraries := True;
+ Proj1 := Project_Tree.Projects;
+ while Proj1 /= null loop
+ if Proj1.Project.Standalone_Library then
+ Stand_Alone_Libraries := True;
end if;
- if Project_Tree.Projects.Table (Proj1).Library then
- MLib.Prj.Check_Library (Proj1, Project_Tree);
+ if Proj1.Project.Library then
+ MLib.Prj.Check_Library
+ (Proj1.Project, Project_Tree);
end if;
- if Project_Tree.Projects.Table
- (Proj1).Need_To_Build_Lib
- then
- Add_To_Library_Projs (Proj1);
+ if Proj1.Project.Need_To_Build_Lib then
+ Add_To_Library_Projs (Proj1.Project);
end if;
+
+ Proj1 := Proj1.Next;
end loop;
-- Check if importing libraries should be regenerated
-- because at least an imported library will be
-- regenerated or is more recent.
- for Proj1 in Project_Table.First ..
- Project_Table.Last (Project_Tree.Projects)
- loop
- if Project_Tree.Projects.Table (Proj1).Library
- and then
- Project_Tree.Projects.Table (Proj1).Library_Kind /=
- Static
- and then not Project_Tree.Projects.Table
- (Proj1).Need_To_Build_Lib
- and then not Project_Tree.Projects.Table
- (Proj1).Externally_Built
+ Proj1 := Project_Tree.Projects;
+ while Proj1 /= null loop
+ if Proj1.Project.Library
+ and then Proj1.Project.Library_Kind /= Static
+ and then not Proj1.Project.Need_To_Build_Lib
+ and then not Proj1.Project.Externally_Built
then
declare
List : Project_List;
- Element : Project_Element;
Proj2 : Project_Id;
Rebuild : Boolean := False;
Lib_Timestamp1 : constant Time_Stamp_Type :=
- Project_Tree.Projects.Table
- (Proj1).Library_TS;
+ Proj1.Project.Library_TS;
begin
- List := Project_Tree.Projects.Table (Proj1).
- All_Imported_Projects;
- while List /= Empty_Project_List loop
- Element :=
- Project_Tree.Project_Lists.Table (List);
- Proj2 := Element.Project;
-
- if
- Project_Tree.Projects.Table (Proj2).Library
- then
- if Project_Tree.Projects.Table (Proj2).
- Need_To_Build_Lib
+ List := Proj1.Project.All_Imported_Projects;
+ while List /= null loop
+ Proj2 := List.Project;
+
+ if Proj2.Library then
+ if Proj2.Need_To_Build_Lib
or else
- (Lib_Timestamp1 <
- Project_Tree.Projects.Table
- (Proj2).Library_TS)
+ (Lib_Timestamp1 < Proj2.Library_TS)
then
Rebuild := True;
exit;
end if;
end if;
- List := Element.Next;
+ List := List.Next;
end loop;
if Rebuild then
- Project_Tree.Projects.Table
- (Proj1).Need_To_Build_Lib := True;
- Add_To_Library_Projs (Proj1);
+ Proj1.Project.Need_To_Build_Lib := True;
+ Add_To_Library_Projs (Proj1.Project);
end if;
end;
end if;
+
+ Proj1 := Proj1.Next;
end loop;
-- Reset the flags Need_To_Build_Lib for the next main,
-- to avoid rebuilding libraries uselessly.
- for Proj1 in Project_Table.First ..
- Project_Table.Last (Project_Tree.Projects)
- loop
- Project_Tree.Projects.Table
- (Proj1).Need_To_Build_Lib := False;
+ Proj1 := Project_Tree.Projects;
+ while Proj1 /= null loop
+ Proj1.Project.Need_To_Build_Lib := False;
+ Proj1 := Proj1.Next;
end loop;
end;
-- If the objects were up-to-date check if the executable file
-- is also up-to-date. For now always bind and link on the JVM
- -- since there is currently no simple way to check the
- -- up-to-date status of objects
+ -- since there is currently no simple way to check whether
+ -- objects are up-to-date.
if Targparm.VM_Target /= JVM_Target
and then First_Compiled_File = No_File
Executable_Obsolete := Youngest_Obj_File /= No_File;
end if;
- -- Return if the executable is up to date
- -- and otherwise motivate the relink/rebind.
+ -- Check if any library file is more recent than the
+ -- executable: there may be an externally built library
+ -- file that has been modified.
+
+ if not Executable_Obsolete
+ and then Main_Project /= No_Project
+ then
+ declare
+ Proj1 : Project_List;
+
+ begin
+ Proj1 := Project_Tree.Projects;
+ while Proj1 /= null loop
+ if Proj1.Project.Library
+ and then
+ Proj1.Project.Library_TS > Executable_Stamp
+ then
+ Executable_Obsolete := True;
+ Youngest_Obj_Stamp := Proj1.Project.Library_TS;
+ Name_Len := 0;
+ Add_Str_To_Name_Buffer ("library ");
+ Add_Str_To_Name_Buffer
+ (Get_Name_String (Proj1.Project.Library_Name));
+ Youngest_Obj_File := Name_Find;
+ exit;
+ end if;
+
+ Proj1 := Proj1.Next;
+ end loop;
+ end;
+ end if;
+
+ -- Return if the executable is up to date and otherwise
+ -- motivate the relink/rebind.
if not Executable_Obsolete then
if not Quiet_Output then
Change_To_Object_Directory (Main_Project);
end if;
- -- If we are here, it means that we need to rebuilt the current
- -- main. So we set Executable_Obsolete to True to make sure that
- -- the subsequent mains will be rebuilt.
+ -- If we are here, it means that we need to rebuilt the current main,
+ -- so we set Executable_Obsolete to True to make sure that subsequent
+ -- mains will be rebuilt.
Main_ALI_In_Place_Mode_Step : declare
ALI_File : File_Name_Type;
-- Set to True when there are shared library project files or
-- when gnatbind is invoked with -shared.
+ Proj : Project_List;
+
begin
-- Check if there are shared libraries, so that gnatbind is
-- called with -shared. Check also if gnatbind is called with
if Main_Project /= No_Project
and then MLib.Tgt.Support_For_Libraries /= Prj.None
then
- for Proj in Project_Table.First ..
- Project_Table.Last (Project_Tree.Projects)
- loop
- if Project_Tree.Projects.Table (Proj).Library
- and then Project_Tree.Projects.Table
- (Proj).Library_Kind /= Static
+ Proj := Project_Tree.Projects;
+ while Proj /= null loop
+ if Proj.Project.Library
+ and then Proj.Project.Library_Kind /= Static
then
Shared_Libs := True;
Bind_Shared := Shared_Switch'Access;
exit;
end if;
+ Proj := Proj.Next;
end loop;
end if;
Args (J) := Binder_Switches.Table (J);
end loop;
- if There_Are_Stand_Alone_Libraries then
+ if Stand_Alone_Libraries then
Last_Arg := Last_Arg + 1;
Args (Last_Arg) := Force_Elab_Flags_String'Access;
end if;
if Main_Project /= No_Project then
-- Put all the source directories in ADA_INCLUDE_PATH,
- -- and all the object directories in ADA_OBJECTS_PATH.
+ -- and all the object directories in ADA_OBJECTS_PATH,
+ -- except those of library projects.
Prj.Env.Set_Ada_Paths (Main_Project, Project_Tree, False);
exception
when others =>
- -- If -dn was not specified, delete the temporary mapping
- -- file, if one was created.
+ -- Delete the temporary mapping file, if one was created.
- if not Debug.Debug_Flag_N
- and then Mapping_Path /= No_Path
- then
- Delete_File (Get_Name_String (Mapping_Path), Discard);
+ if Mapping_Path /= No_Path then
+ Delete_Temporary_File (Project_Tree, Mapping_Path);
end if;
-- And reraise the exception
-- If -dn was not specified, delete the temporary mapping file,
-- if one was created.
- if not Debug.Debug_Flag_N and then Mapping_Path /= No_Path then
- Delete_File (Get_Name_String (Mapping_Path), Discard);
+ if Mapping_Path /= No_Path then
+ Delete_Temporary_File (Project_Tree, Mapping_Path);
end if;
end Bind_Step;
end if;
Linker_Switches_Last : constant Integer := Linker_Switches.Last;
Path_Option : constant String_Access :=
MLib.Linker_Library_Path_Option;
- There_Are_Libraries : Boolean := False;
+ Libraries_Present : Boolean := False;
Current : Natural;
Proj2 : Project_Id;
Depth : Natural;
+ Proj1 : Project_List;
begin
if not Run_Path_Option then
-- Check for library projects
- for Proj1 in Project_Table.First ..
- Project_Table.Last (Project_Tree.Projects)
- loop
- if Proj1 /= Main_Project
- and then
- Project_Tree.Projects.Table (Proj1).Library
+ Proj1 := Project_Tree.Projects;
+ while Proj1 /= null loop
+ if Proj1.Project /= Main_Project
+ and then Proj1.Project.Library
then
-- Add this project to table Library_Projs
- There_Are_Libraries := True;
- Depth := Project_Tree.Projects.Table (Proj1).Depth;
+ Libraries_Present := True;
+ Depth := Proj1.Project.Depth;
Library_Projs.Increment_Last;
Current := Library_Projs.Last;
while Current > 1 loop
Proj2 := Library_Projs.Table (Current - 1);
- exit when Project_Tree.Projects.Table
- (Proj2).Depth <= Depth;
+ exit when Proj2.Depth <= Depth;
Library_Projs.Table (Current) := Proj2;
Current := Current - 1;
end loop;
- Library_Projs.Table (Current) := Proj1;
+ Library_Projs.Table (Current) := Proj1.Project;
-- If it is not a static library and path option
-- is set, add it to the Library_Paths table.
- if Project_Tree.Projects.Table
- (Proj1).Library_Kind /= Static
+ if Proj1.Project.Library_Kind /= Static
and then Path_Option /= null
then
Library_Paths.Increment_Last;
Library_Paths.Table (Library_Paths.Last) :=
new String'
(Get_Name_String
- (Project_Tree.Projects.Table
- (Proj1).Library_Dir.Display_Name));
+ (Proj1.Project.Library_Dir.Display_Name));
end if;
end if;
+
+ Proj1 := Proj1.Next;
end loop;
for Index in 1 .. Library_Projs.Last loop
Linker_Switches.Table (Linker_Switches.Last) :=
new String'("-L" &
Get_Name_String
- (Project_Tree.Projects.Table
- (Library_Projs.Table (Index)).
- Library_Dir.Display_Name));
+ (Library_Projs.Table (Index).
+ Library_Dir.Display_Name));
-- Add the -l switch
Linker_Switches.Table (Linker_Switches.Last) :=
new String'("-l" &
Get_Name_String
- (Project_Tree.Projects.Table
- (Library_Projs.Table (Index)).
- Library_Name));
+ (Library_Projs.Table (Index).
+ Library_Name));
end loop;
end if;
- if There_Are_Libraries then
+ if Libraries_Present then
-- If Path_Option is not null, create the switch
-- ("-Wl,-rpath," or equivalent) with all the non static
-- We do that only if Run_Path_Option is True
-- (not disabled by -R switch).
- if Run_Path_Option and Path_Option /= null then
+ if Run_Path_Option and then Path_Option /= null then
declare
Option : String_Access;
Length : Natural := Path_Option'Length;
Current : Natural;
begin
- for Index in
- Library_Paths.First .. Library_Paths.Last
- loop
- -- Add the length of the library dir plus one
- -- for the directory separator.
-
- Length :=
- Length +
- Library_Paths.Table (Index)'Length + 1;
- end loop;
+ if MLib.Separate_Run_Path_Options then
+
+ -- We are going to create one switch of the form
+ -- "-Wl,-rpath,dir_N" for each directory to
+ -- consider.
+
+ -- One switch for each library directory
+
+ for Index in
+ Library_Paths.First .. Library_Paths.Last
+ loop
+ Linker_Switches.Increment_Last;
+ Linker_Switches.Table
+ (Linker_Switches.Last) := new String'
+ (Path_Option.all &
+ Library_Paths.Table (Index).all);
+ end loop;
- -- Finally, add the length of the standard GNAT
- -- library dir.
+ -- One switch for the standard GNAT library dir
- Length := Length + MLib.Utl.Lib_Directory'Length;
- Option := new String (1 .. Length);
- Option (1 .. Path_Option'Length) := Path_Option.all;
- Current := Path_Option'Length;
+ Linker_Switches.Increment_Last;
+ Linker_Switches.Table
+ (Linker_Switches.Last) := new String'
+ (Path_Option.all & MLib.Utl.Lib_Directory);
- -- Put each library dir followed by a dir separator
+ else
+ -- We are going to create one switch of the form
+ -- "-Wl,-rpath,dir_1:dir_2:dir_3"
+
+ for Index in
+ Library_Paths.First .. Library_Paths.Last
+ loop
+ -- Add the length of the library dir plus one
+ -- for the directory separator.
+
+ Length :=
+ Length +
+ Library_Paths.Table (Index)'Length + 1;
+ end loop;
- for Index in
- Library_Paths.First .. Library_Paths.Last
- loop
- Option
- (Current + 1 ..
+ -- Finally, add the length of the standard GNAT
+ -- library dir.
+
+ Length := Length + MLib.Utl.Lib_Directory'Length;
+ Option := new String (1 .. Length);
+ Option (1 .. Path_Option'Length) :=
+ Path_Option.all;
+ Current := Path_Option'Length;
+
+ -- Put each library dir followed by a dir
+ -- separator.
+
+ for Index in
+ Library_Paths.First .. Library_Paths.Last
+ loop
+ Option
+ (Current + 1 ..
+ Current +
+ Library_Paths.Table (Index)'Length) :=
+ Library_Paths.Table (Index).all;
+ Current :=
Current +
- Library_Paths.Table (Index)'Length) :=
- Library_Paths.Table (Index).all;
- Current :=
- Current +
- Library_Paths.Table (Index)'Length + 1;
- Option (Current) := Path_Separator;
- end loop;
+ Library_Paths.Table (Index)'Length + 1;
+ Option (Current) := Path_Separator;
+ end loop;
- -- Finally put the standard GNAT library dir
+ -- Finally put the standard GNAT library dir
- Option
- (Current + 1 ..
- Current + MLib.Utl.Lib_Directory'Length) :=
- MLib.Utl.Lib_Directory;
+ Option
+ (Current + 1 ..
+ Current + MLib.Utl.Lib_Directory'Length) :=
+ MLib.Utl.Lib_Directory;
- -- And add the switch to the linker switches
+ -- And add the switch to the linker switches
- Linker_Switches.Increment_Last;
- Linker_Switches.Table (Linker_Switches.Last) :=
- Option;
+ Linker_Switches.Increment_Last;
+ Linker_Switches.Table (Linker_Switches.Last) :=
+ Option;
+ end if;
end;
end if;
Successful_Links.Table (Successful_Links.Last) :=
Main_ALI_File;
- elsif Osint.Number_Of_Files = 1 or not Keep_Going then
+ elsif Osint.Number_Of_Files = 1
+ or else not Keep_Going
+ then
Make_Failed ("*** link failed.");
else
not Unique_Compile);
The_Packages : constant Package_Id :=
- Project_Tree.Projects.Table
- (Main_Project).Decl.Packages;
+ Main_Project.Decl.Packages;
Binder_Package : constant Prj.Package_Id :=
Prj.Util.Value_Of
-- Add binder switches from the project file for this main,
-- if any.
- if Do_Bind_Step and Binder_Package /= No_Package then
+ if Do_Bind_Step and then Binder_Package /= No_Package then
if Verbose_Mode then
Write_Str ("Adding binder switches for """);
Write_Str (Main_Unit_File_Name);
end if;
Add_Switches
- (File_Name => Main_Unit_File_Name,
- Index => Main_Index,
- The_Package => Binder_Package,
- Program => Binder);
+ (Project_Node_Tree => Project_Node_Tree,
+ File_Name => Main_Unit_File_Name,
+ Index => Main_Index,
+ The_Package => Binder_Package,
+ Program => Binder);
end if;
-- Add linker switches from the project file for this main,
-- if any.
- if Do_Link_Step and Linker_Package /= No_Package then
+ if Do_Link_Step and then Linker_Package /= No_Package then
if Verbose_Mode then
Write_Str ("Adding linker switches for""");
Write_Str (Main_Unit_File_Name);
end if;
Add_Switches
- (File_Name => Main_Unit_File_Name,
- Index => Main_Index,
- The_Package => Linker_Package,
- Program => Linker);
+ (Project_Node_Tree => Project_Node_Tree,
+ File_Name => Main_Unit_File_Name,
+ Index => Main_Index,
+ The_Package => Linker_Package,
+ Program => Linker);
end if;
-- As we are using a project file, for relative paths we add
-- relative path in the project file.
declare
- Dir_Path : constant String_Access :=
- new String'(Get_Name_String
- (Project_Tree.Projects.Table
- (Main_Project).Directory.Name));
+ Dir_Path : constant String :=
+ Get_Name_String
+ (Main_Project.Directory.Name);
+
begin
for
J in Last_Binder_Switch + 1 .. Binder_Switches.Last
procedure Init_Mapping_File
(Project : Project_Id;
+ Data : in out Project_Compilation_Data;
File_Index : in out Natural)
is
FD : File_Descriptor;
begin
-- Increase the index of the last mapping file for this project
- Last_Mapping_File_Names (Project) :=
- Last_Mapping_File_Names (Project) + 1;
+ Data.Last_Mapping_File_Names := Data.Last_Mapping_File_Names + 1;
-- If there is a project file, call Create_Mapping_File with
-- the project id.
if Project /= No_Project then
Prj.Env.Create_Mapping_File
- (Project, Project_Tree,
- The_Mapping_File_Names
- (Project, Last_Mapping_File_Names (Project)));
+ (Project,
+ In_Tree => Project_Tree,
+ Language => Name_Ada,
+ Name => Data.Mapping_File_Names
+ (Data.Last_Mapping_File_Names));
-- Otherwise, just create an empty file
else
Tempdir.Create_Temp_File
(FD,
- The_Mapping_File_Names
- (No_Project, Last_Mapping_File_Names (No_Project)));
+ Data.Mapping_File_Names (Data.Last_Mapping_File_Names));
if FD = Invalid_FD then
Make_Failed ("disk full");
else
Record_Temp_File
- (The_Mapping_File_Names
- (No_Project, Last_Mapping_File_Names (No_Project)));
+ (Project_Tree,
+ Data.Mapping_File_Names (Data.Last_Mapping_File_Names));
end if;
Close (FD, Status);
-- And return the index of the newly created file
- File_Index := Last_Mapping_File_Names (Project);
+ File_Index := Data.Last_Mapping_File_Names;
end Init_Mapping_File;
------------
-- Initialize --
----------------
- procedure Initialize is
+ procedure Initialize (Project_Node_Tree : out Project_Node_Tree_Ref) is
procedure Check_Version_And_Help is
new Check_Version_And_Help_G (Makeusg);
-- Start of processing for Initialize
begin
- Prj.Set_Mode (Ada_Only);
+ -- Prepare the project's tree, since this is used to hold external
+ -- references, project path and other attributes that can be impacted by
+ -- the command line switches
+
+ Project_Node_Tree := new Project_Node_Tree_Data;
+ Prj.Tree.Initialize (Project_Node_Tree);
-- Override default initialization of Check_Object_Consistency since
-- this is normally False for GNATBIND, but is True for GNATMAKE since
Dependencies.Init;
RTS_Specified := null;
+ N_M_Switch := 0;
Mains.Delete;
- -- Add the directory where gnatmake is invoked in front of the
- -- path, if gnatmake is invoked from a bin directory or with directory
+ -- Add the directory where gnatmake is invoked in front of the path,
+ -- if gnatmake is invoked from a bin directory or with directory
-- information. Only do this if the platform is not VMS, where the
-- notion of path does not really exist.
-- do not include --version or --help.
Scan_Args : for Next_Arg in 1 .. Argument_Count loop
- Scan_Make_Arg (Argument (Next_Arg), And_Save => True);
+ Scan_Make_Arg
+ (Project_Node_Tree, Argument (Next_Arg), And_Save => True);
end loop Scan_Args;
+ if N_M_Switch > 0 and RTS_Specified = null then
+ Process_Multilib (Project_Node_Tree);
+ end if;
+
if Commands_To_Stdout then
Set_Standard_Output;
end if;
(Project => Main_Project,
In_Tree => Project_Tree,
Project_File_Name => Project_File_Name.all,
- Packages_To_Check => Packages_To_Check_By_Gnatmake);
+ Packages_To_Check => Packages_To_Check_By_Gnatmake,
+ Flags => Gnatmake_Flags,
+ In_Node_Tree => Project_Node_Tree);
-- The parsing of project files may have changed the current output
Write_Eol;
end if;
- -- We add the source directories and the object directories
- -- to the search paths.
+ -- We add the source directories and the object directories to the
+ -- search paths.
+ -- ??? Why do we need these search directories, we already know the
+ -- locations from parsing the project, except for the runtime which
+ -- has its own directories anyway
Add_Source_Directories (Main_Project, Project_Tree);
- Add_Object_Directories (Main_Project, Project_Tree);
-
- -- Compute depth of each project
-
- for Proj in Project_Table.First ..
- Project_Table.Last (Project_Tree.Projects)
- loop
- Project_Tree.Projects.Table (Proj).Seen := False;
- Project_Tree.Projects.Table (Proj).Depth := 0;
- end loop;
-
- Recursive_Compute_Depth (Main_Project, Depth => 1);
-
- -- For each project compute the list of the projects it imports
- -- directly or indirectly.
+ Add_Object_Directories (Main_Project);
- for Proj in Project_Table.First ..
- Project_Table.Last (Project_Tree.Projects)
- loop
- Compute_All_Imported_Projects (Proj);
- end loop;
+ Recursive_Compute_Depth (Main_Project);
+ Compute_All_Imported_Projects (Project_Tree);
else
Into_Q : Boolean)
is
Put_In_Q : Boolean := Into_Q;
- Unit : Unit_Data;
+ Unit : Unit_Index;
Sfile : File_Name_Type;
Index : Int;
- Extending : constant Boolean :=
- Project_Tree.Projects.Table
- (The_Project).Extends /= No_Project;
+ Extending : constant Boolean := The_Project.Extends /= No_Project;
function Check_Project (P : Project_Id) return Boolean;
-- Returns True if P is The_Project or a project extended by The_Project
function Check_Project (P : Project_Id) return Boolean is
begin
- if All_Projects or P = The_Project then
+ if All_Projects or else P = The_Project then
return True;
elsif Extending then
declare
- Data : Project_Data :=
- Project_Tree.Projects.Table (The_Project);
+ Proj : Project_Id;
begin
- loop
- if P = Data.Extends then
+ Proj := The_Project;
+ while Proj /= null loop
+ if P = Proj.Extends then
return True;
end if;
- Data := Project_Tree.Projects.Table (Data.Extends);
- exit when Data.Extends = No_Project;
+ Proj := Proj.Extends;
end loop;
end;
end if;
begin
-- For all the sources in the project files,
- for Id in Unit_Table.First ..
- Unit_Table.Last (Project_Tree.Units)
- loop
- Unit := Project_Tree.Units.Table (Id);
+ Unit := Units_Htable.Get_First (Project_Tree.Units_HT);
+ while Unit /= null loop
Sfile := No_File;
Index := 0;
-- If there is a source for the body, and the body has not been
- -- locally removed,
+ -- locally removed.
- if Unit.File_Names (Body_Part).Name /= No_File
- and then Unit.File_Names (Body_Part).Path.Name /= Slash
+ if Unit.File_Names (Impl) /= null
+ and then not Unit.File_Names (Impl).Locally_Removed
then
-- And it is a source for the specified project
- if Check_Project (Unit.File_Names (Body_Part).Project) then
+ if Check_Project (Unit.File_Names (Impl).Project) then
-- If we don't have a spec, we cannot consider the source
- -- if it is a subunit
+ -- if it is a subunit.
- if Unit.File_Names (Specification).Name = No_File then
+ if Unit.File_Names (Spec) = null then
declare
Src_Ind : Source_File_Index;
begin
Src_Ind := Sinput.P.Load_Project_File
(Get_Name_String
- (Unit.File_Names (Body_Part).Path.Name));
+ (Unit.File_Names (Impl).Path.Name));
-- If it is a subunit, discard it
Sfile := No_File;
Index := 0;
else
- Sfile := Unit.File_Names (Body_Part).Display_Name;
- Index := Unit.File_Names (Body_Part).Index;
+ Sfile := Unit.File_Names (Impl).Display_File;
+ Index := Unit.File_Names (Impl).Index;
end if;
end;
else
- Sfile := Unit.File_Names (Body_Part).Display_Name;
- Index := Unit.File_Names (Body_Part).Index;
+ Sfile := Unit.File_Names (Impl).Display_File;
+ Index := Unit.File_Names (Impl).Index;
end if;
end if;
- elsif Unit.File_Names (Specification).Name /= No_File
- and then Unit.File_Names (Specification).Path.Name /= Slash
- and then Check_Project (Unit.File_Names (Specification).Project)
+ elsif Unit.File_Names (Spec) /= null
+ and then not Unit.File_Names (Spec).Locally_Removed
+ and then Check_Project (Unit.File_Names (Spec).Project)
then
- -- If there is no source for the body, but there is a source
- -- for the spec which has not been locally removed, then we take
- -- this one.
+ -- If there is no source for the body, but there is one for the
+ -- spec which has not been locally removed, then we take this one.
- Sfile := Unit.File_Names (Specification).Display_Name;
- Index := Unit.File_Names (Specification).Index;
+ Sfile := Unit.File_Names (Spec).Display_File;
+ Index := Unit.File_Names (Spec).Index;
end if;
-- If Put_In_Q is True, we insert into the Q
Init_Q;
end if;
- -- And of course, we only insert in the Q if the source is not
- -- marked.
+ -- And of course, only insert in the Q if the source is not marked
if Sfile /= No_File and then not Is_Marked (Sfile, Index) then
if Verbose_Mode then
Init_Q;
end if;
end if;
+
+ Unit := Units_Htable.Get_Next (Project_Tree.Units_HT);
end loop;
end Insert_Project_Sources;
Full_Lib_File : File_Name_Type) return Boolean
is
begin
- -- There is something to check only when using project files.
- -- Otherwise, this function returns True (last line of the function).
+ -- There is something to check only when using project files. Otherwise,
+ -- this function returns True (last line of the function).
if Main_Project /= No_Project then
declare
Get_Name_String (Source_File);
Saved_Verbosity : constant Verbosity := Current_Verbosity;
Project : Project_Id := No_Project;
- Data : Project_Data;
Path_Name : Path_Name_Type := No_Path;
pragma Warnings (Off, Path_Name);
Path => Path_Name);
Current_Verbosity := Saved_Verbosity;
- -- If this source is in a project, check that the ALI file is
- -- in its object directory. If it is not, return False, so that
- -- the ALI file will not be skipped.
+ -- If this source is in a project, check that the ALI file is in
+ -- its object directory. If it is not, return False, so that the
+ -- ALI file will not be skipped.
if Project /= No_Project then
- Data := Project_Tree.Projects.Table (Project);
-
declare
Object_Directory : constant String :=
Normalize_Pathname
(Get_Name_String
- (Data.Object_Directory.Display_Name));
+ (Project.
+ Object_Directory.Display_Name));
Olast : Natural := Object_Directory'Last;
N : Name_Id;
B : Byte;
- begin
- if On_Command_Line then
- declare
- Real_Path : constant String := Normalize_Pathname (Dir);
+ function Base_Directory return String;
+ -- If Dir comes from the command line, empty string (relative paths are
+ -- resolved with respect to the current directory), else return the main
+ -- project's directory.
- begin
- if Real_Path'Length = 0 then
- Name_Len := Dir'Length;
- Name_Buffer (1 .. Name_Len) := Dir;
+ --------------------
+ -- Base_Directory --
+ --------------------
- else
- Name_Len := Real_Path'Length;
- Name_Buffer (1 .. Name_Len) := Real_Path;
- end if;
- end;
+ function Base_Directory return String is
+ begin
+ if On_Command_Line then
+ return "";
+ else
+ return Get_Name_String (Main_Project.Directory.Display_Name);
+ end if;
+ end Base_Directory;
- else
- declare
- Real_Path : constant String :=
- Normalize_Pathname
- (Dir,
- Get_Name_String
- (Project_Tree.Projects.Table
- (Main_Project).Directory.Display_Name));
+ Real_Path : constant String := Normalize_Pathname (Dir, Base_Directory);
- begin
- if Real_Path'Length = 0 then
- Name_Len := Dir'Length;
- Name_Buffer (1 .. Name_Len) := Dir;
+ -- Start of processing for Mark_Directory
- else
- Name_Len := Real_Path'Length;
- Name_Buffer (1 .. Name_Len) := Real_Path;
- end if;
- end;
+ begin
+ Name_Len := 0;
+
+ if Real_Path'Length = 0 then
+ Add_Str_To_Name_Buffer (Dir);
+
+ else
+ Add_Str_To_Name_Buffer (Real_Path);
end if;
-- Last character is supposed to be a directory separator
if not Is_Directory_Separator (Name_Buffer (Name_Len)) then
- Name_Len := Name_Len + 1;
- Name_Buffer (Name_Len) := Directory_Separator;
+ Add_Char_To_Name_Buffer (Directory_Separator);
end if;
-- Add flags to the already existing flags
Set_Name_Table_Byte (N, B or Mark);
end Mark_Directory;
- -----------------------------
- -- Recursive_Compute_Depth --
- -----------------------------
+ ----------------------
+ -- Process_Multilib --
+ ----------------------
- procedure Recursive_Compute_Depth
- (Project : Project_Id;
- Depth : Natural)
+ procedure Process_Multilib
+ (Project_Node_Tree : Project_Node_Tree_Ref)
is
- List : Project_List;
- Proj : Project_Id;
+ Output_FD : File_Descriptor;
+ Output_Name : String_Access;
+ Arg_Index : Natural := 0;
+ Success : Boolean := False;
+ Return_Code : Integer := 0;
+ Multilib_Gcc_Path : String_Access;
+ Multilib_Gcc : String_Access;
+ N_Read : Integer := 0;
+ Line : String (1 .. 1000);
+ Args : Argument_List (1 .. N_M_Switch + 1);
begin
- -- Nothing to do if there is no project or if the project has already
- -- been seen or if the depth is large enough.
+ pragma Assert (N_M_Switch > 0 and RTS_Specified = null);
- if Project = No_Project
- or else Project_Tree.Projects.Table (Project).Seen
- or else Project_Tree.Projects.Table (Project).Depth >= Depth
- then
+ -- In case we detected a multilib switch and the user has not
+ -- manually specified a specific RTS we emulate the following command:
+ -- gnatmake $FLAGS --RTS=$(gcc -print-multi-directory $FLAGS)
+
+ -- First select the flags which might have an impact on multilib
+ -- processing. Note that this is an heuristic selection and it
+ -- will need to be maintained over time. The condition has to
+ -- be kept synchronized with N_M_Switch counting in Scan_Make_Arg.
+
+ for Next_Arg in 1 .. Argument_Count loop
+ declare
+ Argv : constant String := Argument (Next_Arg);
+ begin
+ if Argv'Length > 2
+ and then Argv (1) = '-'
+ and then Argv (2) = 'm'
+ and then Argv /= "-margs"
+
+ -- Ignore -mieee to avoid spawning an extra gcc in this case
+
+ and then Argv /= "-mieee"
+ then
+ Arg_Index := Arg_Index + 1;
+ Args (Arg_Index) := new String'(Argv);
+ end if;
+ end;
+ end loop;
+
+ pragma Assert (Arg_Index = N_M_Switch);
+
+ Args (Args'Last) := new String'("-print-multi-directory");
+
+ -- Call the GCC driver with the collected flags and save its
+ -- output. Alternate design would be to link in gnatmake the
+ -- relevant part of the GCC driver.
+
+ if Saved_Gcc /= null then
+ Multilib_Gcc := Saved_Gcc;
+ else
+ Multilib_Gcc := Gcc;
+ end if;
+
+ Multilib_Gcc_Path := GNAT.OS_Lib.Locate_Exec_On_Path (Multilib_Gcc.all);
+
+ Create_Temp_Output_File (Output_FD, Output_Name);
+
+ if Output_FD = Invalid_FD then
return;
end if;
- Project_Tree.Projects.Table (Project).Depth := Depth;
+ GNAT.OS_Lib.Spawn
+ (Multilib_Gcc_Path.all, Args, Output_FD, Return_Code, False);
+ Close (Output_FD);
+
+ if Return_Code /= 0 then
+ return;
+ end if;
- -- Mark project as Seen to avoid endless loop caused by limited withs
+ -- Parse the GCC driver output which is a single line, removing CR/LF
- Project_Tree.Projects.Table (Project).Seen := True;
+ Output_FD := Open_Read (Output_Name.all, Binary);
- List := Project_Tree.Projects.Table (Project).Imported_Projects;
+ if Output_FD = Invalid_FD then
+ return;
+ end if;
- -- Visit each imported project
+ N_Read := Read (Output_FD, Line (1)'Address, Line'Length);
+ Close (Output_FD);
+ Delete_File (Output_Name.all, Success);
- while List /= Empty_Project_List loop
- Proj := Project_Tree.Project_Lists.Table (List).Project;
- List := Project_Tree.Project_Lists.Table (List).Next;
- Recursive_Compute_Depth
- (Project => Proj,
- Depth => Depth + 1);
+ for J in reverse 1 .. N_Read loop
+ if Line (J) = ASCII.CR or else Line (J) = ASCII.LF then
+ N_Read := N_Read - 1;
+ else
+ exit;
+ end if;
end loop;
- -- Visit a project being extended, if any
+ -- In case the standard RTS is selected do nothing
+
+ if N_Read = 0 or else Line (1 .. N_Read) = "." then
+ return;
+ end if;
+
+ -- Otherwise add -margs --RTS=output
+
+ Scan_Make_Arg (Project_Node_Tree, "-margs", And_Save => True);
+ Scan_Make_Arg
+ (Project_Node_Tree, "--RTS=" & Line (1 .. N_Read), And_Save => True);
+ end Process_Multilib;
+
+ -----------------------------
+ -- Recursive_Compute_Depth --
+ -----------------------------
+
+ procedure Recursive_Compute_Depth (Project : Project_Id) is
+ use Project_Boolean_Htable;
+ Seen : Project_Boolean_Htable.Instance := Project_Boolean_Htable.Nil;
+
+ procedure Recurse (Prj : Project_Id; Depth : Natural);
+ -- Recursive procedure that does the work, keeping track of the depth
+
+ -------------
+ -- Recurse --
+ -------------
+
+ procedure Recurse (Prj : Project_Id; Depth : Natural) is
+ List : Project_List;
+ Proj : Project_Id;
+
+ begin
+ if Prj.Depth >= Depth or else Get (Seen, Prj) then
+ return;
+ end if;
+
+ -- We need a test to avoid infinite recursions with limited withs:
+ -- If we have A -> B -> A, then when set level of A to n, we try and
+ -- set level of B to n+1, and then level of A to n + 2, ...
+
+ Set (Seen, Prj, True);
+
+ Prj.Depth := Depth;
+
+ -- Visit each imported project
+
+ List := Prj.Imported_Projects;
+ while List /= null loop
+ Proj := List.Project;
+ List := List.Next;
+ Recurse (Prj => Proj, Depth => Depth + 1);
+ end loop;
+
+ -- We again allow changing the depth of this project later on if it
+ -- is in fact imported by a lower-level project.
+
+ Set (Seen, Prj, False);
+ end Recurse;
- Recursive_Compute_Depth
- (Project => Project_Tree.Projects.Table (Project).Extends,
- Depth => Depth + 1);
+ Proj : Project_List;
- -- Reset the Seen flag, as we leave this project
+ -- Start of processing for Recursive_Compute_Depth
+
+ begin
+ Proj := Project_Tree.Projects;
+ while Proj /= null loop
+ Proj.Project.Depth := 0;
+ Proj := Proj.Next;
+ end loop;
- Project_Tree.Projects.Table (Project).Seen := False;
+ Recurse (Project, Depth => 1);
+ Reset (Seen);
end Recursive_Compute_Depth;
-------------------------------
procedure Sigint_Intercepted is
SIGINT : constant := 2;
+
begin
Set_Standard_Error;
Write_Line ("*** Interrupted ***");
-- Scan_Make_Arg --
-------------------
- procedure Scan_Make_Arg (Argv : String; And_Save : Boolean) is
+ procedure Scan_Make_Arg
+ (Project_Node_Tree : Project_Node_Tree_Ref;
+ Argv : String;
+ And_Save : Boolean)
+ is
Success : Boolean;
begin
-- If the previous switch has set the Object_Directory_Present flag
-- (that is we have seen a -D), then the next argument is the path name
- -- of the object directory..
+ -- of the object directory.
elsif Object_Directory_Present
and then not Object_Directory_Seen
Make_Failed ("cannot find object directory """ & Argv & """");
else
- Add_Lib_Search_Dir (Argv);
+ -- Record the object directory. Make sure it ends with a directory
+ -- separator.
- -- Specify the object directory to the binder
+ declare
+ Norm : constant String := Normalize_Pathname (Argv);
- Add_Switch ("-aO" & Argv, Binder, And_Save => And_Save);
+ begin
+ if Norm (Norm'Last) = Directory_Separator then
+ Object_Directory_Path := new String'(Norm);
+ else
+ Object_Directory_Path :=
+ new String'(Norm & Directory_Separator);
+ end if;
- -- Record the object directory. Make sure it ends with a directory
- -- separator.
+ Add_Lib_Search_Dir (Norm);
+
+ -- Specify the object directory to the binder
+
+ Add_Switch ("-aO" & Norm, Binder, And_Save => And_Save);
+ end;
- if Argv (Argv'Last) = Directory_Separator then
- Object_Directory_Path :=
- new String'(Argv);
- else
- Object_Directory_Path :=
- new String'(Argv & Directory_Separator);
- end if;
end if;
-- Then check if we are dealing with -cargs/-bargs/-largs/-margs
raise Program_Error;
end case;
- -- A special test is needed for the -o switch within a -largs
- -- since that is another way to specify the name of the final
- -- executable.
+ -- A special test is needed for the -o switch within a -largs since that
+ -- is another way to specify the name of the final executable.
elsif Program_Args = Linker
and then Argv = "-o"
Make_Failed ("switch -o not allowed within a -largs. " &
"Use -o directly.");
- -- Check to see if we are reading switches after a -cargs,
- -- -bargs or -largs switch. If yes save it.
+ -- Check to see if we are reading switches after a -cargs, -bargs or
+ -- -largs switch. If so, save it.
elsif Program_Args /= None then
for J in 2 .. Program_Args.all'Last loop
Add_Switch
- (Program_Args.all (J).all,
- Compiler,
- And_Save => And_Save);
+ (Program_Args.all (J).all, Compiler, And_Save => And_Save);
end loop;
end;
Argv (1 .. 5) = "--RTS"
then
Add_Switch (Argv, Compiler, And_Save => And_Save);
- Add_Switch (Argv, Binder, And_Save => And_Save);
+ Add_Switch (Argv, Binder, And_Save => And_Save);
if Argv'Length <= 6 or else Argv (6) /= '=' then
Make_Failed ("missing path for --RTS");
RTS_Src_Path_Name := Src_Path_Name;
RTS_Lib_Path_Name := Lib_Path_Name;
- elsif Src_Path_Name = null
- and Lib_Path_Name = null
+ elsif Src_Path_Name = null
+ and then Lib_Path_Name = null
then
Make_Failed ("RTS path not valid: missing " &
"adainclude and adalib directories");
end;
end if;
+ elsif Argv'Length >= 8 and then
+ Argv (1 .. 8) = "--param="
+ then
+ Add_Switch (Argv, Compiler, And_Save => And_Save);
+ Add_Switch (Argv, Linker, And_Save => And_Save);
+
else
- Scan_Make_Switches (Argv, Success);
+ Scan_Make_Switches (Project_Node_Tree, Argv, Success);
end if;
-- If we have seen a regular switch process it
elsif (Argv'Length > 5 and then Argv (1 .. 5) = "-RTS=")
or else (Argv'Length > 5 and then Argv (1 .. 5) = "-GCC=")
+ or else (Argv'Length > 8 and then Argv (1 .. 7) = "-param=")
or else (Argv'Length > 10 and then Argv (1 .. 10) = "-GNATLINK=")
or else (Argv'Length > 10 and then Argv (1 .. 10) = "-GNATBIND=")
then
-- -Idir
elsif Argv (2) = 'I' then
- Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
+ Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
Add_Switch (Argv, Compiler, And_Save => And_Save);
- Add_Switch (Argv, Binder, And_Save => And_Save);
+ Add_Switch (Argv, Binder, And_Save => And_Save);
-- -aIdir (to gcc this is like a -I switch)
elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aI" then
Add_Source_Search_Dir (Argv (4 .. Argv'Last), And_Save);
- Add_Switch ("-I" & Argv (4 .. Argv'Last),
- Compiler,
- And_Save => And_Save);
+ Add_Switch
+ ("-I" & Argv (4 .. Argv'Last), Compiler, And_Save => And_Save);
Add_Switch (Argv, Binder, And_Save => And_Save);
-- -aOdir
elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aL" then
Mark_Directory (Argv (4 .. Argv'Last), Ada_Lib_Dir, And_Save);
Add_Library_Search_Dir (Argv (4 .. Argv'Last), And_Save);
- Add_Switch ("-aO" & Argv (4 .. Argv'Last),
- Binder,
- And_Save => And_Save);
+ Add_Switch
+ ("-aO" & Argv (4 .. Argv'Last), Binder, And_Save => And_Save);
-- -aamp_target=...
elsif Argv (2) = 'A' then
Mark_Directory (Argv (3 .. Argv'Last), Ada_Lib_Dir, And_Save);
- Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
+ Add_Source_Search_Dir (Argv (3 .. Argv'Last), And_Save);
Add_Library_Search_Dir (Argv (3 .. Argv'Last), And_Save);
- Add_Switch ("-I" & Argv (3 .. Argv'Last),
- Compiler,
- And_Save => And_Save);
- Add_Switch ("-aO" & Argv (3 .. Argv'Last),
- Binder,
- And_Save => And_Save);
+ Add_Switch
+ ("-I" & Argv (3 .. Argv'Last), Compiler, And_Save => And_Save);
+ Add_Switch
+ ("-aO" & Argv (3 .. Argv'Last), Binder, And_Save => And_Save);
-- -Ldir
Add_Switch (Argv, Linker, And_Save => And_Save);
-- For -gxxxxx, -pg, -mxxx, -fxxx: give the switch to both the
- -- compiler and the linker (except for -gnatxxx which is only for
- -- the compiler). Some of the -mxxx (for example -m64) and -fxxx
- -- (for example -ftest-coverage for gcov) need to be used when
- -- compiling the binder generated files, and using all these gcc
- -- switches for the binder generated files should not be a problem.
+ -- compiler and the linker (except for -gnatxxx which is only for the
+ -- compiler). Some of the -mxxx (for example -m64) and -fxxx (for
+ -- example -ftest-coverage for gcov) need to be used when compiling
+ -- the binder generated files, and using all these gcc switches for
+ -- the binder generated files should not be a problem.
elsif
(Argv (2) = 'g' and then (Argv'Last < 5
or else (Argv (2) = 'f' and then Argv'Last > 2)
then
Add_Switch (Argv, Compiler, And_Save => And_Save);
- Add_Switch (Argv, Linker, And_Save => And_Save);
+ Add_Switch (Argv, Linker, And_Save => And_Save);
+
+ -- The following condition has to be kept synchronized with
+ -- the Process_Multilib one.
+
+ if Argv (2) = 'm'
+ and then Argv /= "-mieee"
+ then
+ N_M_Switch := N_M_Switch + 1;
+ end if;
-- -C=<mapping file>
elsif Argv'Last = 2 and then Argv (2) = 'D' then
if Project_File_Name /= null then
- Make_Failed ("-D cannot be used in conjunction with a " &
- "project file");
+ Make_Failed
+ ("-D cannot be used in conjunction with a project file");
else
- Scan_Make_Switches (Argv, Success);
+ Scan_Make_Switches (Project_Node_Tree, Argv, Success);
end if;
-- -d
- elsif Argv (2) = 'd'
- and then Argv'Last = 2
- then
+ elsif Argv (2) = 'd' and then Argv'Last = 2 then
Display_Compilation_Progress := True;
-- -i
elsif Argv'Last = 2 and then Argv (2) = 'i' then
if Project_File_Name /= null then
- Make_Failed ("-i cannot be used in conjunction with a " &
- "project file");
+ Make_Failed
+ ("-i cannot be used in conjunction with a project file");
else
- Scan_Make_Switches (Argv, Success);
+ Scan_Make_Switches (Project_Node_Tree, Argv, Success);
end if;
-- -j (need to save the result)
elsif Argv (2) = 'j' then
- Scan_Make_Switches (Argv, Success);
+ Scan_Make_Switches (Project_Node_Tree, Argv, Success);
if And_Save then
Saved_Maximum_Processes := Maximum_Processes;
-- -m
- elsif Argv (2) = 'm'
- and then Argv'Last = 2
- then
+ elsif Argv (2) = 'm' and then Argv'Last = 2 then
Minimal_Recompilation := True;
-- -u
- elsif Argv (2) = 'u'
- and then Argv'Last = 2
- then
- Unique_Compile := True;
- Compile_Only := True;
- Do_Bind_Step := False;
- Do_Link_Step := False;
+ elsif Argv (2) = 'u' and then Argv'Last = 2 then
+ Unique_Compile := True;
+ Compile_Only := True;
+ Do_Bind_Step := False;
+ Do_Link_Step := False;
-- -U
and then Argv'Last = 2
then
Unique_Compile_All_Projects := True;
- Unique_Compile := True;
- Compile_Only := True;
- Do_Bind_Step := False;
- Do_Link_Step := False;
+ Unique_Compile := True;
+ Compile_Only := True;
+ Do_Bind_Step := False;
+ Do_Link_Step := False;
-- -Pprj or -P prj (only once, and only on the command line)
Make_Failed ("cannot have several project files specified");
elsif Object_Directory_Path /= null then
- Make_Failed ("-D cannot be used in conjunction with a " &
- "project file");
+ Make_Failed
+ ("-D cannot be used in conjunction with a project file");
elsif In_Place_Mode then
- Make_Failed ("-i cannot be used in conjunction with a " &
- "project file");
+ Make_Failed
+ ("-i cannot be used in conjunction with a project file");
elsif not And_Save then
- -- It could be a tool other than gnatmake (i.e, gnatdist)
+ -- It could be a tool other than gnatmake (e.g. gnatdist)
-- or a -P switch inside a project file.
Fail
-- -Xext=val (External assignment)
elsif Argv (2) = 'X'
- and then Is_External_Assignment (Argv)
+ and then Is_External_Assignment (Project_Node_Tree, Argv)
then
- -- Is_External_Assignment has side effects
- -- when it returns True;
+ -- Is_External_Assignment has side effects when it returns True
null;
- -- If -gnath is present, then generate the usage information
- -- right now and do not pass this option on to the compiler calls.
+ -- If -gnath is present, then generate the usage information right
+ -- now and do not pass this option on to the compiler calls.
elsif Argv = "-gnath" then
Usage;
- -- If -gnatc is specified, make sure the bind step and the link
- -- step are not executed.
+ -- If -gnatc is specified, make sure the bind and link steps are not
+ -- executed.
elsif Argv'Length >= 6 and then Argv (2 .. 6) = "gnatc" then
- -- If -gnatc is specified, make sure the bind step and the link
- -- step are not executed.
+ -- If -gnatc is specified, make sure the bind and link steps are
+ -- not executed.
Add_Switch (Argv, Compiler, And_Save => And_Save);
- Operating_Mode := Check_Semantics;
+ Operating_Mode := Check_Semantics;
Check_Object_Consistency := False;
Compile_Only := True;
- Do_Bind_Step := False;
- Do_Link_Step := False;
+ Do_Bind_Step := False;
+ Do_Link_Step := False;
elsif Argv (2 .. Argv'Last) = "nostdlib" then
No_Stdinc := True;
Add_Switch (Argv, Compiler, And_Save => And_Save);
- Add_Switch (Argv, Binder, And_Save => And_Save);
+ Add_Switch (Argv, Binder, And_Save => And_Save);
-- All other switches are processed by Scan_Make_Switches. If the
-- call returns with Gnatmake_Switch_Found = False, then the switch
-- is passed to the compiler.
else
- Scan_Make_Switches (Argv, Gnatmake_Switch_Found);
+ Scan_Make_Switches
+ (Project_Node_Tree, Argv, Gnatmake_Switch_Found);
if not Gnatmake_Switch_Found then
Add_Switch (Argv, Compiler, And_Save => And_Save);
(Source_File : File_Name_Type;
Source_File_Name : String;
Source_Index : Int;
- Naming : Naming_Data;
+ Project : Project_Id;
In_Package : Package_Id;
Allow_ALI : Boolean) return Variable_Value
is
+ Lang : constant Language_Ptr := Get_Language_From_Name (Project, "ada");
+
Switches : Variable_Value;
Defaults : constant Array_Element_Id :=
-- Check also without the suffix
- if Switches = Nil_Variable_Value then
+ if Switches = Nil_Variable_Value
+ and then Lang /= null
+ then
declare
+ Naming : Lang_Naming_Data renames Lang.Config.Naming_Data;
Name : String (1 .. Source_File_Name'Length + 3);
Last : Positive := Source_File_Name'Length;
Spec_Suffix : constant String :=
- Spec_Suffix_Of (Project_Tree, "ada", Naming);
+ Get_Name_String (Naming.Spec_Suffix);
Body_Suffix : constant String :=
- Body_Suffix_Of (Project_Tree, "ada", Naming);
+ Get_Name_String (Naming.Body_Suffix);
Truncated : Boolean := False;
begin
end if;
if Truncated then
- Name_Len := Last;
- Name_Buffer (1 .. Name_Len) := Name (1 .. Last);
+ Name_Len := 0;
+ Add_Str_To_Name_Buffer (Name (1 .. Last));
Switches :=
Prj.Util.Value_Of
(Index => Name_Find,
In_Array => Switches_Array,
In_Tree => Project_Tree);
- if Switches = Nil_Variable_Value
- and then Allow_ALI
- then
+ if Switches = Nil_Variable_Value and then Allow_ALI then
Last := Source_File_Name'Length;
while Name (Last) /= '.' loop
Last := Last - 1;
end loop;
- Name (Last + 1 .. Last + 3) := "ali";
- Name_Len := Last + 3;
- Name_Buffer (1 .. Name_Len) := Name (1 .. Name_Len);
+ Name_Len := 0;
+ Add_Str_To_Name_Buffer (Name (1 .. Last));
+ Add_Str_To_Name_Buffer ("ali");
+
Switches :=
Prj.Util.Value_Of
(Index => Name_Find,
end if;
end Usage;
- -----------------
- -- Verbose_Msg --
- -----------------
-
- procedure Verbose_Msg
- (N1 : Name_Id;
- S1 : String;
- N2 : Name_Id := No_Name;
- S2 : String := "";
- Prefix : String := " -> ";
- Minimum_Verbosity : Verbosity_Level_Type := Opt.Low)
- is
- begin
- if (not Verbose_Mode) or else (Minimum_Verbosity > Verbosity_Level) then
- return;
- end if;
-
- Write_Str (Prefix);
- Write_Str ("""");
- Write_Name (N1);
- Write_Str (""" ");
- Write_Str (S1);
-
- if N2 /= No_Name then
- Write_Str (" """);
- Write_Name (N2);
- Write_Str (""" ");
- end if;
-
- Write_Str (S2);
- Write_Eol;
- end Verbose_Msg;
-
- procedure Verbose_Msg
- (N1 : File_Name_Type;
- S1 : String;
- N2 : File_Name_Type := No_File;
- S2 : String := "";
- Prefix : String := " -> ";
- Minimum_Verbosity : Verbosity_Level_Type := Opt.Low)
- is
- begin
- Verbose_Msg
- (Name_Id (N1), S1, Name_Id (N2), S2, Prefix, Minimum_Verbosity);
- end Verbose_Msg;
-
begin
-- Make sure that in case of failure, the temp files will be deleted