Skip to content

Commit

Permalink
Remove dependency on compare_to_case
Browse files Browse the repository at this point in the history
  • Loading branch information
mosteo committed Nov 22, 2024
1 parent b487316 commit d12d420
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 29 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion alire.gpr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ with "ajunitgen";
with "ansiada";
with "c_strings";
with "clic";
with "compare_to_case";
with "den";
with "dirty_booleans";
with "diskflags";
Expand Down
5 changes: 0 additions & 5 deletions alire.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion deps/compare_to_case
Submodule compare_to_case deleted from 7934e3
4 changes: 2 additions & 2 deletions src/alire/alire-meta.ads
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package Alire.Meta with Preelaborate is

package Working_Tree is

Commit : constant String := "unknown";
Changes : constant String := "unknown";
Commit : constant String := "c3dade93403aaacec59097e450a22ce83e0ceb0f";
Changes : constant String := "dirty";

end Working_Tree;

Expand Down
37 changes: 20 additions & 17 deletions src/alire/alire-solver.adb
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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
Expand 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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
,
Expand All @@ -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)
,
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
50 changes: 50 additions & 0 deletions src/alire/alire-utils-comparisons.ads
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit d12d420

Please sign in to comment.