From 8ddac311656dcda2e79203d87d2bbb2cb4cf0f15 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Fri, 9 Mar 2018 10:32:30 +0100 Subject: [PATCH] Better expression requisites --- index/alire-index-adacurses.ads | 4 +- index/alire-index-alire.ads | 19 ++++----- index/alire-index-dak.ads | 8 ++-- index/alire-index-libadacrypt.ads | 6 +-- index/alire-index-openglada.ads | 6 +-- index/alire-index-sdlada.ads | 4 +- index/alire-index-whitakers_words.ads | 2 +- src/alire-gpr.adb | 6 +-- src/alire-index.ads | 24 +++++------ src/alire-requisites-comparables.ads | 14 ++++-- src/alire-requisites-platform.ads | 51 +++++++++++++--------- src/alire-requisites.ads | 61 --------------------------- 12 files changed, 79 insertions(+), 126 deletions(-) diff --git a/index/alire-index-adacurses.ads b/index/alire-index-adacurses.ads index 7161d2e4..3494957c 100644 --- a/index/alire-index-adacurses.ads +++ b/index/alire-index-adacurses.ads @@ -19,7 +19,7 @@ package Alire.Index.Adacurses is Dependencies => On_Condition - (Distribution_Is (Debian) or Distribution_Is (Ubuntu), + (Distribution = Debian or Distribution = Ubuntu, When_True => When_Available (Within_Major (NcursesAda.V_5)), When_False => Unavailable), @@ -35,7 +35,7 @@ package Alire.Index.Adacurses is Dependencies => On_Condition - (Distribution_Is (Debian) or Distribution_Is (Ubuntu), + (Distribution = Debian or Distribution = Ubuntu, When_True => When_Available (Within_Major (NcursesAda.V_3)), When_False => Unavailable), diff --git a/index/alire-index-alire.ads b/index/alire-index-alire.ads index bd8a0830..b71557cf 100644 --- a/index/alire-index-alire.ads +++ b/index/alire-index-alire.ads @@ -28,7 +28,7 @@ package Alire.Index.Alire is Dependencies => Current ("half_life_3") and -- unconditional On_Condition -- conditional - (System_Is (GNU_Linux), + (Operating_System = GNU_Linux, When_True => At_Least ("elite_horizons", V ("2.0")) and At_Least ("star_citizen", V ("3.0")), -- Wish... When_False => At_Least ("windows_100", V ("1.0"))) and @@ -55,26 +55,26 @@ package Alire.Index.Alire is -- Path separators are always "/" and internally converted to native ones On_Condition - (System_Is (Windows), + (Operating_System = Windows, GPR_File ("project_win.gpr")) and On_Condition - (System_Is (GNU_Linux), - On_Condition (Distribution_Is (Ubuntu), -- Nested conditions + (Operating_System = GNU_Linux, + On_Condition (Distribution = Ubuntu, -- Nested conditions GPR_File ("project_ubuntu.gpr"))) and -- Conditional project file On_Condition - (System_Is (GNU_Linux), + (Operating_System = GNU_Linux, Comment ("Long life the penguin")) and -- Conditions on operating system On_Condition - (not Compiler_Is (GNAT_Unknown), + (Compiler = GNAT_Unknown, -- /= also works Comment ("Never saw that compiler") and Comment ("But I would like to")) and -- Conditions on compiler version On_Condition - (Version_Is (Ubuntu_Artful), + (Distro_Release = Ubuntu_Artful, When_True => Comment ("Living on the edge"), When_False => Comment ("I am a rock")) and -- Conditions on distribution release @@ -84,8 +84,7 @@ package Alire.Index.Alire is -- Unconditional properties Available_When => -- Impossible mix - OS = GNU_Linux or OS /= GNU_Linux or - (System_Is (Windows) and System_Is (GNU_Linux)) or - (Compiler_Is (GNAT_Unknown) and not Compiler_Is (GNAT_Unknown))); + (Operating_System = Windows and Operating_System /= GNU_Linux) or + (Compiler = GNAT_Unknown and Compiler /= GNAT_Unknown)); end Alire.Index.Alire; diff --git a/index/alire-index-dak.ads b/index/alire-index-dak.ads index cf10f636..46ea0f39 100644 --- a/index/alire-index-dak.ads +++ b/index/alire-index-dak.ads @@ -279,16 +279,16 @@ package Alire.Index.DAK is GPR_File ("test_components/components-odbc-odbc_bindings_tests.gpr") and On_Condition - (System_Is (GNU_Linux), + (Operating_System = GNU_Linux, GPR_External ("odbc", "unixODBC")) and On_Condition - (System_Is (Windows), + (Operating_System = Windows, GPR_External ("odbc", "ODBC32")) and On_Condition - (Word_Size_Is (Bits_32), + (Word_Size = Bits_32, GPR_External ("arch", "i686")) and On_Condition - (Word_Size_Is (Bits_64), + (Word_Size = Bits_64, GPR_External ("arch", "x86_64")) ); diff --git a/index/alire-index-libadacrypt.ads b/index/alire-index-libadacrypt.ads index 49e2fe6d..ba8cd6c9 100644 --- a/index/alire-index-libadacrypt.ads +++ b/index/alire-index-libadacrypt.ads @@ -36,14 +36,14 @@ package Alire.Index.Libadacrypt is GPR_File ("acltest.gpr") and On_Condition - (System_Is (GNU_Linux), + (Operating_System = GNU_Linux, GPR_External ("system", "unix")) and On_Condition - (System_Is (Windows), + (Operating_System = Windows, GPR_External ("system", "windows")), Available_When => - not Compiler_Is (GNAT_FSF_7_2) + Compiler > GNAT_FSF_7_2 -- It fails self-tests; might be a spureous warning ); diff --git a/index/alire-index-openglada.ads b/index/alire-index-openglada.ads index fc022cd7..933367e1 100644 --- a/index/alire-index-openglada.ads +++ b/index/alire-index-openglada.ads @@ -18,7 +18,7 @@ package Alire.Index.OpenGLAda is Dependencies => On_Condition - (System_Is (GNU_Linux), + (Operating_System = GNU_Linux, Within_Major (Libglfw3.V_3) and Within_Major (LibX11.V_2)), Properties => @@ -49,10 +49,10 @@ package Alire.Index.OpenGLAda is GPR_File ("opengl-test.gpr") and On_Condition - (System_Is (GNU_Linux), GPR_External ("Windowing_System", "x11")), + (Operating_System = GNU_Linux, GPR_External ("Windowing_System", "x11")), Available_When => - System_Is (GNU_Linux) + Operating_System = GNU_Linux ); end Alire.Index.OpenGLAda; diff --git a/index/alire-index-sdlada.ads b/index/alire-index-sdlada.ads index a817843e..161e2cc3 100644 --- a/index/alire-index-sdlada.ads +++ b/index/alire-index-sdlada.ads @@ -54,11 +54,11 @@ package Alire.Index.SDLAda is GPR_External ("SDL_MODE", "release") and On_Condition - (System_Is (GNU_Linux), + (Operating_System = GNU_Linux, GPR_External ("SDL_PLATFORM", "linux")), Available_When => - System_Is (GNU_Linux) + Operating_System = GNU_Linux ); end Alire.Index.SDLAda; diff --git a/index/alire-index-whitakers_words.ads b/index/alire-index-whitakers_words.ads index 2ad0e3f9..e72caedf 100644 --- a/index/alire-index-whitakers_words.ads +++ b/index/alire-index-whitakers_words.ads @@ -32,7 +32,7 @@ package Alire.Index.Whitakers_Words is GPR_File ("words.gpr"), Available_When => - not Compiler_Is (GNAT_FSF_7_2) -- bug with SAL library not binding + Compiler > GNAT_FSF_7_2 -- bug with SAL library failing binding ); end Alire.Index.Whitakers_Words; diff --git a/src/alire-gpr.adb b/src/alire-gpr.adb index 97edaa85..cc9912bd 100644 --- a/src/alire-gpr.adb +++ b/src/alire-gpr.adb @@ -21,11 +21,11 @@ package body Alire.GPR is begin case V.Kind is when Free_String => - return V.Name & " = "; + return V.Name & " := "; when Enumeration => - return V.Name & " = " & Listify (V.Values); + return V.Name & " := " & Listify (V.Values); when External => - return V.Name & " = " & V.Value.First_Element; + return V.Name & " := " & V.Value.First_Element; end case; end Image; diff --git a/src/alire-index.ads b/src/alire-index.ads index 44a540bb..743c837c 100644 --- a/src/alire-index.ads +++ b/src/alire-index.ads @@ -231,25 +231,23 @@ package Alire.Index is -- REQUISITES -- ------------------ - use all type Requisites.Tree; - 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 Compiler is new Requisites.Platform.Compilers.Factory; + function Compiler_Is_Native return Release_Requisites renames Plat_Reqs.Compiler_Is_Native; + use all type Requisites.Platform.Compilers.Comparable; - function Distribution_Is (V : Platforms.Distributions) return Release_Requisites renames Plat_Reqs.Distribution_Is; + function Distribution is new Requisites.Platform.Distributions.Factory; + use all type Requisites.Platform.Distributions.Comparable; - function OS return Requisites.Platform.Systs.Comparable renames Requisites.Platform.Systs.New_Comparable; - use all type Requisites.Platform.Systs.Comparable; + function Operating_System is new Requisites.Platform.Op_Systems.Factory; + use all type Requisites.Platform.Op_Systems.Comparable; - function System_Is (V : Platforms.Operating_Systems) return Release_Requisites renames Plat_Reqs.System_Is; + function Distro_Release is new Requisites.Platform.Versions.Factory; + use all type Requisites.Platform.Versions.Comparable; - 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; + function Word_Size is new Requisites.Platform.Word_Sizes.Factory; + use all type Requisites.Platform.Word_Sizes.Comparable; ---------------------- -- Set_Root_Project -- diff --git a/src/alire-requisites-comparables.ads b/src/alire-requisites-comparables.ads index b19e2a69..730dffd5 100644 --- a/src/alire-requisites-comparables.ads +++ b/src/alire-requisites-comparables.ads @@ -1,3 +1,5 @@ +with Alire.Utils; + generic -- Encapsulated basic type type Value is private; @@ -21,6 +23,10 @@ package Alire.Requisites.Comparables with Preelaborate is not overriding function New_Comparable return Comparable; -- This is the root function that can be renamed to a sensible name to appear in expressions + generic + function Factory return Comparable; + -- Alternatively this makes for a simpler instantiation since no profile is needed + function "=" (L : Comparable; R : Value) return Tree; function "=" (L : Value; R : Comparable) return Tree; @@ -53,13 +59,15 @@ private (case R.Kind is when Base => raise Constraint_Error with "Is_Satisfied: Requisite without operation", when Equality => R.Value = Element (P), - when Ordering => R.Value < Element (P)); + when Ordering => Element (P) < R.Value); overriding function Image (R : Comparable) return String is (case R.Kind is when Base => raise Constraint_Error with "Image: Requisite without operation", - when Equality => Name & " = " & Image (R.Value), - when Ordering => Name & " < " & Image (R.Value)); + when Equality => Name & " = " & Utils.To_Mixed_Case (Image (R.Value)), + when Ordering => Name & " < " & Utils.To_Mixed_Case (Image (R.Value))); + + function Factory return Comparable is (New_Comparable); use all type Tree; diff --git a/src/alire-requisites-platform.ads b/src/alire-requisites-platform.ads index 7ffaf7e0..66e6c4f9 100644 --- a/src/alire-requisites-platform.ads +++ b/src/alire-requisites-platform.ads @@ -5,36 +5,45 @@ with Alire.Requisites.Comparables; package Alire.Requisites.Platform with Preelaborate is - package Plat renames Properties.Platform; + package Ps renames Platforms; + package PrPl renames Properties.Platform; - use all type Platforms.Compilers; + use all type Ps.Compilers; use all type Tree; - package Systs is new Comparables - (Platforms.Operating_Systems, Platforms."<", Platforms.Operating_Systems'Image, - Properties.Platform.Operating_Systems.Property, - Properties.Platform.Operating_Systems.Element, + package Op_Systems is new Comparables + (Ps.Operating_Systems, Ps."<", Ps.Operating_Systems'Image, + PrPl.Operating_Systems.Property, + PrPl.Operating_Systems.Element, "OS"); - 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; + package Compilers is new Comparables + (Ps.Compilers, Ps."<", Ps.Compilers'Image, + PrPl.Compilers.Property, + PrPl.Compilers.Element, + "Compiler"); + use all type Compilers.Comparable; + function Compiler is new Compilers.Factory; function Compiler_Is_Native return Tree is - (Compiler_Less_Than (GNAT_GPL_2017) and not Compiler_Is (GNAT_Unknown)); + (Compiler < GNAT_GPL_2017 and Compiler /= 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; + package Distributions is new Comparables + (Ps.Distributions, Ps."<", Ps.Distributions'Image, + PrPl.Distributions.Property, + PrPl.Distributions.Element, + "Distribution"); - package Systems is new Requisites.For_Value_Property (Plat.Operating_Systems, "OS"); - function System_Is (V : Platforms.Operating_Systems) return Tree renames Systems.New_Equality; + package Versions is new Comparables + (Ps.Versions, Ps."<", Ps.Versions'Image, + PrPl.Versions.Property, + PrPl.Versions.Element, + "Version"); - package Versions is new Requisites.For_Value_Property (Plat.Versions, "Version"); - function Version_Is (V : Platforms.Versions) return Tree renames Versions.New_Equality; - - package Word_Sizes is new Requisites.For_Value_Property (Plat.Word_Sizes, "Arquitecture width"); - function Word_Size_Is (V : Platforms.Word_Sizes) return Tree renames Word_Sizes.New_Equality; + package Word_Sizes is new Comparables + (Ps.Word_Sizes, Ps."<", Ps.Word_Sizes'Image, + PrPl.Word_Sizes.Property, + PrPl.Word_Sizes.Element, + "Word_Size"); end Alire.Requisites.Platform; diff --git a/src/alire-requisites.ads b/src/alire-requisites.ads index fb01d960..7e549f6a 100644 --- a/src/alire-requisites.ads +++ b/src/alire-requisites.ads @@ -1,6 +1,5 @@ with Alire.Boolean_Trees; with Alire.Properties; -with Alire.Utils; package Alire.Requisites with Preelaborate is @@ -72,64 +71,4 @@ package Alire.Requisites with Preelaborate is end For_Property; - -------------- - -- EXTRAS -- - -------------- - - -- This following requisite is a matching requisite for value properties - -- Concevably, this could be expanded to offer >=, <, <=... - - generic - with package Values is new Properties.Values (<>); - -- The property that encapsulates the requisite value - - Name : String; -- used for image "Name is Mixed_Case (Image (Value))" - package For_Value_Property is - - package Value_Requisites is new For_Property (Values.Property); - - 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))); - - 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); - - 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;