@@ -12,20 +12,15 @@ with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
12
12
with Ada.Text_IO ; use Ada.Text_IO;
13
13
14
14
with GNAT.Directory_Operations ; use GNAT.Directory_Operations;
15
- with GNAT.Expect ; use GNAT.Expect;
16
15
with GNAT.OS_Lib ; use GNAT.OS_Lib;
17
- with GNAT.String_Split ; use GNAT.String_Split;
18
16
with GNAT.Table ;
19
17
with GNAT.Task_Lock ;
20
18
21
- with Gnatcheck.Compiler ; use Gnatcheck.Compiler;
22
19
with Gnatcheck.Diagnoses ; use Gnatcheck.Diagnoses;
23
20
with Gnatcheck.Ids ; use Gnatcheck.Ids;
24
21
with Gnatcheck.Output ; use Gnatcheck.Output;
25
22
with Gnatcheck.String_Utilities ; use Gnatcheck.String_Utilities;
26
23
27
- with GNATCOLL.VFS ; use GNATCOLL.VFS;
28
-
29
24
with GPR2.Build.Source ;
30
25
with GPR2.Path_Name ;
31
26
with GPR2.Project.Tree ;
@@ -34,7 +29,6 @@ with GPR2.Project.View;
34
29
with Langkit_Support.Generic_API.Introspection ;
35
30
36
31
with Libadalang.Analysis ; use Libadalang.Analysis;
37
- with Libadalang.Auto_Provider ; use Libadalang.Auto_Provider;
38
32
with Libadalang.Project_Provider ; use Libadalang.Project_Provider;
39
33
with Libadalang.Iterators ;
40
34
with Libadalang.Generic_API ; use Libadalang.Generic_API;
@@ -234,6 +228,9 @@ package body Gnatcheck.Source_Table is
234
228
Duplication_Report : Boolean := True;
235
229
Status : SF_Status := Waiting)
236
230
is
231
+ use GPR2;
232
+ use GPR2.Project.Tree;
233
+
237
234
Old_SF : SF_Id;
238
235
New_SF : SF_Id;
239
236
@@ -242,63 +239,53 @@ package body Gnatcheck.Source_Table is
242
239
First_Idx : Natural;
243
240
Last_Idx : Natural;
244
241
245
- use GPR2;
246
- use GPR2.Project.Tree;
242
+ Root : constant GPR2.Project.View.Object :=
243
+ Arg_Project.Tree.Namespace_Root_Projects.First_Element;
244
+ Res : constant GPR2.Build.Source.Object :=
245
+ Root.View_Db.Visible_Source
246
+ (GPR2.Path_Name.Simple_Name (Filename_Type (Fname)));
247
247
begin
248
248
Free (Full_Source_Name_String);
249
249
Free (Short_Source_Name_String);
250
250
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" );
251
+ if not Res.Is_Defined then
252
+ if Is_Regular_File (Fname) then
253
+ Warning (Fname & " is not in the analysed project closure (" &
254
+ String (Arg_Project.Tree.Root_Project.Name) & " )" );
255
+ else
256
+ Warning (Fname & " not found" );
257
+ end if ;
270
258
Missing_File_Detected := True;
271
259
return ;
272
260
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);
261
+ Short_Source_Name_String :=
262
+ new String'(Res.Path_Name.String_Value);
280
263
end if ;
281
264
265
+ Full_Source_Name_String := new String'
266
+ (Normalize_Pathname
267
+ (Short_Source_Name_String.all ,
268
+ Resolve_Links => False,
269
+ Case_Sensitive => True));
270
+ Free (Short_Source_Name_String);
271
+
282
272
Short_Source_Name_String := new String'(Base_Name (Fname));
283
273
Hash_Index := Hash (To_Lower (Short_Source_Name_String.all ));
284
274
285
275
-- Check if we already have a file with the same short name:
286
-
287
276
if Present (Hash_Table (Hash_Index)) then
288
277
Old_SF := File_Find (Full_Source_Name_String.all );
289
278
279
+ -- Check if we already stored exactly the same file.
290
280
if Present (Old_SF) then
291
- -- This means that we have already stored exactly the same file.
292
-
293
281
if Duplication_Report then
294
282
Error (Short_Source_Name_String.all & " duplicated" );
295
283
end if ;
296
-
297
284
return ;
298
285
286
+ -- Else, look for files with the same name but with a difference path
299
287
else
300
288
Old_SF := Same_Name_File_Find (Full_Source_Name_String.all );
301
-
302
289
if Present (Old_SF) then
303
290
Error (" more than one version of "
304
291
& Short_Source_Name_String.all & " processed" );
@@ -307,7 +294,6 @@ package body Gnatcheck.Source_Table is
307
294
end if ;
308
295
309
296
-- If we are here, we have to store the file in the table
310
-
311
297
Source_File_Table.Append (New_SF_Record);
312
298
Last_Arg_Source := Source_File_Table.Last;
313
299
New_SF := Last_Arg_Source;
@@ -1408,134 +1394,11 @@ package body Gnatcheck.Source_Table is
1408
1394
Partition : GPR2_Provider_And_Projects_Array_Access;
1409
1395
1410
1396
function Create_Context return Checker_App.Lkql_Context is
1411
- Ctx : Checker_App.Lkql_Context;
1412
- Files : File_Array_Access;
1413
- Last : Natural := 0 ;
1414
-
1415
- procedure Add_Runtime_Files ;
1416
- -- Add to Files all the GNAT native runtime files, if found
1417
-
1418
- -- ---------------------
1419
- -- Add_Runtime_Files --
1420
- -- ---------------------
1421
-
1422
- procedure Add_Runtime_Files is
1423
- Gnatls : String_Access := Locate_Exec_On_Path (Gnatls_Exec);
1424
- Verbose : aliased String := " -v" ;
1425
- Status : aliased Integer;
1426
-
1427
- begin
1428
- if Gnatls = null then
1429
- return ;
1430
- end if ;
1431
-
1432
- -- Spawn gnatls -v
1433
-
1434
- declare
1435
- use Ada.Directories;
1436
-
1437
- Output : constant String :=
1438
- Get_Command_Output (Gnatls.all ,
1439
- [Verbose'Unchecked_Access],
1440
- " " , Status'Unchecked_Access, True);
1441
- Lines : String_List_Access;
1442
- Ada_Include_Path : String_Access;
1443
- Found : Boolean := False;
1444
-
1445
- procedure Add_File (Dir : Directory_Entry_Type);
1446
- -- Add the given directory entry Dir to Files
1447
-
1448
- -- ------------
1449
- -- Add_File --
1450
- -- ------------
1451
-
1452
- procedure Add_File (Dir : Directory_Entry_Type) is
1453
- begin
1454
- Last := @ + 1 ;
1455
- Files (Last) := Create (+Full_Name (Dir));
1456
- end Add_File ;
1457
-
1458
- begin
1459
- if Status /= 0 then
1460
- Free (Gnatls);
1461
- return ;
1462
- end if ;
1463
-
1464
- -- and look for the line containing "adainclude"
1465
-
1466
- for Line of Create (Output, [ASCII.LF, ASCII.CR], Multiple)
1467
- loop
1468
- Found := Has_Suffix (Line, " adainclude" );
1469
-
1470
- if Found then
1471
- Ada_Include_Path :=
1472
- new String'(Remove_Spaces (Line));
1473
- exit ;
1474
- end if ;
1475
- end loop ;
1476
-
1477
- Free (Lines);
1478
-
1479
- if not Found then
1480
- Free (Gnatls);
1481
- return ;
1482
- end if ;
1483
-
1484
- -- We then list all the *.ads files.
1485
- -- We only need to process spec files, runtime body files are not
1486
- -- needed to analyze user code and will slow down the startup
1487
- -- phase.
1488
-
1489
- Search (Ada_Include_Path.all , " *.ads" ,
1490
- Process => Add_File'Access );
1491
- Free (Ada_Include_Path);
1492
- Free (Gnatls);
1493
- end ;
1494
- end Add_Runtime_Files ;
1495
-
1496
1397
Charset : constant String := To_String (Arg.Charset.Get);
1497
-
1398
+ Ctx : Checker_App.Lkql_Context;
1498
1399
begin
1499
- -- If no project specified, create an auto provider with all the source
1500
- -- files listed in the command line, stored in Temporary_File_Storage,
1501
- -- as well as all runtime files, these are needed for proper name
1502
- -- resolution.
1503
-
1504
- if not Gnatcheck_Prj.Is_Specified then
1505
- declare
1506
- procedure Add_File (File_Name : String);
1507
- -- Add File_Name to Files
1508
-
1509
- -- ------------
1510
- -- Add_File --
1511
- -- ------------
1512
-
1513
- procedure Add_File (File_Name : String) is
1514
- begin
1515
- Last := @ + 1 ;
1516
- Files (Last) := Create (+File_Name);
1517
- end Add_File ;
1518
-
1519
- begin
1520
- Files := new File_Array
1521
- (1 .. Natural (Length (Temporary_File_Storage)) + 4096 );
1522
- -- Enough to hold all files on the command line and all runtime
1523
- -- files.
1524
-
1525
- Temp_Storage_Iterate (Add_File'Access );
1526
- Add_Runtime_Files;
1527
- Ctx.Analysis_Ctx := Create_Context
1528
- (Charset => Charset,
1529
- Unit_Provider => Create_Auto_Provider_Reference
1530
- (Files (1 .. Last), Charset),
1531
- Event_Handler => EHR_Object);
1532
- Unchecked_Free (Files);
1533
- end ;
1534
-
1535
- -- Otherwise use a project unit provider
1536
-
1537
- elsif Gnatcheck_Prj.Tree.Is_Defined and then not In_Aggregate_Project
1538
- then
1400
+ -- Use a project unit provider, even with the implicit project
1401
+ if not In_Aggregate_Project then
1539
1402
if Partition = null then
1540
1403
Partition :=
1541
1404
Create_Project_Unit_Providers (Gnatcheck_Prj.Tree);
0 commit comments