Condition trees setup

This commit is contained in:
Jano at Zelda
2018-02-12 13:47:43 +01:00
parent 518fb55d50
commit b202121f66
9 changed files with 133 additions and 16 deletions
+1
View File
@@ -1,3 +1,4 @@
with "condtrees";
with "semantic_versioning";
with "simple_logging";
@@ -0,0 +1,15 @@
with Alire.Repositories.Local;
with Alire.Requisites;
with Alire.Properties.Platform;
package Alire.Index.Example_Dependencies is
V_1_0_0 : constant Release :=
Register ("example_dependencies",
V ("1.0.0"),
Repositories.Local.Repo,
Repositories.Local.Local_Id,
Properties => Default_Properties and Available_On (GNU_Linux),
Requisites => No_Requisites and (No_Requisites or No_Requisites));
end Alire.Index.Example_Dependencies;
+29 -1
View File
@@ -1,7 +1,11 @@
with Alire.Containers;
with Alire.Depends;
with Alire.Platform;
with Alire.Properties;
with Alire.Properties.Platform;
with Alire.Releases;
with Alire.Repositories.Git;
with Alire.Requisites;
with Semantic_Versioning;
@@ -27,7 +31,9 @@ package Alire.Index is
Hosting : Repositories.Repository'Class;
Id : Repositories.Release_Id;
Depends_On : Dependencies := Depends.Nothing;
Native : Boolean := False) return Release;
Properties : Alire.Properties.Vector := Alire.Properties.Property_Vectors.Empty_Vector;
Requisites : Alire.Requisites.Tree := Alire.Requisites.No_Requisites;
Native : Boolean := False) return Release;
function Register_Git (Project : Project_Name;
Version : Semantic_Versioning.Version;
@@ -57,6 +63,28 @@ package Alire.Index is
function More_Than (P : Project_Name; V : Version) return Dependencies;
function Exactly (P : Project_Name; V : Version) return Dependencies;
function Except (P : Project_Name; V : Version) return Dependencies;
-- Shortcuts for properties/requisites:
use all type Platform.Operating_Systems;
use all type Properties.Property'Class; -- for "and" operator
use all type Requisites.Tree; -- for logical operators
Default_Properties : constant Properties.Vector := Properties.Property_Vectors.Empty_Vector;
No_Requisites : constant Requisites.Tree := Requisites.No_Requisites;
function Verifies (P : Properties.Property'Class) return Properties.Vector;
function "+" (P : Properties.Property'Class) return Properties.Vector renames Verifies;
function Require (R : Requisites.Requisite'Class) return Requisites.Tree;
function "+" (R : Requisites.Requisite'Class) return Requisites.Tree renames Require;
-- Specific shortcuts:
function Available_On (V : Alire.Platform.Operating_Systems) return Properties.Property'Class
renames Properties.Platform.Available_On;
function Compiles_With (C : Alire.Platform.Compilers) return Properties.Property'Class
renames Properties.Platform.Compiles_With;
private
+7 -7
View File
@@ -1,13 +1,13 @@
package Alire.Platform with Preelaborate is
type Operating_Systems is (Unknown,
Linux,
-- OSs supported by a release
type Operating_Systems is (Cross_Platform,
GNU_Linux,
Windows);
type Compilers is (Unknown,
GNAT_GPL_2017,
GNAT_FSF_7_2);
function Compiler return Compilers is (Unknown);
-- Compilers known to compile a release
type Compilers is (GNAT_Any,
GNAT_FSF_7_2,
GNAT_GPL_2017);
end Alire.Platform;
+20
View File
@@ -0,0 +1,20 @@
with Alire.Platform;
package Alire.Properties.Platform with Preelaborate is
package Compilers is new Values (Alire.Platform.Compilers);
package Operating_Systems is new Values (Alire.Platform.Operating_Systems);
function Available_On (V : Alire.Platform.Operating_Systems) return Property'Class;
function Compiles_With (C : Alire.Platform.Compilers) return Property'Class;
private
function Available_On (V : Alire.Platform.Operating_Systems) return Property'Class is
(Operating_Systems.New_Property (V));
function Compiles_With (C : Alire.Platform.Compilers) return Property'Class is
(Compilers.New_Property (C));
end Alire.Properties.Platform;
+28 -1
View File
@@ -9,10 +9,37 @@ package Alire.Properties with Preelaborate is
-- multiple inheritance for the simplest design.
-- Instead, a first check of matching tags is done and then the checks can proceed.
type Property is tagged null record;
type Property is interface;
package Property_Vectors is new Ada.Containers.Indefinite_Vectors (Positive, Property'Class);
subtype Vector is Property_Vectors.Vector;
function "and" (L, R : Property'Class) return Vector;
function "and" (L : Vector; R : Property'Class) return Vector;
-- A generic helper to simply store/retrieve e.g. an enumerated type
generic
type Value is private;
package Values is
type Property (<>) is new Properties.Property with private;
function New_Property (V : Value) return Property;
function Element (P : Property) return Value;
private
type Property is new Properties.Property with record
V : Value;
end record;
function New_Property (V : Value) return Property is (V => V);
function Element (P : Property) return Value is (P.V);
end Values;
end Alire.Properties;
+10
View File
@@ -1,5 +1,7 @@
with Alire.Depends;
with Alire.Properties;
with Alire.Repositories;
with Alire.Requisites;
package Alire.Releases
with Preelaborate
@@ -14,6 +16,8 @@ is
Repository : Repositories.Repository'Class;
Id : Repositories.Release_Id;
Depends_On : Dependencies;
Properties : Alire.Properties.Vector;
Requisites : Alire.Requisites.Tree;
Native : Boolean) return Release;
function "<" (L, R : Release) return Boolean;
@@ -45,6 +49,8 @@ private
Repository : Repositories.Repository_H;
Id : Repositories.Release_Id (1 .. Id_Len);
Depends_On : Dependencies;
Props : Properties.Vector;
Reqs : Requisites.Tree;
Native : Boolean;
end record;
@@ -53,6 +59,8 @@ private
Repository : Repositories.Repository'Class;
Id : Repositories.Release_Id;
Depends_On : Dependencies;
Properties : Alire.Properties.Vector;
Requisites : Alire.Requisites.Tree;
Native : Boolean) return Release is
(Project'Length, Id'Length,
Project,
@@ -60,6 +68,8 @@ private
Repositories.To_Holder (Repository),
Id,
Depends_On,
Properties,
Requisites,
Native);
function "<" (L, R : Release) return Boolean is
+5
View File
@@ -0,0 +1,5 @@
package Alire.Requisites.Platform with Preelaborate is
end Alire.Requisites.Platform;
+18 -7
View File
@@ -1,7 +1,7 @@
with Ada.Containers.Indefinite_Multiway_Trees;
with Alire.Properties;
with Condtrees;
package Alire.Requisites with Preelaborate is
use Properties;
@@ -14,10 +14,6 @@ package Alire.Requisites with Preelaborate is
function Is_Applicable (R : Requisite; P : Property'Class) return Boolean is (False);
-- Initially there is no compatibility. See helper package below
package Requisite_Trees is new Ada.Containers.Indefinite_Multiway_Trees (Requisite'Class);
subtype Tree is Requisite_Trees.Tree;
-- The following package is the building block to be used to define new compatibility checks.
-- Here we tie a class of properties and requisites (e.g., versions and version sets) that make sense.
-- A release has a list of properties, and a tree of requisites to be applied to potential dependencies.
@@ -26,7 +22,8 @@ package Alire.Requisites with Preelaborate is
type Compatible_Property is new Property with private;
package Property_Checker is
type Requisite is abstract new Requisites.Requisite with null record;
type Requisite is Abstract
new Requisites.Requisite with null record;
function Is_Satisfied (R : Requisite; P : Compatible_Property) return Boolean is abstract;
-- This is the important function to override by Requisite implementations
@@ -44,4 +41,18 @@ package Alire.Requisites with Preelaborate is
end Property_Checker;
-- Trees of requisites to be matched against a list of properties in a release
function Satisfies (R : Requisite'Class; P : Properties.Vector) return Boolean;
-- True if any of the properties in the vector satisfies the requisite
package Requisite_Trees is new Condtrees (Properties.Vector,
Requisite'Class,
Satisfies);
subtype Tree is Requisite_Trees.Tree;
function No_Requisites return Requisite_Trees.Tree is (Requisite_Trees.Empty_Tree);
-- Function instead of constant to keep Preelaborate
end Alire.Requisites;