Skip to content

Commit

Permalink
WIP: migrated a few more, use builtin check
Browse files Browse the repository at this point in the history
  • Loading branch information
mosteo committed Aug 22, 2023
1 parent b6beddf commit 08db489
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 139 deletions.
79 changes: 78 additions & 1 deletion src/alire/alire-config-builtins.ads
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,95 @@ 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,
Help =>
"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;
19 changes: 18 additions & 1 deletion src/alire/alire-config-edit.adb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
with Ada.Text_IO;

with Alire.Config.Builtins;
with Alire.Environment;
with Alire.Paths;
with Alire.Platforms.Folders;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
40 changes: 1 addition & 39 deletions src/alire/alire-config-edit.ads
Original file line number Diff line number Diff line change
Expand Up @@ -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" &
Expand Down Expand Up @@ -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."))

);

Expand Down
33 changes: 19 additions & 14 deletions src/alire/alire-config.adb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -124,23 +125,27 @@ 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;

-----------------
-- 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;
77 changes: 16 additions & 61 deletions src/alire/alire-config.ads
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
11 changes: 4 additions & 7 deletions src/alire/alire-index.ads
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/alire/alire-roots.adb
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 08db489

Please sign in to comment.