From 89379d248640ec67747b2b5f0a6a38f8213a8306 Mon Sep 17 00:00:00 2001 From: "Alejandro R. Mosteo" Date: Mon, 26 Feb 2024 18:29:55 +0100 Subject: [PATCH] Don't run OS initialization during elaboration As this makes impossible to tweak such initialization with `alr config`. --- src/alire/alire-platforms-current.ads | 9 +++++++++ .../os_freebsd/alire-platforms-current__freebsd.adb | 6 ++++++ .../os_linux/alire-platforms-current__linux.adb | 6 ++++++ .../os_macos/alire-platforms-current__macos.adb | 6 ++++++ .../os_windows/alire-platforms-current__windows.adb | 11 +++++++++-- src/alr/alr-commands-config.ads | 4 +++- src/alr/alr-commands.adb | 12 ++++++++++++ 7 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/alire/alire-platforms-current.ads b/src/alire/alire-platforms-current.ads index 5baae4b92..738075925 100644 --- a/src/alire/alire-platforms-current.ads +++ b/src/alire/alire-platforms-current.ads @@ -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 -- -------------------------------- diff --git a/src/alire/os_freebsd/alire-platforms-current__freebsd.adb b/src/alire/os_freebsd/alire-platforms-current__freebsd.adb index baaf885bf..d4ab8fb56 100644 --- a/src/alire/os_freebsd/alire-platforms-current__freebsd.adb +++ b/src/alire/os_freebsd/alire-platforms-current__freebsd.adb @@ -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; diff --git a/src/alire/os_linux/alire-platforms-current__linux.adb b/src/alire/os_linux/alire-platforms-current__linux.adb index 802574644..cbe071ff2 100644 --- a/src/alire/os_linux/alire-platforms-current__linux.adb +++ b/src/alire/os_linux/alire-platforms-current__linux.adb @@ -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; diff --git a/src/alire/os_macos/alire-platforms-current__macos.adb b/src/alire/os_macos/alire-platforms-current__macos.adb index faa45aef2..8e220465a 100644 --- a/src/alire/os_macos/alire-platforms-current__macos.adb +++ b/src/alire/os_macos/alire-platforms-current__macos.adb @@ -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; diff --git a/src/alire/os_windows/alire-platforms-current__windows.adb b/src/alire/os_windows/alire-platforms-current__windows.adb index 971f7e2dd..7dde4c851 100644 --- a/src/alire/os_windows/alire-platforms-current__windows.adb +++ b/src/alire/os_windows/alire-platforms-current__windows.adb @@ -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; diff --git a/src/alr/alr-commands-config.ads b/src/alr/alr-commands-config.ads index b675a16cb..32d3101c5 100644 --- a/src/alr/alr-commands-config.ads +++ b/src/alr/alr-commands-config.ads @@ -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; diff --git a/src/alr/alr-commands.adb b/src/alr/alr-commands.adb index 3917bdf62..f20a0ad6f 100644 --- a/src/alr/alr-commands.adb +++ b/src/alr/alr-commands.adb @@ -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;