A new environment variable GPR_PROJECT_PATH_FILE is used by the Project
Manager to set up the project path. When defined, GPR_PROJECT_PATH_FILE
indicates the path of a text file that contains directories to be added
to the project path. GPR_PROJECT_PATH_FILE is taken into account before
GPR_PROJECT_PATH.
The test for this is to create a text file containing the path names
of project directories, to define GPR_PROJECT_PATH_FILE with the path
name of this file and to invoke gnatmake with project files that need
to have the project path correctly defined.

Tested on x86_64-pc-linux-gnu, committed on trunk

2013-04-11  Vincent Celier  <cel...@adacore.com>

        * prj-env.adb (Initialize_Default_Project_Path): Take
        into account a project path file, specified by environment
        variable GPR_PROJECT_PATH_FILE, before taking into account
        GPR_PROJECT_PATH.
        * projects.texi: Add documentation for GPR_PROJECT_PATH_FILE

Index: prj-env.adb
===================================================================
--- prj-env.adb (revision 197743)
+++ prj-env.adb (working copy)
@@ -23,6 +23,8 @@
 --                                                                          --
 ------------------------------------------------------------------------------
 
+with Ada.Text_IO; use Ada.Text_IO;
+
 with Fmap;
 with Hostparm;
 with Makeutl;  use Makeutl;
@@ -1895,14 +1897,17 @@
       New_Len         : Positive;
       New_Last        : Positive;
 
-      Ada_Project_Path : constant String := "ADA_PROJECT_PATH";
-      Gpr_Project_Path : constant String := "GPR_PROJECT_PATH";
-      --  Name of alternate env. variable that contain path name(s) of
-      --  directories where project files may reside. GPR_PROJECT_PATH has
-      --  precedence over ADA_PROJECT_PATH.
+      Ada_Project_Path      : constant String := "ADA_PROJECT_PATH";
+      Gpr_Project_Path      : constant String := "GPR_PROJECT_PATH";
+      Gpr_Project_Path_File : constant String := "GPR_PROJECT_PATH_FILE";
+      --  Names of alternate env. variable that contain path name(s) of
+      --  directories where project files may reside. They are taken into
+      --  account in this order: GPR_PROJECT_PATH_FILE, GPR_PROJECT_PATH,
+      --  ADA_PROJECT_PATH.
 
-      Gpr_Prj_Path : String_Access;
-      Ada_Prj_Path : String_Access;
+      Gpr_Prj_Path_File : String_Access;
+      Gpr_Prj_Path      : String_Access;
+      Ada_Prj_Path      : String_Access;
       --  The path name(s) of directories where project files may reside.
       --  May be empty.
 
@@ -1926,9 +1931,51 @@
 
       --  If environment variables are defined and not empty, add their content
 
-      Gpr_Prj_Path := Getenv (Gpr_Project_Path);
-      Ada_Prj_Path := Getenv (Ada_Project_Path);
+      Gpr_Prj_Path_File := Getenv (Gpr_Project_Path_File);
+      Gpr_Prj_Path      := Getenv (Gpr_Project_Path);
+      Ada_Prj_Path      := Getenv (Ada_Project_Path);
 
+      if Gpr_Prj_Path_File.all /= "" then
+         declare
+            File : Ada.Text_IO.File_Type;
+            Line : String (1 .. 10_000);
+            Last : Natural;
+
+            Tmp : String_Access;
+
+         begin
+            Open (File, In_File, Gpr_Prj_Path_File.all);
+
+            while not End_Of_File (File) loop
+               Get_Line (File, Line, Last);
+
+               if Last /= 0
+                 and then (Last = 1 or else Line (1 .. 2) /= "--")
+               then
+                  Tmp := Self.Path;
+                  Self.Path :=
+                    new String'
+                      (Tmp.all & Path_Separator & Line (1 .. Last));
+                  Free (Tmp);
+               end if;
+
+               if Current_Verbosity = High then
+                  Debug_Output ("Adding directory to Project_Path: """
+                                & Line (1 .. Last) & '"');
+               end if;
+            end loop;
+
+            Close (File);
+
+         exception
+            when others =>
+               Write_Str ("warning: could not read project path file """);
+               Write_Str (Gpr_Prj_Path_File.all);
+               Write_Line ("""");
+         end;
+
+      end if;
+
       if Gpr_Prj_Path.all /= "" then
          Add_Directories (Self, Gpr_Prj_Path.all);
       end if;
Index: projects.texi
===================================================================
--- projects.texi       (revision 197784)
+++ projects.texi       (working copy)
@@ -1209,12 +1209,18 @@
   current project file.
 
 @item
+@cindex @code{GPR_PROJECT_PATH_FILE}
+@cindex @code{GPR_PROJECT_PATH}
 @cindex @code{ADA_PROJECT_PATH}
-@cindex @code{GPR_PROJECT_PATH}
   Then it is searched relative to all the directories specified in the
-  ^environment variables^logical names^ @b{GPR_PROJECT_PATH} and
-  @b{ADA_PROJECT_PATH} (in that order) if they exist. The former is
-  recommended, the latter is kept for backward compatibility.
+  ^environment variables^logical names^ @b{GPR_PROJECT_PATH_FILE},
+  @b{GPR_PROJECT_PATH} and @b{ADA_PROJECT_PATH} (in that order) if they exist.
+  The value of @b{GPR_PROJECT_PATH_FILE}, when defined, is the path name of
+  a text file that contains project directory path names, one per line.
+  @b{GPR_PROJECT_PATH} and @b{ADA_PROJECT_PATH}, when defined, contain
+  project directory path names separated by directory separators.
+  @b{ADA_PROJECT_PATH} is used for compatibility, it is recommended to
+  use @b{GPR_PROJECT_PATH_FILE} or @b{GPR_PROJECT_PATH}.
 
 @item Finally, it is searched relative to the default project directories.
   Such directories depends on the tool used. The different locations searched

Reply via email to