Skip to content

Commit 204da50

Browse files
committed
GNATCOLL.Projects: fix Library_Files for C/C++ headers
Never consider header files as being the "main source" for a LI file. These are always produced from ".c"/".cpp" files (i.e. bodies). TN: V816-018 Change-Id: Iefa81413c8e53002b9c67bd65bc5e44e04c8235c
1 parent c4d84d7 commit 204da50

File tree

7 files changed

+43
-1
lines changed

7 files changed

+43
-1
lines changed

src/gnatcoll-projects.adb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ package body GNATCOLL.Projects is
11701170
-- same basename as Key, even if we skip the header files.
11711171

11721172
if Extended_P = SFD.Project
1173-
and then +SFD.File.File_Extension not in ".h" | ".hpp"
1173+
and then Kind_To_Part (SFD.Source) = Unit_Body
11741174
then
11751175
Local_Obj_Map.Include (Key, SFD);
11761176

testsuite/tests/projects/library_files_c++/bar.hh

Whitespace-only changes.

testsuite/tests/projects/library_files_c++/foo.cpp

Whitespace-only changes.

testsuite/tests/projects/library_files_c++/foo.hh

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
project P is
2+
for Languages use ("C++");
3+
end P;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
with GNATCOLL.Projects; use GNATCOLL.Projects;
2+
with GNATCOLL.VFS; use GNATCOLL.VFS;
3+
4+
with Test_Assert;
5+
6+
function Test return Integer is
7+
Env : Project_Environment_Access;
8+
Tree : Project_Tree;
9+
LIL : Library_Info_List;
10+
LI : Library_Info;
11+
begin
12+
Initialize (Env);
13+
Tree.Load (Env => Env, Root_Project_Path => Create (+"p.gpr"));
14+
15+
Tree.Root_Project.Library_Files (List => LIL, ALI_Ext => "^.*\.gli$");
16+
Test_Assert.Assert
17+
(Integer (LIL.Length), 1, "unexpected number of library files");
18+
19+
LI := LIL.First_Element;
20+
Test_Assert.Assert
21+
(+LI.Library_File.Base_Name,
22+
"foo.cpp.gli",
23+
"unexpected LI file name");
24+
Test_Assert.Assert
25+
(+LI.Source.File.Base_Name,
26+
"foo.cpp",
27+
"unexpected source file associated to foo.cpp.gli");
28+
29+
LIL.Clear;
30+
Tree.Unload;
31+
Free (Env);
32+
return Test_Assert.Report;
33+
end Test;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
description:
2+
Library_File used to assume C/C++ bodies had ".c"/".cc" suffixes (it's
3+
wrong for C++ by default, and both can be configured anyway), and used to
4+
assume that C++ headers had ".hpp" suffixes (likewise, and it's ".hh" by
5+
default).
6+
data: ["p.gpr", "foo.cpp", "foo.cpp.gli", "foo.hh", "bar.hh", "bar.hh.gli"]

0 commit comments

Comments
 (0)