Skip to content

Commit 3ba0f76

Browse files
committed
Merge branch 'topic/source_fetch_cleanup' into 'master'
Enhance the GNATcheck performance when running without a project file Closes #312 See merge request eng/libadalang/langkit-query-language!276
2 parents 6b9d840 + 91f856f commit 3ba0f76

File tree

7 files changed

+62
-186
lines changed

7 files changed

+62
-186
lines changed

lkql_checker/src/gnatcheck-compiler.adb

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,22 +1519,6 @@ package body Gnatcheck.Compiler is
15191519
end if;
15201520
end GPRbuild_Exec;
15211521

1522-
----------------
1523-
-- Gnatls_Exec --
1524-
----------------
1525-
1526-
function Gnatls_Exec return String is
1527-
use Ada.Strings.Unbounded;
1528-
begin
1529-
if Has_Access_To_Codepeer then
1530-
return "codepeer-gnatls";
1531-
elsif To_String (Target) /= "" then
1532-
return To_String (Target) & "-gnatls";
1533-
else
1534-
return "gnatls";
1535-
end if;
1536-
end Gnatls_Exec;
1537-
15381522
-------------------------
15391523
-- Set_Compiler_Checks --
15401524
-------------------------

lkql_checker/src/gnatcheck-compiler.ads

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ package Gnatcheck.Compiler is
2626
function GPRbuild_Exec return String;
2727
-- Return the executable name to use in order to spawn a GPRBuild process
2828

29-
function Gnatls_Exec return String;
30-
-- Return the executable name to use in order to spawn a GNATLS process
31-
3229
--------------------------------------------------------
3330
-- Using in GNATCHECK checks performed by the compiler --
3431
--------------------------------------------------------

lkql_checker/src/gnatcheck-source_table.adb

Lines changed: 29 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,15 @@ with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
1212
with Ada.Text_IO; use Ada.Text_IO;
1313

1414
with GNAT.Directory_Operations; use GNAT.Directory_Operations;
15-
with GNAT.Expect; use GNAT.Expect;
1615
with GNAT.OS_Lib; use GNAT.OS_Lib;
17-
with GNAT.String_Split; use GNAT.String_Split;
1816
with GNAT.Table;
1917
with GNAT.Task_Lock;
2018

21-
with Gnatcheck.Compiler; use Gnatcheck.Compiler;
2219
with Gnatcheck.Diagnoses; use Gnatcheck.Diagnoses;
2320
with Gnatcheck.Ids; use Gnatcheck.Ids;
2421
with Gnatcheck.Output; use Gnatcheck.Output;
2522
with Gnatcheck.String_Utilities; use Gnatcheck.String_Utilities;
2623

27-
with GNATCOLL.VFS; use GNATCOLL.VFS;
28-
2924
with GPR2.Build.Source;
3025
with GPR2.Path_Name;
3126
with GPR2.Project.Tree;
@@ -34,7 +29,6 @@ with GPR2.Project.View;
3429
with Langkit_Support.Generic_API.Introspection;
3530

3631
with Libadalang.Analysis; use Libadalang.Analysis;
37-
with Libadalang.Auto_Provider; use Libadalang.Auto_Provider;
3832
with Libadalang.Project_Provider; use Libadalang.Project_Provider;
3933
with Libadalang.Iterators;
4034
with Libadalang.Generic_API; use Libadalang.Generic_API;
@@ -234,6 +228,9 @@ package body Gnatcheck.Source_Table is
234228
Duplication_Report : Boolean := True;
235229
Status : SF_Status := Waiting)
236230
is
231+
use GPR2;
232+
use GPR2.Project.Tree;
233+
237234
Old_SF : SF_Id;
238235
New_SF : SF_Id;
239236

@@ -242,63 +239,53 @@ package body Gnatcheck.Source_Table is
242239
First_Idx : Natural;
243240
Last_Idx : Natural;
244241

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)));
247247
begin
248248
Free (Full_Source_Name_String);
249249
Free (Short_Source_Name_String);
250250

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;
270258
Missing_File_Detected := True;
271259
return;
272260
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);
280263
end if;
281264

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+
282272
Short_Source_Name_String := new String'(Base_Name (Fname));
283273
Hash_Index := Hash (To_Lower (Short_Source_Name_String.all));
284274

285275
-- Check if we already have a file with the same short name:
286-
287276
if Present (Hash_Table (Hash_Index)) then
288277
Old_SF := File_Find (Full_Source_Name_String.all);
289278

279+
-- Check if we already stored exactly the same file.
290280
if Present (Old_SF) then
291-
-- This means that we have already stored exactly the same file.
292-
293281
if Duplication_Report then
294282
Error (Short_Source_Name_String.all & " duplicated");
295283
end if;
296-
297284
return;
298285

286+
-- Else, look for files with the same name but with a difference path
299287
else
300288
Old_SF := Same_Name_File_Find (Full_Source_Name_String.all);
301-
302289
if Present (Old_SF) then
303290
Error ("more than one version of "
304291
& Short_Source_Name_String.all & " processed");
@@ -307,7 +294,6 @@ package body Gnatcheck.Source_Table is
307294
end if;
308295

309296
-- If we are here, we have to store the file in the table
310-
311297
Source_File_Table.Append (New_SF_Record);
312298
Last_Arg_Source := Source_File_Table.Last;
313299
New_SF := Last_Arg_Source;
@@ -1408,134 +1394,11 @@ package body Gnatcheck.Source_Table is
14081394
Partition : GPR2_Provider_And_Projects_Array_Access;
14091395

14101396
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-
14961397
Charset : constant String := To_String (Arg.Charset.Get);
1497-
1398+
Ctx : Checker_App.Lkql_Context;
14981399
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
15391402
if Partition = null then
15401403
Partition :=
15411404
Create_Project_Unit_Providers (Gnatcheck_Prj.Tree);

lkql_jit/language/src/main/java/com/adacore/lkql_jit/utils/source_location/SourceSectionWrapper.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ public String[] getLines() {
6464

6565
@Override
6666
public String fileName() {
67-
return Paths.get(sourceSection.getSource().getPath()).getFileName().toString();
67+
if (sourceSection.getSource().getPath() != null) {
68+
return Paths.get(sourceSection.getSource().getPath()).getFileName().toString();
69+
}
70+
return sourceSection.getSource().getName();
6871
}
6972

7073
@Override
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)