From ef13b1bc8a33ac17614ff800f2ba53d56a6aeda8 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Wed, 18 Aug 2021 19:04:15 +0200 Subject: [PATCH] Allow to configure toolchain locally (#788) --- src/alire/alire-config.ads | 2 ++ src/alire/alire-toolchains.adb | 14 ++++++++------ src/alire/alire-toolchains.ads | 6 ++++-- src/alire/alire.ads | 2 +- src/alr/alr-commands-toolchain.adb | 25 ++++++++++++++++++++++++- src/alr/alr-commands-toolchain.ads | 9 +++++++-- src/alr/alr-commands.adb | 9 +++++++-- 7 files changed, 53 insertions(+), 14 deletions(-) diff --git a/src/alire/alire-config.ads b/src/alire/alire-config.ads index 1d777c5b..f0fa943a 100644 --- a/src/alire/alire-config.ads +++ b/src/alire/alire-config.ads @@ -63,6 +63,8 @@ package Alire.Config with Preelaborate is -- is returned. type Level is (Global, Local); + -- Ordering is important, as Globals are loaded first and overridden by any + -- Local definition loaded later. -- TODO: refactor this globals package into a type that can be -- passed around. diff --git a/src/alire/alire-toolchains.adb b/src/alire/alire-toolchains.adb index f754666a..8d78c169 100644 --- a/src/alire/alire-toolchains.adb +++ b/src/alire/alire-toolchains.adb @@ -28,7 +28,7 @@ package body Alire.Toolchains is -- Assistant -- --------------- - procedure Assistant is + procedure Assistant (Level : Config.Level) is package Release_Vectors is new Ada.Containers.Indefinite_Vectors (Positive, Releases.Release, Releases."="); @@ -152,7 +152,7 @@ package body Alire.Toolchains is -- Store tool milestone after successful deployment - Config.Edit.Set (Path => Config.Edit.Filepath (Config.Global), + Config.Edit.Set (Path => Config.Edit.Filepath (Level), Key => Tool_Key (Release.Name), Value => Release.Milestone.Image); @@ -176,7 +176,7 @@ package body Alire.Toolchains is -- Clean up stored version - Config.Edit.Unset (Path => Config.Edit.Filepath (Config.Global), + Config.Edit.Unset (Path => Config.Edit.Filepath (Level), Key => Tool_Key (Crate)); else @@ -246,7 +246,7 @@ package body Alire.Toolchains is -- The user has already chosen, so disable the assistant - Config.Edit.Set (Config.Edit.Filepath (Config.Global), + Config.Edit.Set (Config.Edit.Filepath (Level), Config.Keys.Toolchain_Assistant, "false"); @@ -279,8 +279,10 @@ package body Alire.Toolchains is procedure Unconfigure (Crate : Crate_Name) is begin - Config.Edit.Unset (Config.Edit.Filepath (Config.Global), - Tool_Key (Crate)); + for Level in Config.Level loop + Config.Edit.Unset (Config.Edit.Filepath (Level), + Tool_Key (Crate)); + end loop; end Unconfigure; end Alire.Toolchains; diff --git a/src/alire/alire-toolchains.ads b/src/alire/alire-toolchains.ads index eadd54c5..2acef762 100644 --- a/src/alire/alire-toolchains.ads +++ b/src/alire/alire-toolchains.ads @@ -1,6 +1,6 @@ with Ada.Containers.Indefinite_Ordered_Sets; -private with Alire.Config; +with Alire.Config; with Alire.Dependencies; private with Alire.Milestones; with Alire.TTY; @@ -20,9 +20,11 @@ package Alire.Toolchains is function Any_Tool (Crate : Crate_Name) return Dependencies.Dependency; -- Returns a dependency on crate* - procedure Assistant; + procedure Assistant (Level : Config.Level); -- Runs the interactive assistant to select the default toolchain. By -- default, the native Alire-provided compiler for Current_OS is proposed. + -- This information may apply config-wide or workspace-wide. Installation + -- goes, in any case, to the config cache location. -- The following functions will transform any `gnat_XXX` dependency on -- plain `gnat`. This way we need to to litter the callers with similar diff --git a/src/alire/alire.ads b/src/alire/alire.ads index 89d8164a..3d6a11e1 100644 --- a/src/alire/alire.ads +++ b/src/alire/alire.ads @@ -9,7 +9,7 @@ with Simple_Logging; package Alire with Preelaborate is - Version : constant String := "1.1.0-dev+toolchain"; + Version : constant String := "1.1.0-dev+local-toolchain"; -- 1.1.0-dev: begin post-1.0 changes -- 1.0.0: no changes since rc3 -- 1.0.0-rc3: added help colors PR diff --git a/src/alr/alr-commands-toolchain.adb b/src/alr/alr-commands-toolchain.adb index 60681e11..a2d1931b 100644 --- a/src/alr/alr-commands-toolchain.adb +++ b/src/alr/alr-commands-toolchain.adb @@ -32,6 +32,13 @@ package body Alr.Commands.Toolchain is Long_Switch => "--install", Help => "Install a toolchain component"); + Define_Switch + (Config, + Cmd.Local'Access, + Switch => "", + Long_Switch => "--local", + Help => "Store toolchain configuration in local workspace"); + Define_Switch (Config, Cmd.S_Select'Access, @@ -227,17 +234,33 @@ 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"); + end if; + -- Dispatch to subcommands if Cmd.S_Select then + Cmd.Requires_Full_Index; - Alire.Toolchains.Assistant; + + if Cmd.Local then + Cmd.Requires_Valid_Session; + end if; + + Alire.Toolchains.Assistant (if Cmd.Local + then Alire.Config.Local + else Alire.Config.Global); + elsif Cmd.Uninstall then Uninstall (Cmd, Argument (1)); + elsif Cmd.Install then Install (Cmd, Argument (1)); + else Cmd.List; + end if; exception diff --git a/src/alr/alr-commands-toolchain.ads b/src/alr/alr-commands-toolchain.ads index 5b38cdd8..ba9290af 100644 --- a/src/alr/alr-commands-toolchain.ads +++ b/src/alr/alr-commands-toolchain.ads @@ -26,7 +26,10 @@ package Alr.Commands.Toolchain is .New_Line .Append ("Use --select without arguments to run the assistant to " - & "select the default toolchain for this configuration.") + & "select the default toolchain for this configuration. " + & "Adding --local will instead make the selection apply " + & "only to the workspace (overridding a possible " + & "configuration-wide selection).") .New_Line .Append ("Specify --install/--uninstall and a crate name with optional " @@ -48,12 +51,14 @@ package Alr.Commands.Toolchain is overriding function Usage_Custom_Parameters (Cmd : Command) return String - is ("[-u|--uninstall] [-i|--install crate[version set]] | --select"); + is ("[-u|--uninstall] [-i|--install crate[version set]] |" + & " --select [--local]"); private type Command is new Commands.Command with record Install : aliased Boolean := False; + Local : aliased Boolean := False; S_Select : aliased Boolean := False; Uninstall : aliased Boolean := False; end record; diff --git a/src/alr/alr-commands.adb b/src/alr/alr-commands.adb index bd9dc6c0..c97c45f2 100644 --- a/src/alr/alr-commands.adb +++ b/src/alr/alr-commands.adb @@ -559,9 +559,14 @@ package body Alr.Commands is return; end if; - if Conf.Get (Conf.Keys.Toolchain_Assistant, Default => True) then + -- Unless the command is precisely to configure the toolchain, ask the + -- user for its preference at this time. + + if Cmd not in Commands.Toolchain.Command'Class and then + Conf.Get (Conf.Keys.Toolchain_Assistant, Default => True) + then Cmd.Requires_Full_Index; - Alire.Toolchains.Assistant; + Alire.Toolchains.Assistant (Conf.Global); end if; Trace.Debug ("Workspace is being checked and loaded for the first time"); -- 2.39.5