public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Ada: improvement in handling of library projects
@ 2004-10-27 10:06 Arnaud Charlet
  2004-10-27 14:11 ` Arnaud Charlet
  0 siblings, 1 reply; 2+ messages in thread
From: Arnaud Charlet @ 2004-10-27 10:06 UTC (permalink / raw)
  To: gcc-patches; +Cc: Vincent Celier

[-- Attachment #1: Type: text/plain, Size: 803 bytes --]

Tested on x86-linux

To create a library project for an externally built library,
the object files will not be supplied. The ALI files will be in the
object directory, read-only. There will be no ALI files in the library
directory. To bind, gnatbind need to find the ALI file. So, when there are
no ALI files in the library directory, the object directory will be put
in the object path, instead of the library directory, so that gnatbind can
find the read-only ALI files.

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


[-- Attachment #2: difs.21 --]
[-- Type: text/plain, Size: 4406 bytes --]

Index: prj-env.adb
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ada/prj-env.adb,v
retrieving revision 1.19
diff -u -p -r1.19 prj-env.adb
--- prj-env.adb	4 Oct 2004 14:55:06 -0000	1.19
+++ prj-env.adb	27 Oct 2004 09:33:20 -0000
@@ -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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Ada: improvement in handling of library projects
  2004-10-27 10:06 Ada: improvement in handling of library projects Arnaud Charlet
@ 2004-10-27 14:11 ` Arnaud Charlet
  0 siblings, 0 replies; 2+ messages in thread
From: Arnaud Charlet @ 2004-10-27 14:11 UTC (permalink / raw)
  To: Arnaud Charlet; +Cc: gcc-patches, Vincent Celier

Committed on mainline.

> Tested on x86-linux
> To create a library project for an externally built library,
> [...]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-10-27 13:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-27 10:06 Ada: improvement in handling of library projects Arnaud Charlet
2004-10-27 14:11 ` Arnaud Charlet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).