Skip to content

Commit

Permalink
Merge branch 'mr/pmderodat/gpr2-separates' into 'master'
Browse files Browse the repository at this point in the history
Libadalang.Project_Provider: add a trace for unit resolution

See merge request eng/libadalang/libadalang!1683
  • Loading branch information
pmderodat committed Jul 11, 2024
2 parents f9dc445 + 2d3973b commit 17d3eb2
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 22 deletions.
44 changes: 36 additions & 8 deletions extensions/src/libadalang-project_provider.adb
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ package body Libadalang.Project_Provider is
and then Unit_Files.Reference (Prj_Pos).Element.all
/= Part.Unit_Files.Reference (Part_Pos).Element.all
then
if Trace.Is_Active then
Trace.Trace
if Partition_Trace.Is_Active then
Partition_Trace.Trace
("Found conflicting source files for unit "
& To_String (Unit_Name) & " in " & Name (Project)
& " and " & Part_Image (Part));
Expand Down Expand Up @@ -390,7 +390,8 @@ package body Libadalang.Project_Provider is
is
Partition : Aggregate_Part_Vectors.Vector;
begin
Trace.Increase_Indent ("Trying to partition " & Name (Root (Tree)));
Partition_Trace.Increase_Indent
("Trying to partition " & Name (Root (Tree)));

if Is_Aggregate_Project (Root (Tree)) then

Expand Down Expand Up @@ -488,22 +489,23 @@ package body Libadalang.Project_Provider is
end;
end if;

Trace.Decrease_Indent;
Partition_Trace.Decrease_Indent;

-- For debuggability, log how the Tree was partitioned

if Trace.Is_Active then
Trace.Increase_Indent ("Input project partitioned into:");
if Partition_Trace.Is_Active then
Partition_Trace.Increase_Indent ("Input project partitioned into:");
for Cur in Partition.Iterate loop
declare
N : constant Positive :=
Aggregate_Part_Vectors.To_Index (Cur);
Part : Aggregate_Part renames Partition.Element (N).all;
begin
Trace.Trace ("Part" & N'Image & ": " & Part_Image (Part));
Partition_Trace.Trace
("Part" & N'Image & ": " & Part_Image (Part));
end;
end loop;
Trace.Decrease_Indent;
Partition_Trace.Decrease_Indent;
end if;

-- For GPR2, make sure that all projects are namespace roots
Expand Down Expand Up @@ -693,6 +695,27 @@ package body Libadalang.Project_Provider is
Filename : in out US.Unbounded_String;
PLE_Root_Index : in out Natural)
is
function Request_Image return String
is (Kind'Image & " of unit " & Image (Name, With_Quotes => True));

procedure Trace_Found;
-- Assuming that we found the requested unit, log information about it
-- to the project provider trace.

-----------------
-- Trace_Found --
-----------------

procedure Trace_Found is
begin
if Resolution_Trace.Is_Active then
Resolution_Trace.Trace
(Request_Image & " is located in "
& US.To_String (Filename)
& " at" & PLE_Root_Index'Image);
end if;
end Trace_Found;

Str_Name : constant String :=
Libadalang.Unit_Files.Unit_String_Name (Name);
begin
Expand Down Expand Up @@ -732,6 +755,7 @@ package body Libadalang.Project_Provider is
if Fullname'Length /= 0 then
GNAT.Task_Lock.Unlock;
Filename := US.To_Unbounded_String (Fullname);
Trace_Found;
return;
end if;
end;
Expand Down Expand Up @@ -770,6 +794,7 @@ package body Libadalang.Project_Provider is
US.To_Unbounded_String (String (Unit.Source.Value));
PLE_Root_Index :=
(if Unit.Index = 0 then 1 else Positive (Unit.Index));
Trace_Found;
return;
end if;
end;
Expand All @@ -779,6 +804,9 @@ package body Libadalang.Project_Provider is
-- If we reach this point, we have not found a unit handled by this
-- provider that matches the requested name/kind.

if Resolution_Trace.Is_Active then
Resolution_Trace.Trace ("No unit found for " & Request_Image);
end if;
Filename := US.Null_Unbounded_String;
PLE_Root_Index := 1;
end Get_Unit_Location;
Expand Down
11 changes: 9 additions & 2 deletions extensions/src/libadalang-project_provider.ads
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ package Libadalang.Project_Provider is
package LAL renames Libadalang.Analysis;
package Prj renames GNATCOLL.Projects;

Trace : constant GNATCOLL.Traces.Trace_Handle := GNATCOLL.Traces.Create
("LIBADALANG.PROJECT_PROVIDER", GNATCOLL.Traces.From_Config);
Trace : constant GNATCOLL.Traces.Trace_Handle :=
GNATCOLL.Traces.Create
("LIBADALANG.PROJECT_PROVIDER", GNATCOLL.Traces.From_Config);
Partition_Trace : constant GNATCOLL.Traces.Trace_Handle :=
GNATCOLL.Traces.Create
("LIBADALANG.PROJECT_PROVIDER.PARTITION", GNATCOLL.Traces.From_Config);
Resolution_Trace : constant GNATCOLL.Traces.Trace_Handle :=
GNATCOLL.Traces.Create
("LIBADALANG.PROJECT_PROVIDER.RESOLUTION", GNATCOLL.Traces.From_Config);

Unsupported_View_Error : exception;
-- See the ``Create_Project_Unit_Provider`` functions below
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ procedure Main is
PAPs : GPR2_Provider_And_Projects_Array_Access;

begin
GNATCOLL.Traces.Parse_Config ("LIBADALANG.PROJECT_PROVIDER=yes");
GNATCOLL.Traces.Parse_Config ("LIBADALANG.PROJECT_PROVIDER.PARTITION=yes");
Put_Line ("Loading the project:");
Options.Add_Switch (GPR2.Options.P, "ap1.gpr");
if not Tree.Load (Options, With_Runtime => True)
Expand Down
10 changes: 5 additions & 5 deletions testsuite/tests/ada_api/gpr2_project_partition/basic/test.out
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Loading the project:
[LIBADALANG.PROJECT_PROVIDER] Trying to partition AP1
[LIBADALANG.PROJECT_PROVIDER] Found conflicting source files for unit P1 in P3 and <P1, P2>
[LIBADALANG.PROJECT_PROVIDER] Input project partitioned into:
[LIBADALANG.PROJECT_PROVIDER] Part 1: <P1, P2>
[LIBADALANG.PROJECT_PROVIDER] Part 2: <P3>
[LIBADALANG.PROJECT_PROVIDER.PARTITION] Trying to partition AP1
[LIBADALANG.PROJECT_PROVIDER.PARTITION] Found conflicting source files for unit P1 in P3 and <P1, P2>
[LIBADALANG.PROJECT_PROVIDER.PARTITION] Input project partitioned into:
[LIBADALANG.PROJECT_PROVIDER.PARTITION] Part 1: <P1, P2>
[LIBADALANG.PROJECT_PROVIDER.PARTITION] Part 2: <P3>
* P1 P2
* P3

Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/ada_api/project_partition/basic/main.adb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ procedure Main is
PAPs : Provider_And_Projects_Array_Access;

begin
GNATCOLL.Traces.Parse_Config ("LIBADALANG.PROJECT_PROVIDER=yes");
GNATCOLL.Traces.Parse_Config ("LIBADALANG.PROJECT_PROVIDER.PARTITION=yes");
Put_Line ("Loading the project:");
Initialize (Env);
Load (Tree.all, Create (+"ap1.gpr"), Env);
Expand Down
10 changes: 5 additions & 5 deletions testsuite/tests/ada_api/project_partition/basic/test.out
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Loading the project:
[LIBADALANG.PROJECT_PROVIDER] Trying to partition AP1
[LIBADALANG.PROJECT_PROVIDER] Found conflicting source files for unit p1 in P3 and <P1, P2>
[LIBADALANG.PROJECT_PROVIDER] Input project partitioned into:
[LIBADALANG.PROJECT_PROVIDER] Part 1: <P1, P2>
[LIBADALANG.PROJECT_PROVIDER] Part 2: <P3>
[LIBADALANG.PROJECT_PROVIDER.PARTITION] Trying to partition AP1
[LIBADALANG.PROJECT_PROVIDER.PARTITION] Found conflicting source files for unit p1 in P3 and <P1, P2>
[LIBADALANG.PROJECT_PROVIDER.PARTITION] Input project partitioned into:
[LIBADALANG.PROJECT_PROVIDER.PARTITION] Part 1: <P1, P2>
[LIBADALANG.PROJECT_PROVIDER.PARTITION] Part 2: <P3>
* P1 P2
* P3

Expand Down

0 comments on commit 17d3eb2

Please sign in to comment.