diff --git a/.gitmodules b/.gitmodules index 879f8c809..f150d0ee9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -57,9 +57,6 @@ [submodule "deps/dirty_booleans"] path = deps/dirty_booleans url = https://github.com/mosteo/dirty_booleans -[submodule "deps/compare_to_case"] - path = deps/compare_to_case - url = https://github.com/mosteo/compare_to_case [submodule "deps/den"] path = deps/den url = https://github.com/mosteo/den diff --git a/alire.toml b/alire.toml index 81d4840df..66e590be1 100644 --- a/alire.toml +++ b/alire.toml @@ -21,7 +21,6 @@ ajunitgen = "^1.0.1" ansiada = "^1.1" c_strings = "^1.0" clic = "~0.3" -compare_to_case = "~0.1" den = "~0.1" dirty_booleans = "~0.1" diskflags = "~0.1" @@ -72,10 +71,6 @@ commit = "e4d58ad90bf32bc44304197e5906a519f5a9a7bf" url = "https://github.com/alire-project/clic" commit = "56bbdc008e16996b6f76e443fd0165a240de1b13" -[pins.compare_to_case] -url = "https://github.com/mosteo/compare_to_case" -commit = "7934e319711995cf5960774f938c4d3ab5e0b7b6" - [pins.den] url = "https://github.com/mosteo/den" commit = "653a4c9ba4469d7e1a8896088789b6514ecdf834" diff --git a/deps/compare_to_case b/deps/compare_to_case deleted file mode 160000 index 7934e3197..000000000 --- a/deps/compare_to_case +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7934e319711995cf5960774f938c4d3ab5e0b7b6 diff --git a/src/alire/alire-solver.adb b/src/alire/alire-solver.adb index ae9ae5860..d4f86cc9e 100644 --- a/src/alire/alire-solver.adb +++ b/src/alire/alire-solver.adb @@ -9,12 +9,11 @@ with Alire.Platforms.Current; with Alire.Releases.Containers; with Alire.Root; with Alire.Toolchains; +with Alire.Utils.Comparisons; with Alire.Utils.TTY; with CLIC.User_Input; -with Compare_To_Case; - with Stopwatch; with System.Pool_Local; @@ -430,14 +429,14 @@ package body Alire.Solver is -- the number of remaining unsolved dependencies as the heuristic. function Is_Better (L, R : in out Search_State) return Boolean is - use all type Compare_To_Case.Result; - use all type Compare_To_Case.Bool_Result; + use all type Utils.Comparisons.Result; + use all type Utils.Comparisons.Bool_Result; use type Alire.Solutions.Compositions; function Compare is - new Compare_To_Case.Compare (Alire.Solutions.Compositions); + new Utils.Comparisons.Compare (Alire.Solutions.Compositions); function Compare is - new Compare_To_Case.Compare (Natural); + new Utils.Comparisons.Compare (Natural); LS : Solution renames L.Solution; RS : Solution renames R.Solution; @@ -446,7 +445,7 @@ package body Alire.Solver is -- Preferred_Compiler -- ------------------------ - function Preferred_Compiler return Compare_To_Case.Result is + function Preferred_Compiler return Utils.Comparisons.Result is function L_GNAT return Release is (LS.Releases_Providing (GNAT_Crate).First_Element); @@ -458,7 +457,7 @@ package body Alire.Solver is ----------------------- function Preferred_Version (L, R : Semver.Version) - return Compare_To_Case.Result + return Utils.Comparisons.Result is use type Semver.Version; begin @@ -472,6 +471,8 @@ package body Alire.Solver is end if; end Preferred_Version; + use Utils; + begin -- Preferred compiler order is, according to our docs and tests: -- - No specific compiler at all @@ -484,7 +485,7 @@ package body Alire.Solver is -- - No specific compiler at all - case Compare_To_Case.Which_One + case Comparisons.Which_One (LS.Releases_Providing (GNAT_Crate).Is_Empty, RS.Releases_Providing (GNAT_Crate).Is_Empty) is @@ -499,7 +500,7 @@ package body Alire.Solver is -- - The selected compiler, if defined if Selected_Compiler.Exists then - case Compare_To_Case.Which_One + case Comparisons.Which_One (LS.Contains (Selected_Compiler.Milestone), RS.Contains (Selected_Compiler.Milestone)) is @@ -512,7 +513,7 @@ package body Alire.Solver is -- Prefer external compilers - case Compare_To_Case.Which_One + case Comparisons.Which_One (not LS.Releases_Providing (GNAT_Crate).Is_Empty and then not L_GNAT.Origin.Is_Index_Provided, not RS.Releases_Providing (GNAT_Crate).Is_Empty and then @@ -530,7 +531,7 @@ package body Alire.Solver is -- Prefer newest installed native compiler - case Compare_To_Case.Which_One + case Comparisons.Which_One (LS.Contains_Release (GNAT_Native_Crate) and then Tools.Contains (L_GNAT) , @@ -551,7 +552,7 @@ package body Alire.Solver is -- Prefer newest installed any (cross) compiler - case Compare_To_Case.Which_One + case Comparisons.Which_One (not LS.Releases_Providing (GNAT_Crate).Is_Empty and then Tools.Contains (L_GNAT) , @@ -576,7 +577,7 @@ package body Alire.Solver is -- Prefer native compiler - case Compare_To_Case.Which_One + case Comparisons.Which_One (L.Solution.Contains_Release (GNAT_Native_Crate), R.Solution.Contains_Release (GNAT_Native_Crate)) is @@ -593,7 +594,7 @@ package body Alire.Solver is -- Prefer newest installed any (cross) compiler - case Compare_To_Case.Which_One + case Comparisons.Which_One (not LS.Releases_Providing (GNAT_Crate).Is_Empty, not RS.Releases_Providing (GNAT_Crate).Is_Empty) is @@ -611,6 +612,8 @@ package body Alire.Solver is return Equal; end Preferred_Compiler; + use Utils; + begin -- TODO: all the following comparisons will be performed N log @@ -625,7 +628,7 @@ package body Alire.Solver is -- Prefer states that might lead to a complete solution (those -- include states that already are completely explored). - case Compare_To_Case.Which_One + case Comparisons.Which_One (Is_Potentially_Complete (L), Is_Potentially_Complete (R)) is @@ -686,7 +689,7 @@ package body Alire.Solver is -- All else being equal, the best solution is preferred - case Compare_To_Case.Which_One + case Comparisons.Which_One (L.Solution.Is_Better (R.Solution), R.Solution.Is_Better (L.Solution)) is diff --git a/src/alire/alire-utils-comparisons.ads b/src/alire/alire-utils-comparisons.ads new file mode 100644 index 000000000..7775acf26 --- /dev/null +++ b/src/alire/alire-utils-comparisons.ads @@ -0,0 +1,50 @@ +package Alire.Utils.Comparisons with Preelaborate is + + type Result is (Left, Equal, Right); + + type Bool_Result is (Left, Right, None, Both); + + ------------- + -- Compare -- + ------------- + + generic + type Comparable (<>) is limited private; + with function "<" (L, R : Comparable) return Boolean is <>; + function Compare (L, R : Comparable) return Result + with Post => Compare'Result = + (if L < R + then Left + else (if R < L + then Right + else Equal)); + + --------------- + -- Which_One -- + --------------- + + function Which_One (L, R : Boolean) return Bool_Result + is (if L and then not R then + Left + elsif R and then not L then + Right + elsif L then + Both + else + None); + +private + + ------------- + -- Compare -- + ------------- + + function Compare (L, R : Comparable) return Result + is (if L < R then + Left + elsif R < L then + Right + else + Equal); + +end Alire.Utils.Comparisons;