Experiments on conditional availability

This commit is contained in:
Alejandro R Mosteo
2018-03-08 15:22:53 +01:00
parent 68e9182483
commit a676dcb9eb
9 changed files with 152 additions and 52 deletions
+27
View File
@@ -0,0 +1,27 @@
with Alire.Index.NcursesAda;
package Alire.Index.Adacurses is
Name : constant String := "adacurses";
Desc : constant String := "Wrapper on different packagings of NcursesAda";
Repo : constant String := "https://github.com/alire-project/adacurses-wrapper.git";
V_6 : constant Release :=
Register (Name,
V ("6.0+20170708-2"),
Desc,
Git (Repo, "4ccb20409becb50c0b5fd29effb676b650608326"),
Dependencies =>
On_Condition
(Distribution_Is (Debian) or Distribution_Is (Ubuntu),
When_True => When_Available (Within_Major (NcursesAda.V_5)),
When_False => Unavailable),
Properties =>
Comment ("AdaCurses is the project name used by upstream, thus adacurses.gpr") and
Comment ("However, some distros (e.g., Debian family) use ncursesada.gpr") and
Comment ("This package wraps these differences so clients can always safely use adacurses")
);
end Alire.Index.Adacurses;
@@ -0,0 +1,13 @@
package Alire.Index.Native_Template is
-- Name : constant String := "";
-- Desc : constant String := "";
--
-- V : constant Release :=
-- Register (Name,
-- V (""),
-- Desc,
-- Native ((Debian | Ubuntu => Packaged_As (""),
-- others => Unavailable)));
end Alire.Index.Native_Template;
+26
View File
@@ -0,0 +1,26 @@
package Alire.Index.NcursesAda is
Name : constant String := "ncursesada";
Desc : constant String := "Ada binding to the ncurses text interface library";
V_5 : constant Release :=
Register (Name,
V ("5.0.0+6.0.20170708-2"),
Desc,
Native ((Debian | Ubuntu => Packaged_As ("libncursesada5-dev"),
others => Unavailable)),
Available_When => Compiler_Is_Native
-- Unfortunately packaged libs can't be used with non-platform compilers due to .ali clashes
);
V_3 : constant Release :=
Register (Name,
V ("3.0.0+5.9.20140726-1build1"),
Desc,
Native ((Debian | Ubuntu => Packaged_As ("libncursesada3-dev"),
others => Unavailable)),
Available_When => Compiler_Is_Native);
end Alire.Index.NcursesAda;
+1 -1
View File
@@ -52,7 +52,7 @@ package body Alire.Index is
-- Optional
Dependencies : Release_Dependencies := No_Dependencies;
Properties : Release_Properties := No_Properties;
Private_Properties : Build_Properties := No_Properties;
Private_Properties : Release_Properties := No_Properties;
Available_When : Alire.Requisites.Tree := No_Requisites)
return Release
is
+26 -33
View File
@@ -32,16 +32,9 @@ package Alire.Index is
-- Index types --
-----------------
subtype Release_Dependencies is Conditional.Dependencies;
subtype Release_Properties is Conditional.Properties;
Subtype Build_Properties is Conditional.Properties;
-- We separate properties of a release in two sets:
-- Properties that are of interest to the user of a project,
-- and properties that concern only the alr packaging.
-- This is purely for reading clarity. Only GPR_Config at this time belongs to the latter set
-- Unfortunately it would be too much a hassle to have separate types for those, so this is only
-- checked at runtime. I'm not sure that this separation is really useful yet anyway.
subtype Release_Dependencies is Conditional.Dependencies;
subtype Release_Properties is Conditional.Properties;
subtype Release_Requisites is Requisites.Tree;
No_Dependencies : constant Release_Dependencies := Conditional.For_Dependencies.Empty;
No_Properties : constant Release_Properties := Conditional.For_Properties.Empty;
@@ -50,17 +43,17 @@ package Alire.Index is
subtype Release is Alire.Releases.Release;
function Register (-- Mandatory
Project : Project_Name;
Version : Semantic_Versioning.Version;
Description : Project_Description;
Origin : Origins.Origin;
Project : Project_Name;
Version : Semantic_Versioning.Version;
Description : Project_Description;
Origin : Origins.Origin;
-- we force naming beyond this point with this ugly guard:
XXXXXXXXXXXXXX : Utils.XXX_XXX := Utils.XXX_XXX_XXX;
XXXXXXXXXXXXXX : Utils.XXX_XXX := Utils.XXX_XXX_XXX;
-- Optional
Dependencies : Release_Dependencies := No_Dependencies;
Properties : Release_Properties := No_Properties;
Private_Properties : Build_Properties := No_Properties;
Available_When : Alire.Requisites.Tree := No_Requisites)
Dependencies : Release_Dependencies := No_Dependencies;
Properties : Release_Properties := No_Properties;
Private_Properties : Release_Properties := No_Properties;
Available_When : Release_Requisites := No_Requisites)
return Release;
-- Properties are generally interesting to the user
-- Private_Properties are only interesting to alr
@@ -108,7 +101,7 @@ package Alire.Index is
package Semver renames Semantic_Versioning;
function V (Semantic_Version : String) return Semver.Version
renames Semver.New_Version;
renames Semver.Relaxed;
function On (Name : Project_Name;
Versions : Semver.Version_Set)
@@ -237,21 +230,21 @@ package Alire.Index is
------------------
-- REQUISITES --
------------------
function Compiler_Is (V : Platforms.Compilers) return Requisites.Tree
renames Requisites.Platform.Compiler_Is;
function Distribution_Is (V : Platforms.Distributions) return Requisites.Tree
renames Requisites.Platform.Distribution_Is;
function System_Is (V : Platforms.Operating_Systems) return Requisites.Tree
renames Requisites.Platform.System_Is;
function Version_is (V : Platforms.Versions) return Requisites.Tree
renames Requisites.Platform.Version_Is;
package Plat_Reqs renames Requisites.Platform;
function Compiler_Is_Native return Release_Requisites renames Plat_Reqs.Compiler_Is_Native;
function Compiler_Is (V : Platforms.Compilers) return Release_Requisites renames Plat_Reqs.Compiler_Is;
function Compiler_Less_Than (V : Platforms.Compilers) return Release_Requisites renames Plat_Reqs.Compiler_Less_Than;
function Compiler_At_Least (V : Platforms.Compilers) return Release_Requisites is (not Compiler_Less_Than (V));
function Distribution_Is (V : Platforms.Distributions) return Release_Requisites renames Plat_Reqs.Distribution_Is;
function System_Is (V : Platforms.Operating_Systems) return Release_Requisites renames Plat_Reqs.System_Is;
function Word_Size_Is (V : Platforms.Word_Sizes) return Requisites.Tree
renames Requisites.Platform.Word_Size_Is;
function Version_is (V : Platforms.Versions) return Release_Requisites renames Plat_Reqs.Version_Is;
function Word_Size_Is (V : Platforms.Word_Sizes) return Release_Requisites renames Plat_Reqs.Word_Size_Is;
----------------------
-- Set_Root_Project --
+4 -1
View File
@@ -1,5 +1,6 @@
with Alire.Conditional_Values;
with Alire.Platforms;
with Alire.Requisites.Booleans;
with GNAT.IO; -- To keep preelaborable
@@ -250,7 +251,9 @@ package body Alire.Releases is
R.Dependencies.Evaluate (P),
R.Properties.Evaluate (P),
R.Priv_Props.Evaluate (P),
R.Available)
(if R.Available.Check (P)
then Requisites.Booleans.Always_True
else Requisites.Booleans.Always_False))
do
null;
end return;
+16
View File
@@ -0,0 +1,16 @@
package Alire.Requisites.Booleans with Preelaborate is
type Requisite_True is new Requisite with null record;
type Requisite_False is new Requisite with null record;
function Satisfies (R : Requisite_True; P : Property'Class) return Boolean is (True);
function Image (R : Requisite_True) return String is ("True");
function Satisfies (R : Requisite_False; P : Property'Class) return Boolean is (False);
function Image (R : Requisite_False) return String is ("False");
function Always_True return Tree is (Trees.Leaf (Requisite_True'(null record)));
function Always_False return Tree is (Trees.Leaf (Requisite_False'(null record)));
end Alire.Requisites.Booleans;
+9
View File
@@ -5,9 +5,18 @@ package Alire.Requisites.Platform with Preelaborate is
package Plat renames Properties.Platform;
use all type Platforms.Compilers;
use all type Tree;
package Compilers is new Requisites.For_Value_Property (Plat.Compilers, "Compiler");
function Compiler_Is (V : Platforms.Compilers) return Tree renames Compilers.New_Equality;
package Compilers_Less is new Compilers.Comparators (Platforms."<", "<");
function Compiler_Less_Than (V : Platforms.Compilers) return Tree renames Compilers_Less.New_Comparator;
function Compiler_Is_Native return Tree is
(Compiler_Less_Than (GNAT_GPL_2017) and not Compiler_Is (GNAT_Unknown));
package Distributions is new Requisites.For_Value_Property (Plat.Distributions, "Distribution");
function Distribution_Is (V : Platforms.Distributions) return Tree renames Distributions.New_Equality;
+30 -17
View File
@@ -88,28 +88,15 @@ package Alire.Requisites with Preelaborate is
package Value_Requisites is new For_Property (Values.Property);
type Equality is new Value_Requisites.Requisite with private;
function New_Equality (V : Values.Value) return Tree;
overriding function Is_Satisfied (R : Equality;
P : Values.Property)
return Boolean;
overriding function Image (R : Equality)
return String;
private
function Mix (S : String) return String renames Utils.To_Mixed_Case;
use all type Values.Value;
type Equality is new Value_Requisites.Requisite with record
Value : Values.Value;
end record;
function New_Equality (V : Values.Value) return Tree is
(Trees.Leaf (Equality'(Value => V)));
(Trees.Leaf (Equality'(Value => V)));
function Mix (S : String) return String renames Utils.To_Mixed_Case;
use all type Values.Value;
overriding function Is_Satisfied (R : Equality; P : Values.Property) return Boolean is
(R.Value = P.Element);
@@ -117,6 +104,32 @@ package Alire.Requisites with Preelaborate is
overriding function Image (R : Equality) return String is
(Name & " is " & Mix (Values.Image (R.Value)));
-----------------
-- Comparators --
-----------------
generic
with function Compare (L, R : Values.Value) return Boolean;
Image_Of_Compare : String; -- e.g., "<"
package Comparators is
type Comparator is new Value_Requisites.Requisite with record
Value : Values.Value;
end record;
function New_Comparator (V : Values.Value) return Tree is (Trees.Leaf (Comparator'(Value => V)));
overriding function Is_Satisfied (R : Comparator;
P : Values.Property)
return Boolean is
(Compare (P.Element, R.Value));
overriding function Image (R : Comparator)
return String is
(Name & " " & Image_Of_Compare & " " & Mix (Values.Image (R.Value)));
end Comparators;
end For_Value_Property;
end Alire.Requisites;