------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
-- --
|
-- --
|
-- GNAT COMPILER COMPONENTS --
|
-- GNAT COMPILER COMPONENTS --
|
-- --
|
-- --
|
-- P R J . E X T --
|
-- P R J . E X T --
|
-- --
|
-- --
|
-- B o d y --
|
-- B o d y --
|
-- --
|
-- --
|
-- Copyright (C) 2000-2009, Free Software Foundation, Inc. --
|
-- Copyright (C) 2000-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 System.OS_Lib; use System.OS_Lib;
|
with System.OS_Lib; use System.OS_Lib;
|
with Hostparm;
|
with Hostparm;
|
with Makeutl; use Makeutl;
|
with Makeutl; use Makeutl;
|
with Opt;
|
with Opt;
|
with Osint; use Osint;
|
with Osint; use Osint;
|
with Prj.Tree; use Prj.Tree;
|
with Prj.Tree; use Prj.Tree;
|
with Sdefault;
|
with Sdefault;
|
|
|
package body Prj.Ext is
|
package body Prj.Ext is
|
|
|
No_Project_Default_Dir : constant String := "-";
|
No_Project_Default_Dir : constant String := "-";
|
-- Indicator in the project path to indicate that the default search
|
-- Indicator in the project path to indicate that the default search
|
-- directories should not be added to the path
|
-- directories should not be added to the path
|
|
|
Uninitialized_Prefix : constant String := '#' & Path_Separator;
|
Uninitialized_Prefix : constant String := '#' & Path_Separator;
|
-- Prefix to indicate that the project path has not been initilized yet.
|
-- Prefix to indicate that the project path has not been initilized yet.
|
-- Must be two characters long
|
-- Must be two characters long
|
|
|
procedure Initialize_Project_Path (Tree : Prj.Tree.Project_Node_Tree_Ref);
|
procedure Initialize_Project_Path (Tree : Prj.Tree.Project_Node_Tree_Ref);
|
-- Initialize Current_Project_Path
|
-- Initialize Current_Project_Path
|
|
|
---------
|
---------
|
-- Add --
|
-- Add --
|
---------
|
---------
|
|
|
procedure Add
|
procedure Add
|
(Tree : Prj.Tree.Project_Node_Tree_Ref;
|
(Tree : Prj.Tree.Project_Node_Tree_Ref;
|
External_Name : String;
|
External_Name : String;
|
Value : String)
|
Value : String)
|
is
|
is
|
The_Key : Name_Id;
|
The_Key : Name_Id;
|
The_Value : Name_Id;
|
The_Value : Name_Id;
|
begin
|
begin
|
Name_Len := Value'Length;
|
Name_Len := Value'Length;
|
Name_Buffer (1 .. Name_Len) := Value;
|
Name_Buffer (1 .. Name_Len) := Value;
|
The_Value := Name_Find;
|
The_Value := Name_Find;
|
Name_Len := External_Name'Length;
|
Name_Len := External_Name'Length;
|
Name_Buffer (1 .. Name_Len) := External_Name;
|
Name_Buffer (1 .. Name_Len) := External_Name;
|
Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
|
Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
|
The_Key := Name_Find;
|
The_Key := Name_Find;
|
Name_To_Name_HTable.Set (Tree.External_References, The_Key, The_Value);
|
Name_To_Name_HTable.Set (Tree.External_References, The_Key, The_Value);
|
end Add;
|
end Add;
|
|
|
----------------------------------
|
----------------------------------
|
-- Add_Search_Project_Directory --
|
-- Add_Search_Project_Directory --
|
----------------------------------
|
----------------------------------
|
|
|
procedure Add_Search_Project_Directory
|
procedure Add_Search_Project_Directory
|
(Tree : Prj.Tree.Project_Node_Tree_Ref;
|
(Tree : Prj.Tree.Project_Node_Tree_Ref;
|
Path : String)
|
Path : String)
|
is
|
is
|
Tmp : String_Access;
|
Tmp : String_Access;
|
begin
|
begin
|
if Tree.Project_Path = null then
|
if Tree.Project_Path = null then
|
Tree.Project_Path := new String'(Uninitialized_Prefix & Path);
|
Tree.Project_Path := new String'(Uninitialized_Prefix & Path);
|
else
|
else
|
Tmp := Tree.Project_Path;
|
Tmp := Tree.Project_Path;
|
Tree.Project_Path := new String'(Tmp.all & Path_Separator & Path);
|
Tree.Project_Path := new String'(Tmp.all & Path_Separator & Path);
|
Free (Tmp);
|
Free (Tmp);
|
end if;
|
end if;
|
end Add_Search_Project_Directory;
|
end Add_Search_Project_Directory;
|
|
|
-----------
|
-----------
|
-- Check --
|
-- Check --
|
-----------
|
-----------
|
|
|
function Check
|
function Check
|
(Tree : Prj.Tree.Project_Node_Tree_Ref;
|
(Tree : Prj.Tree.Project_Node_Tree_Ref;
|
Declaration : String) return Boolean
|
Declaration : String) return Boolean
|
is
|
is
|
begin
|
begin
|
for Equal_Pos in Declaration'Range loop
|
for Equal_Pos in Declaration'Range loop
|
if Declaration (Equal_Pos) = '=' then
|
if Declaration (Equal_Pos) = '=' then
|
exit when Equal_Pos = Declaration'First;
|
exit when Equal_Pos = Declaration'First;
|
Add
|
Add
|
(Tree => Tree,
|
(Tree => Tree,
|
External_Name =>
|
External_Name =>
|
Declaration (Declaration'First .. Equal_Pos - 1),
|
Declaration (Declaration'First .. Equal_Pos - 1),
|
Value =>
|
Value =>
|
Declaration (Equal_Pos + 1 .. Declaration'Last));
|
Declaration (Equal_Pos + 1 .. Declaration'Last));
|
return True;
|
return True;
|
end if;
|
end if;
|
end loop;
|
end loop;
|
|
|
return False;
|
return False;
|
end Check;
|
end Check;
|
|
|
-----------------------------
|
-----------------------------
|
-- Initialize_Project_Path --
|
-- Initialize_Project_Path --
|
-----------------------------
|
-----------------------------
|
|
|
procedure Initialize_Project_Path (Tree : Prj.Tree.Project_Node_Tree_Ref) is
|
procedure Initialize_Project_Path (Tree : Prj.Tree.Project_Node_Tree_Ref) is
|
Add_Default_Dir : Boolean := True;
|
Add_Default_Dir : Boolean := True;
|
First : Positive;
|
First : Positive;
|
Last : Positive;
|
Last : Positive;
|
New_Len : Positive;
|
New_Len : Positive;
|
New_Last : Positive;
|
New_Last : Positive;
|
|
|
Ada_Project_Path : constant String := "ADA_PROJECT_PATH";
|
Ada_Project_Path : constant String := "ADA_PROJECT_PATH";
|
Gpr_Project_Path : constant String := "GPR_PROJECT_PATH";
|
Gpr_Project_Path : constant String := "GPR_PROJECT_PATH";
|
-- Name of alternate env. variable that contain path name(s) of
|
-- Name of alternate env. variable that contain path name(s) of
|
-- directories where project files may reside. GPR_PROJECT_PATH has
|
-- directories where project files may reside. GPR_PROJECT_PATH has
|
-- precedence over ADA_PROJECT_PATH.
|
-- precedence over ADA_PROJECT_PATH.
|
|
|
Gpr_Prj_Path : String_Access := Getenv (Gpr_Project_Path);
|
Gpr_Prj_Path : String_Access := Getenv (Gpr_Project_Path);
|
Ada_Prj_Path : String_Access := Getenv (Ada_Project_Path);
|
Ada_Prj_Path : String_Access := Getenv (Ada_Project_Path);
|
-- The path name(s) of directories where project files may reside.
|
-- The path name(s) of directories where project files may reside.
|
-- May be empty.
|
-- May be empty.
|
|
|
begin
|
begin
|
-- The current directory is always first in the search path. Since the
|
-- The current directory is always first in the search path. Since the
|
-- Project_Path currently starts with '#:' as a sign that it isn't
|
-- Project_Path currently starts with '#:' as a sign that it isn't
|
-- initialized, we simply replace '#' with '.'
|
-- initialized, we simply replace '#' with '.'
|
|
|
if Tree.Project_Path = null then
|
if Tree.Project_Path = null then
|
Tree.Project_Path := new String'('.' & Path_Separator);
|
Tree.Project_Path := new String'('.' & Path_Separator);
|
else
|
else
|
Tree.Project_Path (Tree.Project_Path'First) := '.';
|
Tree.Project_Path (Tree.Project_Path'First) := '.';
|
end if;
|
end if;
|
|
|
-- Then the reset of the project path (if any) currently contains the
|
-- Then the reset of the project path (if any) currently contains the
|
-- directories added through Add_Search_Project_Directory
|
-- directories added through Add_Search_Project_Directory
|
|
|
-- If environment variables are defined and not empty, add their content
|
-- If environment variables are defined and not empty, add their content
|
|
|
if Gpr_Prj_Path.all /= "" then
|
if Gpr_Prj_Path.all /= "" then
|
Add_Search_Project_Directory (Tree, Gpr_Prj_Path.all);
|
Add_Search_Project_Directory (Tree, Gpr_Prj_Path.all);
|
end if;
|
end if;
|
|
|
Free (Gpr_Prj_Path);
|
Free (Gpr_Prj_Path);
|
|
|
if Ada_Prj_Path.all /= "" then
|
if Ada_Prj_Path.all /= "" then
|
Add_Search_Project_Directory (Tree, Ada_Prj_Path.all);
|
Add_Search_Project_Directory (Tree, Ada_Prj_Path.all);
|
end if;
|
end if;
|
|
|
Free (Ada_Prj_Path);
|
Free (Ada_Prj_Path);
|
|
|
-- Copy to Name_Buffer, since we will need to manipulate the path
|
-- Copy to Name_Buffer, since we will need to manipulate the path
|
|
|
Name_Len := Tree.Project_Path'Length;
|
Name_Len := Tree.Project_Path'Length;
|
Name_Buffer (1 .. Name_Len) := Tree.Project_Path.all;
|
Name_Buffer (1 .. Name_Len) := Tree.Project_Path.all;
|
|
|
-- Scan the directory path to see if "-" is one of the directories.
|
-- Scan the directory path to see if "-" is one of the directories.
|
-- Remove each occurrence of "-" and set Add_Default_Dir to False.
|
-- Remove each occurrence of "-" and set Add_Default_Dir to False.
|
-- Also resolve relative paths and symbolic links.
|
-- Also resolve relative paths and symbolic links.
|
|
|
First := 3;
|
First := 3;
|
loop
|
loop
|
while First <= Name_Len
|
while First <= Name_Len
|
and then (Name_Buffer (First) = Path_Separator)
|
and then (Name_Buffer (First) = Path_Separator)
|
loop
|
loop
|
First := First + 1;
|
First := First + 1;
|
end loop;
|
end loop;
|
|
|
exit when First > Name_Len;
|
exit when First > Name_Len;
|
|
|
Last := First;
|
Last := First;
|
|
|
while Last < Name_Len
|
while Last < Name_Len
|
and then Name_Buffer (Last + 1) /= Path_Separator
|
and then Name_Buffer (Last + 1) /= Path_Separator
|
loop
|
loop
|
Last := Last + 1;
|
Last := Last + 1;
|
end loop;
|
end loop;
|
|
|
-- If the directory is "-", set Add_Default_Dir to False and
|
-- If the directory is "-", set Add_Default_Dir to False and
|
-- remove from path.
|
-- remove from path.
|
|
|
if Name_Buffer (First .. Last) = No_Project_Default_Dir then
|
if Name_Buffer (First .. Last) = No_Project_Default_Dir then
|
Add_Default_Dir := False;
|
Add_Default_Dir := False;
|
|
|
for J in Last + 1 .. Name_Len loop
|
for J in Last + 1 .. Name_Len loop
|
Name_Buffer (J - No_Project_Default_Dir'Length - 1) :=
|
Name_Buffer (J - No_Project_Default_Dir'Length - 1) :=
|
Name_Buffer (J);
|
Name_Buffer (J);
|
end loop;
|
end loop;
|
|
|
Name_Len := Name_Len - No_Project_Default_Dir'Length - 1;
|
Name_Len := Name_Len - No_Project_Default_Dir'Length - 1;
|
|
|
-- After removing the '-', go back one character to get the next
|
-- After removing the '-', go back one character to get the next
|
-- directory correctly.
|
-- directory correctly.
|
|
|
Last := Last - 1;
|
Last := Last - 1;
|
|
|
elsif not Hostparm.OpenVMS
|
elsif not Hostparm.OpenVMS
|
or else not Is_Absolute_Path (Name_Buffer (First .. Last))
|
or else not Is_Absolute_Path (Name_Buffer (First .. Last))
|
then
|
then
|
-- On VMS, only expand relative path names, as absolute paths
|
-- On VMS, only expand relative path names, as absolute paths
|
-- may correspond to multi-valued VMS logical names.
|
-- may correspond to multi-valued VMS logical names.
|
|
|
declare
|
declare
|
New_Dir : constant String :=
|
New_Dir : constant String :=
|
Normalize_Pathname
|
Normalize_Pathname
|
(Name_Buffer (First .. Last),
|
(Name_Buffer (First .. Last),
|
Resolve_Links => Opt.Follow_Links_For_Dirs);
|
Resolve_Links => Opt.Follow_Links_For_Dirs);
|
|
|
begin
|
begin
|
-- If the absolute path was resolved and is different from
|
-- If the absolute path was resolved and is different from
|
-- the original, replace original with the resolved path.
|
-- the original, replace original with the resolved path.
|
|
|
if New_Dir /= Name_Buffer (First .. Last)
|
if New_Dir /= Name_Buffer (First .. Last)
|
and then New_Dir'Length /= 0
|
and then New_Dir'Length /= 0
|
then
|
then
|
New_Len := Name_Len + New_Dir'Length - (Last - First + 1);
|
New_Len := Name_Len + New_Dir'Length - (Last - First + 1);
|
New_Last := First + New_Dir'Length - 1;
|
New_Last := First + New_Dir'Length - 1;
|
Name_Buffer (New_Last + 1 .. New_Len) :=
|
Name_Buffer (New_Last + 1 .. New_Len) :=
|
Name_Buffer (Last + 1 .. Name_Len);
|
Name_Buffer (Last + 1 .. Name_Len);
|
Name_Buffer (First .. New_Last) := New_Dir;
|
Name_Buffer (First .. New_Last) := New_Dir;
|
Name_Len := New_Len;
|
Name_Len := New_Len;
|
Last := New_Last;
|
Last := New_Last;
|
end if;
|
end if;
|
end;
|
end;
|
end if;
|
end if;
|
|
|
First := Last + 1;
|
First := Last + 1;
|
end loop;
|
end loop;
|
|
|
Free (Tree.Project_Path);
|
Free (Tree.Project_Path);
|
|
|
-- Set the initial value of Current_Project_Path
|
-- Set the initial value of Current_Project_Path
|
|
|
if Add_Default_Dir then
|
if Add_Default_Dir then
|
declare
|
declare
|
Prefix : String_Ptr := Sdefault.Search_Dir_Prefix;
|
Prefix : String_Ptr := Sdefault.Search_Dir_Prefix;
|
|
|
begin
|
begin
|
if Prefix = null then
|
if Prefix = null then
|
Prefix := new String'(Executable_Prefix_Path);
|
Prefix := new String'(Executable_Prefix_Path);
|
|
|
if Prefix.all /= "" then
|
if Prefix.all /= "" then
|
Add_Str_To_Name_Buffer
|
Add_Str_To_Name_Buffer
|
(Path_Separator & Prefix.all &
|
(Path_Separator & Prefix.all &
|
"share" & Directory_Separator & "gpr");
|
"share" & Directory_Separator & "gpr");
|
Add_Str_To_Name_Buffer
|
Add_Str_To_Name_Buffer
|
(Path_Separator & Prefix.all &
|
(Path_Separator & Prefix.all &
|
Directory_Separator & "lib" &
|
Directory_Separator & "lib" &
|
Directory_Separator & "gnat");
|
Directory_Separator & "gnat");
|
end if;
|
end if;
|
|
|
else
|
else
|
Tree.Project_Path :=
|
Tree.Project_Path :=
|
new String'(Name_Buffer (1 .. Name_Len) & Path_Separator &
|
new String'(Name_Buffer (1 .. Name_Len) & Path_Separator &
|
Prefix.all &
|
Prefix.all &
|
".." & Directory_Separator &
|
".." & Directory_Separator &
|
".." & Directory_Separator &
|
".." & Directory_Separator &
|
".." & Directory_Separator & "gnat");
|
".." & Directory_Separator & "gnat");
|
end if;
|
end if;
|
|
|
Free (Prefix);
|
Free (Prefix);
|
end;
|
end;
|
end if;
|
end if;
|
|
|
if Tree.Project_Path = null then
|
if Tree.Project_Path = null then
|
Tree.Project_Path := new String'(Name_Buffer (1 .. Name_Len));
|
Tree.Project_Path := new String'(Name_Buffer (1 .. Name_Len));
|
end if;
|
end if;
|
end Initialize_Project_Path;
|
end Initialize_Project_Path;
|
|
|
------------------
|
------------------
|
-- Project_Path --
|
-- Project_Path --
|
------------------
|
------------------
|
|
|
function Project_Path (Tree : Project_Node_Tree_Ref) return String is
|
function Project_Path (Tree : Project_Node_Tree_Ref) return String is
|
begin
|
begin
|
if Tree.Project_Path = null
|
if Tree.Project_Path = null
|
or else Tree.Project_Path (Tree.Project_Path'First) = '#'
|
or else Tree.Project_Path (Tree.Project_Path'First) = '#'
|
then
|
then
|
Initialize_Project_Path (Tree);
|
Initialize_Project_Path (Tree);
|
end if;
|
end if;
|
|
|
return Tree.Project_Path.all;
|
return Tree.Project_Path.all;
|
end Project_Path;
|
end Project_Path;
|
|
|
-----------
|
-----------
|
-- Reset --
|
-- Reset --
|
-----------
|
-----------
|
|
|
procedure Reset (Tree : Prj.Tree.Project_Node_Tree_Ref) is
|
procedure Reset (Tree : Prj.Tree.Project_Node_Tree_Ref) is
|
begin
|
begin
|
Name_To_Name_HTable.Reset (Tree.External_References);
|
Name_To_Name_HTable.Reset (Tree.External_References);
|
end Reset;
|
end Reset;
|
|
|
----------------------
|
----------------------
|
-- Set_Project_Path --
|
-- Set_Project_Path --
|
----------------------
|
----------------------
|
|
|
procedure Set_Project_Path
|
procedure Set_Project_Path
|
(Tree : Project_Node_Tree_Ref;
|
(Tree : Project_Node_Tree_Ref;
|
New_Path : String) is
|
New_Path : String) is
|
begin
|
begin
|
Free (Tree.Project_Path);
|
Free (Tree.Project_Path);
|
Tree.Project_Path := new String'(New_Path);
|
Tree.Project_Path := new String'(New_Path);
|
end Set_Project_Path;
|
end Set_Project_Path;
|
|
|
--------------
|
--------------
|
-- Value_Of --
|
-- Value_Of --
|
--------------
|
--------------
|
|
|
function Value_Of
|
function Value_Of
|
(Tree : Prj.Tree.Project_Node_Tree_Ref;
|
(Tree : Prj.Tree.Project_Node_Tree_Ref;
|
External_Name : Name_Id;
|
External_Name : Name_Id;
|
With_Default : Name_Id := No_Name)
|
With_Default : Name_Id := No_Name)
|
return Name_Id
|
return Name_Id
|
is
|
is
|
The_Value : Name_Id;
|
The_Value : Name_Id;
|
Name : String := Get_Name_String (External_Name);
|
Name : String := Get_Name_String (External_Name);
|
|
|
begin
|
begin
|
Canonical_Case_File_Name (Name);
|
Canonical_Case_File_Name (Name);
|
Name_Len := Name'Length;
|
Name_Len := Name'Length;
|
Name_Buffer (1 .. Name_Len) := Name;
|
Name_Buffer (1 .. Name_Len) := Name;
|
The_Value :=
|
The_Value :=
|
Name_To_Name_HTable.Get (Tree.External_References, Name_Find);
|
Name_To_Name_HTable.Get (Tree.External_References, Name_Find);
|
|
|
if The_Value /= No_Name then
|
if The_Value /= No_Name then
|
return The_Value;
|
return The_Value;
|
end if;
|
end if;
|
|
|
-- Find if it is an environment, if it is, put value in the hash table
|
-- Find if it is an environment, if it is, put value in the hash table
|
|
|
declare
|
declare
|
Env_Value : String_Access := Getenv (Name);
|
Env_Value : String_Access := Getenv (Name);
|
|
|
begin
|
begin
|
if Env_Value /= null and then Env_Value'Length > 0 then
|
if Env_Value /= null and then Env_Value'Length > 0 then
|
Name_Len := Env_Value'Length;
|
Name_Len := Env_Value'Length;
|
Name_Buffer (1 .. Name_Len) := Env_Value.all;
|
Name_Buffer (1 .. Name_Len) := Env_Value.all;
|
The_Value := Name_Find;
|
The_Value := Name_Find;
|
Name_To_Name_HTable.Set
|
Name_To_Name_HTable.Set
|
(Tree.External_References, External_Name, The_Value);
|
(Tree.External_References, External_Name, The_Value);
|
Free (Env_Value);
|
Free (Env_Value);
|
return The_Value;
|
return The_Value;
|
|
|
else
|
else
|
Free (Env_Value);
|
Free (Env_Value);
|
return With_Default;
|
return With_Default;
|
end if;
|
end if;
|
end;
|
end;
|
end Value_Of;
|
end Value_Of;
|
|
|
end Prj.Ext;
|
end Prj.Ext;
|
|
|