diff --git a/alire.gpr b/alire.gpr index 15bb12d4..e782307e 100644 --- a/alire.gpr +++ b/alire.gpr @@ -1,3 +1,4 @@ +with "condtrees"; with "semantic_versioning"; with "simple_logging"; diff --git a/index/alire-index-example_dependencies.ads b/index/alire-index-example_dependencies.ads new file mode 100644 index 00000000..0ac22ae1 --- /dev/null +++ b/index/alire-index-example_dependencies.ads @@ -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; diff --git a/src/alire-index.ads b/src/alire-index.ads index 0b25dff1..d75ce919 100644 --- a/src/alire-index.ads +++ b/src/alire-index.ads @@ -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 diff --git a/src/alire-platform.ads b/src/alire-platform.ads index f46a0d4a..899b2d65 100644 --- a/src/alire-platform.ads +++ b/src/alire-platform.ads @@ -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; diff --git a/src/alire-properties-platform.ads b/src/alire-properties-platform.ads new file mode 100644 index 00000000..d469eb36 --- /dev/null +++ b/src/alire-properties-platform.ads @@ -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; diff --git a/src/alire-properties.ads b/src/alire-properties.ads index 541bfb3e..2f4bee9b 100644 --- a/src/alire-properties.ads +++ b/src/alire-properties.ads @@ -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; diff --git a/src/alire-releases.ads b/src/alire-releases.ads index ac47064a..17485795 100644 --- a/src/alire-releases.ads +++ b/src/alire-releases.ads @@ -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 diff --git a/src/alire-requisites-platform.ads b/src/alire-requisites-platform.ads new file mode 100644 index 00000000..c4808159 --- /dev/null +++ b/src/alire-requisites-platform.ads @@ -0,0 +1,5 @@ +package Alire.Requisites.Platform with Preelaborate is + + + +end Alire.Requisites.Platform; diff --git a/src/alire-requisites.ads b/src/alire-requisites.ads index ccf02047..4abce556 100644 --- a/src/alire-requisites.ads +++ b/src/alire-requisites.ads @@ -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;