From a54e730f051e732791413f0580034fc3503e0000 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Tue, 18 Jul 2023 13:16:57 +0200 Subject: [PATCH] Bits from the `alr share` feat to be kept (#1399) * Bits from the `alr share` feat to be kept * Code review changes * Update CLIC pin * Use upstream CLIC repository --- alire.toml | 6 +++--- deps/clic | 2 +- deps/minirest | 2 +- src/alire/alire-config-edit.adb | 19 +++++++++++++++++ src/alire/alire-config-edit.ads | 4 ++++ src/alire/alire-origins.ads | 14 ++++++++++--- src/alire/alire-roots.adb | 8 ++++---- src/alire/alire-roots.ads | 2 +- src/alire/alire-shared.adb | 4 ++-- src/alire/alire-solutions-diffs.adb | 2 +- src/alire/alire-toolchains.adb | 7 ++++--- src/alr/alr-commands-toolchain.adb | 4 ++-- src/alr/alr-commands-withing.adb | 4 ++++ src/alr/alr-commands.ads | 4 ++++ testsuite/drivers/asserts.py | 32 +++++++++++++++++++++-------- 15 files changed, 85 insertions(+), 29 deletions(-) diff --git a/alire.toml b/alire.toml index a84eca86..59873a8c 100644 --- a/alire.toml +++ b/alire.toml @@ -15,7 +15,7 @@ project-files = ["alr.gpr"] executables = ["alr"] [[depends-on]] -aaa = "~0.2.7" +aaa = "~0.3.0" ada_toml = "~0.3" ajunitgen = "^1.0.1" ansiada = "^1.0" @@ -45,9 +45,9 @@ windows = { ALIRE_OS = "windows" } # Some dependencies require precise versions during the development cycle: [[pins]] -aaa = { url = "https://github.com/mosteo/aaa", commit = "f60254934a7d6e39b72380b496527295602f75e3" } +aaa = { url = "https://github.com/mosteo/aaa", commit = "fbfffb1cb269a852201d172119d94f3024b617f2" } ada_toml = { url = "https://github.com/mosteo/ada-toml", commit = "da4e59c382ceb0de6733d571ecbab7ea4919b33d" } -clic = { url = "https://github.com/alire-project/clic", commit = "8d26222de71014554999e48c821906fca0e3dc41" } +clic = { url = "https://github.com/alire-project/clic", commit = "6879b90876a1c918b4e112f59c6db0e25b713f52" } gnatcoll = { url = "https://github.com/alire-project/gnatcoll-core.git", commit = "403efe11405113cf12ae3d014df474cf7a046176" } minirest = { url = "https://github.com/mosteo/minirest.git", commit = "9045d8faafcea996fa7b51ccda84c54712eff821" } semantic_versioning = { url = "https://github.com/alire-project/semantic_versioning", commit = "2f23fc5f6b4855b836b599adf292fed9c0ed4144" } diff --git a/deps/clic b/deps/clic index 8d26222d..6879b908 160000 --- a/deps/clic +++ b/deps/clic @@ -1 +1 @@ -Subproject commit 8d26222de71014554999e48c821906fca0e3dc41 +Subproject commit 6879b90876a1c918b4e112f59c6db0e25b713f52 diff --git a/deps/minirest b/deps/minirest index 9045d8fa..834835b0 160000 --- a/deps/minirest +++ b/deps/minirest @@ -1 +1 @@ -Subproject commit 9045d8faafcea996fa7b51ccda84c54712eff821 +Subproject commit 834835b04457349f516ce7d7de51b59703facaa0 diff --git a/src/alire/alire-config-edit.adb b/src/alire/alire-config-edit.adb index 7967b37f..9f50e3a9 100644 --- a/src/alire/alire-config-edit.adb +++ b/src/alire/alire-config-edit.adb @@ -67,6 +67,25 @@ package body Alire.Config.Edit is end case; end Set; + ----------- + -- Unset -- + ----------- + + procedure Unset (Level : Config.Level; + Key : CLIC.Config.Config_Key) + is + begin + if CLIC.Config.Edit.Unset (Filepath (Level), Key, Quiet => True) then + Trace.Debug ("Config key " & Key & " unset from " & Level'Image + & "configuration at " & Filepath (Level)); + Load_Config; + else + Trace.Debug ("Config key " & Key & " requested to be unset at level " + & Level'Image & " but it was already unset at " + & Filepath (Level)); + end if; + end Unset; + ----------------- -- Set_Boolean -- ----------------- diff --git a/src/alire/alire-config-edit.ads b/src/alire/alire-config-edit.ads index a34aa12e..011bb873 100644 --- a/src/alire/alire-config-edit.ads +++ b/src/alire/alire-config-edit.ads @@ -36,6 +36,10 @@ package Alire.Config.Edit is -- here all non-preelaborable things related to config loading. This -- way, querying stays preelaborable. + procedure Unset (Level : Config.Level; + Key : CLIC.Config.Config_Key); + -- 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. -- In order of decreasing precedence: diff --git a/src/alire/alire-origins.ads b/src/alire/alire-origins.ads index 450021c1..233fbf83 100644 --- a/src/alire/alire-origins.ads +++ b/src/alire/alire-origins.ads @@ -37,9 +37,16 @@ package Alire.Origins is subtype Archive_Kinds is Kinds with Static_Predicate => Archive_Kinds in Binary_Archive | Source_Archive; + subtype Deployable_Kinds is Kinds + with Static_Predicate => Deployable_Kinds not in External; + -- Origins that require deployment + subtype External_Kinds is Kinds with Static_Predicate => External_Kinds in External | System; + subtype Source_Kinds is Kinds range Filesystem .. Source_Archive; + -- These are kinds that have actual sources that are deployed and built + subtype VCS_Kinds is Kinds range Git .. SVN; type Source_Archive_Format is (Unknown, Tarball, Zip_Archive); @@ -100,10 +107,11 @@ package Alire.Origins is function Package_Name (This : Origin) return String with Pre => This.Kind = System; - function Is_Regular (This : Origin) return Boolean is + function Is_Index_Provided (This : Origin) return Boolean is (This.Kind not in External | System); - -- A regular origin is one that is compiled from sources, instead of coming - -- from external definitions (detected or not). + -- One that is deployed via built sources or fetched binaries pointed to by + -- an index, instead of coming from locally detected executables or system + -- packages. function Short_Unique_Id (This : Origin) return String with Pre => This.Kind in Git | Hg | Archive_Kinds; diff --git a/src/alire/alire-roots.adb b/src/alire/alire-roots.adb index 25cef86f..0a0bdebb 100644 --- a/src/alire/alire-roots.adb +++ b/src/alire/alire-roots.adb @@ -56,9 +56,9 @@ package body Alire.Roots is -- Relocate to the release folder CD : Directories.Guard - (if State.Has_Release and then State.Release.Origin.Is_Regular - then Directories.Enter (This.Release_Base (State.Crate)) - else Directories.Stay) with Unreferenced; + (if State.Has_Release and then State.Release.Origin.Is_Index_Provided + then Directories.Enter (This.Release_Base (State.Crate)) + else Directories.Stay) with Unreferenced; --------------------------- -- Run_Pre_Build_Actions -- @@ -696,7 +696,7 @@ package body Alire.Roots is -- Binary releases are always installed as shared releases Shared.Share (Rel); - elsif Dep.Is_Shared and then not Rel.Origin.Is_Regular then + elsif Dep.Is_Shared and then not Rel.Origin.Is_Index_Provided then -- Externals shouldn't leave a trace in the binary cache Trace.Debug ("deploy: skip shared external"); diff --git a/src/alire/alire-roots.ads b/src/alire/alire-roots.ads index ca23be14..663138c2 100644 --- a/src/alire/alire-roots.ads +++ b/src/alire/alire-roots.ads @@ -377,7 +377,7 @@ private Crate : Crate_Name) return Any_Path; -- The path at which dependencies have to be deployed, which for regular - -- releases is simply ./alire/cache/dependencies, unless overriden by the + -- releases is simply ./alire/cache/dependencies, unless overridden by the -- config option `dependencies.dir` end Alire.Roots; diff --git a/src/alire/alire-shared.adb b/src/alire/alire-shared.adb index 932d3f6e..c8285ab3 100644 --- a/src/alire/alire-shared.adb +++ b/src/alire/alire-shared.adb @@ -78,7 +78,7 @@ package body Alire.Shared is for Release of Index.Releases_Satisfying (Toolchains.Any_Tool (Tool), Root.Platform_Properties) loop - if not Release.Origin.Is_Regular then + if not Release.Origin.Is_Index_Provided then Result.Include (Release); end if; end loop; @@ -220,7 +220,7 @@ package body Alire.Shared is Path : constant Absolute_Path := Shared.Path / Release.Deployment_Folder; begin - if not Release.Origin.Is_Regular then + if not Release.Origin.Is_Index_Provided then Raise_Checked_Error ("Only regular releases deployed through Alire can be removed."); end if; diff --git a/src/alire/alire-solutions-diffs.adb b/src/alire/alire-solutions-diffs.adb index fc2d921c..d102b5af 100644 --- a/src/alire/alire-solutions-diffs.adb +++ b/src/alire/alire-solutions-diffs.adb @@ -42,7 +42,7 @@ package body Alire.Solutions.Diffs is when Unpinned => TTY.Emph (U ("🎈")), -- alts: 𐩒🎈 when Unchanged => TTY.OK (U ("=")), when Missing => TTY.Error (U ("❗")), -- alts: ⚠️❗‼️ - when Shared => TTY.Emph (U ("♻️ ")), -- alts: ♻️♼ + when Shared => TTY.Emph (U ("♻️ ")), -- alts: ♻♻️♼🫴 when Binary => TTY.Warn (U ("📦"))) else (case Change is diff --git a/src/alire/alire-toolchains.adb b/src/alire/alire-toolchains.adb index e4b0f894..df5096bf 100644 --- a/src/alire/alire-toolchains.adb +++ b/src/alire/alire-toolchains.adb @@ -132,7 +132,8 @@ package body Alire.Toolchains is (Index.Releases_Satisfying (Any_Tool (Crate), Env)) loop - if Release.Origin.Is_Regular and then Is_Valid_Choice (Release) + if Release.Origin.Is_Index_Provided and then + Is_Valid_Choice (Release) then -- We want the newest native compiler packaged by Alire to @@ -189,7 +190,7 @@ package body Alire.Toolchains is -- Deploy as a shared install unless external - if Release.Origin.Is_Regular then + if Release.Origin.Is_Index_Provided then Shared.Share (Release); else Trace.Debug @@ -400,7 +401,7 @@ package body Alire.Toolchains is Alire.Config.Edit.Set_Boolean (Level, Key => Tool_Key (Release.Name, For_Is_External), - Value => not Release.Origin.Is_Regular); + Value => not Release.Origin.Is_Index_Provided); end Set_As_Default; ----------------------------- diff --git a/src/alr/alr-commands-toolchain.adb b/src/alr/alr-commands-toolchain.adb index 0f9b61fd..a4f36b2f 100644 --- a/src/alr/alr-commands-toolchain.adb +++ b/src/alr/alr-commands-toolchain.adb @@ -244,7 +244,7 @@ package body Alr.Commands.Toolchain is -- And perform the actual installation if Cmd.Install_Dir.all /= "" then - if Rel.Origin.Is_Regular then + if Rel.Origin.Is_Index_Provided then Shared.Share (Rel, Cmd.Install_Dir.all); else Reportaise_Command_Failed @@ -253,7 +253,7 @@ package body Alr.Commands.Toolchain is & Rel.Milestone.TTY_Image & " is: " & Rel.Origin.Kind'Image); end if; else - if Rel.Origin.Is_Regular then + if Rel.Origin.Is_Index_Provided then Shared.Share (Rel); elsif Rel.Origin.Is_System then Origins.Deployers.Deploy (Rel).Assert; diff --git a/src/alr/alr-commands-withing.adb b/src/alr/alr-commands-withing.adb index 8660ea8b..bce6f55f 100644 --- a/src/alr/alr-commands-withing.adb +++ b/src/alr/alr-commands-withing.adb @@ -228,6 +228,10 @@ package body Alr.Commands.Withing is is Flags : Natural := 0; + ----------- + -- Check -- + ----------- + procedure Check (Flag : Boolean) is begin if Flag then diff --git a/src/alr/alr-commands.ads b/src/alr/alr-commands.ads index 1d9b26b7..a1f3bf5c 100644 --- a/src/alr/alr-commands.ads +++ b/src/alr/alr-commands.ads @@ -146,4 +146,8 @@ private TTY_Underline => Alire.TTY.Underline, TTY_Emph => Alire.TTY.Emph); + Unset : constant String := "unset"; + -- Canary for text switches that can be both ungiven, given without value, + -- and given with value. + end Alr.Commands; diff --git a/testsuite/drivers/asserts.py b/testsuite/drivers/asserts.py index 5097fec4..9515d5b9 100644 --- a/testsuite/drivers/asserts.py +++ b/testsuite/drivers/asserts.py @@ -53,13 +53,17 @@ def assert_contents(dir: str, expected, regex: str = ""): def assert_match(expected_re, actual, label=None, flags=re.S): - if not re.match(expected_re, actual, flags=flags): - text = ['Unexpected {}'.format(label or 'output'), - 'Expecting a match on:', - indent(expected_re), - 'But got:', - indent(actual)] - assert False, '\n'.join(text) + try: + if not re.match(expected_re, actual, flags=flags): + text = ['Unexpected {}'.format(label or 'output'), + 'Expecting a match on:', + indent(expected_re), + 'But got:', + indent(actual)] + assert False, '\n'.join(text) + except re.error as e: + print(f"Invalid regex at assert_match: {expected_re}", file=sys.stderr) + raise def assert_profile(profile: str, crate: str, root: str = "."): @@ -112,4 +116,16 @@ def assert_in_file(path : str, expected : str): with open(path, "r") as f: contents = f.read() assert expected in contents, \ - f"Missing expected string '{expected}' in file {path}:\n{contents}" \ No newline at end of file + f"Missing expected string '{expected}' in file {path}:\n{contents}" + + +def match_deploy_dir(crate : str, path_fragment : str): + """ + Check that a deployment directory for a crate matches a regex. The path + fragment must be anything between the variable name and the crate name in + the output of printenv, e.g.: MAKE_ALIRE_PREFIX= + """ + p = run_alr("printenv") + assert_match(f".*[: ]{crate.upper()}_ALIRE_PREFIX=[^\\n]*" + f"{re.escape(path_fragment)}[^\\n]*{crate}_.*", + p.out) -- 2.39.5