From cc3aaa2010a5a4a0033479bd4385e990c125f813 Mon Sep 17 00:00:00 2001 From: A Date: Tue, 20 Feb 2018 20:50:00 +0100 Subject: [PATCH] Query by name and version set, release report --- deps/semver | 2 +- index/alire-index-rxada.ads | 5 ++- index/alire-index-semantic_versioning.ads | 4 +- src/alire-dependencies.ads | 4 ++ src/alire-index.ads | 5 +++ src/alire-origins.ads | 13 +++++- src/alire-properties-labeled.ads | 44 ++++++++++++++++++ src/alire-properties-platform.ads | 6 ++- src/alire-properties.ads | 7 +++ src/alire-query.adb | 55 ++++++++++++++++++++--- src/alire-query.ads | 20 ++++++++- src/alire-releases.adb | 41 +++++++++++++++++ src/alire-releases.ads | 3 ++ src/alire-utils.adb | 16 +++++++ src/alire-utils.ads | 5 +++ src/alire.ads | 3 ++ 16 files changed, 217 insertions(+), 16 deletions(-) create mode 100644 src/alire-properties-labeled.ads create mode 100644 src/alire-releases.adb create mode 100644 src/alire-utils.adb create mode 100644 src/alire-utils.ads diff --git a/deps/semver b/deps/semver index 9f35b00a..c25fb630 160000 --- a/deps/semver +++ b/deps/semver @@ -1 +1 @@ -Subproject commit 9f35b00a31861ea96085ee553fb6335d74831f5c +Subproject commit c25fb63017b098e8c696f9530e1128fb33948fd5 diff --git a/index/alire-index-rxada.ads b/index/alire-index-rxada.ads index 83946360..7a8015fa 100644 --- a/index/alire-index-rxada.ads +++ b/index/alire-index-rxada.ads @@ -9,6 +9,9 @@ package Alire.Index.RxAda is Register (Name, V ("0.1.0"), Desc, - Hg (Repo, "361d4e2ab20a7dcca007e31bf7094d57b13fee6b")); + Hg (Repo, "361d4e2ab20a7dcca007e31bf7094d57b13fee6b"), + Properties => + Maintainer ("alejandro@mosteo.com") and + Website (Repo)); end Alire.Index.RxAda; diff --git a/index/alire-index-semantic_versioning.ads b/index/alire-index-semantic_versioning.ads index edef4469..819016fc 100644 --- a/index/alire-index-semantic_versioning.ads +++ b/index/alire-index-semantic_versioning.ads @@ -7,8 +7,8 @@ package Alire.Index.Semantic_Versioning is Latest : constant Release := Register (Name, - V ("0.1.0"), + V ("0.1.1"), Desc, - Git (Repo, "9f35b00a31861ea96085ee553fb6335d74831f5c")); + Git (Repo, "c25fb63017b098e8c696f9530e1128fb33948fd5")); end Alire.Index.Semantic_Versioning; diff --git a/src/alire-dependencies.ads b/src/alire-dependencies.ads index 93685e40..3d67fda5 100644 --- a/src/alire-dependencies.ads +++ b/src/alire-dependencies.ads @@ -15,6 +15,7 @@ package Alire.Dependencies with Preelaborate is function Versions (Dep : Dependency) return Semantic_Versioning.Version_Set; + function Image (Dep : Dependency) return String; private @@ -39,4 +40,7 @@ private function Versions (Dep : Dependency) return Semantic_Versioning.Version_Set is (Dep.Versions_H.Element); + function Image (Dep : Dependency) return String is + (Dep.Project & " ver " & Semantic_Versioning.Image (Dep.Versions_H.Element)); + end Alire.Dependencies; diff --git a/src/alire-index.ads b/src/alire-index.ads index 53d144e1..e32eba1a 100644 --- a/src/alire-index.ads +++ b/src/alire-index.ads @@ -6,6 +6,7 @@ with Alire.Dependencies.Vectors; with Alire.Operating_Systems; with Alire.Origins; with Alire.Properties; +with Alire.Properties.Labeled; with Alire.Releases; with Alire.Requisites; with Alire.Requisites.Platform; @@ -82,6 +83,10 @@ package Alire.Index is -- Shortcuts for properties/requisites: + -- "Typed" attributes (named pairs of label-value) + function Maintainer is new Properties.Labeled.Generic_New_Label (Properties.Labeled.Maintainer); + function Website is new Properties.Labeled.Generic_New_Label (Properties.Labeled.Website); + use all type Alire.Dependencies.Vectors.Vector; use all type Compilers.Compilers; use all type Operating_Systems.Operating_Systems; diff --git a/src/alire-origins.ads b/src/alire-origins.ads index c7fba9ed..ab1aac5b 100644 --- a/src/alire-origins.ads +++ b/src/alire-origins.ads @@ -40,6 +40,8 @@ package Alire.Origins with Preelaborate is function New_Apt (Id_As_Package_Name : String) return Origin; + function Image (This : Origin) return String; + private use Ada.Strings.Unbounded; @@ -70,7 +72,7 @@ private To_Unbounded_String (Id)); function New_Apt (Id_As_Package_Name : String) return Origin is - (Filesystem, + (Apt, To_Unbounded_String (Id_As_Package_Name), Null_Unbounded_String); @@ -80,4 +82,13 @@ private function Id (This : Origin) return String is (To_String (This.Id)); + function S (Str : Unbounded_String) return String is (To_String (Str)); + + function Image (This : Origin) return String is + (case This.Kind is + when Git | Hg => "commit " & S (This.Id) & " from " & S (This.URL), + when Apt => "package " & S (This.Id) & " from native package manager (apt)", + when Filesystem => "path " & S (This.Id)); + + end Alire.Origins; diff --git a/src/alire-properties-labeled.ads b/src/alire-properties-labeled.ads new file mode 100644 index 00000000..ee83ff69 --- /dev/null +++ b/src/alire-properties-labeled.ads @@ -0,0 +1,44 @@ +private with Alire.Utils; + +package Alire.Properties.Labeled with Preelaborate is + + -- Properties that have a single string value and a name + + type Labels is (Maintainer, + Website); + + type Label (<>) is new Properties.Property with private; + + function New_Label (Name : Labels; Value : String) return Label; + + function Name (L : Label) return Labels; + + function Value (L : Label) return String; + + overriding function Image (L : Label) return String; + + generic + Name : Labels; + function Generic_New_Label (Value : String) return Label; + -- Returns a vector so its directly usable during indexing + + +private + + type Label (Length : Natural) is new Properties.Property with record + Name : Labels; + Value : String (1 .. Length); + end record; + + function New_Label (Name : Labels; Value : String) return Label is + (Properties.Property with Value'Length, Name, Value); + + function Name (L : Label) return Labels is (L.Name); + + function Value (L : Label) return String is (L.Value); + + function Generic_New_Label (Value : String) return Label is (New_Label (Name, Value)); + + overriding function Image (L : Label) return String is (Utils.To_Mixed_Case (L.Name'Img & ": " & L.Value)); + +end Alire.Properties.Labeled; diff --git a/src/alire-properties-platform.ads b/src/alire-properties-platform.ads index 848a4b3c..799e6b88 100644 --- a/src/alire-properties-platform.ads +++ b/src/alire-properties-platform.ads @@ -3,8 +3,10 @@ with Alire.Operating_Systems; package Alire.Properties.Platform with Preelaborate is - package Compilers is new Values (Alire.Compilers.Compilers); - package Operating_Systems is new Values (Alire.Operating_Systems.Operating_Systems); + package Compilers is new Values (Alire.Compilers.Compilers, + Alire.Compilers.Compilers'IMage); + package Operating_Systems is new Values (Alire.Operating_Systems.Operating_Systems, + Alire.Operating_Systems.Operating_Systems'Image); function Current return Properties.Vector; diff --git a/src/alire-properties.ads b/src/alire-properties.ads index 69f2f66c..6525a26c 100644 --- a/src/alire-properties.ads +++ b/src/alire-properties.ads @@ -11,6 +11,8 @@ package Alire.Properties with Preelaborate is type Property is interface; + function Image (P : Property) return String is abstract; + package Vectors is new Ada.Containers.Indefinite_Vectors (Positive, Property'Class); subtype Vector is Vectors.Vector; @@ -23,6 +25,7 @@ package Alire.Properties with Preelaborate is -- A generic helper to simply store/retrieve e.g. an enumerated type generic type Value is private; + with function Image (V : Value) return String is <>; package Values is type Property (<>) is new Properties.Property with private; @@ -33,6 +36,8 @@ package Alire.Properties with Preelaborate is private + overriding function Image (P : Property) return String; + type Property is new Properties.Property with record V : Value; end record; @@ -41,6 +46,8 @@ package Alire.Properties with Preelaborate is function Element (P : Property) return Value is (P.V); + overriding function Image (P : Property) return String is (Image (P.V)); + end Values; private diff --git a/src/alire-query.adb b/src/alire-query.adb index 80a5b900..f8ddc0c2 100644 --- a/src/alire-query.adb +++ b/src/alire-query.adb @@ -1,19 +1,36 @@ with Alire.Dependencies; - -with Semantic_Versioning; +with Alire.Utils; package body Alire.Query is package Semver renames Semantic_Versioning; + use all type Semver.Version_Set; + + ---------------------- + -- Dependency_Image -- + ---------------------- + + function Dependency_Image (Project : Project_Name; + Versions : Semantic_Versioning.Version_Set; + Policy : Policies := Newest) return String is + (Project & + (if Versions /= Semver.Any + then " version " & Semver.Image (Versions) + else " with " & Utils.To_Mixed_Case (Policy'Img) & " version")); + ------------ -- Exists -- ------------ - function Exists (Project : Project_Name) return Boolean is + function Exists (Project : Project_Name; + Allowed : Semantic_Versioning.Version_Set := Semantic_Versioning.Any) + return Boolean + is + use Semver; begin for R of Releases loop - if R.Project = Project then + if R.Project = Project and then Satisfies (R.Version, Allowed) then return True; end if; end loop; @@ -21,6 +38,29 @@ package body Alire.Query is return False; end Exists; + ---------- + -- Find -- + ---------- + + function Find (Project : Project_Name; + Allowed : Semantic_Versioning.Version_Set := Semantic_Versioning.Any; + Policy : Policies := Newest) return Release + is + use Semantic_Versioning; + begin + for R of reverse Index.Releases loop + if R.Project = Project then + if Satisfies (R.Version, Allowed) then + return R; + else + Trace.Debug ("Skipping unsatisfactory version: " & Image (R.Version)); + end if; + end if; + end loop; + + raise Query_Unsuccessful with "Release not found: " & Project; + end Find; + -------------------- -- Print_Solution -- -------------------- @@ -29,7 +69,7 @@ package body Alire.Query is use Containers.Project_Release_Maps; begin for Rel of I loop - Log (" " & Rel.Milestone_Image, Detail); + Log (" " & Rel.Milestone_Image, Debug); end loop; end Print_Solution; @@ -61,7 +101,7 @@ package body Alire.Query is is begin if Unresolved.Is_Empty then - Log ("Dependencies resolved"); + Log ("Dependencies resolved", Detail); Print_Solution (Frozen); return Frozen; else @@ -115,7 +155,8 @@ package body Alire.Query is ------------- function Resolve (Deps : Index.Dependencies; - Success : out Boolean) return Instance is + Success : out Boolean; + Policy : Policies := Newest) return Instance is begin Success := False; diff --git a/src/alire-query.ads b/src/alire-query.ads index c9a0764b..9ad68eb8 100644 --- a/src/alire-query.ads +++ b/src/alire-query.ads @@ -1,18 +1,34 @@ with Alire.Containers; with Alire.Index; use Alire.Index; +with Semantic_Versioning; + package Alire.Query is + type Policies is (Oldest, Newest); + --subtype Solution is Containers.Version_Map; -- A dependence-valid mapping of project -> version subtype Instance is Containers.Release_Map; -- A list of releases complying with a Solution Empty_Instance : constant Instance := Containers.Project_Release_Maps.Empty_Map; - function Exists (Project : Project_Name) return Boolean; + function Exists (Project : Project_Name; + Allowed : Semantic_Versioning.Version_Set := Semantic_Versioning.Any) + return Boolean; + + function Find (Project : Project_Name; + Allowed : Semantic_Versioning.Version_Set := Semantic_Versioning.Any; + Policy : Policies := Newest) return Release; function Resolve (Deps : Index.Dependencies; - Success : out Boolean) return Instance; + Success : out Boolean; + Policy : Policies := Newest) return Instance; procedure Print_Solution (I : Instance); + + function Dependency_Image (Project : Project_Name; + Versions : Semantic_Versioning.Version_Set; + Policy : Policies := Newest) return String; + end Alire.Query; diff --git a/src/alire-releases.adb b/src/alire-releases.adb new file mode 100644 index 00000000..1043c972 --- /dev/null +++ b/src/alire-releases.adb @@ -0,0 +1,41 @@ +with GNAT.IO; -- To keep preelaborable + +package body Alire.Releases is + + ----------- + -- Print -- + ----------- + + procedure Print (R : Release) is + use GNAT.IO; + begin + -- MILESTONE + Put_Line (R.Milestone_Image & ": " & R.Description); + + -- ORIGIN + Put_Line ("Origin: " & R.Origin.Image); + + -- REQUISITES + if not R.Reqs.Is_Empty then + Put ("Requisites: "); + R.Reqs.Print_Skeleton; + end if; + + -- PROPERTIES + if not R.Props.Is_Empty then + Put_Line ("Properties:"); + for Prop of R.Props loop + Put_Line (" " & Prop.Image); + end loop; + end if; + + -- DEPENDENCIES + if not R.Depends.Is_Empty then + Put_Line ("Dependencies (direct):"); + for Dep of R.Depends loop + Put_Line (" " & Dep.Image); + end loop; + end if; + end Print; + +end Alire.Releases; diff --git a/src/alire-releases.ads b/src/alire-releases.ads index 47681278..931ecadb 100644 --- a/src/alire-releases.ads +++ b/src/alire-releases.ads @@ -39,6 +39,9 @@ package Alire.Releases with Preelaborate is function Is_Native (R : Release) return Boolean; -- not alr packaged but from the platform + + procedure Print (R : Release); + -- Dump info to console private diff --git a/src/alire-utils.adb b/src/alire-utils.adb new file mode 100644 index 00000000..56def7d6 --- /dev/null +++ b/src/alire-utils.adb @@ -0,0 +1,16 @@ +with GNAT.Case_Util; + +package body Alire.Utils is + + ------------------- + -- To_Mixed_Case -- + ------------------- + + function To_Mixed_Case (S : String) return String is + begin + return SMC : String := S do + GNAT.Case_Util.To_Mixed (SMC); + end return; + end To_Mixed_Case; + +end Alire.Utils; diff --git a/src/alire-utils.ads b/src/alire-utils.ads new file mode 100644 index 00000000..6228dc5b --- /dev/null +++ b/src/alire-utils.ads @@ -0,0 +1,5 @@ +package Alire.Utils with Preelaborate is + + function To_Mixed_Case (S : String) return String; + +end Alire.Utils; diff --git a/src/alire.ads b/src/alire.ads index 0a79ee30..0f7ca09f 100644 --- a/src/alire.ads +++ b/src/alire.ads @@ -2,6 +2,9 @@ with Simple_Logging; package Alire with Preelaborate is + Query_Unsuccessful : exception; + -- Raised by subprograms that return releases/dependencies when not found/impossible + subtype URL is String; Max_Name_Length : constant := 72; -- Github maximum is 100 and bitbucket 128, but since Description is 72...