From a676dcb9eb3a9a6448b7c4b22d3383c689ed847c Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Thu, 8 Mar 2018 15:22:53 +0100 Subject: [PATCH] Experiments on conditional availability --- index/native/alire-index-adacurses.ads | 27 +++++++++ index/native/alire-index-native_template.ads | 13 +++++ index/native/alire-index-ncursesada.ads | 26 +++++++++ src/alire-index.adb | 2 +- src/alire-index.ads | 59 +++++++++----------- src/alire-releases.adb | 5 +- src/alire-requisites-booleans.ads | 16 ++++++ src/alire-requisites-platform.ads | 9 +++ src/alire-requisites.ads | 47 ++++++++++------ 9 files changed, 152 insertions(+), 52 deletions(-) create mode 100644 index/native/alire-index-adacurses.ads create mode 100644 index/native/alire-index-native_template.ads create mode 100644 index/native/alire-index-ncursesada.ads create mode 100644 src/alire-requisites-booleans.ads diff --git a/index/native/alire-index-adacurses.ads b/index/native/alire-index-adacurses.ads new file mode 100644 index 00000000..dbb114ec --- /dev/null +++ b/index/native/alire-index-adacurses.ads @@ -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; diff --git a/index/native/alire-index-native_template.ads b/index/native/alire-index-native_template.ads new file mode 100644 index 00000000..461dda82 --- /dev/null +++ b/index/native/alire-index-native_template.ads @@ -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; diff --git a/index/native/alire-index-ncursesada.ads b/index/native/alire-index-ncursesada.ads new file mode 100644 index 00000000..90089d2b --- /dev/null +++ b/index/native/alire-index-ncursesada.ads @@ -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; diff --git a/src/alire-index.adb b/src/alire-index.adb index 0b1fb437..423d2a72 100644 --- a/src/alire-index.adb +++ b/src/alire-index.adb @@ -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 diff --git a/src/alire-index.ads b/src/alire-index.ads index ac23afe6..52c9d466 100644 --- a/src/alire-index.ads +++ b/src/alire-index.ads @@ -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 -- diff --git a/src/alire-releases.adb b/src/alire-releases.adb index b479ad53..347b33fa 100644 --- a/src/alire-releases.adb +++ b/src/alire-releases.adb @@ -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; diff --git a/src/alire-requisites-booleans.ads b/src/alire-requisites-booleans.ads new file mode 100644 index 00000000..9765688e --- /dev/null +++ b/src/alire-requisites-booleans.ads @@ -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; diff --git a/src/alire-requisites-platform.ads b/src/alire-requisites-platform.ads index ab56ecea..76b04543 100644 --- a/src/alire-requisites-platform.ads +++ b/src/alire-requisites-platform.ads @@ -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; diff --git a/src/alire-requisites.ads b/src/alire-requisites.ads index d7cc4734..fb01d960 100644 --- a/src/alire-requisites.ads +++ b/src/alire-requisites.ads @@ -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;