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

GPS confusing GTKAda. #31

Closed
Blady-Com opened this issue Aug 19, 2018 · 4 comments
Closed

GPS confusing GTKAda. #31

Blady-Com opened this issue Aug 19, 2018 · 4 comments

Comments

@Blady-Com
Copy link

Hello,
With some GTKAda programs, setting environment variables such as XDG_DATA_DIRS may puzzle execution from GPS, for instance issuing errors as:
"Couldn't recognize the image file format for file"
GPS sets many of them in execution script, so execution of GTKAda program from GPS may produce these kind of errors.
The workaround is to execute the program from Terminal, same for debugging with GDB.
But before executing GPS executable, the gps script saves GTK env var in GPS_STARTUP env var.
So came up the idea to restore the original values before doing Gtk.Main.Init as:

<...>
with Ada.Environment_Variables;
with Ada.Strings.Fixed;

procedure Restore_GPS_Startup_Values is
procedure Internal_RGSV (Saved_Var_Name, Saved_Var_Value : String) is
GPS_STARTUP : constant String := "GPS_STARTUP_";
Ind : constant Natural :=
Ada.Strings.Fixed.Index (Saved_Var_Name, GPS_STARTUP);
Oringinal_Var_Name : constant String :=
Saved_Var_Name (Ind + GPS_STARTUP'Length .. Saved_Var_Name'Last);
begin
if Ind > 0
and then Ada.Environment_Variables.Exists (Oringinal_Var_Name)
then
if Saved_Var_Value /= "" then
Ada.Environment_Variables.Set
(Oringinal_Var_Name,
Saved_Var_Value);
else
Ada.Environment_Variables.Clear (Oringinal_Var_Name);
end if;
end if;
end Internal_RGSV;
begin
Ada.Environment_Variables.Iterate (Internal_RGSV'Access);
end Restore_GPS_Startup_Values;

procedure Testgtk is
Win : Main_Windows.Main_Window;
begin
Restore_GPS_Startup_Values;
Gtk.Main.Init;
<...>

Now I can launch and debug my GTKAda programs from GPS.
See in attached test26.adb source code, an example with XDG_DATA_DIRS with GPS, output is:
/usr/local/gnat/share
/usr/local/xnadalib-2018/share
where as execution from Terminal, output is:
/usr/local/xnadalib-2018/share
/usr/local/xnadalib-2018/share

Shouldn't GPS do that directly before executing program?

Thanks Pascal.
test26.adb.txt

@reznikmm
Copy link
Member

I'm afraid GPS won't work correctly with this approach. Instead we are going to restore original environment while forking a child process. This requires modifications in GNAT.OS_Lib.Spawn to pass environment. We are working on this.

@Blady-Com
Copy link
Author

Thanks Maxim for the information, regards Pascal.

@Blady-Com
Copy link
Author

Hello Maxim, FYI the issue is still present in GPS Community 2019, regards Pascal.

@VitalijBondarenko
Copy link

The issue is still present in GNAT Studio Community 2020

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

4 participants