Skip to content

Commit a917894

Browse files
committed
Fix duplicating sources in non-aggregate projects
When extended project has package Naming with a naming exception for a particular unit, extending project does not have project Naming declared and source dirs of both projects have file that corresponds to that naming exception, Source_Files returned both of those files, thus creating a duplicate base name in a non-aggregate project. Ignore files that have Replaced_By set to illiminate duplicates. Change-Id: I92102bc73dea352aad1788fbc19a56d05c8161dd TN: U715-007
1 parent 1e9cb6c commit a917894

File tree

9 files changed

+77
-0
lines changed

9 files changed

+77
-0
lines changed

src/gnatcoll-projects.adb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9901,6 +9901,15 @@ package body GNATCOLL.Projects is
99019901
Source := Element (Source_Iter);
99029902
exit when Source = No_Source;
99039903

9904+
if Source.Replaced_By /= No_Source then
9905+
-- In case of extending project inheriting package Naming of
9906+
-- the extended one and source dirs of both projects containing
9907+
-- same naming exception source, we will get a duplicate base
9908+
-- name outside of aggregate project here which is not allowed.
9909+
-- The replaced source needs to be ignored.
9910+
goto Next_Source;
9911+
end if;
9912+
99049913
-- Get the absolute path name for this source
99059914

99069915
Get_Name_String (Source.Path.Display_Name);
@@ -10009,6 +10018,7 @@ package body GNATCOLL.Projects is
1000910018
end if;
1001010019
end;
1001110020

10021+
<<Next_Source>>
1001210022
Next (Source_Iter);
1001310023
end loop;
1001410024

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
project P extends "q/q.gpr" is
2+
end P;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package Pack is
2+
end Pack;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package Pack2 is
2+
end Pack2;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package Pack is
2+
end Pack;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package Pack2 is
2+
end Pack2;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
project Q is
2+
package Naming is
3+
for Spec ("Pack") use "pack.ads_foo";
4+
end Naming;
5+
end Q;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
with GNATCOLL.Projects; use GNATCOLL.Projects;
2+
with GNATCOLL.Projects.Aux;
3+
with GNATCOLL.VFS; use GNATCOLL.VFS;
4+
with Test_Assert;
5+
6+
with Ada.Containers.Indefinite_Ordered_Sets;
7+
8+
function Test return Integer is
9+
PT : Project_Tree;
10+
Env : Project_Environment_Access;
11+
12+
Files : File_Array_Access;
13+
14+
package Sets is new Ada.Containers.Indefinite_Ordered_Sets (String);
15+
use Sets;
16+
17+
Set : Sets.Set;
18+
begin
19+
Initialize (Env);
20+
PT.Load (GNATCOLL.VFS.Create ("p.gpr"), Env);
21+
22+
Files := PT.Root_Project.Source_Files (Recursive => True);
23+
24+
for F of Files.all loop
25+
if Set.Contains (F.Display_Base_Name) then
26+
Test_Assert.Assert
27+
(False, "duplicating source: " & F.Display_Base_Name);
28+
else
29+
Set.Insert (F.Display_Base_Name);
30+
end if;
31+
end loop;
32+
33+
Unchecked_Free (Files);
34+
35+
Set.Clear;
36+
GNATCOLL.Projects.Aux.Delete_All_Temp_Files (PT.Root_Project);
37+
Unload (PT);
38+
Free (Env);
39+
40+
return Test_Assert.Report;
41+
end Test;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
description: >
2+
Check that when extending project has no package Naming
3+
but extended one does and source dirs of both projects
4+
have the same naming exception source Source_Files returns
5+
only one of those sources and not both.
6+
data:
7+
- "test.adb"
8+
- "p.gpr"
9+
- "pack.ads_foo"
10+
- "pack2.ads"
11+
- "q"

0 commit comments

Comments
 (0)