summaryrefslogtreecommitdiff
path: root/gcc/ada/prj-env.adb
diff options
context:
space:
mode:
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2004-10-27 13:38:32 +0000
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2004-10-27 13:38:32 +0000
commit29f86cb285c5f1cfa7c8f1033cd4b5108853cfd2 (patch)
tree24461a54c1ffdb9d4cd2b2b01f4ca8d5ecbe19d2 /gcc/ada/prj-env.adb
parent83b8339a7c0a04401212894fb10019c111433a39 (diff)
downloadgcc-29f86cb285c5f1cfa7c8f1033cd4b5108853cfd2.tar.gz
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 git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@89661 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/prj-env.adb')
-rw-r--r--gcc/ada/prj-env.adb68
1 files changed, 64 insertions, 4 deletions
diff --git a/gcc/ada/prj-env.adb b/gcc/ada/prj-env.adb
index b751e6be7aa..517a2ee57c4 100644
--- a/gcc/ada/prj-env.adb
+++ b/gcc/ada/prj-env.adb
@@ -32,7 +32,8 @@ with Prj.Com; use Prj.Com;
with Table;
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
@@ -135,6 +136,9 @@ package body Prj.Env is
-- Add Object_Dir to object path table. Make sure it is not duplicate
-- 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
(Path_FD : out File_Descriptor;
Path_Name : out Name_Id);
@@ -276,10 +280,18 @@ package body Prj.Env is
and then
(not Including_Libraries or else not Data.Library))
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
- 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
-- For a non library project, add the object directory
@@ -546,6 +558,45 @@ package body Prj.Env is
return Namet.Get_Name_String (Data.File_Names (Body_Part).Path);
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 --
--------------------------------
@@ -1966,9 +2017,18 @@ package body Prj.Env is
(not Including_Libraries or else not Data.Library))
then
-- 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
- 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
-- directory, if it is not a virtual project.