diff --git a/src/alire/alire-config-builtins.ads b/src/alire/alire-config-builtins.ads index 0daff5ebd..34f02290c 100644 --- a/src/alire/alire-config-builtins.ads +++ b/src/alire/alire-config-builtins.ads @@ -14,6 +14,27 @@ package Alire.Config.Builtins is & "location inside the global cache. When false (default), " & "dependencies are sandboxed in each workspace."); + Distribution_Disable_Detection : constant Builtin := New_Builtin + (Key => "distribution.disable_detection", + Def => False, + Help => + "If true, Alire will report an unknown distribution and will not" + & " attempt to use the system package manager."); + + -- EDITOR + + Editor_Cmd : constant Builtin := New_Builtin + (Key => "editor.cmd", + Kind => Cfg_String, + Def => "gnatstudio -P ${GPR_FILE}", + Help => + "Editor command and arguments for editing crate code (alr edit)." & + " The executables and arguments are separated by a single space" & + " character. The token ${GPR_FILE} is replaced by" & + " a path to the project file to open."); + + -- INDEX + Index_Auto_Community : constant Builtin := New_Builtin (Key => "index.auto_community", Def => True, @@ -21,11 +42,67 @@ package Alire.Config.Builtins is "When unset or true, the community index will be added " & "automatically when required if no other index is configured."); + Index_Host : constant Builtin := New_Builtin + (Key => "index.host", + Kind => Cfg_String, + Def => "https://github.com", + Help => "URL of the community index host"); + + Index_Owner : constant Builtin := New_Builtin + (Key => "index.owner", + Kind => Cfg_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, + Def => "alire-index", + Help => "Name of the index repository."); + + -- SOLVER + Solver_Autonarrow : constant Builtin := New_Builtin (Key => "solver.autonarrow", Def => True, Help => "If true, `alr with` will replace 'any' dependencies with the" - & " appropriate caret/tilde dependency."); + & " appropriate caret/tilde dependency."); + + -- TOOLCHAIN + + Toolchain_Assistant : constant Builtin := New_Builtin + (Key => "toolchain.assistant", + Def => True, + Help => + "If true, and assistant to select the default toolchain will run " + & "when first needed."); + + Toolchain_External : constant Builtin := New_Builtin + (Key => "toolchain.external", + Def => True, + Public => False); + -- We use this key to store whether a tool in the toolchain requires + -- external detection. It stores a boolean per tool, e.g, for gprbuild: + -- toolchain.external.gprbuild + + Toolchain_Use : constant Builtin := New_Builtin + (Key => "toolchain.use", + Def => True, + Public => False); + -- We use this key internally to store the configured tools picked + -- up by the user. Not really intended to be set up by users, so + -- not listed as a built-in. Each tool is a child of this key, + -- e.g.: toolchain.use.gnat, toolchain.use.gprbuild + + -- WARNINGS + + Warning_Old_Index : constant Builtin := New_Builtin + (Key => "warning.old_index", + Def => True, + Help => + "If unset or true, a warning will be emitted when " & + "using a compatible index with a lower version than the newest" & + " known."); end Alire.Config.Builtins; diff --git a/src/alire/alire-config-edit.adb b/src/alire/alire-config-edit.adb index 8acdfb7e3..70fc48efa 100644 --- a/src/alire/alire-config-edit.adb +++ b/src/alire/alire-config-edit.adb @@ -1,5 +1,6 @@ with Ada.Text_IO; +with Alire.Config.Builtins; with Alire.Environment; with Alire.Paths; with Alire.Platforms.Folders; @@ -151,7 +152,7 @@ package body Alire.Config.Edit is -- Set variables elsewhere Platforms.Current.Disable_Distribution_Detection := - DB.Get (Keys.Distribution_Disable_Detection, False); + Config.Builtins.Distribution_Disable_Detection.Get; if Platforms.Current.Disable_Distribution_Detection then Trace.Debug ("Distribution detection disabled by configuration"); end if; @@ -215,6 +216,9 @@ package body Alire.Config.Edit is begin for Ent of All_Builtins loop if To_String (Ent.Key) = Key then + + -- Verify the type/specific constraints + case Ent.Kind is when Cfg_Int => Result := Value.Kind = TOML_Integer; @@ -249,6 +253,19 @@ package body Alire.Config.Edit is and then Utils.Is_Valid_GitHub_Username (Value.As_String); end case; + exit when not Result; + + -- Apply the own builtin check if any. + + if Result and then Ent.Check not in null then + if not Ent.Check (Key, Value) then + Trace.Error + ("Invalid value '" & CLIC.Config.Image (Value) & + "' for builtin configuration '" & Key & "'. " & + "Specific builtin check failed."); + end if; + end if; + exit; end if; end loop; diff --git a/src/alire/alire-config-edit.ads b/src/alire/alire-config-edit.ads index 4f0f00dc0..4f04b5bdc 100644 --- a/src/alire/alire-config-edit.ads +++ b/src/alire/alire-config-edit.ads @@ -94,28 +94,6 @@ package Alire.Config.Edit is +("User GitHub login/username. Used to for the maintainers-logins " & "field of a new crate.")), - (+Keys.Editor_Cmd, - Cfg_String, - +("Editor command and arguments for editing crate code (alr edit)." & - " The executables and arguments are separated by a single space" & - " character. The token ${GPR_FILE} is replaced by" & - " a path to the project file to open.")), - - (+Keys.Index_Host, - Cfg_String, - +("URL of the community index host, defaults to " - & Defaults.Index_Host)), - - (+Keys.Index_Owner, - Cfg_String, - +("Owner of the index repository (GitHub user/org), defaults to " - & Defaults.Index_Owner)), - - (+Keys.Index_Repo_Name, - Cfg_String, - +("Name of the index repository, defaults to " - & Defaults.Index_Repo_Name)), - (+Keys.Msys2_Do_Not_Install, Cfg_Bool, +("If true, Alire will not try to automatically" & @@ -144,26 +122,10 @@ package Alire.Config.Edit is & "been ever computed. All updates have to be manually requested " & "through `alr update`")), - (+Keys.Distribution_Disable_Detection, - Cfg_Bool, - +("If true, Alire will report an unknown distribution and will not" - & " attempt to use the system package manager.")), - (+Keys.Warning_Caret, Cfg_Bool, +("If true, Alire will warn about the use of caret (^) " - & "for pre-1 dependencies.")), - - (+Keys.Warning_Old_Index, - Cfg_Bool, - +("When unset (default) or true, a warning will be emitted when " & - "using a compatible index with a lower version than the newest" & - " known.")), - - (+Keys.Toolchain_Assistant, - Cfg_Bool, - +("If true, and assistant to select the default toolchain will run " - & "when first needed.")) + & "for pre-1 dependencies.")) ); diff --git a/src/alire/alire-config.adb b/src/alire/alire-config.adb index a7f3d1c9b..d31c2f86f 100644 --- a/src/alire/alire-config.adb +++ b/src/alire/alire-config.adb @@ -110,11 +110,12 @@ package body Alire.Config is -- New_Builtin -- ----------------- - function New_Builtin (Key : CLIC.Config.Config_Key; - Kind : Builtin_Kind; - Def : String; - Help : String; - Check : CLIC.Config.Check_Import := null) + function New_Builtin (Key : CLIC.Config.Config_Key; + Kind : Builtin_Kind; + Def : String; + Help : String := ""; + Public : Boolean := True; + Check : CLIC.Config.Check_Import := null) return Builtin_Option is begin @@ -124,7 +125,9 @@ package body Alire.Config is Help => +Help, Check => Check) do - All_Builtins.Insert (Key, Result); + if Public then + All_Builtins.Insert (Key, Result); + end if; end return; end New_Builtin; @@ -132,15 +135,17 @@ package body Alire.Config is -- New_Builtin -- ----------------- - function New_Builtin (Key : CLIC.Config.Config_Key; - Def : Boolean; - Help : String; - Check : CLIC.Config.Check_Import := null) + function New_Builtin (Key : CLIC.Config.Config_Key; + Def : Boolean; + Help : String := ""; + Public : Boolean := True; + Check : CLIC.Config.Check_Import := null) return Builtin_Option is (New_Builtin (Key => Key, - Kind => Cfg_Bool, - Def => Def'Image, - Help => Help, - Check => Check)); + Kind => Cfg_Bool, + Def => Def'Image, + Help => Help, + Public => Public, + Check => Check)); end Alire.Config; diff --git a/src/alire/alire-config.ads b/src/alire/alire-config.ads index 924ebffc9..58d639119 100644 --- a/src/alire/alire-config.ads +++ b/src/alire/alire-config.ads @@ -62,55 +62,27 @@ package Alire.Config is procedure Unset (This : Builtin_Option; Level : Config.Level); - function New_Builtin (Key : CLIC.Config.Config_Key; - Kind : Builtin_Kind; - Def : String; - Help : String; - Check : CLIC.Config.Check_Import := null) - return Builtin_Option; - - function New_Builtin (Key : CLIC.Config.Config_Key; - Def : Boolean; - Help : String; - Check : CLIC.Config.Check_Import := null) - return Builtin_Option; + function New_Builtin (Key : CLIC.Config.Config_Key; + Kind : Builtin_Kind; + Def : String; + Help : String := ""; + Public : Boolean := True; + Check : CLIC.Config.Check_Import := null) + return Builtin_Option + with Pre => Help /= "" or not Public; + + function New_Builtin (Key : CLIC.Config.Config_Key; + Def : Boolean; + Help : String := ""; + Public : Boolean := True; + Check : CLIC.Config.Check_Import := null) + return Builtin_Option + with Pre => Help /= "" or not Public; package Keys is use CLIC.Config; - -- A few predefined keys that are used in several places. This list is - -- not exhaustive. - - Editor_Cmd : constant Config_Key := "editor.cmd"; - - Distribution_Disable_Detection : constant Config_Key := - "distribution.disable_detection"; - -- When set to True, distro will be reported as unknown, and in turn no - -- native package manager will be used. - - Index_Host : constant Config_Key := "index.host"; - Index_Owner : constant Config_Key := "index.owner"; - Index_Repo_Name : constant Config_Key := "index.repository_name"; - -- These three conform the URL where the community index is hosted, - -- allowing to override the default. - - Toolchain_Assistant : constant Config_Key := "toolchain.assistant"; - -- When true (default), on first `Requires_Workspace`, the - -- assistant to select a gnat compiler and corresponding gprbuild - -- will be launched. - - Toolchain_External : constant Config_Key := "toolchain.external"; - -- We use this key to store whether a tool in the toolchain requires - -- external detection. It stores a boolean per tool, e.g, for gprbuild: - -- toolchain.external.gprbuild - - Toolchain_Use : constant Config_Key := "toolchain.use"; - -- We use this key internally to store the configured tools picked - -- up by the user. Not really intended to be set up by users, so - -- not listed as a built-in. Each tool is a child of this key, - -- e.g.: toolchain.use.gnat, toolchain.use.gprbuild - Update_Manually : constant Config_Key := "update-manually-only"; -- Used by `get --only` to flag a workspace to not autoupdate itself -- despite having no solution in the lockfile. @@ -122,29 +94,12 @@ package Alire.Config is Warning_Caret : constant Config_Key := "warning.caret"; -- Set to false to disable warnings about caret/tilde use for ^0 deps. - Warning_Old_Index : constant Config_Key := "warning.old_index"; - -- Warn about old but compatible index in use - Msys2_Do_Not_Install : constant Config_Key := "msys2.do_not_install"; Msys2_Install_Dir : constant Config_Key := "msys2.install_dir"; Msys2_Installer : constant Config_Key := "msys2.installer"; Msys2_Installer_URL : constant Config_Key := "msys2.installer_url"; end Keys; - -------------- - -- Defaults -- - -------------- - - package Defaults is - - Index_Host : constant String := "https://github.com"; - Index_Owner : constant String := "alire-project"; - Index_Repo_Name : constant String := "alire-index"; - - Warning_Old_Index : constant Boolean := True; - - end Defaults; - private type Builtin_Option is tagged record diff --git a/src/alire/alire-index.ads b/src/alire/alire-index.ads index 753b6962a..b0be96a09 100644 --- a/src/alire/alire-index.ads +++ b/src/alire/alire-index.ads @@ -1,7 +1,7 @@ private with Alire_Early_Elaboration; pragma Unreferenced (Alire_Early_Elaboration); -with Alire.Config; pragma Unreferenced (Alire.Config); +with Alire.Config.Builtins; with Alire.Crates.Containers; with Alire.Dependencies; with Alire.Origins; @@ -14,15 +14,12 @@ with Semantic_Versioning.Extended; package Alire.Index is - Community_Host : constant String - := Config.DB.Get (Config.Keys.Index_Host, Config.Defaults.Index_Host); + Community_Host : constant String := Config.Builtins.Index_Host.Get; - Community_Organization : constant String - := Config.DB.Get (Config.Keys.Index_Owner, Config.Defaults.Index_Owner); + Community_Organization : constant String := Config.Builtins.Index_Owner.Get; Community_Repo_Name : constant String - := Config.DB.Get (Config.Keys.Index_Repo_Name, - Config.Defaults.Index_Repo_Name); + := Config.Builtins.Index_Repository_Name.Get; Community_Repo : constant URL := "git+" & Community_Host diff --git a/src/alire/alire-roots.adb b/src/alire/alire-roots.adb index f52b2662c..c93e9879b 100644 --- a/src/alire/alire-roots.adb +++ b/src/alire/alire-roots.adb @@ -2,7 +2,6 @@ with Ada.Unchecked_Deallocation; with Alire.Builds; with Alire.Conditional; -with Alire.Config; with Alire.Dependencies.Containers; with Alire.Directories; with Alire.Environment; diff --git a/src/alire/alire-toml_index.adb b/src/alire/alire-toml_index.adb index 216ae6952..20a53b43e 100644 --- a/src/alire/alire-toml_index.adb +++ b/src/alire/alire-toml_index.adb @@ -1,6 +1,6 @@ with Ada.Directories; -with Alire.Config; +with Alire.Config.Builtins; with Alire.Crates; with Alire.Directories; with Alire.TOML_Adapters; @@ -107,8 +107,7 @@ package body Alire.TOML_Index is use type Semantic_Versioning.Version; Warn_Of_Old_Compatible : constant Boolean := - Config.DB.Get (Config.Keys.Warning_Old_Index, - Config.Defaults.Warning_Old_Index); + Config.Builtins.Warning_Old_Index.Get; ---------------------- -- Compare_Branches -- @@ -125,7 +124,7 @@ package body Alire.TOML_Index is & TTY.Emph (Alire.Index.Branch_Kind) & "' but your community index branch is '" & TTY.Emph (Local) & "'", - Disable_Config => Config.Keys.Warning_Old_Index); + Disable_Config => Config.Builtins.Warning_Old_Index.Key); Suggest_Update := True; end if; end Compare_Branches; @@ -183,7 +182,8 @@ package body Alire.TOML_Index is & "' version (" & Version.Image & ") is older than the newest supported by alr (" & Alire.Index.Version.Image & ")", - Disable_Config => Config.Keys.Warning_Old_Index); + Disable_Config => + Config.Builtins.Warning_Old_Index.Key); Suggest_Update := True; elsif not Alire.Index.Valid_Versions.Contains (Version) then diff --git a/src/alire/alire-toolchains.adb b/src/alire/alire-toolchains.adb index 9fc3e7d84..5484e6d52 100644 --- a/src/alire/alire-toolchains.adb +++ b/src/alire/alire-toolchains.adb @@ -415,9 +415,7 @@ package body Alire.Toolchains is procedure Set_Automatic_Assistant (Enabled : Boolean; Level : Config.Level) is begin - Config.Edit.Set_Boolean (Level, - Config.Keys.Toolchain_Assistant, - Enabled); + Config.Builtins.Toolchain_Assistant.Set (Level, Enabled); end Set_Automatic_Assistant; ------------------------ diff --git a/src/alire/alire-toolchains.ads b/src/alire/alire-toolchains.ads index ac4ee2f4c..4b232b45e 100644 --- a/src/alire/alire-toolchains.ads +++ b/src/alire/alire-toolchains.ads @@ -2,7 +2,7 @@ with Ada.Containers.Indefinite_Ordered_Sets; with AAA.Strings; -with Alire.Config; +with Alire.Config.Builtins; with Alire.Dependencies; with Alire.Errors; with Alire.Milestones; @@ -153,7 +153,7 @@ private ----------------------- function Assistant_Enabled return Boolean - is (Config.DB.Get (Config.Keys.Toolchain_Assistant, Default => True)); + is (Config.Builtins.Toolchain_Assistant.Get); ---------------------- -- Tool_Is_External -- @@ -175,8 +175,8 @@ private then Tool_Key (GNAT_Crate, Kind) else CLIC.Config.Config_Key ((case Kind is - when For_Use => Config.Keys.Toolchain_Use, - when For_Is_External => Config.Keys.Toolchain_External) + when For_Use => Config.Builtins.Toolchain_Use.Key, + when For_Is_External => Config.Builtins.Toolchain_External.Key) & "." & Crate.As_String)); -------------------- diff --git a/src/alr/alr-commands-edit.adb b/src/alr/alr-commands-edit.adb index b976c0169..4dbdd4250 100644 --- a/src/alr/alr-commands-edit.adb +++ b/src/alr/alr-commands-edit.adb @@ -1,7 +1,7 @@ with Ada.Containers; with Alire; use Alire; -with Alire.Config; +with Alire.Config.Builtins; with Alire.OS_Lib.Subprocess; with Alire.Platforms.Current; @@ -61,8 +61,10 @@ package body Alr.Commands.Edit is use GNAT.Strings; use Alire.Config; + package Builtins renames Alire.Config.Builtins; + Editor_Cmd : constant String := - Alire.Config.DB.Get (Keys.Editor_Cmd, "gnatstudio -P ${GPR_FILE}"); + Builtins.Editor_Cmd.Get; Edit_Args : AAA.Strings.Vector := AAA.Strings.Split (Editor_Cmd, ' '); begin @@ -72,7 +74,8 @@ package body Alr.Commands.Edit is if Edit_Args.Is_Empty then Reportaise_Command_Failed - ("No editor defined in config key '" & Keys.Editor_Cmd & "'."); + ("No editor defined in config key '" + & Builtins.Editor_Cmd.Key & "'."); end if; Cmd.Requires_Workspace;