From 813fc7bf1866ee281dfa0be67f08016af9279ffe Mon Sep 17 00:00:00 2001 From: Vincent Celier Date: Wed, 27 Oct 2004 15:38:32 +0200 Subject: [PATCH] prj-env.adb: (Contains_ALI_Files): New Boolean function 2004-10-26 Vincent Celier * 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 --- gcc/ada/prj-env.adb | 68 ++++++++++++++++++++++++++++++++++++++++++--- 1 file 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. -- 2.30.2