------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
-- --
|
-- --
|
-- GNAT COMPILER COMPONENTS --
|
-- GNAT COMPILER COMPONENTS --
|
-- --
|
-- --
|
-- P R J . E N V --
|
-- P R J . E N V --
|
-- --
|
-- --
|
-- B o d y --
|
-- B o d y --
|
-- --
|
-- --
|
-- Copyright (C) 2001-2009, Free Software Foundation, Inc. --
|
-- Copyright (C) 2001-2009, Free Software Foundation, Inc. --
|
-- --
|
-- --
|
-- GNAT is free software; you can redistribute it and/or modify it under --
|
-- 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- --
|
-- terms of the GNU General Public License as published by the Free Soft- --
|
-- ware Foundation; either version 3, or (at your option) any later ver- --
|
-- ware Foundation; either version 3, or (at your option) any later ver- --
|
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
|
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
|
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
|
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
|
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
|
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
|
-- for more details. You should have received a copy of the GNU General --
|
-- for more details. You should have received a copy of the GNU General --
|
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
|
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
|
-- http://www.gnu.org/licenses for a complete copy of the license. --
|
-- http://www.gnu.org/licenses for a complete copy of the license. --
|
-- --
|
-- --
|
-- GNAT was originally developed by the GNAT team at New York University. --
|
-- GNAT was originally developed by the GNAT team at New York University. --
|
-- Extensive contributions were provided by Ada Core Technologies Inc. --
|
-- Extensive contributions were provided by Ada Core Technologies Inc. --
|
-- --
|
-- --
|
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
|
|
with Fmap;
|
with Fmap;
|
with Opt;
|
with Opt;
|
with Osint; use Osint;
|
with Osint; use Osint;
|
with Output; use Output;
|
with Output; use Output;
|
with Prj.Com; use Prj.Com;
|
with Prj.Com; use Prj.Com;
|
with Tempdir;
|
with Tempdir;
|
|
|
package body Prj.Env is
|
package body Prj.Env is
|
|
|
Buffer_Initial : constant := 1_000;
|
Buffer_Initial : constant := 1_000;
|
-- Initial size of Buffer
|
-- Initial size of Buffer
|
|
|
-----------------------
|
-----------------------
|
-- Local Subprograms --
|
-- Local Subprograms --
|
-----------------------
|
-----------------------
|
|
|
package Source_Path_Table is new GNAT.Dynamic_Tables
|
package Source_Path_Table is new GNAT.Dynamic_Tables
|
(Table_Component_Type => Name_Id,
|
(Table_Component_Type => Name_Id,
|
Table_Index_Type => Natural,
|
Table_Index_Type => Natural,
|
Table_Low_Bound => 1,
|
Table_Low_Bound => 1,
|
Table_Initial => 50,
|
Table_Initial => 50,
|
Table_Increment => 100);
|
Table_Increment => 100);
|
-- A table to store the source dirs before creating the source path file
|
-- A table to store the source dirs before creating the source path file
|
|
|
package Object_Path_Table is new GNAT.Dynamic_Tables
|
package Object_Path_Table is new GNAT.Dynamic_Tables
|
(Table_Component_Type => Path_Name_Type,
|
(Table_Component_Type => Path_Name_Type,
|
Table_Index_Type => Natural,
|
Table_Index_Type => Natural,
|
Table_Low_Bound => 1,
|
Table_Low_Bound => 1,
|
Table_Initial => 50,
|
Table_Initial => 50,
|
Table_Increment => 100);
|
Table_Increment => 100);
|
-- A table to store the object dirs, before creating the object path file
|
-- A table to store the object dirs, before creating the object path file
|
|
|
procedure Add_To_Buffer
|
procedure Add_To_Buffer
|
(S : String;
|
(S : String;
|
Buffer : in out String_Access;
|
Buffer : in out String_Access;
|
Buffer_Last : in out Natural);
|
Buffer_Last : in out Natural);
|
-- Add a string to Buffer, extending Buffer if needed
|
-- Add a string to Buffer, extending Buffer if needed
|
|
|
procedure Add_To_Path
|
procedure Add_To_Path
|
(Source_Dirs : String_List_Id;
|
(Source_Dirs : String_List_Id;
|
In_Tree : Project_Tree_Ref;
|
In_Tree : Project_Tree_Ref;
|
Buffer : in out String_Access;
|
Buffer : in out String_Access;
|
Buffer_Last : in out Natural);
|
Buffer_Last : in out Natural);
|
-- Add to Ada_Path_Buffer all the source directories in string list
|
-- Add to Ada_Path_Buffer all the source directories in string list
|
-- Source_Dirs, if any.
|
-- Source_Dirs, if any.
|
|
|
procedure Add_To_Path
|
procedure Add_To_Path
|
(Dir : String;
|
(Dir : String;
|
Buffer : in out String_Access;
|
Buffer : in out String_Access;
|
Buffer_Last : in out Natural);
|
Buffer_Last : in out Natural);
|
-- If Dir is not already in the global variable Ada_Path_Buffer, add it.
|
-- If Dir is not already in the global variable Ada_Path_Buffer, add it.
|
-- If Buffer_Last /= 0, prepend a Path_Separator character to Path.
|
-- If Buffer_Last /= 0, prepend a Path_Separator character to Path.
|
|
|
procedure Add_To_Source_Path
|
procedure Add_To_Source_Path
|
(Source_Dirs : String_List_Id;
|
(Source_Dirs : String_List_Id;
|
In_Tree : Project_Tree_Ref;
|
In_Tree : Project_Tree_Ref;
|
Source_Paths : in out Source_Path_Table.Instance);
|
Source_Paths : in out Source_Path_Table.Instance);
|
-- Add to Ada_Path_B all the source directories in string list
|
-- Add to Ada_Path_B all the source directories in string list
|
-- Source_Dirs, if any. Increment Ada_Path_Length.
|
-- Source_Dirs, if any. Increment Ada_Path_Length.
|
|
|
procedure Add_To_Object_Path
|
procedure Add_To_Object_Path
|
(Object_Dir : Path_Name_Type;
|
(Object_Dir : Path_Name_Type;
|
Object_Paths : in out Object_Path_Table.Instance);
|
Object_Paths : in out Object_Path_Table.Instance);
|
-- Add Object_Dir to object path table. Make sure it is not duplicate
|
-- Add Object_Dir to object path table. Make sure it is not duplicate
|
-- and it is the last one in the current table.
|
-- and it is the last one in the current table.
|
|
|
procedure Set_Path_File_Var (Name : String; Value : String);
|
procedure Set_Path_File_Var (Name : String; Value : String);
|
-- Call Setenv, after calling To_Host_File_Spec
|
-- Call Setenv, after calling To_Host_File_Spec
|
|
|
function Ultimate_Extension_Of
|
function Ultimate_Extension_Of
|
(Project : Project_Id) return Project_Id;
|
(Project : Project_Id) return Project_Id;
|
-- Return a project that is either Project or an extended ancestor of
|
-- Return a project that is either Project or an extended ancestor of
|
-- Project that itself is not extended.
|
-- Project that itself is not extended.
|
|
|
----------------------
|
----------------------
|
-- Ada_Include_Path --
|
-- Ada_Include_Path --
|
----------------------
|
----------------------
|
|
|
function Ada_Include_Path
|
function Ada_Include_Path
|
(Project : Project_Id;
|
(Project : Project_Id;
|
In_Tree : Project_Tree_Ref;
|
In_Tree : Project_Tree_Ref;
|
Recursive : Boolean := False) return String
|
Recursive : Boolean := False) return String
|
is
|
is
|
Buffer : String_Access;
|
Buffer : String_Access;
|
Buffer_Last : Natural := 0;
|
Buffer_Last : Natural := 0;
|
|
|
procedure Add (Project : Project_Id; Dummy : in out Boolean);
|
procedure Add (Project : Project_Id; Dummy : in out Boolean);
|
-- Add source dirs of Project to the path
|
-- Add source dirs of Project to the path
|
|
|
---------
|
---------
|
-- Add --
|
-- Add --
|
---------
|
---------
|
|
|
procedure Add (Project : Project_Id; Dummy : in out Boolean) is
|
procedure Add (Project : Project_Id; Dummy : in out Boolean) is
|
pragma Unreferenced (Dummy);
|
pragma Unreferenced (Dummy);
|
begin
|
begin
|
Add_To_Path (Project.Source_Dirs, In_Tree, Buffer, Buffer_Last);
|
Add_To_Path (Project.Source_Dirs, In_Tree, Buffer, Buffer_Last);
|
end Add;
|
end Add;
|
|
|
procedure For_All_Projects is
|
procedure For_All_Projects is
|
new For_Every_Project_Imported (Boolean, Add);
|
new For_Every_Project_Imported (Boolean, Add);
|
|
|
Dummy : Boolean := False;
|
Dummy : Boolean := False;
|
|
|
-- Start of processing for Ada_Include_Path
|
-- Start of processing for Ada_Include_Path
|
|
|
begin
|
begin
|
if Recursive then
|
if Recursive then
|
|
|
-- If it is the first time we call this function for
|
-- If it is the first time we call this function for
|
-- this project, compute the source path
|
-- this project, compute the source path
|
|
|
if Project.Ada_Include_Path = null then
|
if Project.Ada_Include_Path = null then
|
Buffer := new String (1 .. 4096);
|
Buffer := new String (1 .. 4096);
|
For_All_Projects (Project, Dummy);
|
For_All_Projects (Project, Dummy);
|
Project.Ada_Include_Path := new String'(Buffer (1 .. Buffer_Last));
|
Project.Ada_Include_Path := new String'(Buffer (1 .. Buffer_Last));
|
Free (Buffer);
|
Free (Buffer);
|
end if;
|
end if;
|
|
|
return Project.Ada_Include_Path.all;
|
return Project.Ada_Include_Path.all;
|
|
|
else
|
else
|
Buffer := new String (1 .. 4096);
|
Buffer := new String (1 .. 4096);
|
Add_To_Path (Project.Source_Dirs, In_Tree, Buffer, Buffer_Last);
|
Add_To_Path (Project.Source_Dirs, In_Tree, Buffer, Buffer_Last);
|
|
|
declare
|
declare
|
Result : constant String := Buffer (1 .. Buffer_Last);
|
Result : constant String := Buffer (1 .. Buffer_Last);
|
begin
|
begin
|
Free (Buffer);
|
Free (Buffer);
|
return Result;
|
return Result;
|
end;
|
end;
|
end if;
|
end if;
|
end Ada_Include_Path;
|
end Ada_Include_Path;
|
|
|
----------------------
|
----------------------
|
-- Ada_Objects_Path --
|
-- Ada_Objects_Path --
|
----------------------
|
----------------------
|
|
|
function Ada_Objects_Path
|
function Ada_Objects_Path
|
(Project : Project_Id;
|
(Project : Project_Id;
|
Including_Libraries : Boolean := True) return String_Access
|
Including_Libraries : Boolean := True) return String_Access
|
is
|
is
|
Buffer : String_Access;
|
Buffer : String_Access;
|
Buffer_Last : Natural := 0;
|
Buffer_Last : Natural := 0;
|
|
|
procedure Add (Project : Project_Id; Dummy : in out Boolean);
|
procedure Add (Project : Project_Id; Dummy : in out Boolean);
|
-- Add all the object directories of a project to the path
|
-- Add all the object directories of a project to the path
|
|
|
---------
|
---------
|
-- Add --
|
-- Add --
|
---------
|
---------
|
|
|
procedure Add (Project : Project_Id; Dummy : in out Boolean) is
|
procedure Add (Project : Project_Id; Dummy : in out Boolean) is
|
pragma Unreferenced (Dummy);
|
pragma Unreferenced (Dummy);
|
Path : constant Path_Name_Type :=
|
Path : constant Path_Name_Type :=
|
Get_Object_Directory
|
Get_Object_Directory
|
(Project,
|
(Project,
|
Including_Libraries => Including_Libraries,
|
Including_Libraries => Including_Libraries,
|
Only_If_Ada => False);
|
Only_If_Ada => False);
|
begin
|
begin
|
if Path /= No_Path then
|
if Path /= No_Path then
|
Add_To_Path (Get_Name_String (Path), Buffer, Buffer_Last);
|
Add_To_Path (Get_Name_String (Path), Buffer, Buffer_Last);
|
end if;
|
end if;
|
end Add;
|
end Add;
|
|
|
procedure For_All_Projects is
|
procedure For_All_Projects is
|
new For_Every_Project_Imported (Boolean, Add);
|
new For_Every_Project_Imported (Boolean, Add);
|
|
|
Dummy : Boolean := False;
|
Dummy : Boolean := False;
|
|
|
-- Start of processing for Ada_Objects_Path
|
-- Start of processing for Ada_Objects_Path
|
|
|
begin
|
begin
|
-- If it is the first time we call this function for
|
-- If it is the first time we call this function for
|
-- this project, compute the objects path
|
-- this project, compute the objects path
|
|
|
if Project.Ada_Objects_Path = null then
|
if Project.Ada_Objects_Path = null then
|
Buffer := new String (1 .. 4096);
|
Buffer := new String (1 .. 4096);
|
For_All_Projects (Project, Dummy);
|
For_All_Projects (Project, Dummy);
|
|
|
Project.Ada_Objects_Path := new String'(Buffer (1 .. Buffer_Last));
|
Project.Ada_Objects_Path := new String'(Buffer (1 .. Buffer_Last));
|
Free (Buffer);
|
Free (Buffer);
|
end if;
|
end if;
|
|
|
return Project.Ada_Objects_Path;
|
return Project.Ada_Objects_Path;
|
end Ada_Objects_Path;
|
end Ada_Objects_Path;
|
|
|
-------------------
|
-------------------
|
-- Add_To_Buffer --
|
-- Add_To_Buffer --
|
-------------------
|
-------------------
|
|
|
procedure Add_To_Buffer
|
procedure Add_To_Buffer
|
(S : String;
|
(S : String;
|
Buffer : in out String_Access;
|
Buffer : in out String_Access;
|
Buffer_Last : in out Natural)
|
Buffer_Last : in out Natural)
|
is
|
is
|
Last : constant Natural := Buffer_Last + S'Length;
|
Last : constant Natural := Buffer_Last + S'Length;
|
|
|
begin
|
begin
|
while Last > Buffer'Last loop
|
while Last > Buffer'Last loop
|
declare
|
declare
|
New_Buffer : constant String_Access :=
|
New_Buffer : constant String_Access :=
|
new String (1 .. 2 * Buffer'Last);
|
new String (1 .. 2 * Buffer'Last);
|
begin
|
begin
|
New_Buffer (1 .. Buffer_Last) := Buffer (1 .. Buffer_Last);
|
New_Buffer (1 .. Buffer_Last) := Buffer (1 .. Buffer_Last);
|
Free (Buffer);
|
Free (Buffer);
|
Buffer := New_Buffer;
|
Buffer := New_Buffer;
|
end;
|
end;
|
end loop;
|
end loop;
|
|
|
Buffer (Buffer_Last + 1 .. Last) := S;
|
Buffer (Buffer_Last + 1 .. Last) := S;
|
Buffer_Last := Last;
|
Buffer_Last := Last;
|
end Add_To_Buffer;
|
end Add_To_Buffer;
|
|
|
------------------------
|
------------------------
|
-- Add_To_Object_Path --
|
-- Add_To_Object_Path --
|
------------------------
|
------------------------
|
|
|
procedure Add_To_Object_Path
|
procedure Add_To_Object_Path
|
(Object_Dir : Path_Name_Type;
|
(Object_Dir : Path_Name_Type;
|
Object_Paths : in out Object_Path_Table.Instance)
|
Object_Paths : in out Object_Path_Table.Instance)
|
is
|
is
|
begin
|
begin
|
-- Check if the directory is already in the table
|
-- Check if the directory is already in the table
|
|
|
for Index in Object_Path_Table.First ..
|
for Index in Object_Path_Table.First ..
|
Object_Path_Table.Last (Object_Paths)
|
Object_Path_Table.Last (Object_Paths)
|
loop
|
loop
|
|
|
-- If it is, remove it, and add it as the last one
|
-- If it is, remove it, and add it as the last one
|
|
|
if Object_Paths.Table (Index) = Object_Dir then
|
if Object_Paths.Table (Index) = Object_Dir then
|
for Index2 in Index + 1 ..
|
for Index2 in Index + 1 ..
|
Object_Path_Table.Last (Object_Paths)
|
Object_Path_Table.Last (Object_Paths)
|
loop
|
loop
|
Object_Paths.Table (Index2 - 1) := Object_Paths.Table (Index2);
|
Object_Paths.Table (Index2 - 1) := Object_Paths.Table (Index2);
|
end loop;
|
end loop;
|
|
|
Object_Paths.Table
|
Object_Paths.Table
|
(Object_Path_Table.Last (Object_Paths)) := Object_Dir;
|
(Object_Path_Table.Last (Object_Paths)) := Object_Dir;
|
return;
|
return;
|
end if;
|
end if;
|
end loop;
|
end loop;
|
|
|
-- The directory is not already in the table, add it
|
-- The directory is not already in the table, add it
|
|
|
Object_Path_Table.Append (Object_Paths, Object_Dir);
|
Object_Path_Table.Append (Object_Paths, Object_Dir);
|
end Add_To_Object_Path;
|
end Add_To_Object_Path;
|
|
|
-----------------
|
-----------------
|
-- Add_To_Path --
|
-- Add_To_Path --
|
-----------------
|
-----------------
|
|
|
procedure Add_To_Path
|
procedure Add_To_Path
|
(Source_Dirs : String_List_Id;
|
(Source_Dirs : String_List_Id;
|
In_Tree : Project_Tree_Ref;
|
In_Tree : Project_Tree_Ref;
|
Buffer : in out String_Access;
|
Buffer : in out String_Access;
|
Buffer_Last : in out Natural)
|
Buffer_Last : in out Natural)
|
is
|
is
|
Current : String_List_Id := Source_Dirs;
|
Current : String_List_Id := Source_Dirs;
|
Source_Dir : String_Element;
|
Source_Dir : String_Element;
|
begin
|
begin
|
while Current /= Nil_String loop
|
while Current /= Nil_String loop
|
Source_Dir := In_Tree.String_Elements.Table (Current);
|
Source_Dir := In_Tree.String_Elements.Table (Current);
|
Add_To_Path (Get_Name_String (Source_Dir.Display_Value),
|
Add_To_Path (Get_Name_String (Source_Dir.Display_Value),
|
Buffer, Buffer_Last);
|
Buffer, Buffer_Last);
|
Current := Source_Dir.Next;
|
Current := Source_Dir.Next;
|
end loop;
|
end loop;
|
end Add_To_Path;
|
end Add_To_Path;
|
|
|
procedure Add_To_Path
|
procedure Add_To_Path
|
(Dir : String;
|
(Dir : String;
|
Buffer : in out String_Access;
|
Buffer : in out String_Access;
|
Buffer_Last : in out Natural)
|
Buffer_Last : in out Natural)
|
is
|
is
|
Len : Natural;
|
Len : Natural;
|
New_Buffer : String_Access;
|
New_Buffer : String_Access;
|
Min_Len : Natural;
|
Min_Len : Natural;
|
|
|
function Is_Present (Path : String; Dir : String) return Boolean;
|
function Is_Present (Path : String; Dir : String) return Boolean;
|
-- Return True if Dir is part of Path
|
-- Return True if Dir is part of Path
|
|
|
----------------
|
----------------
|
-- Is_Present --
|
-- Is_Present --
|
----------------
|
----------------
|
|
|
function Is_Present (Path : String; Dir : String) return Boolean is
|
function Is_Present (Path : String; Dir : String) return Boolean is
|
Last : constant Integer := Path'Last - Dir'Length + 1;
|
Last : constant Integer := Path'Last - Dir'Length + 1;
|
|
|
begin
|
begin
|
for J in Path'First .. Last loop
|
for J in Path'First .. Last loop
|
|
|
-- Note: the order of the conditions below is important, since
|
-- Note: the order of the conditions below is important, since
|
-- it ensures a minimal number of string comparisons.
|
-- it ensures a minimal number of string comparisons.
|
|
|
if (J = Path'First
|
if (J = Path'First
|
or else Path (J - 1) = Path_Separator)
|
or else Path (J - 1) = Path_Separator)
|
and then
|
and then
|
(J + Dir'Length > Path'Last
|
(J + Dir'Length > Path'Last
|
or else Path (J + Dir'Length) = Path_Separator)
|
or else Path (J + Dir'Length) = Path_Separator)
|
and then Dir = Path (J .. J + Dir'Length - 1)
|
and then Dir = Path (J .. J + Dir'Length - 1)
|
then
|
then
|
return True;
|
return True;
|
end if;
|
end if;
|
end loop;
|
end loop;
|
|
|
return False;
|
return False;
|
end Is_Present;
|
end Is_Present;
|
|
|
-- Start of processing for Add_To_Path
|
-- Start of processing for Add_To_Path
|
|
|
begin
|
begin
|
if Is_Present (Buffer (1 .. Buffer_Last), Dir) then
|
if Is_Present (Buffer (1 .. Buffer_Last), Dir) then
|
|
|
-- Dir is already in the path, nothing to do
|
-- Dir is already in the path, nothing to do
|
|
|
return;
|
return;
|
end if;
|
end if;
|
|
|
Min_Len := Buffer_Last + Dir'Length;
|
Min_Len := Buffer_Last + Dir'Length;
|
|
|
if Buffer_Last > 0 then
|
if Buffer_Last > 0 then
|
|
|
-- Add 1 for the Path_Separator character
|
-- Add 1 for the Path_Separator character
|
|
|
Min_Len := Min_Len + 1;
|
Min_Len := Min_Len + 1;
|
end if;
|
end if;
|
|
|
-- If Ada_Path_Buffer is too small, increase it
|
-- If Ada_Path_Buffer is too small, increase it
|
|
|
Len := Buffer'Last;
|
Len := Buffer'Last;
|
|
|
if Len < Min_Len then
|
if Len < Min_Len then
|
loop
|
loop
|
Len := Len * 2;
|
Len := Len * 2;
|
exit when Len >= Min_Len;
|
exit when Len >= Min_Len;
|
end loop;
|
end loop;
|
|
|
New_Buffer := new String (1 .. Len);
|
New_Buffer := new String (1 .. Len);
|
New_Buffer (1 .. Buffer_Last) := Buffer (1 .. Buffer_Last);
|
New_Buffer (1 .. Buffer_Last) := Buffer (1 .. Buffer_Last);
|
Free (Buffer);
|
Free (Buffer);
|
Buffer := New_Buffer;
|
Buffer := New_Buffer;
|
end if;
|
end if;
|
|
|
if Buffer_Last > 0 then
|
if Buffer_Last > 0 then
|
Buffer_Last := Buffer_Last + 1;
|
Buffer_Last := Buffer_Last + 1;
|
Buffer (Buffer_Last) := Path_Separator;
|
Buffer (Buffer_Last) := Path_Separator;
|
end if;
|
end if;
|
|
|
Buffer (Buffer_Last + 1 .. Buffer_Last + Dir'Length) := Dir;
|
Buffer (Buffer_Last + 1 .. Buffer_Last + Dir'Length) := Dir;
|
Buffer_Last := Buffer_Last + Dir'Length;
|
Buffer_Last := Buffer_Last + Dir'Length;
|
end Add_To_Path;
|
end Add_To_Path;
|
|
|
------------------------
|
------------------------
|
-- Add_To_Source_Path --
|
-- Add_To_Source_Path --
|
------------------------
|
------------------------
|
|
|
procedure Add_To_Source_Path
|
procedure Add_To_Source_Path
|
(Source_Dirs : String_List_Id;
|
(Source_Dirs : String_List_Id;
|
In_Tree : Project_Tree_Ref;
|
In_Tree : Project_Tree_Ref;
|
Source_Paths : in out Source_Path_Table.Instance)
|
Source_Paths : in out Source_Path_Table.Instance)
|
is
|
is
|
Current : String_List_Id := Source_Dirs;
|
Current : String_List_Id := Source_Dirs;
|
Source_Dir : String_Element;
|
Source_Dir : String_Element;
|
Add_It : Boolean;
|
Add_It : Boolean;
|
|
|
begin
|
begin
|
-- Add each source directory
|
-- Add each source directory
|
|
|
while Current /= Nil_String loop
|
while Current /= Nil_String loop
|
Source_Dir := In_Tree.String_Elements.Table (Current);
|
Source_Dir := In_Tree.String_Elements.Table (Current);
|
Add_It := True;
|
Add_It := True;
|
|
|
-- Check if the source directory is already in the table
|
-- Check if the source directory is already in the table
|
|
|
for Index in Source_Path_Table.First ..
|
for Index in Source_Path_Table.First ..
|
Source_Path_Table.Last (Source_Paths)
|
Source_Path_Table.Last (Source_Paths)
|
loop
|
loop
|
-- If it is already, no need to add it
|
-- If it is already, no need to add it
|
|
|
if Source_Paths.Table (Index) = Source_Dir.Value then
|
if Source_Paths.Table (Index) = Source_Dir.Value then
|
Add_It := False;
|
Add_It := False;
|
exit;
|
exit;
|
end if;
|
end if;
|
end loop;
|
end loop;
|
|
|
if Add_It then
|
if Add_It then
|
Source_Path_Table.Append (Source_Paths, Source_Dir.Display_Value);
|
Source_Path_Table.Append (Source_Paths, Source_Dir.Display_Value);
|
end if;
|
end if;
|
|
|
-- Next source directory
|
-- Next source directory
|
|
|
Current := Source_Dir.Next;
|
Current := Source_Dir.Next;
|
end loop;
|
end loop;
|
end Add_To_Source_Path;
|
end Add_To_Source_Path;
|
|
|
--------------------------------
|
--------------------------------
|
-- Create_Config_Pragmas_File --
|
-- Create_Config_Pragmas_File --
|
--------------------------------
|
--------------------------------
|
|
|
procedure Create_Config_Pragmas_File
|
procedure Create_Config_Pragmas_File
|
(For_Project : Project_Id;
|
(For_Project : Project_Id;
|
In_Tree : Project_Tree_Ref)
|
In_Tree : Project_Tree_Ref)
|
is
|
is
|
type Naming_Id is new Nat;
|
type Naming_Id is new Nat;
|
package Naming_Table is new GNAT.Dynamic_Tables
|
package Naming_Table is new GNAT.Dynamic_Tables
|
(Table_Component_Type => Lang_Naming_Data,
|
(Table_Component_Type => Lang_Naming_Data,
|
Table_Index_Type => Naming_Id,
|
Table_Index_Type => Naming_Id,
|
Table_Low_Bound => 1,
|
Table_Low_Bound => 1,
|
Table_Initial => 5,
|
Table_Initial => 5,
|
Table_Increment => 100);
|
Table_Increment => 100);
|
Default_Naming : constant Naming_Id := Naming_Table.First;
|
Default_Naming : constant Naming_Id := Naming_Table.First;
|
Namings : Naming_Table.Instance;
|
Namings : Naming_Table.Instance;
|
-- Table storing the naming data for gnatmake/gprmake
|
-- Table storing the naming data for gnatmake/gprmake
|
|
|
Buffer : String_Access := new String (1 .. Buffer_Initial);
|
Buffer : String_Access := new String (1 .. Buffer_Initial);
|
Buffer_Last : Natural := 0;
|
Buffer_Last : Natural := 0;
|
|
|
File_Name : Path_Name_Type := No_Path;
|
File_Name : Path_Name_Type := No_Path;
|
File : File_Descriptor := Invalid_FD;
|
File : File_Descriptor := Invalid_FD;
|
|
|
Current_Naming : Naming_Id;
|
Current_Naming : Naming_Id;
|
Iter : Source_Iterator;
|
Iter : Source_Iterator;
|
Source : Source_Id;
|
Source : Source_Id;
|
|
|
procedure Check (Project : Project_Id; State : in out Integer);
|
procedure Check (Project : Project_Id; State : in out Integer);
|
-- Recursive procedure that put in the config pragmas file any non
|
-- Recursive procedure that put in the config pragmas file any non
|
-- standard naming schemes, if it is not already in the file, then call
|
-- standard naming schemes, if it is not already in the file, then call
|
-- itself for any imported project.
|
-- itself for any imported project.
|
|
|
procedure Put (Source : Source_Id);
|
procedure Put (Source : Source_Id);
|
-- Put an SFN pragma in the temporary file
|
-- Put an SFN pragma in the temporary file
|
|
|
procedure Put (S : String);
|
procedure Put (S : String);
|
procedure Put_Line (S : String);
|
procedure Put_Line (S : String);
|
-- Output procedures, analogous to normal Text_IO procs of same name.
|
-- Output procedures, analogous to normal Text_IO procs of same name.
|
-- The text is put in Buffer, then it will be writen into a temporary
|
-- The text is put in Buffer, then it will be writen into a temporary
|
-- file with procedure Write_Temp_File below.
|
-- file with procedure Write_Temp_File below.
|
|
|
procedure Write_Temp_File;
|
procedure Write_Temp_File;
|
-- Create a temporary file and put the content of the buffer in it
|
-- Create a temporary file and put the content of the buffer in it
|
|
|
-----------
|
-----------
|
-- Check --
|
-- Check --
|
-----------
|
-----------
|
|
|
procedure Check (Project : Project_Id; State : in out Integer) is
|
procedure Check (Project : Project_Id; State : in out Integer) is
|
pragma Unreferenced (State);
|
pragma Unreferenced (State);
|
Lang : constant Language_Ptr :=
|
Lang : constant Language_Ptr :=
|
Get_Language_From_Name (Project, "ada");
|
Get_Language_From_Name (Project, "ada");
|
Naming : Lang_Naming_Data;
|
Naming : Lang_Naming_Data;
|
|
|
begin
|
begin
|
if Current_Verbosity = High then
|
if Current_Verbosity = High then
|
Write_Str ("Checking project file """);
|
Write_Str ("Checking project file """);
|
Write_Str (Namet.Get_Name_String (Project.Name));
|
Write_Str (Namet.Get_Name_String (Project.Name));
|
Write_Str (""".");
|
Write_Str (""".");
|
Write_Eol;
|
Write_Eol;
|
end if;
|
end if;
|
|
|
if Lang = null then
|
if Lang = null then
|
if Current_Verbosity = High then
|
if Current_Verbosity = High then
|
Write_Line (" Languages does not contain Ada, nothing to do");
|
Write_Line (" Languages does not contain Ada, nothing to do");
|
end if;
|
end if;
|
|
|
return;
|
return;
|
end if;
|
end if;
|
|
|
Naming := Lang.Config.Naming_Data;
|
Naming := Lang.Config.Naming_Data;
|
|
|
-- Is the naming scheme of this project one that we know?
|
-- Is the naming scheme of this project one that we know?
|
|
|
Current_Naming := Default_Naming;
|
Current_Naming := Default_Naming;
|
while Current_Naming <= Naming_Table.Last (Namings)
|
while Current_Naming <= Naming_Table.Last (Namings)
|
and then Namings.Table (Current_Naming).Dot_Replacement =
|
and then Namings.Table (Current_Naming).Dot_Replacement =
|
Naming.Dot_Replacement
|
Naming.Dot_Replacement
|
and then Namings.Table (Current_Naming).Casing =
|
and then Namings.Table (Current_Naming).Casing =
|
Naming.Casing
|
Naming.Casing
|
and then Namings.Table (Current_Naming).Separate_Suffix =
|
and then Namings.Table (Current_Naming).Separate_Suffix =
|
Naming.Separate_Suffix
|
Naming.Separate_Suffix
|
loop
|
loop
|
Current_Naming := Current_Naming + 1;
|
Current_Naming := Current_Naming + 1;
|
end loop;
|
end loop;
|
|
|
-- If we don't know it, add it
|
-- If we don't know it, add it
|
|
|
if Current_Naming > Naming_Table.Last (Namings) then
|
if Current_Naming > Naming_Table.Last (Namings) then
|
Naming_Table.Increment_Last (Namings);
|
Naming_Table.Increment_Last (Namings);
|
Namings.Table (Naming_Table.Last (Namings)) := Naming;
|
Namings.Table (Naming_Table.Last (Namings)) := Naming;
|
|
|
-- Put the SFN pragmas for the naming scheme
|
-- Put the SFN pragmas for the naming scheme
|
|
|
-- Spec
|
-- Spec
|
|
|
Put_Line
|
Put_Line
|
("pragma Source_File_Name_Project");
|
("pragma Source_File_Name_Project");
|
Put_Line
|
Put_Line
|
(" (Spec_File_Name => ""*" &
|
(" (Spec_File_Name => ""*" &
|
Get_Name_String (Naming.Spec_Suffix) & """,");
|
Get_Name_String (Naming.Spec_Suffix) & """,");
|
Put_Line
|
Put_Line
|
(" Casing => " &
|
(" Casing => " &
|
Image (Naming.Casing) & ",");
|
Image (Naming.Casing) & ",");
|
Put_Line
|
Put_Line
|
(" Dot_Replacement => """ &
|
(" Dot_Replacement => """ &
|
Get_Name_String (Naming.Dot_Replacement) & """);");
|
Get_Name_String (Naming.Dot_Replacement) & """);");
|
|
|
-- and body
|
-- and body
|
|
|
Put_Line
|
Put_Line
|
("pragma Source_File_Name_Project");
|
("pragma Source_File_Name_Project");
|
Put_Line
|
Put_Line
|
(" (Body_File_Name => ""*" &
|
(" (Body_File_Name => ""*" &
|
Get_Name_String (Naming.Body_Suffix) & """,");
|
Get_Name_String (Naming.Body_Suffix) & """,");
|
Put_Line
|
Put_Line
|
(" Casing => " &
|
(" Casing => " &
|
Image (Naming.Casing) & ",");
|
Image (Naming.Casing) & ",");
|
Put_Line
|
Put_Line
|
(" Dot_Replacement => """ &
|
(" Dot_Replacement => """ &
|
Get_Name_String (Naming.Dot_Replacement) &
|
Get_Name_String (Naming.Dot_Replacement) &
|
""");");
|
""");");
|
|
|
-- and maybe separate
|
-- and maybe separate
|
|
|
if Naming.Body_Suffix /= Naming.Separate_Suffix then
|
if Naming.Body_Suffix /= Naming.Separate_Suffix then
|
Put_Line ("pragma Source_File_Name_Project");
|
Put_Line ("pragma Source_File_Name_Project");
|
Put_Line
|
Put_Line
|
(" (Subunit_File_Name => ""*" &
|
(" (Subunit_File_Name => ""*" &
|
Get_Name_String (Naming.Separate_Suffix) & """,");
|
Get_Name_String (Naming.Separate_Suffix) & """,");
|
Put_Line
|
Put_Line
|
(" Casing => " &
|
(" Casing => " &
|
Image (Naming.Casing) & ",");
|
Image (Naming.Casing) & ",");
|
Put_Line
|
Put_Line
|
(" Dot_Replacement => """ &
|
(" Dot_Replacement => """ &
|
Get_Name_String (Naming.Dot_Replacement) &
|
Get_Name_String (Naming.Dot_Replacement) &
|
""");");
|
""");");
|
end if;
|
end if;
|
end if;
|
end if;
|
end Check;
|
end Check;
|
|
|
---------
|
---------
|
-- Put --
|
-- Put --
|
---------
|
---------
|
|
|
procedure Put (Source : Source_Id) is
|
procedure Put (Source : Source_Id) is
|
begin
|
begin
|
-- Put the pragma SFN for the unit kind (spec or body)
|
-- Put the pragma SFN for the unit kind (spec or body)
|
|
|
Put ("pragma Source_File_Name_Project (");
|
Put ("pragma Source_File_Name_Project (");
|
Put (Namet.Get_Name_String (Source.Unit.Name));
|
Put (Namet.Get_Name_String (Source.Unit.Name));
|
|
|
if Source.Kind = Spec then
|
if Source.Kind = Spec then
|
Put (", Spec_File_Name => """);
|
Put (", Spec_File_Name => """);
|
else
|
else
|
Put (", Body_File_Name => """);
|
Put (", Body_File_Name => """);
|
end if;
|
end if;
|
|
|
Put (Namet.Get_Name_String (Source.File));
|
Put (Namet.Get_Name_String (Source.File));
|
Put ("""");
|
Put ("""");
|
|
|
if Source.Index /= 0 then
|
if Source.Index /= 0 then
|
Put (", Index =>");
|
Put (", Index =>");
|
Put (Source.Index'Img);
|
Put (Source.Index'Img);
|
end if;
|
end if;
|
|
|
Put_Line (");");
|
Put_Line (");");
|
end Put;
|
end Put;
|
|
|
procedure Put (S : String) is
|
procedure Put (S : String) is
|
begin
|
begin
|
Add_To_Buffer (S, Buffer, Buffer_Last);
|
Add_To_Buffer (S, Buffer, Buffer_Last);
|
|
|
if Current_Verbosity = High then
|
if Current_Verbosity = High then
|
Write_Str (S);
|
Write_Str (S);
|
end if;
|
end if;
|
end Put;
|
end Put;
|
|
|
--------------
|
--------------
|
-- Put_Line --
|
-- Put_Line --
|
--------------
|
--------------
|
|
|
procedure Put_Line (S : String) is
|
procedure Put_Line (S : String) is
|
begin
|
begin
|
-- Add an ASCII.LF to the string. As this config file is supposed to
|
-- Add an ASCII.LF to the string. As this config file is supposed to
|
-- be used only by the compiler, we don't care about the characters
|
-- be used only by the compiler, we don't care about the characters
|
-- for the end of line. In fact we could have put a space, but
|
-- for the end of line. In fact we could have put a space, but
|
-- it is more convenient to be able to read gnat.adc during
|
-- it is more convenient to be able to read gnat.adc during
|
-- development, for which the ASCII.LF is fine.
|
-- development, for which the ASCII.LF is fine.
|
|
|
Put (S);
|
Put (S);
|
Put (S => (1 => ASCII.LF));
|
Put (S => (1 => ASCII.LF));
|
end Put_Line;
|
end Put_Line;
|
|
|
---------------------
|
---------------------
|
-- Write_Temp_File --
|
-- Write_Temp_File --
|
---------------------
|
---------------------
|
|
|
procedure Write_Temp_File is
|
procedure Write_Temp_File is
|
Status : Boolean := False;
|
Status : Boolean := False;
|
Last : Natural;
|
Last : Natural;
|
|
|
begin
|
begin
|
Tempdir.Create_Temp_File (File, File_Name);
|
Tempdir.Create_Temp_File (File, File_Name);
|
|
|
if File /= Invalid_FD then
|
if File /= Invalid_FD then
|
Last := Write (File, Buffer (1)'Address, Buffer_Last);
|
Last := Write (File, Buffer (1)'Address, Buffer_Last);
|
|
|
if Last = Buffer_Last then
|
if Last = Buffer_Last then
|
Close (File, Status);
|
Close (File, Status);
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
if not Status then
|
if not Status then
|
Prj.Com.Fail ("unable to create temporary file");
|
Prj.Com.Fail ("unable to create temporary file");
|
end if;
|
end if;
|
end Write_Temp_File;
|
end Write_Temp_File;
|
|
|
procedure Check_Imported_Projects is
|
procedure Check_Imported_Projects is
|
new For_Every_Project_Imported (Integer, Check);
|
new For_Every_Project_Imported (Integer, Check);
|
|
|
Dummy : Integer := 0;
|
Dummy : Integer := 0;
|
|
|
-- Start of processing for Create_Config_Pragmas_File
|
-- Start of processing for Create_Config_Pragmas_File
|
|
|
begin
|
begin
|
if not For_Project.Config_Checked then
|
if not For_Project.Config_Checked then
|
Naming_Table.Init (Namings);
|
Naming_Table.Init (Namings);
|
|
|
-- Check the naming schemes
|
-- Check the naming schemes
|
|
|
Check_Imported_Projects (For_Project, Dummy, Imported_First => False);
|
Check_Imported_Projects (For_Project, Dummy, Imported_First => False);
|
|
|
-- Visit all the files and process those that need an SFN pragma
|
-- Visit all the files and process those that need an SFN pragma
|
|
|
Iter := For_Each_Source (In_Tree, For_Project);
|
Iter := For_Each_Source (In_Tree, For_Project);
|
while Element (Iter) /= No_Source loop
|
while Element (Iter) /= No_Source loop
|
Source := Element (Iter);
|
Source := Element (Iter);
|
|
|
if Source.Index >= 1
|
if Source.Index >= 1
|
and then not Source.Locally_Removed
|
and then not Source.Locally_Removed
|
and then Source.Unit /= null
|
and then Source.Unit /= null
|
then
|
then
|
Put (Source);
|
Put (Source);
|
end if;
|
end if;
|
|
|
Next (Iter);
|
Next (Iter);
|
end loop;
|
end loop;
|
|
|
-- If there are no non standard naming scheme, issue the GNAT
|
-- If there are no non standard naming scheme, issue the GNAT
|
-- standard naming scheme. This will tell the compiler that
|
-- standard naming scheme. This will tell the compiler that
|
-- a project file is used and will forbid any pragma SFN.
|
-- a project file is used and will forbid any pragma SFN.
|
|
|
if Buffer_Last = 0 then
|
if Buffer_Last = 0 then
|
|
|
Put_Line ("pragma Source_File_Name_Project");
|
Put_Line ("pragma Source_File_Name_Project");
|
Put_Line (" (Spec_File_Name => ""*.ads"",");
|
Put_Line (" (Spec_File_Name => ""*.ads"",");
|
Put_Line (" Dot_Replacement => ""-"",");
|
Put_Line (" Dot_Replacement => ""-"",");
|
Put_Line (" Casing => lowercase);");
|
Put_Line (" Casing => lowercase);");
|
|
|
Put_Line ("pragma Source_File_Name_Project");
|
Put_Line ("pragma Source_File_Name_Project");
|
Put_Line (" (Body_File_Name => ""*.adb"",");
|
Put_Line (" (Body_File_Name => ""*.adb"",");
|
Put_Line (" Dot_Replacement => ""-"",");
|
Put_Line (" Dot_Replacement => ""-"",");
|
Put_Line (" Casing => lowercase);");
|
Put_Line (" Casing => lowercase);");
|
end if;
|
end if;
|
|
|
-- Close the temporary file
|
-- Close the temporary file
|
|
|
Write_Temp_File;
|
Write_Temp_File;
|
|
|
if Opt.Verbose_Mode then
|
if Opt.Verbose_Mode then
|
Write_Str ("Created configuration file """);
|
Write_Str ("Created configuration file """);
|
Write_Str (Get_Name_String (File_Name));
|
Write_Str (Get_Name_String (File_Name));
|
Write_Line ("""");
|
Write_Line ("""");
|
end if;
|
end if;
|
|
|
For_Project.Config_File_Name := File_Name;
|
For_Project.Config_File_Name := File_Name;
|
For_Project.Config_File_Temp := True;
|
For_Project.Config_File_Temp := True;
|
For_Project.Config_Checked := True;
|
For_Project.Config_Checked := True;
|
end if;
|
end if;
|
|
|
Free (Buffer);
|
Free (Buffer);
|
end Create_Config_Pragmas_File;
|
end Create_Config_Pragmas_File;
|
|
|
--------------------
|
--------------------
|
-- Create_Mapping --
|
-- Create_Mapping --
|
--------------------
|
--------------------
|
|
|
procedure Create_Mapping (In_Tree : Project_Tree_Ref) is
|
procedure Create_Mapping (In_Tree : Project_Tree_Ref) is
|
Data : Source_Id;
|
Data : Source_Id;
|
Iter : Source_Iterator;
|
Iter : Source_Iterator;
|
|
|
begin
|
begin
|
Fmap.Reset_Tables;
|
Fmap.Reset_Tables;
|
|
|
Iter := For_Each_Source (In_Tree);
|
Iter := For_Each_Source (In_Tree);
|
loop
|
loop
|
Data := Element (Iter);
|
Data := Element (Iter);
|
exit when Data = No_Source;
|
exit when Data = No_Source;
|
|
|
if Data.Unit /= No_Unit_Index then
|
if Data.Unit /= No_Unit_Index then
|
if Data.Locally_Removed then
|
if Data.Locally_Removed then
|
Fmap.Add_Forbidden_File_Name (Data.File);
|
Fmap.Add_Forbidden_File_Name (Data.File);
|
else
|
else
|
Fmap.Add_To_File_Map
|
Fmap.Add_To_File_Map
|
(Unit_Name => Unit_Name_Type (Data.Unit.Name),
|
(Unit_Name => Unit_Name_Type (Data.Unit.Name),
|
File_Name => Data.File,
|
File_Name => Data.File,
|
Path_Name => File_Name_Type (Data.Path.Name));
|
Path_Name => File_Name_Type (Data.Path.Name));
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
Next (Iter);
|
Next (Iter);
|
end loop;
|
end loop;
|
end Create_Mapping;
|
end Create_Mapping;
|
|
|
-------------------------
|
-------------------------
|
-- Create_Mapping_File --
|
-- Create_Mapping_File --
|
-------------------------
|
-------------------------
|
|
|
procedure Create_Mapping_File
|
procedure Create_Mapping_File
|
(Project : Project_Id;
|
(Project : Project_Id;
|
Language : Name_Id;
|
Language : Name_Id;
|
In_Tree : Project_Tree_Ref;
|
In_Tree : Project_Tree_Ref;
|
Name : out Path_Name_Type)
|
Name : out Path_Name_Type)
|
is
|
is
|
File : File_Descriptor := Invalid_FD;
|
File : File_Descriptor := Invalid_FD;
|
|
|
Buffer : String_Access := new String (1 .. Buffer_Initial);
|
Buffer : String_Access := new String (1 .. Buffer_Initial);
|
Buffer_Last : Natural := 0;
|
Buffer_Last : Natural := 0;
|
|
|
procedure Put_Name_Buffer;
|
procedure Put_Name_Buffer;
|
-- Put the line contained in the Name_Buffer in the global buffer
|
-- Put the line contained in the Name_Buffer in the global buffer
|
|
|
procedure Process (Project : Project_Id; State : in out Integer);
|
procedure Process (Project : Project_Id; State : in out Integer);
|
-- Generate the mapping file for Project (not recursively)
|
-- Generate the mapping file for Project (not recursively)
|
|
|
---------------------
|
---------------------
|
-- Put_Name_Buffer --
|
-- Put_Name_Buffer --
|
---------------------
|
---------------------
|
|
|
procedure Put_Name_Buffer is
|
procedure Put_Name_Buffer is
|
begin
|
begin
|
Name_Len := Name_Len + 1;
|
Name_Len := Name_Len + 1;
|
Name_Buffer (Name_Len) := ASCII.LF;
|
Name_Buffer (Name_Len) := ASCII.LF;
|
|
|
if Current_Verbosity = High then
|
if Current_Verbosity = High then
|
Write_Str ("Mapping file: " & Name_Buffer (1 .. Name_Len));
|
Write_Str ("Mapping file: " & Name_Buffer (1 .. Name_Len));
|
end if;
|
end if;
|
|
|
Add_To_Buffer (Name_Buffer (1 .. Name_Len), Buffer, Buffer_Last);
|
Add_To_Buffer (Name_Buffer (1 .. Name_Len), Buffer, Buffer_Last);
|
end Put_Name_Buffer;
|
end Put_Name_Buffer;
|
|
|
-------------
|
-------------
|
-- Process --
|
-- Process --
|
-------------
|
-------------
|
|
|
procedure Process (Project : Project_Id; State : in out Integer) is
|
procedure Process (Project : Project_Id; State : in out Integer) is
|
pragma Unreferenced (State);
|
pragma Unreferenced (State);
|
Source : Source_Id;
|
Source : Source_Id;
|
Suffix : File_Name_Type;
|
Suffix : File_Name_Type;
|
Iter : Source_Iterator;
|
Iter : Source_Iterator;
|
|
|
begin
|
begin
|
Iter := For_Each_Source (In_Tree, Project, Language => Language);
|
Iter := For_Each_Source (In_Tree, Project, Language => Language);
|
|
|
loop
|
loop
|
Source := Prj.Element (Iter);
|
Source := Prj.Element (Iter);
|
exit when Source = No_Source;
|
exit when Source = No_Source;
|
|
|
if Source.Replaced_By = No_Source
|
if Source.Replaced_By = No_Source
|
and then Source.Path.Name /= No_Path
|
and then Source.Path.Name /= No_Path
|
and then
|
and then
|
(Source.Language.Config.Kind = File_Based
|
(Source.Language.Config.Kind = File_Based
|
or else Source.Unit /= No_Unit_Index)
|
or else Source.Unit /= No_Unit_Index)
|
then
|
then
|
if Source.Unit /= No_Unit_Index then
|
if Source.Unit /= No_Unit_Index then
|
Get_Name_String (Source.Unit.Name);
|
Get_Name_String (Source.Unit.Name);
|
|
|
if Source.Language.Config.Kind = Unit_Based then
|
if Source.Language.Config.Kind = Unit_Based then
|
|
|
-- ??? Mapping_Spec_Suffix could be set in the case of
|
-- ??? Mapping_Spec_Suffix could be set in the case of
|
-- gnatmake as well
|
-- gnatmake as well
|
|
|
Add_Char_To_Name_Buffer ('%');
|
Add_Char_To_Name_Buffer ('%');
|
|
|
if Source.Kind = Spec then
|
if Source.Kind = Spec then
|
Add_Char_To_Name_Buffer ('s');
|
Add_Char_To_Name_Buffer ('s');
|
else
|
else
|
Add_Char_To_Name_Buffer ('b');
|
Add_Char_To_Name_Buffer ('b');
|
end if;
|
end if;
|
|
|
else
|
else
|
case Source.Kind is
|
case Source.Kind is
|
when Spec =>
|
when Spec =>
|
Suffix :=
|
Suffix :=
|
Source.Language.Config.Mapping_Spec_Suffix;
|
Source.Language.Config.Mapping_Spec_Suffix;
|
when Impl | Sep =>
|
when Impl | Sep =>
|
Suffix :=
|
Suffix :=
|
Source.Language.Config.Mapping_Body_Suffix;
|
Source.Language.Config.Mapping_Body_Suffix;
|
end case;
|
end case;
|
|
|
if Suffix /= No_File then
|
if Suffix /= No_File then
|
Add_Str_To_Name_Buffer
|
Add_Str_To_Name_Buffer
|
(Get_Name_String (Suffix));
|
(Get_Name_String (Suffix));
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
Put_Name_Buffer;
|
Put_Name_Buffer;
|
end if;
|
end if;
|
|
|
Get_Name_String (Source.File);
|
Get_Name_String (Source.File);
|
Put_Name_Buffer;
|
Put_Name_Buffer;
|
|
|
if Source.Locally_Removed then
|
if Source.Locally_Removed then
|
Name_Len := 1;
|
Name_Len := 1;
|
Name_Buffer (1) := '/';
|
Name_Buffer (1) := '/';
|
else
|
else
|
Get_Name_String (Source.Path.Name);
|
Get_Name_String (Source.Path.Name);
|
end if;
|
end if;
|
|
|
Put_Name_Buffer;
|
Put_Name_Buffer;
|
end if;
|
end if;
|
|
|
Next (Iter);
|
Next (Iter);
|
end loop;
|
end loop;
|
end Process;
|
end Process;
|
|
|
procedure For_Every_Imported_Project is new
|
procedure For_Every_Imported_Project is new
|
For_Every_Project_Imported (State => Integer, Action => Process);
|
For_Every_Project_Imported (State => Integer, Action => Process);
|
|
|
Dummy : Integer := 0;
|
Dummy : Integer := 0;
|
|
|
-- Start of processing for Create_Mapping_File
|
-- Start of processing for Create_Mapping_File
|
|
|
begin
|
begin
|
For_Every_Imported_Project (Project, Dummy);
|
For_Every_Imported_Project (Project, Dummy);
|
|
|
declare
|
declare
|
Last : Natural;
|
Last : Natural;
|
Status : Boolean := False;
|
Status : Boolean := False;
|
|
|
begin
|
begin
|
Create_Temp_File (In_Tree, File, Name, "mapping");
|
Create_Temp_File (In_Tree, File, Name, "mapping");
|
|
|
if File /= Invalid_FD then
|
if File /= Invalid_FD then
|
Last := Write (File, Buffer (1)'Address, Buffer_Last);
|
Last := Write (File, Buffer (1)'Address, Buffer_Last);
|
|
|
if Last = Buffer_Last then
|
if Last = Buffer_Last then
|
GNAT.OS_Lib.Close (File, Status);
|
GNAT.OS_Lib.Close (File, Status);
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
if not Status then
|
if not Status then
|
Prj.Com.Fail ("could not write mapping file");
|
Prj.Com.Fail ("could not write mapping file");
|
end if;
|
end if;
|
end;
|
end;
|
|
|
Free (Buffer);
|
Free (Buffer);
|
end Create_Mapping_File;
|
end Create_Mapping_File;
|
|
|
----------------------
|
----------------------
|
-- Create_Temp_File --
|
-- Create_Temp_File --
|
----------------------
|
----------------------
|
|
|
procedure Create_Temp_File
|
procedure Create_Temp_File
|
(In_Tree : Project_Tree_Ref;
|
(In_Tree : Project_Tree_Ref;
|
Path_FD : out File_Descriptor;
|
Path_FD : out File_Descriptor;
|
Path_Name : out Path_Name_Type;
|
Path_Name : out Path_Name_Type;
|
File_Use : String)
|
File_Use : String)
|
is
|
is
|
begin
|
begin
|
Tempdir.Create_Temp_File (Path_FD, Path_Name);
|
Tempdir.Create_Temp_File (Path_FD, Path_Name);
|
|
|
if Path_Name /= No_Path then
|
if Path_Name /= No_Path then
|
if Current_Verbosity = High then
|
if Current_Verbosity = High then
|
Write_Line ("Create temp file (" & File_Use & ") "
|
Write_Line ("Create temp file (" & File_Use & ") "
|
& Get_Name_String (Path_Name));
|
& Get_Name_String (Path_Name));
|
end if;
|
end if;
|
|
|
Record_Temp_File (In_Tree, Path_Name);
|
Record_Temp_File (In_Tree, Path_Name);
|
|
|
else
|
else
|
Prj.Com.Fail
|
Prj.Com.Fail
|
("unable to create temporary " & File_Use & " file");
|
("unable to create temporary " & File_Use & " file");
|
end if;
|
end if;
|
end Create_Temp_File;
|
end Create_Temp_File;
|
|
|
--------------------------
|
--------------------------
|
-- Create_New_Path_File --
|
-- Create_New_Path_File --
|
--------------------------
|
--------------------------
|
|
|
procedure Create_New_Path_File
|
procedure Create_New_Path_File
|
(In_Tree : Project_Tree_Ref;
|
(In_Tree : Project_Tree_Ref;
|
Path_FD : out File_Descriptor;
|
Path_FD : out File_Descriptor;
|
Path_Name : out Path_Name_Type)
|
Path_Name : out Path_Name_Type)
|
is
|
is
|
begin
|
begin
|
Create_Temp_File (In_Tree, Path_FD, Path_Name, "path file");
|
Create_Temp_File (In_Tree, Path_FD, Path_Name, "path file");
|
end Create_New_Path_File;
|
end Create_New_Path_File;
|
|
|
------------------------------------
|
------------------------------------
|
-- File_Name_Of_Library_Unit_Body --
|
-- File_Name_Of_Library_Unit_Body --
|
------------------------------------
|
------------------------------------
|
|
|
function File_Name_Of_Library_Unit_Body
|
function File_Name_Of_Library_Unit_Body
|
(Name : String;
|
(Name : String;
|
Project : Project_Id;
|
Project : Project_Id;
|
In_Tree : Project_Tree_Ref;
|
In_Tree : Project_Tree_Ref;
|
Main_Project_Only : Boolean := True;
|
Main_Project_Only : Boolean := True;
|
Full_Path : Boolean := False) return String
|
Full_Path : Boolean := False) return String
|
is
|
is
|
The_Project : Project_Id := Project;
|
The_Project : Project_Id := Project;
|
Original_Name : String := Name;
|
Original_Name : String := Name;
|
|
|
Lang : constant Language_Ptr :=
|
Lang : constant Language_Ptr :=
|
Get_Language_From_Name (Project, "ada");
|
Get_Language_From_Name (Project, "ada");
|
|
|
Unit : Unit_Index;
|
Unit : Unit_Index;
|
The_Original_Name : Name_Id;
|
The_Original_Name : Name_Id;
|
The_Spec_Name : Name_Id;
|
The_Spec_Name : Name_Id;
|
The_Body_Name : Name_Id;
|
The_Body_Name : Name_Id;
|
|
|
begin
|
begin
|
-- ??? Same block in Project_Of
|
-- ??? Same block in Project_Of
|
Canonical_Case_File_Name (Original_Name);
|
Canonical_Case_File_Name (Original_Name);
|
Name_Len := Original_Name'Length;
|
Name_Len := Original_Name'Length;
|
Name_Buffer (1 .. Name_Len) := Original_Name;
|
Name_Buffer (1 .. Name_Len) := Original_Name;
|
The_Original_Name := Name_Find;
|
The_Original_Name := Name_Find;
|
|
|
if Lang /= null then
|
if Lang /= null then
|
declare
|
declare
|
Naming : constant Lang_Naming_Data := Lang.Config.Naming_Data;
|
Naming : constant Lang_Naming_Data := Lang.Config.Naming_Data;
|
Extended_Spec_Name : String :=
|
Extended_Spec_Name : String :=
|
Name & Namet.Get_Name_String
|
Name & Namet.Get_Name_String
|
(Naming.Spec_Suffix);
|
(Naming.Spec_Suffix);
|
Extended_Body_Name : String :=
|
Extended_Body_Name : String :=
|
Name & Namet.Get_Name_String
|
Name & Namet.Get_Name_String
|
(Naming.Body_Suffix);
|
(Naming.Body_Suffix);
|
|
|
begin
|
begin
|
Canonical_Case_File_Name (Extended_Spec_Name);
|
Canonical_Case_File_Name (Extended_Spec_Name);
|
Name_Len := Extended_Spec_Name'Length;
|
Name_Len := Extended_Spec_Name'Length;
|
Name_Buffer (1 .. Name_Len) := Extended_Spec_Name;
|
Name_Buffer (1 .. Name_Len) := Extended_Spec_Name;
|
The_Spec_Name := Name_Find;
|
The_Spec_Name := Name_Find;
|
|
|
Canonical_Case_File_Name (Extended_Body_Name);
|
Canonical_Case_File_Name (Extended_Body_Name);
|
Name_Len := Extended_Body_Name'Length;
|
Name_Len := Extended_Body_Name'Length;
|
Name_Buffer (1 .. Name_Len) := Extended_Body_Name;
|
Name_Buffer (1 .. Name_Len) := Extended_Body_Name;
|
The_Body_Name := Name_Find;
|
The_Body_Name := Name_Find;
|
end;
|
end;
|
|
|
else
|
else
|
Name_Len := Name'Length;
|
Name_Len := Name'Length;
|
Name_Buffer (1 .. Name_Len) := Name;
|
Name_Buffer (1 .. Name_Len) := Name;
|
Canonical_Case_File_Name (Name_Buffer);
|
Canonical_Case_File_Name (Name_Buffer);
|
The_Spec_Name := Name_Find;
|
The_Spec_Name := Name_Find;
|
The_Body_Name := The_Spec_Name;
|
The_Body_Name := The_Spec_Name;
|
end if;
|
end if;
|
|
|
if Current_Verbosity = High then
|
if Current_Verbosity = High then
|
Write_Str ("Looking for file name of """);
|
Write_Str ("Looking for file name of """);
|
Write_Str (Name);
|
Write_Str (Name);
|
Write_Char ('"');
|
Write_Char ('"');
|
Write_Eol;
|
Write_Eol;
|
Write_Str (" Extended Spec Name = """);
|
Write_Str (" Extended Spec Name = """);
|
Write_Str (Get_Name_String (The_Spec_Name));
|
Write_Str (Get_Name_String (The_Spec_Name));
|
Write_Char ('"');
|
Write_Char ('"');
|
Write_Eol;
|
Write_Eol;
|
Write_Str (" Extended Body Name = """);
|
Write_Str (" Extended Body Name = """);
|
Write_Str (Get_Name_String (The_Body_Name));
|
Write_Str (Get_Name_String (The_Body_Name));
|
Write_Char ('"');
|
Write_Char ('"');
|
Write_Eol;
|
Write_Eol;
|
end if;
|
end if;
|
|
|
-- For extending project, search in the extended project if the source
|
-- For extending project, search in the extended project if the source
|
-- is not found. For non extending projects, this loop will be run only
|
-- is not found. For non extending projects, this loop will be run only
|
-- once.
|
-- once.
|
|
|
loop
|
loop
|
-- Loop through units
|
-- Loop through units
|
|
|
Unit := Units_Htable.Get_First (In_Tree.Units_HT);
|
Unit := Units_Htable.Get_First (In_Tree.Units_HT);
|
while Unit /= null loop
|
while Unit /= null loop
|
-- Check for body
|
-- Check for body
|
|
|
if not Main_Project_Only
|
if not Main_Project_Only
|
or else
|
or else
|
(Unit.File_Names (Impl) /= null
|
(Unit.File_Names (Impl) /= null
|
and then Unit.File_Names (Impl).Project = The_Project)
|
and then Unit.File_Names (Impl).Project = The_Project)
|
then
|
then
|
declare
|
declare
|
Current_Name : File_Name_Type;
|
Current_Name : File_Name_Type;
|
begin
|
begin
|
-- Case of a body present
|
-- Case of a body present
|
|
|
if Unit.File_Names (Impl) /= null then
|
if Unit.File_Names (Impl) /= null then
|
Current_Name := Unit.File_Names (Impl).File;
|
Current_Name := Unit.File_Names (Impl).File;
|
|
|
if Current_Verbosity = High then
|
if Current_Verbosity = High then
|
Write_Str (" Comparing with """);
|
Write_Str (" Comparing with """);
|
Write_Str (Get_Name_String (Current_Name));
|
Write_Str (Get_Name_String (Current_Name));
|
Write_Char ('"');
|
Write_Char ('"');
|
Write_Eol;
|
Write_Eol;
|
end if;
|
end if;
|
|
|
-- If it has the name of the original name, return the
|
-- If it has the name of the original name, return the
|
-- original name.
|
-- original name.
|
|
|
if Unit.Name = The_Original_Name
|
if Unit.Name = The_Original_Name
|
or else
|
or else
|
Current_Name = File_Name_Type (The_Original_Name)
|
Current_Name = File_Name_Type (The_Original_Name)
|
then
|
then
|
if Current_Verbosity = High then
|
if Current_Verbosity = High then
|
Write_Line (" OK");
|
Write_Line (" OK");
|
end if;
|
end if;
|
|
|
if Full_Path then
|
if Full_Path then
|
return Get_Name_String
|
return Get_Name_String
|
(Unit.File_Names (Impl).Path.Name);
|
(Unit.File_Names (Impl).Path.Name);
|
|
|
else
|
else
|
return Get_Name_String (Current_Name);
|
return Get_Name_String (Current_Name);
|
end if;
|
end if;
|
|
|
-- If it has the name of the extended body name,
|
-- If it has the name of the extended body name,
|
-- return the extended body name
|
-- return the extended body name
|
|
|
elsif Current_Name = File_Name_Type (The_Body_Name) then
|
elsif Current_Name = File_Name_Type (The_Body_Name) then
|
if Current_Verbosity = High then
|
if Current_Verbosity = High then
|
Write_Line (" OK");
|
Write_Line (" OK");
|
end if;
|
end if;
|
|
|
if Full_Path then
|
if Full_Path then
|
return Get_Name_String
|
return Get_Name_String
|
(Unit.File_Names (Impl).Path.Name);
|
(Unit.File_Names (Impl).Path.Name);
|
|
|
else
|
else
|
return Get_Name_String (The_Body_Name);
|
return Get_Name_String (The_Body_Name);
|
end if;
|
end if;
|
|
|
else
|
else
|
if Current_Verbosity = High then
|
if Current_Verbosity = High then
|
Write_Line (" not good");
|
Write_Line (" not good");
|
end if;
|
end if;
|
end if;
|
end if;
|
end if;
|
end if;
|
end;
|
end;
|
end if;
|
end if;
|
|
|
-- Check for spec
|
-- Check for spec
|
|
|
if not Main_Project_Only
|
if not Main_Project_Only
|
or else
|
or else
|
(Unit.File_Names (Spec) /= null
|
(Unit.File_Names (Spec) /= null
|
and then Unit.File_Names (Spec).Project =
|
and then Unit.File_Names (Spec).Project =
|
The_Project)
|
The_Project)
|
then
|
then
|
declare
|
declare
|
Current_Name : File_Name_Type;
|
Current_Name : File_Name_Type;
|
|
|
begin
|
begin
|
-- Case of spec present
|
-- Case of spec present
|
|
|
if Unit.File_Names (Spec) /= null then
|
if Unit.File_Names (Spec) /= null then
|
Current_Name := Unit.File_Names (Spec).File;
|
Current_Name := Unit.File_Names (Spec).File;
|
if Current_Verbosity = High then
|
if Current_Verbosity = High then
|
Write_Str (" Comparing with """);
|
Write_Str (" Comparing with """);
|
Write_Str (Get_Name_String (Current_Name));
|
Write_Str (Get_Name_String (Current_Name));
|
Write_Char ('"');
|
Write_Char ('"');
|
Write_Eol;
|
Write_Eol;
|
end if;
|
end if;
|
|
|
-- If name same as original name, return original name
|
-- If name same as original name, return original name
|
|
|
if Unit.Name = The_Original_Name
|
if Unit.Name = The_Original_Name
|
or else
|
or else
|
Current_Name = File_Name_Type (The_Original_Name)
|
Current_Name = File_Name_Type (The_Original_Name)
|
then
|
then
|
if Current_Verbosity = High then
|
if Current_Verbosity = High then
|
Write_Line (" OK");
|
Write_Line (" OK");
|
end if;
|
end if;
|
|
|
if Full_Path then
|
if Full_Path then
|
return Get_Name_String
|
return Get_Name_String
|
(Unit.File_Names (Spec).Path.Name);
|
(Unit.File_Names (Spec).Path.Name);
|
else
|
else
|
return Get_Name_String (Current_Name);
|
return Get_Name_String (Current_Name);
|
end if;
|
end if;
|
|
|
-- If it has the same name as the extended spec name,
|
-- If it has the same name as the extended spec name,
|
-- return the extended spec name.
|
-- return the extended spec name.
|
|
|
elsif Current_Name = File_Name_Type (The_Spec_Name) then
|
elsif Current_Name = File_Name_Type (The_Spec_Name) then
|
if Current_Verbosity = High then
|
if Current_Verbosity = High then
|
Write_Line (" OK");
|
Write_Line (" OK");
|
end if;
|
end if;
|
|
|
if Full_Path then
|
if Full_Path then
|
return Get_Name_String
|
return Get_Name_String
|
(Unit.File_Names (Spec).Path.Name);
|
(Unit.File_Names (Spec).Path.Name);
|
else
|
else
|
return Get_Name_String (The_Spec_Name);
|
return Get_Name_String (The_Spec_Name);
|
end if;
|
end if;
|
|
|
else
|
else
|
if Current_Verbosity = High then
|
if Current_Verbosity = High then
|
Write_Line (" not good");
|
Write_Line (" not good");
|
end if;
|
end if;
|
end if;
|
end if;
|
end if;
|
end if;
|
end;
|
end;
|
end if;
|
end if;
|
|
|
Unit := Units_Htable.Get_Next (In_Tree.Units_HT);
|
Unit := Units_Htable.Get_Next (In_Tree.Units_HT);
|
end loop;
|
end loop;
|
|
|
-- If we are not in an extending project, give up
|
-- If we are not in an extending project, give up
|
|
|
exit when not Main_Project_Only
|
exit when not Main_Project_Only
|
or else The_Project.Extends = No_Project;
|
or else The_Project.Extends = No_Project;
|
|
|
-- Otherwise, look in the project we are extending
|
-- Otherwise, look in the project we are extending
|
|
|
The_Project := The_Project.Extends;
|
The_Project := The_Project.Extends;
|
end loop;
|
end loop;
|
|
|
-- We don't know this file name, return an empty string
|
-- We don't know this file name, return an empty string
|
|
|
return "";
|
return "";
|
end File_Name_Of_Library_Unit_Body;
|
end File_Name_Of_Library_Unit_Body;
|
|
|
-------------------------
|
-------------------------
|
-- For_All_Object_Dirs --
|
-- For_All_Object_Dirs --
|
-------------------------
|
-------------------------
|
|
|
procedure For_All_Object_Dirs (Project : Project_Id) is
|
procedure For_All_Object_Dirs (Project : Project_Id) is
|
procedure For_Project (Prj : Project_Id; Dummy : in out Integer);
|
procedure For_Project (Prj : Project_Id; Dummy : in out Integer);
|
-- Get all object directories of Prj
|
-- Get all object directories of Prj
|
|
|
-----------------
|
-----------------
|
-- For_Project --
|
-- For_Project --
|
-----------------
|
-----------------
|
|
|
procedure For_Project (Prj : Project_Id; Dummy : in out Integer) is
|
procedure For_Project (Prj : Project_Id; Dummy : in out Integer) is
|
pragma Unreferenced (Dummy);
|
pragma Unreferenced (Dummy);
|
begin
|
begin
|
-- ??? Set_Ada_Paths has a different behavior for library project
|
-- ??? Set_Ada_Paths has a different behavior for library project
|
-- files, should we have the same ?
|
-- files, should we have the same ?
|
|
|
if Prj.Object_Directory /= No_Path_Information then
|
if Prj.Object_Directory /= No_Path_Information then
|
Get_Name_String (Prj.Object_Directory.Display_Name);
|
Get_Name_String (Prj.Object_Directory.Display_Name);
|
Action (Name_Buffer (1 .. Name_Len));
|
Action (Name_Buffer (1 .. Name_Len));
|
end if;
|
end if;
|
end For_Project;
|
end For_Project;
|
|
|
procedure Get_Object_Dirs is
|
procedure Get_Object_Dirs is
|
new For_Every_Project_Imported (Integer, For_Project);
|
new For_Every_Project_Imported (Integer, For_Project);
|
Dummy : Integer := 1;
|
Dummy : Integer := 1;
|
|
|
-- Start of processing for For_All_Object_Dirs
|
-- Start of processing for For_All_Object_Dirs
|
|
|
begin
|
begin
|
Get_Object_Dirs (Project, Dummy);
|
Get_Object_Dirs (Project, Dummy);
|
end For_All_Object_Dirs;
|
end For_All_Object_Dirs;
|
|
|
-------------------------
|
-------------------------
|
-- For_All_Source_Dirs --
|
-- For_All_Source_Dirs --
|
-------------------------
|
-------------------------
|
|
|
procedure For_All_Source_Dirs
|
procedure For_All_Source_Dirs
|
(Project : Project_Id;
|
(Project : Project_Id;
|
In_Tree : Project_Tree_Ref)
|
In_Tree : Project_Tree_Ref)
|
is
|
is
|
procedure For_Project (Prj : Project_Id; Dummy : in out Integer);
|
procedure For_Project (Prj : Project_Id; Dummy : in out Integer);
|
-- Get all object directories of Prj
|
-- Get all object directories of Prj
|
|
|
-----------------
|
-----------------
|
-- For_Project --
|
-- For_Project --
|
-----------------
|
-----------------
|
|
|
procedure For_Project (Prj : Project_Id; Dummy : in out Integer) is
|
procedure For_Project (Prj : Project_Id; Dummy : in out Integer) is
|
pragma Unreferenced (Dummy);
|
pragma Unreferenced (Dummy);
|
Current : String_List_Id := Prj.Source_Dirs;
|
Current : String_List_Id := Prj.Source_Dirs;
|
The_String : String_Element;
|
The_String : String_Element;
|
|
|
begin
|
begin
|
-- If there are Ada sources, call action with the name of every
|
-- If there are Ada sources, call action with the name of every
|
-- source directory.
|
-- source directory.
|
|
|
if Has_Ada_Sources (Project) then
|
if Has_Ada_Sources (Project) then
|
while Current /= Nil_String loop
|
while Current /= Nil_String loop
|
The_String := In_Tree.String_Elements.Table (Current);
|
The_String := In_Tree.String_Elements.Table (Current);
|
Action (Get_Name_String (The_String.Display_Value));
|
Action (Get_Name_String (The_String.Display_Value));
|
Current := The_String.Next;
|
Current := The_String.Next;
|
end loop;
|
end loop;
|
end if;
|
end if;
|
end For_Project;
|
end For_Project;
|
|
|
procedure Get_Source_Dirs is
|
procedure Get_Source_Dirs is
|
new For_Every_Project_Imported (Integer, For_Project);
|
new For_Every_Project_Imported (Integer, For_Project);
|
Dummy : Integer := 1;
|
Dummy : Integer := 1;
|
|
|
-- Start of processing for For_All_Source_Dirs
|
-- Start of processing for For_All_Source_Dirs
|
|
|
begin
|
begin
|
Get_Source_Dirs (Project, Dummy);
|
Get_Source_Dirs (Project, Dummy);
|
end For_All_Source_Dirs;
|
end For_All_Source_Dirs;
|
|
|
-------------------
|
-------------------
|
-- Get_Reference --
|
-- Get_Reference --
|
-------------------
|
-------------------
|
|
|
procedure Get_Reference
|
procedure Get_Reference
|
(Source_File_Name : String;
|
(Source_File_Name : String;
|
In_Tree : Project_Tree_Ref;
|
In_Tree : Project_Tree_Ref;
|
Project : out Project_Id;
|
Project : out Project_Id;
|
Path : out Path_Name_Type)
|
Path : out Path_Name_Type)
|
is
|
is
|
begin
|
begin
|
-- Body below could use some comments ???
|
-- Body below could use some comments ???
|
|
|
if Current_Verbosity > Default then
|
if Current_Verbosity > Default then
|
Write_Str ("Getting Reference_Of (""");
|
Write_Str ("Getting Reference_Of (""");
|
Write_Str (Source_File_Name);
|
Write_Str (Source_File_Name);
|
Write_Str (""") ... ");
|
Write_Str (""") ... ");
|
end if;
|
end if;
|
|
|
declare
|
declare
|
Original_Name : String := Source_File_Name;
|
Original_Name : String := Source_File_Name;
|
Unit : Unit_Index;
|
Unit : Unit_Index;
|
|
|
begin
|
begin
|
Canonical_Case_File_Name (Original_Name);
|
Canonical_Case_File_Name (Original_Name);
|
Unit := Units_Htable.Get_First (In_Tree.Units_HT);
|
Unit := Units_Htable.Get_First (In_Tree.Units_HT);
|
|
|
while Unit /= null loop
|
while Unit /= null loop
|
if Unit.File_Names (Spec) /= null
|
if Unit.File_Names (Spec) /= null
|
and then Unit.File_Names (Spec).File /= No_File
|
and then Unit.File_Names (Spec).File /= No_File
|
and then
|
and then
|
(Namet.Get_Name_String
|
(Namet.Get_Name_String
|
(Unit.File_Names (Spec).File) = Original_Name
|
(Unit.File_Names (Spec).File) = Original_Name
|
or else (Unit.File_Names (Spec).Path /=
|
or else (Unit.File_Names (Spec).Path /=
|
No_Path_Information
|
No_Path_Information
|
and then
|
and then
|
Namet.Get_Name_String
|
Namet.Get_Name_String
|
(Unit.File_Names (Spec).Path.Name) =
|
(Unit.File_Names (Spec).Path.Name) =
|
Original_Name))
|
Original_Name))
|
then
|
then
|
Project := Ultimate_Extension_Of
|
Project := Ultimate_Extension_Of
|
(Project => Unit.File_Names (Spec).Project);
|
(Project => Unit.File_Names (Spec).Project);
|
Path := Unit.File_Names (Spec).Path.Display_Name;
|
Path := Unit.File_Names (Spec).Path.Display_Name;
|
|
|
if Current_Verbosity > Default then
|
if Current_Verbosity > Default then
|
Write_Str ("Done: Spec.");
|
Write_Str ("Done: Spec.");
|
Write_Eol;
|
Write_Eol;
|
end if;
|
end if;
|
|
|
return;
|
return;
|
|
|
elsif Unit.File_Names (Impl) /= null
|
elsif Unit.File_Names (Impl) /= null
|
and then Unit.File_Names (Impl).File /= No_File
|
and then Unit.File_Names (Impl).File /= No_File
|
and then
|
and then
|
(Namet.Get_Name_String
|
(Namet.Get_Name_String
|
(Unit.File_Names (Impl).File) = Original_Name
|
(Unit.File_Names (Impl).File) = Original_Name
|
or else (Unit.File_Names (Impl).Path /=
|
or else (Unit.File_Names (Impl).Path /=
|
No_Path_Information
|
No_Path_Information
|
and then Namet.Get_Name_String
|
and then Namet.Get_Name_String
|
(Unit.File_Names (Impl).Path.Name) =
|
(Unit.File_Names (Impl).Path.Name) =
|
Original_Name))
|
Original_Name))
|
then
|
then
|
Project := Ultimate_Extension_Of
|
Project := Ultimate_Extension_Of
|
(Project => Unit.File_Names (Impl).Project);
|
(Project => Unit.File_Names (Impl).Project);
|
Path := Unit.File_Names (Impl).Path.Display_Name;
|
Path := Unit.File_Names (Impl).Path.Display_Name;
|
|
|
if Current_Verbosity > Default then
|
if Current_Verbosity > Default then
|
Write_Str ("Done: Body.");
|
Write_Str ("Done: Body.");
|
Write_Eol;
|
Write_Eol;
|
end if;
|
end if;
|
|
|
return;
|
return;
|
end if;
|
end if;
|
|
|
Unit := Units_Htable.Get_Next (In_Tree.Units_HT);
|
Unit := Units_Htable.Get_Next (In_Tree.Units_HT);
|
end loop;
|
end loop;
|
end;
|
end;
|
|
|
Project := No_Project;
|
Project := No_Project;
|
Path := No_Path;
|
Path := No_Path;
|
|
|
if Current_Verbosity > Default then
|
if Current_Verbosity > Default then
|
Write_Str ("Cannot be found.");
|
Write_Str ("Cannot be found.");
|
Write_Eol;
|
Write_Eol;
|
end if;
|
end if;
|
end Get_Reference;
|
end Get_Reference;
|
|
|
----------------
|
----------------
|
-- Initialize --
|
-- Initialize --
|
----------------
|
----------------
|
|
|
procedure Initialize (In_Tree : Project_Tree_Ref) is
|
procedure Initialize (In_Tree : Project_Tree_Ref) is
|
begin
|
begin
|
In_Tree.Private_Part.Current_Source_Path_File := No_Path;
|
In_Tree.Private_Part.Current_Source_Path_File := No_Path;
|
In_Tree.Private_Part.Current_Object_Path_File := No_Path;
|
In_Tree.Private_Part.Current_Object_Path_File := No_Path;
|
end Initialize;
|
end Initialize;
|
|
|
-------------------
|
-------------------
|
-- Print_Sources --
|
-- Print_Sources --
|
-------------------
|
-------------------
|
|
|
-- Could use some comments in this body ???
|
-- Could use some comments in this body ???
|
|
|
procedure Print_Sources (In_Tree : Project_Tree_Ref) is
|
procedure Print_Sources (In_Tree : Project_Tree_Ref) is
|
Unit : Unit_Index;
|
Unit : Unit_Index;
|
|
|
begin
|
begin
|
Write_Line ("List of Sources:");
|
Write_Line ("List of Sources:");
|
|
|
Unit := Units_Htable.Get_First (In_Tree.Units_HT);
|
Unit := Units_Htable.Get_First (In_Tree.Units_HT);
|
|
|
while Unit /= No_Unit_Index loop
|
while Unit /= No_Unit_Index loop
|
Write_Str (" ");
|
Write_Str (" ");
|
Write_Line (Namet.Get_Name_String (Unit.Name));
|
Write_Line (Namet.Get_Name_String (Unit.Name));
|
|
|
if Unit.File_Names (Spec).File /= No_File then
|
if Unit.File_Names (Spec).File /= No_File then
|
if Unit.File_Names (Spec).Project = No_Project then
|
if Unit.File_Names (Spec).Project = No_Project then
|
Write_Line (" No project");
|
Write_Line (" No project");
|
|
|
else
|
else
|
Write_Str (" Project: ");
|
Write_Str (" Project: ");
|
Get_Name_String
|
Get_Name_String
|
(Unit.File_Names (Spec).Project.Path.Name);
|
(Unit.File_Names (Spec).Project.Path.Name);
|
Write_Line (Name_Buffer (1 .. Name_Len));
|
Write_Line (Name_Buffer (1 .. Name_Len));
|
end if;
|
end if;
|
|
|
Write_Str (" spec: ");
|
Write_Str (" spec: ");
|
Write_Line
|
Write_Line
|
(Namet.Get_Name_String
|
(Namet.Get_Name_String
|
(Unit.File_Names (Spec).File));
|
(Unit.File_Names (Spec).File));
|
end if;
|
end if;
|
|
|
if Unit.File_Names (Impl).File /= No_File then
|
if Unit.File_Names (Impl).File /= No_File then
|
if Unit.File_Names (Impl).Project = No_Project then
|
if Unit.File_Names (Impl).Project = No_Project then
|
Write_Line (" No project");
|
Write_Line (" No project");
|
|
|
else
|
else
|
Write_Str (" Project: ");
|
Write_Str (" Project: ");
|
Get_Name_String
|
Get_Name_String
|
(Unit.File_Names (Impl).Project.Path.Name);
|
(Unit.File_Names (Impl).Project.Path.Name);
|
Write_Line (Name_Buffer (1 .. Name_Len));
|
Write_Line (Name_Buffer (1 .. Name_Len));
|
end if;
|
end if;
|
|
|
Write_Str (" body: ");
|
Write_Str (" body: ");
|
Write_Line
|
Write_Line
|
(Namet.Get_Name_String (Unit.File_Names (Impl).File));
|
(Namet.Get_Name_String (Unit.File_Names (Impl).File));
|
end if;
|
end if;
|
|
|
Unit := Units_Htable.Get_Next (In_Tree.Units_HT);
|
Unit := Units_Htable.Get_Next (In_Tree.Units_HT);
|
end loop;
|
end loop;
|
|
|
Write_Line ("end of List of Sources.");
|
Write_Line ("end of List of Sources.");
|
end Print_Sources;
|
end Print_Sources;
|
|
|
----------------
|
----------------
|
-- Project_Of --
|
-- Project_Of --
|
----------------
|
----------------
|
|
|
function Project_Of
|
function Project_Of
|
(Name : String;
|
(Name : String;
|
Main_Project : Project_Id;
|
Main_Project : Project_Id;
|
In_Tree : Project_Tree_Ref) return Project_Id
|
In_Tree : Project_Tree_Ref) return Project_Id
|
is
|
is
|
Result : Project_Id := No_Project;
|
Result : Project_Id := No_Project;
|
|
|
Original_Name : String := Name;
|
Original_Name : String := Name;
|
|
|
Lang : constant Language_Ptr :=
|
Lang : constant Language_Ptr :=
|
Get_Language_From_Name (Main_Project, "ada");
|
Get_Language_From_Name (Main_Project, "ada");
|
|
|
Unit : Unit_Index;
|
Unit : Unit_Index;
|
|
|
Current_Name : File_Name_Type;
|
Current_Name : File_Name_Type;
|
The_Original_Name : File_Name_Type;
|
The_Original_Name : File_Name_Type;
|
The_Spec_Name : File_Name_Type;
|
The_Spec_Name : File_Name_Type;
|
The_Body_Name : File_Name_Type;
|
The_Body_Name : File_Name_Type;
|
|
|
begin
|
begin
|
-- ??? Same block in File_Name_Of_Library_Unit_Body
|
-- ??? Same block in File_Name_Of_Library_Unit_Body
|
Canonical_Case_File_Name (Original_Name);
|
Canonical_Case_File_Name (Original_Name);
|
Name_Len := Original_Name'Length;
|
Name_Len := Original_Name'Length;
|
Name_Buffer (1 .. Name_Len) := Original_Name;
|
Name_Buffer (1 .. Name_Len) := Original_Name;
|
The_Original_Name := Name_Find;
|
The_Original_Name := Name_Find;
|
|
|
if Lang /= null then
|
if Lang /= null then
|
declare
|
declare
|
Naming : Lang_Naming_Data renames Lang.Config.Naming_Data;
|
Naming : Lang_Naming_Data renames Lang.Config.Naming_Data;
|
Extended_Spec_Name : String :=
|
Extended_Spec_Name : String :=
|
Name & Namet.Get_Name_String
|
Name & Namet.Get_Name_String
|
(Naming.Spec_Suffix);
|
(Naming.Spec_Suffix);
|
Extended_Body_Name : String :=
|
Extended_Body_Name : String :=
|
Name & Namet.Get_Name_String
|
Name & Namet.Get_Name_String
|
(Naming.Body_Suffix);
|
(Naming.Body_Suffix);
|
|
|
begin
|
begin
|
Canonical_Case_File_Name (Extended_Spec_Name);
|
Canonical_Case_File_Name (Extended_Spec_Name);
|
Name_Len := Extended_Spec_Name'Length;
|
Name_Len := Extended_Spec_Name'Length;
|
Name_Buffer (1 .. Name_Len) := Extended_Spec_Name;
|
Name_Buffer (1 .. Name_Len) := Extended_Spec_Name;
|
The_Spec_Name := Name_Find;
|
The_Spec_Name := Name_Find;
|
|
|
Canonical_Case_File_Name (Extended_Body_Name);
|
Canonical_Case_File_Name (Extended_Body_Name);
|
Name_Len := Extended_Body_Name'Length;
|
Name_Len := Extended_Body_Name'Length;
|
Name_Buffer (1 .. Name_Len) := Extended_Body_Name;
|
Name_Buffer (1 .. Name_Len) := Extended_Body_Name;
|
The_Body_Name := Name_Find;
|
The_Body_Name := Name_Find;
|
end;
|
end;
|
|
|
else
|
else
|
The_Spec_Name := The_Original_Name;
|
The_Spec_Name := The_Original_Name;
|
The_Body_Name := The_Original_Name;
|
The_Body_Name := The_Original_Name;
|
end if;
|
end if;
|
|
|
Unit := Units_Htable.Get_First (In_Tree.Units_HT);
|
Unit := Units_Htable.Get_First (In_Tree.Units_HT);
|
while Unit /= null loop
|
while Unit /= null loop
|
|
|
-- Case of a body present
|
-- Case of a body present
|
|
|
if Unit.File_Names (Impl) /= null then
|
if Unit.File_Names (Impl) /= null then
|
Current_Name := Unit.File_Names (Impl).File;
|
Current_Name := Unit.File_Names (Impl).File;
|
|
|
-- If it has the name of the original name or the body name,
|
-- If it has the name of the original name or the body name,
|
-- we have found the project.
|
-- we have found the project.
|
|
|
if Unit.Name = Name_Id (The_Original_Name)
|
if Unit.Name = Name_Id (The_Original_Name)
|
or else Current_Name = The_Original_Name
|
or else Current_Name = The_Original_Name
|
or else Current_Name = The_Body_Name
|
or else Current_Name = The_Body_Name
|
then
|
then
|
Result := Unit.File_Names (Impl).Project;
|
Result := Unit.File_Names (Impl).Project;
|
exit;
|
exit;
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
-- Check for spec
|
-- Check for spec
|
|
|
if Unit.File_Names (Spec) /= null then
|
if Unit.File_Names (Spec) /= null then
|
Current_Name := Unit.File_Names (Spec).File;
|
Current_Name := Unit.File_Names (Spec).File;
|
|
|
-- If name same as the original name, or the spec name, we have
|
-- If name same as the original name, or the spec name, we have
|
-- found the project.
|
-- found the project.
|
|
|
if Unit.Name = Name_Id (The_Original_Name)
|
if Unit.Name = Name_Id (The_Original_Name)
|
or else Current_Name = The_Original_Name
|
or else Current_Name = The_Original_Name
|
or else Current_Name = The_Spec_Name
|
or else Current_Name = The_Spec_Name
|
then
|
then
|
Result := Unit.File_Names (Spec).Project;
|
Result := Unit.File_Names (Spec).Project;
|
exit;
|
exit;
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
Unit := Units_Htable.Get_Next (In_Tree.Units_HT);
|
Unit := Units_Htable.Get_Next (In_Tree.Units_HT);
|
end loop;
|
end loop;
|
|
|
-- Get the ultimate extending project
|
-- Get the ultimate extending project
|
|
|
if Result /= No_Project then
|
if Result /= No_Project then
|
while Result.Extended_By /= No_Project loop
|
while Result.Extended_By /= No_Project loop
|
Result := Result.Extended_By;
|
Result := Result.Extended_By;
|
end loop;
|
end loop;
|
end if;
|
end if;
|
|
|
return Result;
|
return Result;
|
end Project_Of;
|
end Project_Of;
|
|
|
-------------------
|
-------------------
|
-- Set_Ada_Paths --
|
-- Set_Ada_Paths --
|
-------------------
|
-------------------
|
|
|
procedure Set_Ada_Paths
|
procedure Set_Ada_Paths
|
(Project : Project_Id;
|
(Project : Project_Id;
|
In_Tree : Project_Tree_Ref;
|
In_Tree : Project_Tree_Ref;
|
Including_Libraries : Boolean)
|
Including_Libraries : Boolean)
|
|
|
is
|
is
|
Source_Paths : Source_Path_Table.Instance;
|
Source_Paths : Source_Path_Table.Instance;
|
Object_Paths : Object_Path_Table.Instance;
|
Object_Paths : Object_Path_Table.Instance;
|
-- List of source or object dirs. Only computed the first time this
|
-- List of source or object dirs. Only computed the first time this
|
-- procedure is called (since Source_FD is then reused)
|
-- procedure is called (since Source_FD is then reused)
|
|
|
Source_FD : File_Descriptor := Invalid_FD;
|
Source_FD : File_Descriptor := Invalid_FD;
|
Object_FD : File_Descriptor := Invalid_FD;
|
Object_FD : File_Descriptor := Invalid_FD;
|
-- The temporary files to store the paths. These are only created the
|
-- The temporary files to store the paths. These are only created the
|
-- first time this procedure is called, and reused from then on.
|
-- first time this procedure is called, and reused from then on.
|
|
|
Process_Source_Dirs : Boolean := False;
|
Process_Source_Dirs : Boolean := False;
|
Process_Object_Dirs : Boolean := False;
|
Process_Object_Dirs : Boolean := False;
|
|
|
Status : Boolean;
|
Status : Boolean;
|
-- For calls to Close
|
-- For calls to Close
|
|
|
Last : Natural;
|
Last : Natural;
|
Buffer : String_Access := new String (1 .. Buffer_Initial);
|
Buffer : String_Access := new String (1 .. Buffer_Initial);
|
Buffer_Last : Natural := 0;
|
Buffer_Last : Natural := 0;
|
|
|
procedure Recursive_Add (Project : Project_Id; Dummy : in out Boolean);
|
procedure Recursive_Add (Project : Project_Id; Dummy : in out Boolean);
|
-- Recursive procedure to add the source/object paths of extended/
|
-- Recursive procedure to add the source/object paths of extended/
|
-- imported projects.
|
-- imported projects.
|
|
|
-------------------
|
-------------------
|
-- Recursive_Add --
|
-- Recursive_Add --
|
-------------------
|
-------------------
|
|
|
procedure Recursive_Add (Project : Project_Id; Dummy : in out Boolean) is
|
procedure Recursive_Add (Project : Project_Id; Dummy : in out Boolean) is
|
pragma Unreferenced (Dummy);
|
pragma Unreferenced (Dummy);
|
|
|
Path : Path_Name_Type;
|
Path : Path_Name_Type;
|
|
|
begin
|
begin
|
-- ??? This is almost the equivalent of For_All_Source_Dirs
|
-- ??? This is almost the equivalent of For_All_Source_Dirs
|
|
|
if Process_Source_Dirs then
|
if Process_Source_Dirs then
|
|
|
-- Add to path all source directories of this project if there are
|
-- Add to path all source directories of this project if there are
|
-- Ada sources.
|
-- Ada sources.
|
|
|
if Has_Ada_Sources (Project) then
|
if Has_Ada_Sources (Project) then
|
Add_To_Source_Path (Project.Source_Dirs, In_Tree, Source_Paths);
|
Add_To_Source_Path (Project.Source_Dirs, In_Tree, Source_Paths);
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
if Process_Object_Dirs then
|
if Process_Object_Dirs then
|
Path := Get_Object_Directory
|
Path := Get_Object_Directory
|
(Project,
|
(Project,
|
Including_Libraries => Including_Libraries,
|
Including_Libraries => Including_Libraries,
|
Only_If_Ada => True);
|
Only_If_Ada => True);
|
|
|
if Path /= No_Path then
|
if Path /= No_Path then
|
Add_To_Object_Path (Path, Object_Paths);
|
Add_To_Object_Path (Path, Object_Paths);
|
end if;
|
end if;
|
end if;
|
end if;
|
end Recursive_Add;
|
end Recursive_Add;
|
|
|
procedure For_All_Projects is
|
procedure For_All_Projects is
|
new For_Every_Project_Imported (Boolean, Recursive_Add);
|
new For_Every_Project_Imported (Boolean, Recursive_Add);
|
|
|
Dummy : Boolean := False;
|
Dummy : Boolean := False;
|
|
|
-- Start of processing for Set_Ada_Paths
|
-- Start of processing for Set_Ada_Paths
|
|
|
begin
|
begin
|
-- If it is the first time we call this procedure for this project,
|
-- If it is the first time we call this procedure for this project,
|
-- compute the source path and/or the object path.
|
-- compute the source path and/or the object path.
|
|
|
if Project.Include_Path_File = No_Path then
|
if Project.Include_Path_File = No_Path then
|
Source_Path_Table.Init (Source_Paths);
|
Source_Path_Table.Init (Source_Paths);
|
Process_Source_Dirs := True;
|
Process_Source_Dirs := True;
|
Create_New_Path_File
|
Create_New_Path_File
|
(In_Tree, Source_FD, Project.Include_Path_File);
|
(In_Tree, Source_FD, Project.Include_Path_File);
|
end if;
|
end if;
|
|
|
-- For the object path, we make a distinction depending on
|
-- For the object path, we make a distinction depending on
|
-- Including_Libraries.
|
-- Including_Libraries.
|
|
|
if Including_Libraries then
|
if Including_Libraries then
|
if Project.Objects_Path_File_With_Libs = No_Path then
|
if Project.Objects_Path_File_With_Libs = No_Path then
|
Object_Path_Table.Init (Object_Paths);
|
Object_Path_Table.Init (Object_Paths);
|
Process_Object_Dirs := True;
|
Process_Object_Dirs := True;
|
Create_New_Path_File
|
Create_New_Path_File
|
(In_Tree, Object_FD, Project.Objects_Path_File_With_Libs);
|
(In_Tree, Object_FD, Project.Objects_Path_File_With_Libs);
|
end if;
|
end if;
|
|
|
else
|
else
|
if Project.Objects_Path_File_Without_Libs = No_Path then
|
if Project.Objects_Path_File_Without_Libs = No_Path then
|
Object_Path_Table.Init (Object_Paths);
|
Object_Path_Table.Init (Object_Paths);
|
Process_Object_Dirs := True;
|
Process_Object_Dirs := True;
|
Create_New_Path_File
|
Create_New_Path_File
|
(In_Tree, Object_FD, Project.Objects_Path_File_Without_Libs);
|
(In_Tree, Object_FD, Project.Objects_Path_File_Without_Libs);
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
-- If there is something to do, set Seen to False for all projects,
|
-- If there is something to do, set Seen to False for all projects,
|
-- then call the recursive procedure Add for Project.
|
-- then call the recursive procedure Add for Project.
|
|
|
if Process_Source_Dirs or Process_Object_Dirs then
|
if Process_Source_Dirs or Process_Object_Dirs then
|
For_All_Projects (Project, Dummy);
|
For_All_Projects (Project, Dummy);
|
end if;
|
end if;
|
|
|
-- Write and close any file that has been created. Source_FD is not set
|
-- Write and close any file that has been created. Source_FD is not set
|
-- when this subprogram is called a second time or more, since we reuse
|
-- when this subprogram is called a second time or more, since we reuse
|
-- the previous version of the file.
|
-- the previous version of the file.
|
|
|
if Source_FD /= Invalid_FD then
|
if Source_FD /= Invalid_FD then
|
Buffer_Last := 0;
|
Buffer_Last := 0;
|
|
|
for Index in Source_Path_Table.First ..
|
for Index in Source_Path_Table.First ..
|
Source_Path_Table.Last (Source_Paths)
|
Source_Path_Table.Last (Source_Paths)
|
loop
|
loop
|
Get_Name_String (Source_Paths.Table (Index));
|
Get_Name_String (Source_Paths.Table (Index));
|
Name_Len := Name_Len + 1;
|
Name_Len := Name_Len + 1;
|
Name_Buffer (Name_Len) := ASCII.LF;
|
Name_Buffer (Name_Len) := ASCII.LF;
|
Add_To_Buffer (Name_Buffer (1 .. Name_Len), Buffer, Buffer_Last);
|
Add_To_Buffer (Name_Buffer (1 .. Name_Len), Buffer, Buffer_Last);
|
end loop;
|
end loop;
|
|
|
Last := Write (Source_FD, Buffer (1)'Address, Buffer_Last);
|
Last := Write (Source_FD, Buffer (1)'Address, Buffer_Last);
|
|
|
if Last = Buffer_Last then
|
if Last = Buffer_Last then
|
Close (Source_FD, Status);
|
Close (Source_FD, Status);
|
|
|
else
|
else
|
Status := False;
|
Status := False;
|
end if;
|
end if;
|
|
|
if not Status then
|
if not Status then
|
Prj.Com.Fail ("could not write temporary file");
|
Prj.Com.Fail ("could not write temporary file");
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
if Object_FD /= Invalid_FD then
|
if Object_FD /= Invalid_FD then
|
Buffer_Last := 0;
|
Buffer_Last := 0;
|
|
|
for Index in Object_Path_Table.First ..
|
for Index in Object_Path_Table.First ..
|
Object_Path_Table.Last (Object_Paths)
|
Object_Path_Table.Last (Object_Paths)
|
loop
|
loop
|
Get_Name_String (Object_Paths.Table (Index));
|
Get_Name_String (Object_Paths.Table (Index));
|
Name_Len := Name_Len + 1;
|
Name_Len := Name_Len + 1;
|
Name_Buffer (Name_Len) := ASCII.LF;
|
Name_Buffer (Name_Len) := ASCII.LF;
|
Add_To_Buffer (Name_Buffer (1 .. Name_Len), Buffer, Buffer_Last);
|
Add_To_Buffer (Name_Buffer (1 .. Name_Len), Buffer, Buffer_Last);
|
end loop;
|
end loop;
|
|
|
Last := Write (Object_FD, Buffer (1)'Address, Buffer_Last);
|
Last := Write (Object_FD, Buffer (1)'Address, Buffer_Last);
|
|
|
if Last = Buffer_Last then
|
if Last = Buffer_Last then
|
Close (Object_FD, Status);
|
Close (Object_FD, Status);
|
else
|
else
|
Status := False;
|
Status := False;
|
end if;
|
end if;
|
|
|
if not Status then
|
if not Status then
|
Prj.Com.Fail ("could not write temporary file");
|
Prj.Com.Fail ("could not write temporary file");
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
-- Set the env vars, if they need to be changed, and set the
|
-- Set the env vars, if they need to be changed, and set the
|
-- corresponding flags.
|
-- corresponding flags.
|
|
|
if In_Tree.Private_Part.Current_Source_Path_File /=
|
if In_Tree.Private_Part.Current_Source_Path_File /=
|
Project.Include_Path_File
|
Project.Include_Path_File
|
then
|
then
|
In_Tree.Private_Part.Current_Source_Path_File :=
|
In_Tree.Private_Part.Current_Source_Path_File :=
|
Project.Include_Path_File;
|
Project.Include_Path_File;
|
Set_Path_File_Var
|
Set_Path_File_Var
|
(Project_Include_Path_File,
|
(Project_Include_Path_File,
|
Get_Name_String (In_Tree.Private_Part.Current_Source_Path_File));
|
Get_Name_String (In_Tree.Private_Part.Current_Source_Path_File));
|
end if;
|
end if;
|
|
|
if Including_Libraries then
|
if Including_Libraries then
|
if In_Tree.Private_Part.Current_Object_Path_File /=
|
if In_Tree.Private_Part.Current_Object_Path_File /=
|
Project.Objects_Path_File_With_Libs
|
Project.Objects_Path_File_With_Libs
|
then
|
then
|
In_Tree.Private_Part.Current_Object_Path_File :=
|
In_Tree.Private_Part.Current_Object_Path_File :=
|
Project.Objects_Path_File_With_Libs;
|
Project.Objects_Path_File_With_Libs;
|
Set_Path_File_Var
|
Set_Path_File_Var
|
(Project_Objects_Path_File,
|
(Project_Objects_Path_File,
|
Get_Name_String
|
Get_Name_String
|
(In_Tree.Private_Part.Current_Object_Path_File));
|
(In_Tree.Private_Part.Current_Object_Path_File));
|
end if;
|
end if;
|
|
|
else
|
else
|
if In_Tree.Private_Part.Current_Object_Path_File /=
|
if In_Tree.Private_Part.Current_Object_Path_File /=
|
Project.Objects_Path_File_Without_Libs
|
Project.Objects_Path_File_Without_Libs
|
then
|
then
|
In_Tree.Private_Part.Current_Object_Path_File :=
|
In_Tree.Private_Part.Current_Object_Path_File :=
|
Project.Objects_Path_File_Without_Libs;
|
Project.Objects_Path_File_Without_Libs;
|
Set_Path_File_Var
|
Set_Path_File_Var
|
(Project_Objects_Path_File,
|
(Project_Objects_Path_File,
|
Get_Name_String
|
Get_Name_String
|
(In_Tree.Private_Part.Current_Object_Path_File));
|
(In_Tree.Private_Part.Current_Object_Path_File));
|
end if;
|
end if;
|
end if;
|
end if;
|
|
|
Free (Buffer);
|
Free (Buffer);
|
end Set_Ada_Paths;
|
end Set_Ada_Paths;
|
|
|
-----------------------
|
-----------------------
|
-- Set_Path_File_Var --
|
-- Set_Path_File_Var --
|
-----------------------
|
-----------------------
|
|
|
procedure Set_Path_File_Var (Name : String; Value : String) is
|
procedure Set_Path_File_Var (Name : String; Value : String) is
|
Host_Spec : String_Access := To_Host_File_Spec (Value);
|
Host_Spec : String_Access := To_Host_File_Spec (Value);
|
begin
|
begin
|
if Host_Spec = null then
|
if Host_Spec = null then
|
Prj.Com.Fail
|
Prj.Com.Fail
|
("could not convert file name """ & Value & """ to host spec");
|
("could not convert file name """ & Value & """ to host spec");
|
else
|
else
|
Setenv (Name, Host_Spec.all);
|
Setenv (Name, Host_Spec.all);
|
Free (Host_Spec);
|
Free (Host_Spec);
|
end if;
|
end if;
|
end Set_Path_File_Var;
|
end Set_Path_File_Var;
|
|
|
---------------------------
|
---------------------------
|
-- Ultimate_Extension_Of --
|
-- Ultimate_Extension_Of --
|
---------------------------
|
---------------------------
|
|
|
function Ultimate_Extension_Of
|
function Ultimate_Extension_Of
|
(Project : Project_Id) return Project_Id
|
(Project : Project_Id) return Project_Id
|
is
|
is
|
Result : Project_Id;
|
Result : Project_Id;
|
|
|
begin
|
begin
|
Result := Project;
|
Result := Project;
|
while Result.Extended_By /= No_Project loop
|
while Result.Extended_By /= No_Project loop
|
Result := Result.Extended_By;
|
Result := Result.Extended_By;
|
end loop;
|
end loop;
|
|
|
return Result;
|
return Result;
|
end Ultimate_Extension_Of;
|
end Ultimate_Extension_Of;
|
|
|
end Prj.Env;
|
end Prj.Env;
|
|
|