Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange behavior with library import resolution (with in GPR files) #8

Open
Heziode opened this issue Jun 23, 2023 · 0 comments
Open

Comments

@Heziode
Copy link

Heziode commented Jun 23, 2023

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:

  1. Run the command alr get -b lace_opengl to obtain the Lace_OpenGL project and build it using Alire.
  2. Navigate to the lace_opengl_0.1.0_672a6415/library directory.
  3. 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:

  1. Navigate to the /tmp/lace_opengl_0.1.0_672a6415 directory.
  2. Run the command eval `alr printenv` to retrieve the source environment from Alire.
  3. Navigate to the sub-directory library
  4. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant