Skip to content

Commit

Permalink
Don't run OS initialization during elaboration
Browse files Browse the repository at this point in the history
As this makes impossible to tweak such initialization with `alr config`.
  • Loading branch information
mosteo committed Feb 26, 2024
1 parent 64f73f3 commit 89379d2
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/alire/alire-platforms-current.ads
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ package Alire.Platforms.Current is

function Operating_System return Platforms.Operating_Systems;

----------------------
-- Self configuration

procedure Initialize;
-- Do any initialization that is necessary for this platform. This is
-- called as soon as we know the user is not running `alr config`, as we
-- want to allow the opportunity to configure things without triggering
-- this initialization.

--------------------------------
-- Portable derived utilities --
--------------------------------
Expand Down
6 changes: 6 additions & 0 deletions src/alire/os_freebsd/alire-platforms-current__freebsd.adb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,10 @@ package body Alire.Platforms.Current is
function Operating_System return Alire.Platforms.Operating_Systems
is (Alire.Platforms.FreeBSD);

----------------
-- Initialize --
----------------

procedure Initialize is null;

end Alire.Platforms.Current;
6 changes: 6 additions & 0 deletions src/alire/os_linux/alire-platforms-current__linux.adb
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,10 @@ package body Alire.Platforms.Current is
function Operating_System return Alire.Platforms.Operating_Systems
is (Alire.Platforms.Linux);

----------------
-- Initialize --
----------------

procedure Initialize is null;

end Alire.Platforms.Current;
6 changes: 6 additions & 0 deletions src/alire/os_macos/alire-platforms-current__macos.adb
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,10 @@ package body Alire.Platforms.Current is

function Operating_System return Platforms.Operating_Systems is (MacOS);

----------------
-- Initialize --
----------------

procedure Initialize is null;

end Alire.Platforms.Current;
11 changes: 9 additions & 2 deletions src/alire/os_windows/alire-platforms-current__windows.adb
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,13 @@ package body Alire.Platforms.Current is

end Setup_Msys2;

begin
Setup_Msys2;
----------------
-- Initialize --
----------------

procedure Initialize is
begin
Setup_Msys2;
end Initialize;

end Alire.Platforms.Current;
4 changes: 3 additions & 1 deletion src/alr/alr-commands-config.ads
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ package Alr.Commands.Config is

type Command is new Commands.Command with private;

Command_Name : constant String := "config";

overriding
function Name (Cmd : Command) return CLIC.Subcommand.Identifier
is ("config");
is (Command_Name);

overriding
procedure Execute (Cmd : in out Command;
Expand Down
12 changes: 12 additions & 0 deletions src/alr/alr-commands.adb
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,19 @@ package body Alr.Commands is

Create_Alire_Folders;

declare
use AAA.Strings;
begin
-- Once we know the user is not trying to configure, run the
-- platform-specific initialization (which may rely on such config).
if To_Lower_Case (Sub_Cmd.What_Command) /= Config.Command_Name
then
Alire.Platforms.Current.Initialize;
Trace.Debug ("Platform-specific initialization done.");
else
Trace.Debug
("Platform-specific initialization skipped (alr config).");
end if;

Set_Builtin_Aliases;

Expand Down

0 comments on commit 89379d2

Please sign in to comment.