From 5d82a061439883644f9c49a334197d6cb083d063 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Tue, 12 Mar 2024 12:36:14 +0100 Subject: [PATCH] Remainders of the config --> settings refactor (#1631) * Remainders of the config --> settings refactor * Fix Windows-only builtins --- UPGRADING.md | 23 ++++++++++++-- doc/settings.md | 4 +-- src/alire/alire-index_on_disk-updates.adb | 2 +- src/alire/alire-settings-builtins.ads | 24 +++++++-------- src/alire/alire-settings-edit.adb | 28 ++++++++--------- src/alire/alire-settings-edit.ads | 28 +++++++++-------- src/alire/alire-settings.adb | 30 +++++++++---------- src/alire/alire-settings.ads | 18 +++++------ .../alire-settings-builtins-windows.ads | 6 ++-- 9 files changed, 92 insertions(+), 71 deletions(-) diff --git a/UPGRADING.md b/UPGRADING.md index 1020de0b..9f796b8b 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -3,6 +3,25 @@ There are no special preparations to be made in advance to upgrading. However, please check out the following information. +### Refactored features + +The following features have changed in version `2.0`, with the corresponding +replacements: + +- "Alire configuration" is now renamed to "Alire settings", to distinguish it + from a crate configuration. This entails a few changes: + - `ALR_CONFIG` environment variable is now `ALIRE_SETTINGS_DIR`. + - `alr config` is now `alr settings`. + - `alr -c|--config` is now `alr -s|--settings`. + +- Installation of toolchains for use outside of Alire control is no longer done + through `alr toolchain`, but through `alr install`: + - `alr toolchain --install|--uninstall|--install-dir` no longer exist. + - `alr toolchain --select` remains as the way to select a default toolchain + for use by Alire. + - `alr install` will create a standard prefix structure, with binaries found + at `/bin`. The default prefix location is `/.alire`. + ### Obsolete large folders Changes in default storage locations mean that the following folders, if @@ -33,9 +52,9 @@ If you want to have a fallback to be able to downgrade, you have two safe options: - Use the newer version with its own separate configuration storage. You can override - the default location by providing a new path in the `ALR_CONFIG` environment + the default location by providing a new path in the `ALIRE_SETTINGS_DIR` environment variable. - Keep a backup of your current configuration at the default location, which is `.config/alire` within your user's home. You can restore this folder in sync with - its older `alr` version. \ No newline at end of file + its older `alr` version. diff --git a/doc/settings.md b/doc/settings.md index 26295053..fb3e75ef 100644 --- a/doc/settings.md +++ b/doc/settings.md @@ -69,8 +69,8 @@ including their default values and a short explanation of their effects. By default, `alr` stores its global settings at `/.config/alire`. You can use any other location by setting in the environment the variable -`ALR_CONFIG=`, or by using the global `-c` -switch: `alr -c `. +`ALIRE_SETTINGS_DIR=`, or by using the global `-s` +switch: `alr -s `. Using pristine default settings can be useful to isolate the source of errors by ensuring that a misconfiguration is not at play. diff --git a/src/alire/alire-index_on_disk-updates.adb b/src/alire/alire-index_on_disk-updates.adb index 29a0b980..3fe21e27 100644 --- a/src/alire/alire-index_on_disk-updates.adb +++ b/src/alire/alire-index_on_disk-updates.adb @@ -8,7 +8,7 @@ with CLIC.User_Input; package body Alire.Index_On_Disk.Updates is package Builtins renames Settings.Builtins; - subtype Int is Settings.Config_Int; + subtype Int is Settings.Setting_Int; Epoch : constant Ada.Calendar.Time := Ada.Calendar.Time_Of (Year => 2017, diff --git a/src/alire/alire-settings-builtins.ads b/src/alire/alire-settings-builtins.ads index d4c87f6a..70b144c8 100644 --- a/src/alire/alire-settings-builtins.ads +++ b/src/alire/alire-settings-builtins.ads @@ -12,7 +12,7 @@ package Alire.Settings.Builtins is Cache_Dir : constant Builtin := New_Builtin (Key => "cache.dir", - Kind => Cfg_Absolute_Path, + Kind => Stn_Absolute_Path, Def => "", Help => "Directory where Alire will store its cache."); @@ -46,7 +46,7 @@ package Alire.Settings.Builtins is Distribution_Override : constant Builtin := New_Builtin (Key => "distribution.override", - Kind => Cfg_String, + Kind => Stn_String, Check => Checks.Valid_Distro'Access, Def => "", Help => @@ -57,7 +57,7 @@ package Alire.Settings.Builtins is Editor_Cmd : constant Builtin := New_Builtin (Key => "editor.cmd", - Kind => Cfg_String, + Kind => Stn_String, Def => "", Help => "Editor command and arguments for editing crate code (alr edit)." & @@ -76,7 +76,7 @@ package Alire.Settings.Builtins is Index_Auto_Update : constant Builtin := New_Builtin (Key => "index.auto_update", - Kind => Cfg_Int, + Kind => Stn_Int, Def => "24", -- hours Help => "Hours between automatic index refresh. Set to 0 to disable."); @@ -90,25 +90,25 @@ package Alire.Settings.Builtins is Index_Last_Update : constant Builtin := New_Builtin (Key => "index.last_update", Public => False, - Kind => Cfg_Int, + Kind => Stn_Int, Def => "0", -- seconds since epoch Help => "Timestamp of last index auto-refresh (seconds)"); Index_Host : constant Builtin := New_Builtin (Key => "index.host", - Kind => Cfg_String, + Kind => Stn_String, Def => "https://github.com", Help => "URL of the community index host"); Index_Owner : constant Builtin := New_Builtin (Key => "index.owner", - Kind => Cfg_String, + Kind => Stn_String, Def => "alire-project", Help => "Owner of the index repository (GitHub user/org)."); Index_Repository_Name : constant Builtin := New_Builtin (Key => "index.repository_name", - Kind => Cfg_String, + Kind => Stn_String, Def => "alire-index", Help => "Name of the index repository."); @@ -132,7 +132,7 @@ package Alire.Settings.Builtins is Toolchain_Dir : constant Builtin := New_Builtin (Key => "toolchain.dir", - Kind => Cfg_Absolute_Path, + Kind => Stn_Absolute_Path, Def => "", Help => "Directory where Alire will store its toolchains."); @@ -169,21 +169,21 @@ package Alire.Settings.Builtins is User_Email : constant Builtin := New_Builtin (Key => "user.email", - Kind => Cfg_Email, + Kind => Stn_Email, Help => "User email address. Used for the authors and" & " maintainers field of a new crate."); User_Name : constant Builtin := New_Builtin (Key => "user.name", - Kind => Cfg_String, + Kind => Stn_String, Help => "User full name. Used for the authors and " & "maintainers field of a new crate."); User_Github_Login : constant Builtin := New_Builtin (Key => "user.github_login", - Kind => Cfg_GitHub_Login, + Kind => Stn_GitHub_Login, Help => "User GitHub login/username. Used to for the maintainers-logins " & "field of a new crate."); diff --git a/src/alire/alire-settings-edit.adb b/src/alire/alire-settings-edit.adb index 37bdc40b..0962c134 100644 --- a/src/alire/alire-settings-edit.adb +++ b/src/alire/alire-settings-edit.adb @@ -35,7 +35,7 @@ package body Alire.Settings.Edit is is begin if not CLIC.Config.Edit.Set (Filepath (Local), Key, Value, Check) then - Raise_Checked_Error ("Cannot set local config key"); + Raise_Checked_Error ("Cannot set local settings key"); end if; -- Reload after change @@ -52,7 +52,7 @@ package body Alire.Settings.Edit is is begin if not CLIC.Config.Edit.Set (Filepath (Global), Key, Value, Check) then - Raise_Checked_Error ("Cannot set global config key"); + Raise_Checked_Error ("Cannot set global settings key"); end if; -- Reload after change @@ -84,11 +84,11 @@ package body Alire.Settings.Edit is is begin if CLIC.Config.Edit.Unset (Filepath (Level), Key, Quiet => True) then - Trace.Debug ("Config key " & Key & " unset from " & Level'Image + Trace.Debug ("Setting key " & Key & " unset from " & Level'Image & "configuration at " & Filepath (Level)); Load_Settings; else - Trace.Debug ("Config key " & Key & " requested to be unset at level " + Trace.Debug ("Setting key " & Key & " requested to be unset at level " & Level'Image & " but it was already unset at " & Filepath (Level)); end if; @@ -107,7 +107,7 @@ package body Alire.Settings.Edit is (Boolean, TOML_Boolean, Boolean'Image); begin Assert (Set_Boolean_Impl (Filepath (Level), Key, Value, Check), - "Cannot set config key '" & Key & "' at level " & Level'Image); + "Cannot set setting key '" & Key & "' at level " & Level'Image); -- Reload after change Load_Settings; end Set_Boolean; @@ -197,7 +197,7 @@ package body Alire.Settings.Edit is end if; end loop; - Config_Loaded := True; + Settings_Loaded := True; -- Set variables elsewhere @@ -290,18 +290,18 @@ package body Alire.Settings.Edit is -- Verify the type/specific constraints case Ent.Kind is - when Cfg_Int => + when Stn_Int => Result := Value.Kind = TOML_Integer; - when Cfg_Float => + when Stn_Float => Result := Value.Kind = TOML_Float; - when Cfg_Bool => + when Stn_Bool => Result := Value.Kind = TOML_Boolean; - when Cfg_String => + when Stn_String => Result := Value.Kind = TOML_String; - when Cfg_Absolute_Path => + when Stn_Absolute_Path => Result := Value.Kind = TOML_String and then Check_Absolute_Path (Value.As_String); - when Cfg_Existing_Absolute_Path => + when Stn_Existing_Absolute_Path => Result := Value.Kind = TOML_String and then Check_Absolute_Path (Value.As_String); if Result and then @@ -314,11 +314,11 @@ package body Alire.Settings.Edit is & "please create it beforehand or recheck it."); return False; end if; - when Cfg_Email => + when Stn_Email => Result := Value.Kind = TOML_String and then Alire.Utils.Could_Be_An_Email (Value.As_String, With_Name => False); - when Cfg_GitHub_Login => + when Stn_GitHub_Login => Result := Value.Kind = TOML_String and then Utils.Is_Valid_GitHub_Username (Value.As_String); end case; diff --git a/src/alire/alire-settings-edit.ads b/src/alire/alire-settings-edit.ads index a80effcc..196a66c9 100644 --- a/src/alire/alire-settings-edit.ads +++ b/src/alire/alire-settings-edit.ads @@ -8,7 +8,7 @@ with TOML; package Alire.Settings.Edit is - -- Shortcuts that use the standard config locations. These interpret the + -- Shortcuts that use the standard settings locations. These interpret the -- value in string as a TOML type whenever possible. procedure Set_Locally (Key : CLIC.Config.Config_Key; @@ -40,40 +40,42 @@ package Alire.Settings.Edit is -- Unset a key at a level; silently succeed even if the key was undefined. function Path return Absolute_Path; - -- The in-use global config folder path. + -- The in-use global settings folder path. -- In order of decreasing precedence: -- * A manually set path with Set_Path (below) - -- * An ALR_CONFIG env given folder + -- * An ALIRE_SETTINGS_DIR env given folder -- * Default per-platform path (see alire-platforms-*) function Cache_Path return Absolute_Path; -- The location for data that will be recreated if missing; its value in -- precedence order is: - -- 1) Config builtin 'cache.dir' + -- 1) Setting builtin 'cache.dir' -- 2) if Path above is overridden, Path/cache -- 3) Platforms.Folders.Cache procedure Set_Path (Path : Absolute_Path); - -- Override global config folder path + -- Override global settings folder path function Is_At_Default_Dir return Boolean; - -- Says if we are using the default config location (no -c or env override) + -- Says if we are using the default settings location (no -c or env + -- override). function Indexes_Directory return Absolute_Path is (Path / "indexes"); function Filepath (Lvl : Level) return Absolute_Path with Pre => Lvl /= Local or else Directories.Detect_Root_Path /= ""; - -- Return path of the configuration file corresponding to the given + -- Return path of the settings file corresponding to the given -- configuration level. - -- Support for built-in config variables. See Alire.Settings.Builtins also. + -- Support for built-in settings variables. See Alire.Settings.Builtins + -- also. function Builtins_Info return AAA.Strings.Vector; - -- Return a String_Vector with the documentation of builtin configuration + -- Return a String_Vector with the documentation of builtin settings -- options in text format. procedure Print_Builtins_Doc; - -- Print a Markdown documentation for the built-in configuration options + -- Print a Markdown documentation for the built-in settings options function Valid_Builtin (Key : CLIC.Config.Config_Key; Value : TOML.TOML_Value) @@ -83,9 +85,9 @@ package Alire.Settings.Edit is private procedure Load_Settings; - -- Clear and reload all configuration. Also set some values elsewhere + -- Clear and reload all settings. Also set some values elsewhere -- used to break circularities. Bottom line, this procedure must leave - -- the program-wide configuration ready. This is done during startup from - -- Alire_Early_Elaboration so config is available ASAP. + -- the program-wide settings ready. This is done during startup from + -- Alire_Early_Elaboration so settings are available ASAP. end Alire.Settings.Edit; diff --git a/src/alire/alire-settings.adb b/src/alire/alire-settings.adb index c5d21d5c..41bad57f 100644 --- a/src/alire/alire-settings.adb +++ b/src/alire/alire-settings.adb @@ -9,10 +9,10 @@ package body Alire.Settings is function DB return access constant CLIC.Config.Instance is begin - if Config_Loaded then + if Settings_Loaded then return DB_Instance'Access; else - raise Program_Error with "Attempt to use config database too early"; + raise Program_Error with "Attempt to use settings database too early"; end if; end DB; @@ -34,8 +34,8 @@ package body Alire.Settings is -- Get -- --------- - function Get (This : Builtin_Option) return Config_Int - is (Config_Int'Value + function Get (This : Builtin_Option) return Setting_Int + is (Setting_Int'Value (DB.Get_As_String (+This.Key, +This.Def))); ----------------- @@ -86,7 +86,7 @@ package body Alire.Settings is procedure Set (This : Builtin_Option; Level : Settings.Level; - Value : Config_Int) + Value : Setting_Int) is begin Edit.Set (Level, +This.Key, Value'Image, This.Check); @@ -109,14 +109,14 @@ package body Alire.Settings is function Image (Kind : Builtin_Kind) return String is (case Kind is - when Cfg_Int => "Integer", - when Cfg_Float => "Float", - when Cfg_Bool => "Boolean", - when Cfg_String => "String", - when Cfg_Absolute_Path => "Absolute path", - when Cfg_Existing_Absolute_Path => "Absolute path already existing", - when Cfg_Email => "Email address", - when Cfg_GitHub_Login => "GitHub login"); + when Stn_Int => "Integer", + when Stn_Float => "Float", + when Stn_Bool => "Boolean", + when Stn_String => "String", + when Stn_Absolute_Path => "Absolute path", + when Stn_Existing_Absolute_Path => "Absolute path already existing", + when Stn_Email => "Email address", + when Stn_GitHub_Login => "GitHub login"); ---------------- -- Is_Builtin -- @@ -137,7 +137,7 @@ package body Alire.Settings is return All_Builtins (Key).Kind; end if; - Raise_Checked_Error ("Kind is only valid for builtin config key"); + Raise_Checked_Error ("Kind is only valid for builtin setting key"); end Kind_Of_Builtin; ----------------- @@ -176,7 +176,7 @@ package body Alire.Settings is Check : CLIC.Config.Check_Import := null) return Builtin_Option is (New_Builtin (Key => Key, - Kind => Cfg_Bool, + Kind => Stn_Bool, Def => Def'Image, Help => Help, Public => Public, diff --git a/src/alire/alire-settings.ads b/src/alire/alire-settings.ads index 66597784..b04fa932 100644 --- a/src/alire/alire-settings.ads +++ b/src/alire/alire-settings.ads @@ -14,16 +14,16 @@ package Alire.Settings is -- Ordering is important, as Globals are loaded first and overridden by any -- Local definition loaded later. - subtype Config_Int is Long_Long_Integer; + subtype Setting_Int is Long_Long_Integer; --------------- -- Built-ins -- --------------- - type Builtin_Kind is (Cfg_Int, Cfg_Float, Cfg_Bool, - Cfg_String, Cfg_Absolute_Path, - Cfg_Existing_Absolute_Path, - Cfg_Email, Cfg_GitHub_Login); + type Builtin_Kind is (Stn_Int, Stn_Float, Stn_Bool, + Stn_String, Stn_Absolute_Path, + Stn_Existing_Absolute_Path, + Stn_Email, Stn_GitHub_Login); function Image (Kind : Builtin_Kind) return String; @@ -42,7 +42,7 @@ package Alire.Settings is function Get (This : Builtin_Option) return String; function Get (This : Builtin_Option) return Boolean; - function Get (This : Builtin_Option) return Config_Int; + function Get (This : Builtin_Option) return Setting_Int; procedure Set_Locally (This : Builtin_Option; Value : String); @@ -58,7 +58,7 @@ package Alire.Settings is procedure Set (This : Builtin_Option; Level : Settings.Level; - Value : Config_Int); + Value : Setting_Int); procedure Unset (This : Builtin_Option; Level : Settings.Level); @@ -82,10 +82,10 @@ package Alire.Settings is private - Config_Loaded : Boolean := False; + Settings_Loaded : Boolean := False; DB_Instance : aliased CLIC.Config.Instance; - -- The Alire user configuration database + -- The Alire user settings database type Builtin_Option is tagged record Key : Ada.Strings.Unbounded.Unbounded_String; diff --git a/src/alire/os_windows/alire-settings-builtins-windows.ads b/src/alire/os_windows/alire-settings-builtins-windows.ads index f6a2d90a..19d4f4c8 100644 --- a/src/alire/os_windows/alire-settings-builtins-windows.ads +++ b/src/alire/os_windows/alire-settings-builtins-windows.ads @@ -20,7 +20,7 @@ package Alire.Settings.Builtins.Windows is Msys2_Install_Dir : constant Builtin := New_Builtin (Key => "msys2.install_dir", - Kind => Cfg_Absolute_Path, + Kind => Stn_Absolute_Path, Def => Settings.Edit.Cache_Path / "msys64", Help => "Directory where Alire will detect and/or install" & @@ -28,14 +28,14 @@ package Alire.Settings.Builtins.Windows is Msys2_Installer : constant Builtin := New_Builtin (Key => "msys2.installer", - Kind => Cfg_String, + Kind => Stn_String, Def => Default_Msys2_Installer, Help => "Filename of the executable msys2 installer. (Windows only)"); Msys2_Installer_URL : constant Builtin := New_Builtin (Key => "msys2.installer_url", - Kind => Cfg_String, + Kind => Stn_String, Def => Default_Msys2_Installer_URL, Help => "URL of the executable msys2 installer. (Windows only)"); -- 2.39.5