Strange behavior with library import resolution (with in GPR files)
Nobody has claimed this yet.
- Dominant language
- Ada
- Stars
- 21
- Forks
- 12
- PR merge metrics
- No merged PRs in 30d
Description
I encountered a strange behavior while resolving an issue with a library. I have provided an example program below for reference:
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Environment_Variables;
with Ada.Text_IO;
with Ada.Exceptions;
with GPR2.Project.View;
with GPR2.Project.Tree;
with GPR2.Project.Attribute.Set;
with GPR2.Context;
with GPR2.Message;
with GPR2.Log;
procedure Main is
use Ada;
use GPR2;
use GPR2.Project;
procedure Display (Prj : Project.View.Object);
procedure Display (Att : Project.Attribute.Object);
-------------
-- Display --
-------------
procedure Display (Att : Project.Attribute.Object) is
begin
Text_IO.Put (" " & String (Image (Att.Name.Id.Attr)));
if Att.Has_Index then
Text_IO.Put (" (" & Att.Index.Value & ")");
end if;
Text_IO.Put (" -> ");
for V of Att.Values loop
Text_IO.Put (V.Text & " ");
end loop;
Text_IO.New_Line;
end Display;
procedure Display (Prj : Project.View.Object) is
use GPR2.Project.Attribute.Set;
Is_First : Boolean := True;
begin
if Prj.Has_Imports then
for W of Prj.Imports loop
Ada.Text_IO.Put_Line (String (W.Path_Name.Name));
end loop;
end if;
Text_IO.Put_Line (Prj.Kind'Img);
end Display;
Prj : Project.Tree.Object;
Ctx : Context.Object;
procedure Print_Messages is
begin
if Prj.Has_Messages then
for C in Prj.Log_Messages.Iterate (False, True, True, True, True) loop
Ada.Text_IO.Put_Line (GPR2.Log.Element (C).Format);
end loop;
end if;
end Print_Messages;
begin
-- Check if an argument is provided
if Argument_Count = 0 then
-- No argument provided
Ada.Text_IO.Put_Line ("You need to specify the GPR file to process!");
return;
end if;
Text_IO.Put_Line (Ada.Environment_Variables.Value ("GPR_PROJECT_PATH"));
declare
Arg : Filename_Type := Filename_Type (Argument (1));
begin
Project.Tree.Load
(Self => Prj, Filename => Create (Arg), Context => Ctx);
end;
Display (Prj.Root_Project);
exception
when Ex : others =>
Text_IO.Put_Line (Ada.Exceptions.Exception_Message (Ex));
Print_Messages;
raise;
end Main;
The program produces a gpr2withlist bin file. To reproduce the issue, follow the steps below:
- Run the command
alr get -b lace_openglto obtain the Lace_OpenGL project and build it using Alire. - Navigate to the
lace_opengl_0.1.0_672a6415/librarydirectory. - Execute the command
gpr2withlist opengl.gpr.
The following error occurs:
/tmp/lace_opengl_0.1.0_672a6415/library/opengl.gpr: fatal error, cannot load the project tree
gl.gpr:2:06: error: imported project file "lace_shared.gpr" not found
raised GPR2.PROJECT_ERROR : /tmp/lace_opengl_0.1.0_672a6415/library/opengl.gpr: fatal error, cannot load the project tree
[/workspaces/bench-source/gpr_to_source_dirs/bin/gpr_with_extract]
0x564f753a0304 gpr2__project__tree__load__2 at ???
0x564f753a06d8 gpr2__project__tree__load at ???
0x564f7507552c Main at gpr_with_extract.adb:109
0x564f75078fd3 Main at b__gpr_with_extract.adb:2384
[/lib/x86_64-linux-gnu/libc.so.6]
0x7f3870df0188
0x7f3870df0243
[/workspaces/bench-source/gpr_to_source_dirs/bin/gpr_with_extract]
0x564f750746af _start at ???
0xfffffffffffffffe
As you can see, the error states that the imported project file "lace_shared.gpr" is not found, which is an "expected" behavior, since none of the project and these dependencies are in resolution path (e.g. GPR_PROJECT_PATH).
However, when I perform the following steps, the error changes:
- Navigate to the
/tmp/lace_opengl_0.1.0_672a6415directory. - Run the command
eval `alr printenv`to retrieve the source environment from Alire. - Navigate to the sub-directory
library - Execute the command
gpr2withlist opengl.gpr.
The new error is as follows:
/tmp/lace_opengl_0.1.0_672a6415/alire/cache/dependencies/lace_collada_0.1.0_99d5bbb7/library:/tmp/lace_opengl_0.1.0_672a6415/alire/cache/dependencies/lace_math_0.1.0_3ab67197/library:/tmp/lace_opengl_0.1.0_672a6415/alire/cache/dependencies/lace_shared_0.1.0_bc8f1534:/tmp/lace_opengl_0.1.0_672a6415/alire/cache/dependencies/lace_xml_0.1.0_b6aa904a/library:/tmp/lace_opengl_0.1.0_672a6415/library:.:/tmp/Comps:/tmp/Asiscomps:
/tmp/lace_opengl_0.1.0_672a6415/library/opengl.gpr semantic error
opengl_core.gpr:34:20: error: undefined project "Lace_shared"
raised GPR2.PROJECT_ERROR : /tmp/lace_opengl_0.1
.0_672a6415/library/opengl.gpr semantic error
[/workspaces/bench-source/gpr_to_source_dirs/bin/gpr_with_extract]
0x55ce0f42bec8 gpr2__project__tree__set_context__2 at ???
0x55ce0f42c497 gpr2__project__tree__set_context at ???
0x55ce0f42e407 gpr2__project__tree__load__2 at ???
0x55ce0f42f6d8 gpr2__project__tree__load at ???
0x55ce0f10452c Main at gpr_with_extract.adb:109
0x55ce0f107fd3 Main at b__gpr_with_extract.adb:2384
[/lib/x86_64-linux-gnu/libc.so.6]
0x7f8c78d91188
0x7f8c78d91243
[/workspaces/bench-source/gpr_to_source_dirs/bin/gpr_with_extract]
0x55ce0f1036af _start at ???
0xfffffffffffffffe
Now, the error message states that the project "Lace_shared" is undefined, even though lace_shared.gpr can be resolved.
To work around this issue, it is necessary to edit all .gpr files and move the abstract project to the first imported project.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Project.Tree.Load entry point shown in the example and reproduce the behavior using gpr2withlist on opengl.gpr, both without and after eval alr printenv. Compare resolution of lace_shared.gpr with the later undefined project "Lace_shared" error; done means imported abstract projects resolve consistently without requiring edits to every .gpr file.
Written by the indexing model from the issue text.
Assessment
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100