Skip to content

Commit 2df1c75

Browse files
committed
Enhance the "source not found" message
Add a case when a source is a regular file but not in the current project closure.
1 parent 0f2e4f9 commit 2df1c75

File tree

4 files changed

+55
-34
lines changed

4 files changed

+55
-34
lines changed

lkql_checker/src/gnatcheck-source_table.adb

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ package body Gnatcheck.Source_Table is
234234
Duplication_Report : Boolean := True;
235235
Status : SF_Status := Waiting)
236236
is
237+
use GPR2;
238+
use GPR2.Project.Tree;
239+
237240
Old_SF : SF_Id;
238241
New_SF : SF_Id;
239242

@@ -242,63 +245,53 @@ package body Gnatcheck.Source_Table is
242245
First_Idx : Natural;
243246
Last_Idx : Natural;
244247

245-
use GPR2;
246-
use GPR2.Project.Tree;
248+
Root : constant GPR2.Project.View.Object :=
249+
Arg_Project.Tree.Namespace_Root_Projects.First_Element;
250+
Res : constant GPR2.Build.Source.Object :=
251+
Root.View_Db.Visible_Source
252+
(GPR2.Path_Name.Simple_Name (Filename_Type (Fname)));
247253
begin
248254
Free (Full_Source_Name_String);
249255
Free (Short_Source_Name_String);
250256

251-
if Arg_Project.Tree.Is_Defined then
252-
declare
253-
Root : constant GPR2.Project.View.Object :=
254-
Arg_Project.Tree.Namespace_Root_Projects.First_Element;
255-
Res : constant GPR2.Build.Source.Object :=
256-
Root.View_Db.Visible_Source
257-
(GPR2.Path_Name.Simple_Name (Filename_Type (Fname)));
258-
begin
259-
if not Res.Is_Defined then
260-
Free (Short_Source_Name_String);
261-
else
262-
Short_Source_Name_String :=
263-
new String'(Res.Path_Name.String_Value);
264-
end if;
265-
end;
266-
end if;
267-
268-
if Short_Source_Name_String = null then
269-
Warning (Fname & " not found");
257+
if not Res.Is_Defined then
258+
if Is_Regular_File (Fname) then
259+
Warning (Fname & " is not in the analysed project closure (" &
260+
String (Arg_Project.Tree.Root_Project.Name) & ")");
261+
else
262+
Warning (Fname & " not found");
263+
end if;
270264
Missing_File_Detected := True;
271265
return;
272266
else
273-
Full_Source_Name_String := new String'
274-
(Normalize_Pathname
275-
(Short_Source_Name_String.all,
276-
Resolve_Links => False,
277-
Case_Sensitive => True));
278-
279-
Free (Short_Source_Name_String);
267+
Short_Source_Name_String :=
268+
new String'(Res.Path_Name.String_Value);
280269
end if;
281270

271+
Full_Source_Name_String := new String'
272+
(Normalize_Pathname
273+
(Short_Source_Name_String.all,
274+
Resolve_Links => False,
275+
Case_Sensitive => True));
276+
Free (Short_Source_Name_String);
277+
282278
Short_Source_Name_String := new String'(Base_Name (Fname));
283279
Hash_Index := Hash (To_Lower (Short_Source_Name_String.all));
284280

285281
-- Check if we already have a file with the same short name:
286-
287282
if Present (Hash_Table (Hash_Index)) then
288283
Old_SF := File_Find (Full_Source_Name_String.all);
289284

285+
-- Check if we already stored exactly the same file.
290286
if Present (Old_SF) then
291-
-- This means that we have already stored exactly the same file.
292-
293287
if Duplication_Report then
294288
Error (Short_Source_Name_String.all & " duplicated");
295289
end if;
296-
297290
return;
298291

292+
-- Else, look for files with the same name but with a difference path
299293
else
300294
Old_SF := Same_Name_File_Find (Full_Source_Name_String.all);
301-
302295
if Present (Old_SF) then
303296
Error ("more than one version of "
304297
& Short_Source_Name_String.all & " processed");
@@ -307,7 +300,6 @@ package body Gnatcheck.Source_Table is
307300
end if;
308301

309302
-- If we are here, we have to store the file in the table
310-
311303
Source_File_Table.Append (New_SF_Record);
312304
Last_Arg_Source := Source_File_Table.Last;
313305
New_SF := Last_Arg_Source;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
procedure Proc2 is
2+
begin
3+
null;
4+
end Proc2;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
With a non-existing source file
2+
===============================
3+
4+
gnatcheck: not_a_file.adb not found
5+
gnatcheck: No existing file to process
6+
>>>program returned status code 3
7+
8+
With a file not in the project closure
9+
======================================
10+
11+
gnatcheck: src/proc2.adb is not in the analysed project closure (Default)
12+
gnatcheck: No existing file to process
13+
>>>program returned status code 3
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
driver: gnatcheck
2+
description: Test the behavior when providing a invalid source
3+
format: brief
4+
rules:
5+
- +RGoto_Statements
6+
tests:
7+
- label: With a non-existing source file
8+
input_sources:
9+
- not_a_file.adb
10+
- label: With a file not in the project closure
11+
input_sources:
12+
- src/proc2.adb

0 commit comments

Comments
 (0)