Patchwork [Ada] Action callback gets the project with sources

login
register
mail settings
Submitter Arnaud Charlet
Date July 9, 2012, 1:29 p.m.
Message ID <20120709132924.GA2869@adacore.com>
Download mbox | patch
Permalink /patch/169842/
State New
Headers show

Comments

Arnaud Charlet - July 9, 2012, 1:29 p.m.
For aggregate projects and aggregate libraries we may have multiple
references of the same project. Only one is properly initialized
and can be iterated to get the corresponding sources.

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

2012-07-09  Pascal Obry  <obry@adacore.com>

	* prj.adb (For_Every_Project_Imported_Context): Make sure we
	callback with the project having sources.
	Minor reformatting.

Patch

Index: prj.adb
===================================================================
--- prj.adb	(revision 189366)
+++ prj.adb	(working copy)
@@ -584,8 +584,55 @@ 
             In_Aggregate_Lib      : Boolean;
             From_Encapsulated_Lib : Boolean)
          is
+
+            function Has_Sources (P : Project_Id) return Boolean;
+            --  Returns True if P has sources
+
+            function Get_From_Tree (P : Project_Id) return Project_Id;
+            --  Get project P from Tree. If P has no sources get another
+            --  instance of this project with sources. If P has sources,
+            --  returns it.
+
+            -----------------
+            -- Has_Sources --
+            -----------------
+
+            function Has_Sources (P : Project_Id) return Boolean is
+               Lang : Language_Ptr;
+            begin
+               Lang := P.Languages;
+               while Lang /= No_Language_Index loop
+                  if Lang.First_Source /= No_Source then
+                     return True;
+                  end if;
+                  Lang := Lang.Next;
+               end loop;
+
+               return False;
+            end Has_Sources;
+
+            -------------------
+            -- Get_From_Tree --
+            -------------------
+
+            function Get_From_Tree (P : Project_Id) return Project_Id is
+               List : Project_List := Tree.Projects;
+            begin
+               if not Has_Sources (P) then
+                  while List /= null loop
+                     if List.Project.Name = P.Name
+                       and then Has_Sources (List.Project)
+                     then
+                        return List.Project;
+                     end if;
+                     List := List.Next;
+                  end loop;
+               end if;
+
+               return P;
+            end Get_From_Tree;
+
             List : Project_List;
-            T    : Project_Tree_Ref;
 
          begin
             if not Seen_Name.Contains (Project.Name) then
@@ -597,7 +644,7 @@ 
 
                if not Imported_First then
                   Action
-                    (Project,
+                    (Get_From_Tree (Project),
                      Tree,
                      Project_Context'(In_Aggregate_Lib, From_Encapsulated_Lib),
                      With_State);
@@ -640,23 +687,20 @@ 
                         --  of the aggregate library.
 
                         if Project.Qualifier = Aggregate_Library then
-                           T := Tree;
                            Recursive_Check
-                             (Agg.Project, T,
+                             (Agg.Project, Tree,
                               True,
                               From_Encapsulated_Lib
                                 or else
                                   Project.Standalone_Library = Encapsulated);
 
                         else
-                           T := Agg.Tree;
-
                            --  Use a new context as we want to returns the same
                            --  project in different project tree for aggregated
                            --  projects.
 
                            Recursive_Check_Context
-                             (Agg.Project, T, False, False);
+                             (Agg.Project, Agg.Tree, False, False);
                         end if;
 
                         Agg := Agg.Next;
@@ -666,7 +710,7 @@ 
 
                if Imported_First then
                   Action
-                    (Project,
+                    (Get_From_Tree (Project),
                      Tree,
                      Project_Context'(In_Aggregate_Lib, From_Encapsulated_Lib),
                      With_State);