Better expression requisites

This commit is contained in:
Alejandro R Mosteo
2018-03-09 10:32:30 +01:00
parent a2188c5971
commit 8ddac31165
12 changed files with 79 additions and 126 deletions
+2 -2
View File
@@ -19,7 +19,7 @@ package Alire.Index.Adacurses is
Dependencies => Dependencies =>
On_Condition On_Condition
(Distribution_Is (Debian) or Distribution_Is (Ubuntu), (Distribution = Debian or Distribution = Ubuntu,
When_True => When_Available (Within_Major (NcursesAda.V_5)), When_True => When_Available (Within_Major (NcursesAda.V_5)),
When_False => Unavailable), When_False => Unavailable),
@@ -35,7 +35,7 @@ package Alire.Index.Adacurses is
Dependencies => Dependencies =>
On_Condition On_Condition
(Distribution_Is (Debian) or Distribution_Is (Ubuntu), (Distribution = Debian or Distribution = Ubuntu,
When_True => When_Available (Within_Major (NcursesAda.V_3)), When_True => When_Available (Within_Major (NcursesAda.V_3)),
When_False => Unavailable), When_False => Unavailable),
+9 -10
View File
@@ -28,7 +28,7 @@ package Alire.Index.Alire is
Dependencies => Dependencies =>
Current ("half_life_3") and -- unconditional Current ("half_life_3") and -- unconditional
On_Condition -- conditional On_Condition -- conditional
(System_Is (GNU_Linux), (Operating_System = GNU_Linux,
When_True => At_Least ("elite_horizons", V ("2.0")) and When_True => At_Least ("elite_horizons", V ("2.0")) and
At_Least ("star_citizen", V ("3.0")), -- Wish... At_Least ("star_citizen", V ("3.0")), -- Wish...
When_False => At_Least ("windows_100", V ("1.0"))) and 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 -- Path separators are always "/" and internally converted to native ones
On_Condition On_Condition
(System_Is (Windows), (Operating_System = Windows,
GPR_File ("project_win.gpr")) and GPR_File ("project_win.gpr")) and
On_Condition On_Condition
(System_Is (GNU_Linux), (Operating_System = GNU_Linux,
On_Condition (Distribution_Is (Ubuntu), -- Nested conditions On_Condition (Distribution = Ubuntu, -- Nested conditions
GPR_File ("project_ubuntu.gpr"))) and GPR_File ("project_ubuntu.gpr"))) and
-- Conditional project file -- Conditional project file
On_Condition On_Condition
(System_Is (GNU_Linux), (Operating_System = GNU_Linux,
Comment ("Long life the penguin")) and Comment ("Long life the penguin")) and
-- Conditions on operating system -- Conditions on operating system
On_Condition 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 Comment ("Never saw that compiler") and Comment ("But I would like to")) and
-- Conditions on compiler version -- Conditions on compiler version
On_Condition On_Condition
(Version_Is (Ubuntu_Artful), (Distro_Release = Ubuntu_Artful,
When_True => Comment ("Living on the edge"), When_True => Comment ("Living on the edge"),
When_False => Comment ("I am a rock")) and When_False => Comment ("I am a rock")) and
-- Conditions on distribution release -- Conditions on distribution release
@@ -84,8 +84,7 @@ package Alire.Index.Alire is
-- Unconditional properties -- Unconditional properties
Available_When => -- Impossible mix Available_When => -- Impossible mix
OS = GNU_Linux or OS /= GNU_Linux or (Operating_System = Windows and Operating_System /= GNU_Linux) or
(System_Is (Windows) and System_Is (GNU_Linux)) or (Compiler = GNAT_Unknown and Compiler /= GNAT_Unknown));
(Compiler_Is (GNAT_Unknown) and not Compiler_Is (GNAT_Unknown)));
end Alire.Index.Alire; end Alire.Index.Alire;
+4 -4
View File
@@ -279,16 +279,16 @@ package Alire.Index.DAK is
GPR_File ("test_components/components-odbc-odbc_bindings_tests.gpr") and GPR_File ("test_components/components-odbc-odbc_bindings_tests.gpr") and
On_Condition On_Condition
(System_Is (GNU_Linux), (Operating_System = GNU_Linux,
GPR_External ("odbc", "unixODBC")) and GPR_External ("odbc", "unixODBC")) and
On_Condition On_Condition
(System_Is (Windows), (Operating_System = Windows,
GPR_External ("odbc", "ODBC32")) and GPR_External ("odbc", "ODBC32")) and
On_Condition On_Condition
(Word_Size_Is (Bits_32), (Word_Size = Bits_32,
GPR_External ("arch", "i686")) and GPR_External ("arch", "i686")) and
On_Condition On_Condition
(Word_Size_Is (Bits_64), (Word_Size = Bits_64,
GPR_External ("arch", "x86_64")) GPR_External ("arch", "x86_64"))
); );
+3 -3
View File
@@ -36,14 +36,14 @@ package Alire.Index.Libadacrypt is
GPR_File ("acltest.gpr") and GPR_File ("acltest.gpr") and
On_Condition On_Condition
(System_Is (GNU_Linux), (Operating_System = GNU_Linux,
GPR_External ("system", "unix")) and GPR_External ("system", "unix")) and
On_Condition On_Condition
(System_Is (Windows), (Operating_System = Windows,
GPR_External ("system", "windows")), GPR_External ("system", "windows")),
Available_When => Available_When =>
not Compiler_Is (GNAT_FSF_7_2) Compiler > GNAT_FSF_7_2
-- It fails self-tests; might be a spureous warning -- It fails self-tests; might be a spureous warning
); );
+3 -3
View File
@@ -18,7 +18,7 @@ package Alire.Index.OpenGLAda is
Dependencies => Dependencies =>
On_Condition On_Condition
(System_Is (GNU_Linux), (Operating_System = GNU_Linux,
Within_Major (Libglfw3.V_3) and Within_Major (LibX11.V_2)), Within_Major (Libglfw3.V_3) and Within_Major (LibX11.V_2)),
Properties => Properties =>
@@ -49,10 +49,10 @@ package Alire.Index.OpenGLAda is
GPR_File ("opengl-test.gpr") and GPR_File ("opengl-test.gpr") and
On_Condition On_Condition
(System_Is (GNU_Linux), GPR_External ("Windowing_System", "x11")), (Operating_System = GNU_Linux, GPR_External ("Windowing_System", "x11")),
Available_When => Available_When =>
System_Is (GNU_Linux) Operating_System = GNU_Linux
); );
end Alire.Index.OpenGLAda; end Alire.Index.OpenGLAda;
+2 -2
View File
@@ -54,11 +54,11 @@ package Alire.Index.SDLAda is
GPR_External ("SDL_MODE", "release") and GPR_External ("SDL_MODE", "release") and
On_Condition On_Condition
(System_Is (GNU_Linux), (Operating_System = GNU_Linux,
GPR_External ("SDL_PLATFORM", "linux")), GPR_External ("SDL_PLATFORM", "linux")),
Available_When => Available_When =>
System_Is (GNU_Linux) Operating_System = GNU_Linux
); );
end Alire.Index.SDLAda; end Alire.Index.SDLAda;
+1 -1
View File
@@ -32,7 +32,7 @@ package Alire.Index.Whitakers_Words is
GPR_File ("words.gpr"), GPR_File ("words.gpr"),
Available_When => 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; end Alire.Index.Whitakers_Words;
+3 -3
View File
@@ -21,11 +21,11 @@ package body Alire.GPR is
begin begin
case V.Kind is case V.Kind is
when Free_String => when Free_String =>
return V.Name & " = <string>"; return V.Name & " := <string>";
when Enumeration => when Enumeration =>
return V.Name & " = " & Listify (V.Values); return V.Name & " := " & Listify (V.Values);
when External => when External =>
return V.Name & " = " & V.Value.First_Element; return V.Name & " := " & V.Value.First_Element;
end case; end case;
end Image; end Image;
+11 -13
View File
@@ -231,25 +231,23 @@ package Alire.Index is
-- REQUISITES -- -- REQUISITES --
------------------ ------------------
use all type Requisites.Tree;
package Plat_Reqs renames Requisites.Platform; package Plat_Reqs renames Requisites.Platform;
function Compiler_Is_Native return Release_Requisites renames Plat_Reqs.Compiler_Is_Native; function Compiler is new Requisites.Platform.Compilers.Factory;
function Compiler_Is (V : Platforms.Compilers) return Release_Requisites renames Plat_Reqs.Compiler_Is; function Compiler_Is_Native return Release_Requisites renames Plat_Reqs.Compiler_Is_Native;
function Compiler_Less_Than (V : Platforms.Compilers) return Release_Requisites renames Plat_Reqs.Compiler_Less_Than; use all type Requisites.Platform.Compilers.Comparable;
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 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; function Operating_System is new Requisites.Platform.Op_Systems.Factory;
use all type Requisites.Platform.Systs.Comparable; 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 new Requisites.Platform.Word_Sizes.Factory;
use all type Requisites.Platform.Word_Sizes.Comparable;
function Word_Size_Is (V : Platforms.Word_Sizes) return Release_Requisites renames Plat_Reqs.Word_Size_Is;
---------------------- ----------------------
-- Set_Root_Project -- -- Set_Root_Project --
+11 -3
View File
@@ -1,3 +1,5 @@
with Alire.Utils;
generic generic
-- Encapsulated basic type -- Encapsulated basic type
type Value is private; type Value is private;
@@ -21,6 +23,10 @@ package Alire.Requisites.Comparables with Preelaborate is
not overriding function New_Comparable return Comparable; not overriding function New_Comparable return Comparable;
-- This is the root function that can be renamed to a sensible name to appear in expressions -- 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 : Comparable; R : Value) return Tree;
function "=" (L : Value; R : Comparable) return Tree; function "=" (L : Value; R : Comparable) return Tree;
@@ -53,13 +59,15 @@ private
(case R.Kind is (case R.Kind is
when Base => raise Constraint_Error with "Is_Satisfied: Requisite without operation", when Base => raise Constraint_Error with "Is_Satisfied: Requisite without operation",
when Equality => R.Value = Element (P), 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 overriding function Image (R : Comparable) return String is
(case R.Kind is (case R.Kind is
when Base => raise Constraint_Error with "Image: Requisite without operation", when Base => raise Constraint_Error with "Image: Requisite without operation",
when Equality => Name & " = " & Image (R.Value), when Equality => Name & " = " & Utils.To_Mixed_Case (Image (R.Value)),
when Ordering => Name & " < " & Image (R.Value)); when Ordering => Name & " < " & Utils.To_Mixed_Case (Image (R.Value)));
function Factory return Comparable is (New_Comparable);
use all type Tree; use all type Tree;
+30 -21
View File
@@ -5,36 +5,45 @@ with Alire.Requisites.Comparables;
package Alire.Requisites.Platform with Preelaborate is 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; use all type Tree;
package Systs is new Comparables package Op_Systems is new Comparables
(Platforms.Operating_Systems, Platforms."<", Platforms.Operating_Systems'Image, (Ps.Operating_Systems, Ps."<", Ps.Operating_Systems'Image,
Properties.Platform.Operating_Systems.Property, PrPl.Operating_Systems.Property,
Properties.Platform.Operating_Systems.Element, PrPl.Operating_Systems.Element,
"OS"); "OS");
package Compilers is new Requisites.For_Value_Property (Plat.Compilers, "Compiler"); package Compilers is new Comparables
function Compiler_Is (V : Platforms.Compilers) return Tree renames Compilers.New_Equality; (Ps.Compilers, Ps."<", Ps.Compilers'Image,
PrPl.Compilers.Property,
package Compilers_Less is new Compilers.Comparators (Platforms."<", "<"); PrPl.Compilers.Element,
function Compiler_Less_Than (V : Platforms.Compilers) return Tree renames Compilers_Less.New_Comparator; "Compiler");
use all type Compilers.Comparable;
function Compiler is new Compilers.Factory;
function Compiler_Is_Native return Tree is 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"); package Distributions is new Comparables
function Distribution_Is (V : Platforms.Distributions) return Tree renames Distributions.New_Equality; (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"); package Versions is new Comparables
function System_Is (V : Platforms.Operating_Systems) return Tree renames Systems.New_Equality; (Ps.Versions, Ps."<", Ps.Versions'Image,
PrPl.Versions.Property,
PrPl.Versions.Element,
"Version");
package Versions is new Requisites.For_Value_Property (Plat.Versions, "Version"); package Word_Sizes is new Comparables
function Version_Is (V : Platforms.Versions) return Tree renames Versions.New_Equality; (Ps.Word_Sizes, Ps."<", Ps.Word_Sizes'Image,
PrPl.Word_Sizes.Property,
package Word_Sizes is new Requisites.For_Value_Property (Plat.Word_Sizes, "Arquitecture width"); PrPl.Word_Sizes.Element,
function Word_Size_Is (V : Platforms.Word_Sizes) return Tree renames Word_Sizes.New_Equality; "Word_Size");
end Alire.Requisites.Platform; end Alire.Requisites.Platform;
-61
View File
@@ -1,6 +1,5 @@
with Alire.Boolean_Trees; with Alire.Boolean_Trees;
with Alire.Properties; with Alire.Properties;
with Alire.Utils;
package Alire.Requisites with Preelaborate is package Alire.Requisites with Preelaborate is
@@ -72,64 +71,4 @@ package Alire.Requisites with Preelaborate is
end For_Property; 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; end Alire.Requisites;