Commit ab9f47f1 by Vincent Celier Committed by Arnaud Charlet

prj-ext.adb: Take into account new environment variable GPR_PROJECT_PATH.

2005-11-14  Vincent Celier  <celier@adacore.com>

	* prj-ext.adb: Take into account new environment variable
	GPR_PROJECT_PATH. Warn if both GPR_PROJECT_PATH and ADA_PROJECT_PATH
	are defined.
	(Prj.Ext elaboration): For each directory in the ADA_PROJECT_PATH,
	normalize its path name, making it absolute and resolving symbolic
	links, and replace the original if resolved path is different.

From-SVN: r106994
parent 3c43f853
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 2000-2005 Free Software Foundation, Inc. -- -- Copyright (C) 2000-2005, 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- --
...@@ -25,25 +25,30 @@ ...@@ -25,25 +25,30 @@
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
with Namet; use Namet; with Namet; use Namet;
with Output; use Output;
with Osint; use Osint; with Osint; use Osint;
with Sdefault; with Sdefault;
with GNAT.HTable; with GNAT.HTable;
package body Prj.Ext is package body Prj.Ext is
Gpr_Project_Path : constant String := "GPR_PROJECT_PATH";
Ada_Project_Path : constant String := "ADA_PROJECT_PATH"; Ada_Project_Path : constant String := "ADA_PROJECT_PATH";
-- Name of the env. variable that contains path name(s) of directories -- Name of the env. variables that contain path name(s) of directories
-- where project files may reside. -- where project files may reside. GPR_PROJECT_PATH has precedence over
-- ADA_PROJECT_PATH.
Prj_Path : constant String_Access := Getenv (Ada_Project_Path); Gpr_Prj_Path : constant String_Access := Getenv (Gpr_Project_Path);
Ada_Prj_Path : constant 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.
No_Project_Default_Dir : constant String := "-"; No_Project_Default_Dir : constant String := "-";
Current_Project_Path : String_Access; Current_Project_Path : String_Access;
-- The project path; initialized during elaboration of package -- The project path. Initialized during elaboration of package Contains at
-- Contains at least the current working directory. -- least the current working directory.
package Htable is new GNAT.HTable.Simple_HTable package Htable is new GNAT.HTable.Simple_HTable
(Header_Num => Header_Num, (Header_Num => Header_Num,
...@@ -152,8 +157,7 @@ package body Prj.Ext is ...@@ -152,8 +157,7 @@ package body Prj.Ext is
return The_Value; return The_Value;
end if; end if;
-- Find if it is an environment. -- Find if it is an environment, if it is, put value in the hash table
-- If it is, put the value in the hash table.
declare declare
Env_Value : String_Access := Getenv (Name); Env_Value : String_Access := Getenv (Name);
...@@ -181,14 +185,30 @@ begin ...@@ -181,14 +185,30 @@ begin
Add_Default_Dir : Boolean := True; Add_Default_Dir : Boolean := True;
First : Positive; First : Positive;
Last : Positive; Last : Positive;
New_Len : Positive;
New_Last : Positive;
Prj_Path : String_Access := Gpr_Prj_Path;
begin begin
if Gpr_Prj_Path.all /= "" then
-- Warn if both environment variables are defined
if Ada_Prj_Path.all /= "" then
Write_Line ("Warning: ADA_PROJECT_PATH is not taken into account");
Write_Line (" when GPR_PROJECT_PATH is defined");
end if;
else
Prj_Path := Ada_Prj_Path;
end if;
-- The current directory is always first -- The current directory is always first
Name_Len := 1; Name_Len := 1;
Name_Buffer (Name_Len) := '.'; Name_Buffer (Name_Len) := '.';
-- If env. var. is defined and not empty, add its content -- If environment variable is defined and not empty, add its content
if Prj_Path.all /= "" then if Prj_Path.all /= "" then
Name_Len := Name_Len + 1; Name_Len := Name_Len + 1;
...@@ -198,6 +218,7 @@ begin ...@@ -198,6 +218,7 @@ begin
-- 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 occurence of "-" and set Add_Default_Dir to False. -- Remove each occurence of "-" and set Add_Default_Dir to False.
-- Also resolve relative paths and symbolic links.
First := 3; First := 3;
loop loop
...@@ -229,6 +250,27 @@ begin ...@@ -229,6 +250,27 @@ begin
end loop; end loop;
Name_Len := Name_Len - No_Project_Default_Dir'Length - 1; Name_Len := Name_Len - No_Project_Default_Dir'Length - 1;
else
declare
New_Dir : constant String :=
Normalize_Pathname (Name_Buffer (First .. Last));
begin
-- If the absolute path was resolved and is different from
-- the original, replace original with the resolved path.
if New_Dir /= Name_Buffer (First .. Last)
and then New_Dir'Length /= 0
then
New_Len := Name_Len + New_Dir'Length - (Last - First + 1);
New_Last := First + New_Dir'Length - 1;
Name_Buffer (New_Last + 1 .. New_Len) :=
Name_Buffer (Last + 1 .. Name_Len);
Name_Buffer (First .. New_Last) := New_Dir;
Name_Len := New_Len;
Last := New_Last;
end if;
end;
end if; end if;
First := Last + 1; First := Last + 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment