From bbd9c917fa345ad06b6afdd1c2a1abff685692ff Mon Sep 17 00:00:00 2001 From: "Alejandro R. Mosteo" Date: Mon, 20 Mar 2023 13:26:36 +0100 Subject: [PATCH 1/4] Typed variants of Alire.Config.Edit.Set Mostly because it's too easy to mix Boolean with String --- alire.toml | 2 +- deps/clic | 2 +- dev/edit.sh | 2 +- src/alire/alire-config-edit.adb | 46 ++++++++++++++++++++++++++++++++- src/alire/alire-config-edit.ads | 20 +++++++++++++- 5 files changed, 67 insertions(+), 5 deletions(-) diff --git a/alire.toml b/alire.toml index 8d381337e..544c482fe 100644 --- a/alire.toml +++ b/alire.toml @@ -47,7 +47,7 @@ windows = { ALIRE_OS = "windows" } [[pins]] aaa = { url = "https://github.com/mosteo/aaa", commit = "906d9eaf4fb8efabfbc3d8cfb34d04ceec340e13" } ada_toml = { url = "https://github.com/mosteo/ada-toml", commit = "da4e59c382ceb0de6733d571ecbab7ea4919b33d" } -clic = { url = "https://github.com/alire-project/clic", commit = "102bc38c7e9469112145e12100449664b5c74764" } +clic = { url = "https://github.com/alire-project/clic", commit = "84a68fa5e39195614f985b6c0b3d67cbdec5b09e" } gnatcoll = { url = "https://github.com/alire-project/gnatcoll-core.git", commit = "92bb91130a9ec628b4c48b7ef9fe7f24d9dc25fa" } semantic_versioning = { url = "https://github.com/alire-project/semantic_versioning", commit = "c2345fca8b685d6d3fc9334fac81140a0cdbea89" } simple_logging = { url = "https://github.com/alire-project/simple_logging", commit = "2b62010b6d66c106c65eb9ae604aabcf64522fac" } diff --git a/deps/clic b/deps/clic index 102bc38c7..84a68fa5e 160000 --- a/deps/clic +++ b/deps/clic @@ -1 +1 @@ -Subproject commit 102bc38c7e9469112145e12100449664b5c74764 +Subproject commit 84a68fa5e39195614f985b6c0b3d67cbdec5b09e diff --git a/dev/edit.sh b/dev/edit.sh index dcc39a496..66ca7ca90 100755 --- a/dev/edit.sh +++ b/dev/edit.sh @@ -1 +1 @@ -gnatstudio -P alr_env & +gnatstudio -P alr_env & >/dev/null 2>&1 diff --git a/src/alire/alire-config-edit.adb b/src/alire/alire-config-edit.adb index fa3e8f2e4..eb72fa2eb 100644 --- a/src/alire/alire-config-edit.adb +++ b/src/alire/alire-config-edit.adb @@ -5,7 +5,7 @@ with Alire.Platforms.Folders; with Alire.Platforms.Current; with Alire.Utils; -with CLIC.Config.Edit; +with CLIC.Config.Edit.Typed; with CLIC.Config.Load; package body Alire.Config.Edit is @@ -13,6 +13,7 @@ package body Alire.Config.Edit is use Ada.Strings.Unbounded; use AAA.Strings; use TOML; + package Typed renames CLIC.Config.Edit.Typed; type String_Access is access String; Config_Path : String_Access; @@ -67,6 +68,49 @@ package body Alire.Config.Edit is end case; end Set; + ----------------- + -- Set_Boolean -- + ----------------- + + procedure Set_Boolean (Level : Config.Level; + Key : CLIC.Config.Config_Key; + Value : Boolean; + Check : CLIC.Config.Check_Import := null) + is + + begin + Assert (Typed.Set_Boolean (Filepath (Level), Key, Value, Check), + "Cannot set config key '" & Key & "' at level " & Level'Image); + end Set_Boolean; + + ----------------- + -- Set_Integer -- + ----------------- + + procedure Set_Integer (Level : Config.Level; + Key : CLIC.Config.Config_Key; + Value : Integer; + Check : CLIC.Config.Check_Import := null) + is + begin + Assert (Typed.Set_Integer (Filepath (Level), Key, Value, Check), + "Cannot set config key '" & Key & "' at level " & Level'Image); + end Set_Integer; + + --------------- + -- Set_Float -- + --------------- + + procedure Set_Float (Level : Config.Level; + Key : CLIC.Config.Config_Key; + Value : Float; + Check : CLIC.Config.Check_Import := null) + is + begin + Assert (Typed.Set_Float (Filepath (Level), Key, Value, Check), + "Cannot set config key '" & Key & "' at level " & Level'Image); + end Set_Float; + -------------- -- Filepath -- -------------- diff --git a/src/alire/alire-config-edit.ads b/src/alire/alire-config-edit.ads index 0547a8d61..182aa490d 100644 --- a/src/alire/alire-config-edit.ads +++ b/src/alire/alire-config-edit.ads @@ -7,7 +7,8 @@ with Alire.Directories; package Alire.Config.Edit is - -- Shortcuts that use the standard config locations: + -- Shortcuts that use the standard config locations. These interpret the + -- value in string as a TOML type whenever possible. procedure Set_Locally (Key : CLIC.Config.Config_Key; Value : String; @@ -22,6 +23,23 @@ package Alire.Config.Edit is Value : String; Check : CLIC.Config.Check_Import := null); + -- Typed alternatives + + procedure Set_Boolean (Level : Config.Level; + Key : CLIC.Config.Config_Key; + Value : Boolean; + Check : CLIC.Config.Check_Import := null); + + procedure Set_Integer (Level : Config.Level; + Key : CLIC.Config.Config_Key; + Value : Integer; + Check : CLIC.Config.Check_Import := null); + + procedure Set_Float (Level : Config.Level; + Key : CLIC.Config.Config_Key; + Value : Float; + Check : CLIC.Config.Check_Import := null); + -- To ease the pain with circularities in old GNAT versions, we have also -- here all non-preelaborable things related to config loading. This -- way, querying stays preelaborable. From 8abeff99b86e0f57242b96aeaa7ebe9f6947f338 Mon Sep 17 00:00:00 2001 From: "Alejandro R. Mosteo" Date: Tue, 21 Mar 2023 14:48:16 +0100 Subject: [PATCH 2/4] Migrate raw uses to typed uses --- deps/clic | 2 +- deps/semantic_versioning | 2 +- deps/simple_logging | 2 +- src/alire/alire-config-edit.adb | 18 ++++-------------- src/alire/alire-config-edit.ads | 5 ----- src/alire/alire-selftest.adb | 24 ++++++++++++++++++++++++ src/alire/alire-toolchains.adb | 10 +++++----- src/alire/alire-toolchains.ads | 18 +++++++++--------- src/alr/alr-commands-config.adb | 27 +++++++++++++++++++++------ src/alr/alr-commands-get.adb | 6 ++++-- 10 files changed, 70 insertions(+), 44 deletions(-) diff --git a/deps/clic b/deps/clic index 84a68fa5e..059dfbf33 160000 --- a/deps/clic +++ b/deps/clic @@ -1 +1 @@ -Subproject commit 84a68fa5e39195614f985b6c0b3d67cbdec5b09e +Subproject commit 059dfbf33f6f8a17c74b0d0e560be652957d7c1d diff --git a/deps/semantic_versioning b/deps/semantic_versioning index c2345fca8..2f23fc5f6 160000 --- a/deps/semantic_versioning +++ b/deps/semantic_versioning @@ -1 +1 @@ -Subproject commit c2345fca8b685d6d3fc9334fac81140a0cdbea89 +Subproject commit 2f23fc5f6b4855b836b599adf292fed9c0ed4144 diff --git a/deps/simple_logging b/deps/simple_logging index 2b62010b6..3505dc645 160000 --- a/deps/simple_logging +++ b/deps/simple_logging @@ -1 +1 @@ -Subproject commit 2b62010b6d66c106c65eb9ae604aabcf64522fac +Subproject commit 3505dc645f3eef6799a486aae223d37e88cfc4d5 diff --git a/src/alire/alire-config-edit.adb b/src/alire/alire-config-edit.adb index eb72fa2eb..d439d70a8 100644 --- a/src/alire/alire-config-edit.adb +++ b/src/alire/alire-config-edit.adb @@ -81,6 +81,8 @@ package body Alire.Config.Edit is begin Assert (Typed.Set_Boolean (Filepath (Level), Key, Value, Check), "Cannot set config key '" & Key & "' at level " & Level'Image); + -- Reload after change + Load_Config; end Set_Boolean; ----------------- @@ -95,22 +97,10 @@ package body Alire.Config.Edit is begin Assert (Typed.Set_Integer (Filepath (Level), Key, Value, Check), "Cannot set config key '" & Key & "' at level " & Level'Image); + -- Reload after change + Load_Config; end Set_Integer; - --------------- - -- Set_Float -- - --------------- - - procedure Set_Float (Level : Config.Level; - Key : CLIC.Config.Config_Key; - Value : Float; - Check : CLIC.Config.Check_Import := null) - is - begin - Assert (Typed.Set_Float (Filepath (Level), Key, Value, Check), - "Cannot set config key '" & Key & "' at level " & Level'Image); - end Set_Float; - -------------- -- Filepath -- -------------- diff --git a/src/alire/alire-config-edit.ads b/src/alire/alire-config-edit.ads index 182aa490d..15e62eb68 100644 --- a/src/alire/alire-config-edit.ads +++ b/src/alire/alire-config-edit.ads @@ -35,11 +35,6 @@ package Alire.Config.Edit is Value : Integer; Check : CLIC.Config.Check_Import := null); - procedure Set_Float (Level : Config.Level; - Key : CLIC.Config.Config_Key; - Value : Float; - Check : CLIC.Config.Check_Import := null); - -- To ease the pain with circularities in old GNAT versions, we have also -- here all non-preelaborable things related to config loading. This -- way, querying stays preelaborable. diff --git a/src/alire/alire-selftest.adb b/src/alire/alire-selftest.adb index 38ca72fb1..fb8eb8469 100644 --- a/src/alire/alire-selftest.adb +++ b/src/alire/alire-selftest.adb @@ -14,6 +14,30 @@ package body Alire.Selftest is Config.Edit.Set_Globally (Key, Val); pragma Assert (Config.DB.Defined (Key)); pragma Assert (Config.DB.Get (Key, "snafu") = Val); + + -- Check typed storing + + -- Raw storing of integer + Config.Edit.Set_Globally (Key, "777"); + pragma Assert (Integer (Config.DB.Get (Key, 0)) = 777); + + -- Typed storing of integer + Config.Edit.Set_Integer (Config.Global, Key, 888); + pragma Assert (Integer (Config.DB.Get (Key, 0)) = 888); + + -- Raw storing of boolean + Config.Edit.Set_Globally (Key, "true"); + pragma Assert (Config.DB.Get (Key, False) = True); + + -- Typed storing of boolean + Config.Edit.Set_Boolean (Config.Global, Key, False); + pragma Assert (Config.DB.Get (Key, True) = False); + + -- Raw storing of boolean with wrong type + Config.Edit.Set_Globally (Key, "True"); + -- This causes a string to be stored, as in TOML only "true" is bool + pragma Assert (Config.DB.Get (Key, "False") = "True"); + end Check_Config_Changes; ------------------------ diff --git a/src/alire/alire-toolchains.adb b/src/alire/alire-toolchains.adb index 2ff8ecb50..ff712eb56 100644 --- a/src/alire/alire-toolchains.adb +++ b/src/alire/alire-toolchains.adb @@ -346,10 +346,10 @@ package body Alire.Toolchains is (Level, Key => Tool_Key (Release.Name), Value => Release.Milestone.Image); - Alire.Config.Edit.Set + Alire.Config.Edit.Set_Boolean (Level, Key => Tool_Key (Release.Name, For_Is_External), - Value => Boolean'(not Release.Origin.Is_Regular)'Image); + Value => not Release.Origin.Is_Regular); end Set_As_Default; ----------------------------- @@ -359,9 +359,9 @@ package body Alire.Toolchains is procedure Set_Automatic_Assistant (Enabled : Boolean; Level : Config.Level) is begin - Config.Edit.Set (Level, - Config.Keys.Toolchain_Assistant, - (if Enabled then "true" else "false")); + Config.Edit.Set_Boolean (Level, + Config.Keys.Toolchain_Assistant, + Enabled); end Set_Automatic_Assistant; ------------------------ diff --git a/src/alire/alire-toolchains.ads b/src/alire/alire-toolchains.ads index be55f3551..74c4692a7 100644 --- a/src/alire/alire-toolchains.ads +++ b/src/alire/alire-toolchains.ads @@ -113,6 +113,15 @@ private function Assistant_Enabled return Boolean is (Config.DB.Get (Config.Keys.Toolchain_Assistant, Default => True)); + ---------------------- + -- Tool_Is_External -- + ---------------------- + + function Tool_Is_External (Crate : Crate_Name) return Boolean + is (Boolean'Value + (Config.DB.Get_As_String -- because it could be stored as bool or string + (Tool_Key (Crate, For_Is_External), "True"))); + -------------- -- Tool_Key -- -------------- @@ -128,15 +137,6 @@ private when For_Is_External => Config.Keys.Toolchain_External) & "." & Crate.As_String)); - ---------------------- - -- Tool_Is_External -- - ---------------------- - - function Tool_Is_External (Crate : Crate_Name) return Boolean - is (Boolean'Value - (Config.DB.Get - (Tool_Key (Crate, For_Is_External), Default => "True"))); - -------------------- -- Tool_Milestone -- -------------------- diff --git a/src/alr/alr-commands-config.adb b/src/alr/alr-commands-config.adb index b6699c74a..b990a089e 100644 --- a/src/alr/alr-commands-config.adb +++ b/src/alr/alr-commands-config.adb @@ -1,10 +1,12 @@ -with CLIC.Config.Info; -with CLIC.Config.Edit; +with AAA.Enum_Tools; with Alire.Config; with Alire.Config.Edit; with Alire.Root; +with CLIC.Config.Info; +with CLIC.Config.Edit; + package body Alr.Commands.Config is ------------- @@ -105,10 +107,23 @@ package body Alr.Commands.Config is Key & "'"); end if; - Alire.Config.Edit.Set - (Lvl, - Key, Val, - Check => Alire.Config.Edit.Valid_Builtin'Access); + -- Check explicitly for booleans to store the proper TOML type + -- regardless of the capitalization used by the user. + declare + function Is_Boolean is new AAA.Enum_Tools.Is_Valid (Boolean); + begin + if Is_Boolean (Val) then + Alire.Config.Edit.Set_Boolean + (Lvl, + Key, Boolean'Value (Val), + Check => Alire.Config.Edit.Valid_Builtin'Access); + else + Alire.Config.Edit.Set + (Lvl, + Key, Val, + Check => Alire.Config.Edit.Valid_Builtin'Access); + end if; + end; end; elsif Cmd.Unset then diff --git a/src/alr/alr-commands-get.adb b/src/alr/alr-commands-get.adb index 7cc9db04c..c1fcc191b 100644 --- a/src/alr/alr-commands-get.adb +++ b/src/alr/alr-commands-get.adb @@ -161,8 +161,10 @@ package body Alr.Commands.Get is Trace.Info ("Because --only was used, automatic dependency" & " retrieval is disabled in this workspace:" & " use `alr update` to apply dependency changes"); - Alire.Config.Edit.Set_Locally - (Alire.Config.Keys.Update_Manually, "true"); + Alire.Config.Edit.Set_Boolean + (Alire.Config.Local, + Alire.Config.Keys.Update_Manually, + True); if not CLIC.User_Input.Not_Interactive then Alire.Roots.Print_Nested_Crates (Cmd.Root.Path); From c758f8038aa3f26d7bbb8c61912207dbdd06f869 Mon Sep 17 00:00:00 2001 From: "Alejandro R. Mosteo" Date: Wed, 22 Mar 2023 16:32:31 +0100 Subject: [PATCH 3/4] Leave only needed instances --- deps/clic | 2 +- src/alire/alire-config-edit.adb | 24 ++++-------------------- src/alire/alire-config-edit.ads | 5 ----- src/alire/alire-selftest.adb | 4 ---- 4 files changed, 5 insertions(+), 30 deletions(-) diff --git a/deps/clic b/deps/clic index 059dfbf33..a21521f63 160000 --- a/deps/clic +++ b/deps/clic @@ -1 +1 @@ -Subproject commit 059dfbf33f6f8a17c74b0d0e560be652957d7c1d +Subproject commit a21521f634f2f3604c6f86df4e456490ad02a052 diff --git a/src/alire/alire-config-edit.adb b/src/alire/alire-config-edit.adb index d439d70a8..bedfb046d 100644 --- a/src/alire/alire-config-edit.adb +++ b/src/alire/alire-config-edit.adb @@ -5,7 +5,7 @@ with Alire.Platforms.Folders; with Alire.Platforms.Current; with Alire.Utils; -with CLIC.Config.Edit.Typed; +with CLIC.Config.Edit; with CLIC.Config.Load; package body Alire.Config.Edit is @@ -13,7 +13,6 @@ package body Alire.Config.Edit is use Ada.Strings.Unbounded; use AAA.Strings; use TOML; - package Typed renames CLIC.Config.Edit.Typed; type String_Access is access String; Config_Path : String_Access; @@ -77,30 +76,15 @@ package body Alire.Config.Edit is Value : Boolean; Check : CLIC.Config.Check_Import := null) is - + function Set_Boolean_Impl is new CLIC.Config.Edit.Set_Typed + (Boolean, TOML_Boolean, Boolean'Image); begin - Assert (Typed.Set_Boolean (Filepath (Level), Key, Value, Check), + Assert (Set_Boolean_Impl (Filepath (Level), Key, Value, Check), "Cannot set config key '" & Key & "' at level " & Level'Image); -- Reload after change Load_Config; end Set_Boolean; - ----------------- - -- Set_Integer -- - ----------------- - - procedure Set_Integer (Level : Config.Level; - Key : CLIC.Config.Config_Key; - Value : Integer; - Check : CLIC.Config.Check_Import := null) - is - begin - Assert (Typed.Set_Integer (Filepath (Level), Key, Value, Check), - "Cannot set config key '" & Key & "' at level " & Level'Image); - -- Reload after change - Load_Config; - end Set_Integer; - -------------- -- Filepath -- -------------- diff --git a/src/alire/alire-config-edit.ads b/src/alire/alire-config-edit.ads index 15e62eb68..423ea828b 100644 --- a/src/alire/alire-config-edit.ads +++ b/src/alire/alire-config-edit.ads @@ -30,11 +30,6 @@ package Alire.Config.Edit is Value : Boolean; Check : CLIC.Config.Check_Import := null); - procedure Set_Integer (Level : Config.Level; - Key : CLIC.Config.Config_Key; - Value : Integer; - Check : CLIC.Config.Check_Import := null); - -- To ease the pain with circularities in old GNAT versions, we have also -- here all non-preelaborable things related to config loading. This -- way, querying stays preelaborable. diff --git a/src/alire/alire-selftest.adb b/src/alire/alire-selftest.adb index fb8eb8469..9d2ab80e9 100644 --- a/src/alire/alire-selftest.adb +++ b/src/alire/alire-selftest.adb @@ -21,10 +21,6 @@ package body Alire.Selftest is Config.Edit.Set_Globally (Key, "777"); pragma Assert (Integer (Config.DB.Get (Key, 0)) = 777); - -- Typed storing of integer - Config.Edit.Set_Integer (Config.Global, Key, 888); - pragma Assert (Integer (Config.DB.Get (Key, 0)) = 888); - -- Raw storing of boolean Config.Edit.Set_Globally (Key, "true"); pragma Assert (Config.DB.Get (Key, False) = True); From 3cf821795191715ae19a0bc8857c4e764b61e627 Mon Sep 17 00:00:00 2001 From: "Alejandro R. Mosteo" Date: Thu, 30 Mar 2023 12:56:57 +0200 Subject: [PATCH 4/4] Update clic dependency --- alire.toml | 2 +- deps/clic | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/alire.toml b/alire.toml index 544c482fe..bff046368 100644 --- a/alire.toml +++ b/alire.toml @@ -47,7 +47,7 @@ windows = { ALIRE_OS = "windows" } [[pins]] aaa = { url = "https://github.com/mosteo/aaa", commit = "906d9eaf4fb8efabfbc3d8cfb34d04ceec340e13" } ada_toml = { url = "https://github.com/mosteo/ada-toml", commit = "da4e59c382ceb0de6733d571ecbab7ea4919b33d" } -clic = { url = "https://github.com/alire-project/clic", commit = "84a68fa5e39195614f985b6c0b3d67cbdec5b09e" } +clic = { url = "https://github.com/alire-project/clic", commit = "ce4668206bbd038e857ce6a2d463c3de9a0cc9bb" } gnatcoll = { url = "https://github.com/alire-project/gnatcoll-core.git", commit = "92bb91130a9ec628b4c48b7ef9fe7f24d9dc25fa" } semantic_versioning = { url = "https://github.com/alire-project/semantic_versioning", commit = "c2345fca8b685d6d3fc9334fac81140a0cdbea89" } simple_logging = { url = "https://github.com/alire-project/simple_logging", commit = "2b62010b6d66c106c65eb9ae604aabcf64522fac" } diff --git a/deps/clic b/deps/clic index a21521f63..ce4668206 160000 --- a/deps/clic +++ b/deps/clic @@ -1 +1 @@ -Subproject commit a21521f634f2f3604c6f86df4e456490ad02a052 +Subproject commit ce4668206bbd038e857ce6a2d463c3de9a0cc9bb