From c0e12b33816886f37e47ab344117e519cfc95ed6 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Mon, 23 Aug 2021 13:57:01 +0200 Subject: [PATCH] Implement `alr toolchain --disable-assistant` (#803) * Implement `alr toolchain --disable-assistant` * Disable the assistant in testsuite using new swithc --- src/alire/alire-toolchains.adb | 16 +++++++++++++--- src/alire/alire-toolchains.ads | 3 +++ src/alr/alr-commands-toolchain.adb | 30 +++++++++++++++++++++++++++--- src/alr/alr-commands-toolchain.ads | 1 + testsuite/drivers/alr.py | 3 +-- 5 files changed, 45 insertions(+), 8 deletions(-) diff --git a/src/alire/alire-toolchains.adb b/src/alire/alire-toolchains.adb index 8d78c169..63809492 100644 --- a/src/alire/alire-toolchains.adb +++ b/src/alire/alire-toolchains.adb @@ -246,9 +246,7 @@ package body Alire.Toolchains is -- The user has already chosen, so disable the assistant - Config.Edit.Set (Config.Edit.Filepath (Level), - Config.Keys.Toolchain_Assistant, - "false"); + Set_Automatic_Assistant (False, Level); -- Finally deploy selections @@ -258,6 +256,18 @@ package body Alire.Toolchains is end Assistant; + ----------------------------- + -- Set_Automatic_Assistant -- + ----------------------------- + + procedure Set_Automatic_Assistant (Enabled : Boolean; Level : Config.Level) + is + begin + Config.Edit.Set (Config.Edit.Filepath (Level), + Config.Keys.Toolchain_Assistant, + (if Enabled then "true" else "false")); + end Set_Automatic_Assistant; + ------------------------ -- Tool_Is_Configured -- ------------------------ diff --git a/src/alire/alire-toolchains.ads b/src/alire/alire-toolchains.ads index 2acef762..01f1c34e 100644 --- a/src/alire/alire-toolchains.ads +++ b/src/alire/alire-toolchains.ads @@ -30,6 +30,9 @@ package Alire.Toolchains is -- plain `gnat`. This way we need to to litter the callers with similar -- transformations, as we always want whatever gnat_XXX is used for "gnat". + procedure Set_Automatic_Assistant (Enabled : Boolean; Level : Config.Level); + -- Enable/Disable the automatic assistant on next run + function Tool_Is_Configured (Crate : Crate_Name) return Boolean; -- Say if a tool is actually configured by the user diff --git a/src/alr/alr-commands-toolchain.adb b/src/alr/alr-commands-toolchain.adb index a2d1931b..6d775a30 100644 --- a/src/alr/alr-commands-toolchain.adb +++ b/src/alr/alr-commands-toolchain.adb @@ -25,6 +25,12 @@ package body Alr.Commands.Toolchain is is use GNAT.Command_Line; begin + Define_Switch + (Config, + Cmd.Disable'Access, + Long_Switch => "--disable-assistant", + Help => "Disable autorun of selection assistant"); + Define_Switch (Config, Cmd.Install'Access, @@ -210,7 +216,9 @@ package body Alr.Commands.Toolchain is -- Validation - if Cmd.Uninstall and then Cmd.S_Select then + if Alire.Utils.Count_True + ((Cmd.Disable, Cmd.Install, Cmd.S_Select, Cmd.Uninstall)) > 1 + then Reportaise_Wrong_Arguments ("The provided switches cannot be used simultaneously"); end if; @@ -234,8 +242,14 @@ package body Alr.Commands.Toolchain is ("Toolchain installation does not accept any arguments"); end if; - if Cmd.Local and then not Cmd.S_Select then - Reportaise_Wrong_Arguments ("--local requires --select"); + if Cmd.Local and then not (Cmd.S_Select or else Cmd.Disable) then + Reportaise_Wrong_Arguments + ("--local requires --select or --disable-assistant"); + end if; + + if Cmd.Disable and then Num_Arguments /= 0 then + Reportaise_Wrong_Arguments + ("Disabling the assistant does not admit any extra arguments"); end if; -- Dispatch to subcommands @@ -258,6 +272,16 @@ package body Alr.Commands.Toolchain is elsif Cmd.Install then Install (Cmd, Argument (1)); + elsif Cmd.Disable then + Alire.Toolchains.Set_Automatic_Assistant (False, + (if Cmd.Local + then Alire.Config.Local + else Alire.Config.Global)); + Alire.Put_Info + ("Assistant disabled in " + & TTY.Emph (if Cmd.Local then "local" else "global") + & " configuration."); + else Cmd.List; diff --git a/src/alr/alr-commands-toolchain.ads b/src/alr/alr-commands-toolchain.ads index ba9290af..453722bb 100644 --- a/src/alr/alr-commands-toolchain.ads +++ b/src/alr/alr-commands-toolchain.ads @@ -57,6 +57,7 @@ package Alr.Commands.Toolchain is private type Command is new Commands.Command with record + Disable : aliased Boolean := False; Install : aliased Boolean := False; Local : aliased Boolean := False; S_Select : aliased Boolean := False; diff --git a/testsuite/drivers/alr.py b/testsuite/drivers/alr.py index 5e8fd7a3..8bf1eb8c 100644 --- a/testsuite/drivers/alr.py +++ b/testsuite/drivers/alr.py @@ -40,8 +40,7 @@ def prepare_env(config_dir, env): # Disable selection of toolchain to preserve older behavior. Tests that # require a configured compiler will have to set it up explicitly. - run_alr("config", "--global", "--set", "toolchain.assistant", "false", - "-c", config_dir) + run_alr("toolchain", "--disable-assistant", "-c", config_dir) # Pass config location explicitly since env is not yet applied # If distro detection is disabled via environment, configure so in alr -- 2.39.5