Commit 813fc7bf by Vincent Celier Committed by Arnaud Charlet

prj-env.adb: (Contains_ALI_Files): New Boolean function

2004-10-26  Vincent Celier  <celier@gnat.com>

	* prj-env.adb: (Contains_ALI_Files): New Boolean function
	(Ada_Objects_Path.Add): For a library project, add to the object path
	the library directory only if there is no object directory or if the
	library directory contains ALI files.
	(Set_Ada_Paths.Add.Recursive_Add): Ditto

From-SVN: r89661
parent 73f17ac8
...@@ -32,7 +32,8 @@ with Prj.Com; use Prj.Com; ...@@ -32,7 +32,8 @@ with Prj.Com; use Prj.Com;
with Table; with Table;
with Tempdir; with Tempdir;
with GNAT.OS_Lib; use GNAT.OS_Lib; with GNAT.Directory_Operations; use GNAT.Directory_Operations;
with GNAT.OS_Lib; use GNAT.OS_Lib;
package body Prj.Env is package body Prj.Env is
...@@ -135,6 +136,9 @@ package body Prj.Env is ...@@ -135,6 +136,9 @@ package body Prj.Env is
-- 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.
function Contains_ALI_Files (Dir : Name_Id) return Boolean;
-- Return True if there is at least one ALI file in the directory Dir
procedure Create_New_Path_File procedure Create_New_Path_File
(Path_FD : out File_Descriptor; (Path_FD : out File_Descriptor;
Path_Name : out Name_Id); Path_Name : out Name_Id);
...@@ -276,10 +280,18 @@ package body Prj.Env is ...@@ -276,10 +280,18 @@ package body Prj.Env is
and then and then
(not Including_Libraries or else not Data.Library)) (not Including_Libraries or else not Data.Library))
then then
-- For a library project, add the library directory -- For a library project, add the library directory,
-- if there is no object directory or if it contains ALI
-- files; otherwise add the object directory.
if Data.Library then if Data.Library then
Add_To_Path (Get_Name_String (Data.Library_Dir)); if Data.Object_Directory = No_Name
or else Contains_ALI_Files (Data.Library_Dir)
then
Add_To_Path (Get_Name_String (Data.Library_Dir));
else
Add_To_Path (Get_Name_String (Data.Object_Directory));
end if;
else else
-- For a non library project, add the object directory -- For a non library project, add the object directory
...@@ -546,6 +558,45 @@ package body Prj.Env is ...@@ -546,6 +558,45 @@ package body Prj.Env is
return Namet.Get_Name_String (Data.File_Names (Body_Part).Path); return Namet.Get_Name_String (Data.File_Names (Body_Part).Path);
end Body_Path_Name_Of; end Body_Path_Name_Of;
------------------------
-- Contains_ALI_Files --
------------------------
function Contains_ALI_Files (Dir : Name_Id) return Boolean is
Dir_Name : constant String := Get_Name_String (Dir);
Direct : Dir_Type;
Name : String (1 .. 1_000);
Last : Natural;
Result : Boolean := False;
begin
Open (Direct, Dir_Name);
-- For each file in the directory, check if it is an ALI file
loop
Read (Direct, Name, Last);
exit when Last = 0;
Canonical_Case_File_Name (Name (1 .. Last));
Result := Last >= 5 and then Name (Last - 3 .. Last) = ".ali";
exit when Result;
end loop;
Close (Direct);
return Result;
exception
-- If there is any problem, close the directory if open and return
-- True; the library directory will be added to the path.
when others =>
if Is_Open (Direct) then
Close (Direct);
end if;
return True;
end Contains_ALI_Files;
-------------------------------- --------------------------------
-- Create_Config_Pragmas_File -- -- Create_Config_Pragmas_File --
-------------------------------- --------------------------------
...@@ -1966,9 +2017,18 @@ package body Prj.Env is ...@@ -1966,9 +2017,18 @@ package body Prj.Env is
(not Including_Libraries or else not Data.Library)) (not Including_Libraries or else not Data.Library))
then then
-- For a library project, add the library directory -- For a library project, add the library directory
-- if there is no object directory or if the library
-- directory contains ALI files; otherwise add the
-- object directory.
if Data.Library then if Data.Library then
Add_To_Object_Path (Data.Library_Dir); if Data.Object_Directory = No_Name
or else Contains_ALI_Files (Data.Library_Dir)
then
Add_To_Object_Path (Data.Library_Dir);
else
Add_To_Object_Path (Data.Object_Directory);
end if;
-- For a non-library project, add the object -- For a non-library project, add the object
-- directory, if it is not a virtual project. -- directory, if it is not a virtual project.
......
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