A project that is imported by an extended project was not allowed to be extended. This patch fixes this.
Invoking gnatmake -P test_util.gpr should not result in an error such as cannot extend an already imported project file or cannot import an already extended project file with "test_b.gpr"; with "test_a.gpr"; project Test_Unit is end Test_Unit; project A is end A; project Test_A extends "a.gpr" is end Test_A; with "a.gpr"; project B is end B; project Test_B extends "b.gpr" is end Test_B; Tested on x86_64-pc-linux-gnu, committed on trunk 2014-01-21 Vincent Celier <cel...@adacore.com> * prj-part.adb (Parse_Single_Project): Accept to extend a project if it has only be imported by an project being extended. When a project that has only been imported by a project being extended is imported by another project that is not being extended, reset the previous indication, so that it will be an error if this project is extended later. * prj-tree.adb (Create_Project): Include component From_Extended in table Projects_HT * prj-tree.ads (Project_Name_And_Node): New Boolean component From_Extended
Index: prj-part.adb =================================================================== --- prj-part.adb (revision 206804) +++ prj-part.adb (working copy) @@ -1325,11 +1325,20 @@ "cannot extend the same project file several times", Token_Ptr); end if; - else + elsif not A_Project_Name_And_Node.From_Extended then Error_Msg (Env.Flags, "cannot extend an already imported project file", Token_Ptr); + + else + -- Register this project as being extended + + A_Project_Name_And_Node.Extended := True; + Tree_Private_Part.Projects_Htable.Set + (In_Tree.Projects_HT, + A_Project_Name_And_Node.Name, + A_Project_Name_And_Node); end if; elsif A_Project_Name_And_Node.Extended then @@ -1372,6 +1381,16 @@ "cannot import an already extended project file", Token_Ptr); end if; + + elsif A_Project_Name_And_Node.From_Extended then + -- This project is now imported from a non extending project. + -- Indicate this in has table Projects.HT. + + A_Project_Name_And_Node.From_Extended := False; + Tree_Private_Part.Projects_Htable.Set + (In_Tree.Projects_HT, + A_Project_Name_And_Node.Name, + A_Project_Name_And_Node); end if; Project := A_Project_Name_And_Node.Node; @@ -1933,6 +1952,7 @@ Node => Project, Canonical_Path => Canonical_Path_Name, Extended => Extended, + From_Extended => From_Extended /= None, Proj_Qualifier => Project_Qualifier_Of (Project, In_Tree))); end if; Index: prj-tree.adb =================================================================== --- prj-tree.adb (revision 206804) +++ prj-tree.adb (working copy) @@ -1321,8 +1321,7 @@ begin pragma Assert (Present (Node) - and then - In_Tree.Project_Nodes.Table (Node).Kind = N_Term); + and then In_Tree.Project_Nodes.Table (Node).Kind = N_Term); return In_Tree.Project_Nodes.Table (Node).Field2; end Next_Term; @@ -1332,18 +1331,17 @@ function Next_Variable (Node : Project_Node_Id; - In_Tree : Project_Node_Tree_Ref) - return Project_Node_Id + In_Tree : Project_Node_Tree_Ref) return Project_Node_Id is begin pragma Assert (Present (Node) and then - (In_Tree.Project_Nodes.Table (Node).Kind = - N_Typed_Variable_Declaration + (In_Tree.Project_Nodes.Table (Node).Kind = + N_Typed_Variable_Declaration or else - In_Tree.Project_Nodes.Table (Node).Kind = - N_Variable_Declaration)); + In_Tree.Project_Nodes.Table (Node).Kind = + N_Variable_Declaration)); return In_Tree.Project_Nodes.Table (Node).Field3; end Next_Variable; @@ -2925,6 +2923,7 @@ Canonical_Path => No_Path, Node => Project, Extended => False, + From_Extended => False, Proj_Qualifier => Qualifier)); end if; Index: prj-tree.ads =================================================================== --- prj-tree.ads (revision 206804) +++ prj-tree.ads (working copy) @@ -1476,6 +1476,10 @@ Extended : Boolean; -- True when the project is being extended by another project + From_Extended : Boolean; + -- True when the project is only imported by projects that are + -- extended. + Proj_Qualifier : Project_Qualifier; -- The project qualifier of the project, if any end record; @@ -1486,6 +1490,7 @@ Node => Empty_Node, Canonical_Path => No_Path, Extended => True, + From_Extended => False, Proj_Qualifier => Unspecified); package Projects_Htable is new GNAT.Dynamic_HTables.Simple_HTable