From dab6d196c923d75b2ebcbb963f5717319c6046a9 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Fri, 2 Mar 2018 19:36:37 +0100 Subject: [PATCH] Conditional props/deps seemingly working --- index/alire-index-alire.ads | 6 +++--- src/alire-conditional_values.adb | 34 +++++++++++++++++++++++++++++++- src/alire-conditional_values.ads | 9 --------- src/alire-index.ads | 8 +++++++- src/alire-releases.adb | 12 +++++------ src/alire-releases.ads | 18 ++++++++++------- src/alire-root_project.adb | 2 +- src/alire-types.ads | 14 +++++++++++++ 8 files changed, 75 insertions(+), 28 deletions(-) create mode 100644 src/alire-types.ads diff --git a/index/alire-index-alire.ads b/index/alire-index-alire.ads index 8e56807b..3dd148e6 100644 --- a/index/alire-index-alire.ads +++ b/index/alire-index-alire.ads @@ -29,9 +29,9 @@ package Alire.Index.Alire is Current ("half_life_3") and -- unconditional If_Platform -- conditional (System_Is (GNU_Linux), - When_True => At_Least ("elite_horizons", "2.0") and - At_Least ("star_citizen", "3.0"), -- Wish... - When_False => At_Least ("windows_100", "1.0")), + 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"))), Properties => GPR_Scenario ("Build", "Debug" or "Release") and diff --git a/src/alire-conditional_values.adb b/src/alire-conditional_values.adb index e910b3a2..ab77a5cb 100644 --- a/src/alire-conditional_values.adb +++ b/src/alire-conditional_values.adb @@ -1,5 +1,32 @@ package body Alire.Conditional_Values is + ----------- + -- "and" -- + ----------- + + function "and" (L, R : Conditional_Value) return Conditional_Value is + begin + return Result : Conditional_Value do + if L.Is_Empty and then R.Is_Empty then + null; -- nothing to do nor return + else + declare + Inner : Vector_Inner; + begin + if not L.Is_Empty then + Inner.Values.Append (L.Constant_Reference); + end if; + + if not R.Is_Empty then + Inner.Values.Append (R.Constant_Reference); + end if; + + Result.Replace_Element (Inner); + end; + end if; + end return; + end "and"; + -------------- -- Evaluate -- -------------- @@ -30,8 +57,13 @@ package body Alire.Conditional_Values is end case; end Evaluate; + Empty_Value : Values; begin - return Evaluate (This.Constant_Reference); + if This.Is_Empty then + return Empty_Value; + else + return Evaluate (This.Constant_Reference); + end if; end Evaluate; -------------- diff --git a/src/alire-conditional_values.ads b/src/alire-conditional_values.ads index 650a77e5..a8c20d62 100644 --- a/src/alire-conditional_values.ads +++ b/src/alire-conditional_values.ads @@ -164,15 +164,6 @@ private function False_Value (This : Conditional_Value) return Conditional_Value is (This.As_Conditional.Else_Value); - ----------- - -- "and" -- - ----------- - - use all type Vectors.Vector; - - function "and" (L, R : Conditional_Value) return Conditional_Value is - (To_Holder (Vector_Inner'(Values => L.Element & R.Element))); - ----------- -- Empty -- ----------- diff --git a/src/alire-index.ads b/src/alire-index.ads index b9597c54..a44593a2 100644 --- a/src/alire-index.ads +++ b/src/alire-index.ads @@ -108,7 +108,7 @@ package Alire.Index is function Current (P : Project_Name) return Release_Dependencies is (On (P, Semver.Any)); - -- These take a project name and a version string + -- These take a project name and a semantic version (see V above) function Within_Major is new Releases.From_Names (Semver.Within_Major); function Within_Minor is new Releases.From_Names (Semver.Within_Minor); function At_Least is new Releases.From_Names (Semver.At_Least); @@ -117,6 +117,9 @@ package Alire.Index is function More_Than is new Releases.From_Names (Semver.More_Than); function Exactly is new Releases.From_Names (Semver.Exactly); function Except is new Releases.From_Names (Semver.Except); + + function "and" (L, R : Release_Dependencies) return Release_Dependencies + renames Conditional.For_Dependencies."and"; ------------------ -- PROPERTIES -- @@ -171,6 +174,9 @@ package Alire.Index is function License (L : Licensing.Licenses) return Properties.Vector is (+Properties.Licenses.Values.New_Property (L)); function License (L : Licensing.Licenses) return Conditional.Properties is (U (License (L))); + function "and" (L, R : Release_Properties) return Release_Properties + renames Conditional.For_Properties."and"; + -- function "and" (D1, D2 : Dependencies.Vector) return Dependencies.Vector renames Alire.Dependencies.Vectors."and"; -- function "and" (P1, P2 : Properties.Vector) return Properties.Vector renames Alire.Properties."and"; diff --git a/src/alire-releases.adb b/src/alire-releases.adb index 360620d1..3dc381d6 100644 --- a/src/alire-releases.adb +++ b/src/alire-releases.adb @@ -31,7 +31,7 @@ package body Alire.Releases is ---------------- function Executables (R : Release; - P : Properties.Vector := Properties.No_Properties) + P : Properties.Vector) return Utils.String_Vector is begin return Exes : Utils.String_Vector := Values (R.Properties.Evaluate (P), Executable) do @@ -48,7 +48,7 @@ package body Alire.Releases is --------------- function GPR_Files (R : Release; - P : Properties.Vector := Properties.No_Properties) + P : Properties.Vector) return Utils.String_Vector is begin return Files : Utils.String_Vector := Values (R.Properties.Evaluate (P), GPR_File) do @@ -110,11 +110,11 @@ package body Alire.Releases is end if; -- DEPENDENCIES - if not R.Depends.Is_Empty then + if not R.Dependencies.Is_Empty then Put_Line ("Dependencies (direct):"); - for Dep of R.Depends loop - Put_Line (" " & Dep.Image); - end loop; +-- for Dep of R.Depends loop +-- Put_Line (" " & Dep.Image); +-- end loop; end if; end Print; diff --git a/src/alire-releases.ads b/src/alire-releases.ads index da68fac0..950af1ac 100644 --- a/src/alire-releases.ads +++ b/src/alire-releases.ads @@ -33,9 +33,11 @@ package Alire.Releases with Preelaborate is function Project (R : Release) return Project_Name; function Description (R : Release) return Project_Description; function Version (R : Release) return Semantic_Versioning.Version; + function Depends (R : Release; - P : Properties.Vector := Properties.No_Properties) + P : Properties.Vector) return Dependencies.Vector; + function Origin (R : Release) return Origins.Origin; function Available (R : Release) return Requisites.Tree; @@ -43,13 +45,13 @@ package Alire.Releases with Preelaborate is -- We encapsulate here the fixing of platform extension function Executables (R : Release; - P : Properties.Vector := Properties.No_Properties) + P : Properties.Vector) return Utils.String_Vector; -- Only explicity declared ones -- Under some conditions (usually current platform) function GPR_Files (R : Release; - P : Properties.Vector := Properties.No_Properties) + P : Properties.Vector) return Utils.String_Vector; -- Explicitly declared ones, or if default one if none declared -- Under some conditions (usually current platform) @@ -81,7 +83,7 @@ package Alire.Releases with Preelaborate is generic with function Condition (V : Semantic_Versioning.Version) return Semantic_Versioning.Version_Set; function From_Names (P : Project_Name; - V : Semantic_Versioning.Version_String) return Conditional.Dependencies; + V : Semantic_Versioning.Version) return Conditional.Dependencies; private @@ -129,10 +131,12 @@ private function Project (R : Release) return Project_Name is (R.Name); function Description (R : Release) return Project_Description is (R.Description); function Version (R : Release) return Semantic_Versioning.Version is (R.Version); + function Depends (R : Release; - P : Properties.Vector := Properties.No_Properties) + P : Properties.Vector) return Dependencies.Vector is (R.Dependencies.Evaluate (P)); + function Origin (R : Release) return Origins.Origin is (R.Origin); function Available (R : Release) return Requisites.Tree is (R.Available); @@ -160,7 +164,7 @@ private (On (R.Project, Condition (R.Version))); function From_Names (P : Project_Name; - V : Semantic_Versioning.Version_String) return Conditional.Dependencies is - (On (P, Condition (Semantic_Versioning.New_Version (V)))); + V : Semantic_Versioning.Version) return Conditional.Dependencies is + (On (P, Condition (V))); end Alire.Releases; diff --git a/src/alire-root_project.adb b/src/alire-root_project.adb index f5de890a..5862f683 100644 --- a/src/alire-root_project.adb +++ b/src/alire-root_project.adb @@ -45,7 +45,7 @@ package body Alire.Root_Project is Version, New_Filesystem (Ada.Directories.Current_Directory), Depends_On, - Properties => Conditions.Properties.Empty_Vector, + Properties => Index.No_Properties, Available => Requisites.No_Requisites); begin if Index.Exists (Project, Version) then diff --git a/src/alire-types.ads b/src/alire-types.ads new file mode 100644 index 00000000..d3fb492d --- /dev/null +++ b/src/alire-types.ads @@ -0,0 +1,14 @@ +with Alire.Conditional; +with Alire.Dependencies.Vectors; + +package Alire.Types with Preelaborate is + + -- Recopilation of types for convenient use in alr + + subtype Platform_Dependencies is Dependencies.Vectors.Vector; + -- A plain vector + + subtype Abstract_Dependencies is Conditional.Dependencies; + -- Conditional dependencies as yet unmaterialized for a precise platform + +end Alire.Types;