Miscellaneous refactoring

This commit is contained in:
Jano at Zelda
2018-02-16 19:58:27 +01:00
parent 724359c0d1
commit ec00e07e79
13 changed files with 183 additions and 189 deletions
+2
View File
@@ -4,6 +4,8 @@ with Ada.Containers.Indefinite_Ordered_Sets;
with Alire.Releases; with Alire.Releases;
with Semantic_Versioning;
package Alire.Containers with Preelaborate is package Alire.Containers with Preelaborate is
package Release_Sets is new Ada.Containers.Indefinite_Ordered_Sets (Releases.Release, package Release_Sets is new Ada.Containers.Indefinite_Ordered_Sets (Releases.Release,
+36
View File
@@ -0,0 +1,36 @@
with Ada.Containers.Indefinite_Vectors;
package Alire.Dependencies.Vectors with Preelaborate is
-- Dependencies are a plain list (vector) of individual dependencies
-- There's nothing preventing giving version sets on the same project as distinct dependencies
package Dependency_Vectors is new Ada.Containers.Indefinite_Vectors (Positive, Dependency);
type Vector is new Dependency_Vectors.Vector with private;
function No_Dependencies return Vector;
-- Creation of dependency vectors
function New_Dependency (Name : Project_Name;
Versions : Semantic_Versioning.Version_Set) return Vector;
function "and" (Dep1, Dep2 : Vector) return Vector is (Dep1 & Dep2);
private
type Vector is new Dependency_Vectors.Vector with null record;
-- New type so the "and" function is primitive
function No_Dependencies return Vector is (Dependency_Vectors.Empty_Vector with null record);
--------------------
-- New_Dependency --
--------------------
function New_Dependency (Name : Project_Name;
Versions : Semantic_Versioning.Version_Set) return Vector is
(To_Vector ((Name'Length, Name, To_Holder (Versions)), 1));
end Alire.Dependencies.Vectors;
+42
View File
@@ -0,0 +1,42 @@
private with Ada.Containers.Indefinite_Holders;
with Semantic_Versioning;
package Alire.Dependencies with Preelaborate is
-- A single dependency is a project name plus a version set
type Dependency (<>) is tagged private;
function New_Dependency (Name : Project_Name;
Versions : Semantic_Versioning.Version_Set) return Dependency;
function Project (Dep : Dependency) return Project_Name;
function Versions (Dep : Dependency) return Semantic_Versioning.Version_Set;
private
use all type Semantic_Versioning.Version;
package Version_Holders is new Ada.Containers.Indefinite_Holders
(Semantic_Versioning.Version_Set, Semantic_Versioning."=");
type Version_Set_Holder is new Version_Holders.Holder with null record;
type Dependency (Name_Len : Positive) is tagged record
Project : Project_Name (1 .. Name_Len);
Versions_H : Version_Set_holder;
end record;
function New_Dependency (Name : Project_Name;
Versions : Semantic_Versioning.Version_Set) return Dependency
is ((Name'Length, Name, To_Holder (Versions)));
function Project (Dep : Dependency) return Project_Name is (Dep.Project);
function Versions (Dep : Dependency) return Semantic_Versioning.Version_Set is
(Dep.Versions_H.Element);
end Alire.Dependencies;
-28
View File
@@ -1,28 +0,0 @@
with Ada.Containers.Indefinite_Vectors;
package Alire.Depends with Preelaborate is
package Dependency_Vectors is new Ada.Containers.Indefinite_Vectors
(Positive, Dependency);
type Dependencies is new Dependency_Vectors.Vector with null record ;
function Nothing return Dependencies is (Dependency_Vectors.Empty_Vector with null record);
function New_Dependency (Name : Project_Name;
Versions : Semantic_Versioning.Version_Set) return Dependencies;
function Depends_On (Name : Project_Name;
Versions : Semantic_Versioning.Version_Set) return Dependencies renames New_Dependency;
function On (Name : Project_Name;
Versions : Semantic_Versioning.Version_Set) return Dependencies renames New_Dependency;
function "and" (Dep1, Dep2 : Dependencies) return Dependencies;
private
function New_Dependency (Name : Project_Name;
Versions : Semantic_Versioning.Version_Set) return Dependencies
is (To_Vector ((Name'Length, Name, To_Holder (Versions)), 1));
function "and" (Dep1, Dep2 : Dependencies) return Dependencies is (Dep1 & Dep2);
end Alire.Depends;
+4 -4
View File
@@ -14,10 +14,10 @@ package body Alire.Index is
Description : Project_Description; Description : Project_Description;
Hosting : Repositories.Repository'Class; Hosting : Repositories.Repository'Class;
Id : Repositories.Release_Id; Id : Repositories.Release_Id;
Depends_On : Dependencies := Depends.Nothing; Depends_On : Dependencies := No_Dependencies;
Properties : Alire.Properties.Vector := Alire.Properties.Vectors.Empty_Vector; Properties : Alire.Properties.Vector := No_Properties;
Requisites : Alire.Requisites.Tree := Alire.Requisites.No_Requisites; Requisites : Alire.Requisites.Tree := No_Requisites;
Available_When : Alire.Requisites.Tree := Alire.Requisites.No_Requisites; Available_When : Alire.Requisites.Tree := No_Requisites;
Native : Boolean := False) return Release Native : Boolean := False) return Release
is is
begin begin
+26 -23
View File
@@ -2,7 +2,7 @@ private with Alire_Early_Elaboration; pragma Unreferenced (Alire_Early_Elaborati
with Alire.Containers; with Alire.Containers;
with Alire.Compilers; with Alire.Compilers;
with Alire.Depends; with Alire.Dependencies.Vectors;
with Alire.Operating_Systems; with Alire.Operating_Systems;
with Alire.Properties; with Alire.Properties;
with Alire.Releases; with Alire.Releases;
@@ -16,8 +16,11 @@ package Alire.Index is
Releases : Containers.Release_Set; Releases : Containers.Release_Set;
subtype Dependencies is Depends.Dependencies; subtype Dependencies is Alire.Dependencies.Vectors.Vector;
use all type Dependencies;
No_Dependencies : constant Dependencies := Alire.Dependencies.Vectors.No_Dependencies;
No_Properties : constant Properties.Vector := Properties.Vectors.Empty_Vector;
No_Requisites : constant Requisites.Tree := Requisites.Trees.Empty_Tree;
subtype Release is Alire.Releases.Release; subtype Release is Alire.Releases.Release;
@@ -28,10 +31,10 @@ package Alire.Index is
Hosting : Repositories.Repository'Class; Hosting : Repositories.Repository'Class;
Id : Repositories.Release_Id; Id : Repositories.Release_Id;
-- Optional -- Optional
Depends_On : Dependencies := Depends.Nothing; Depends_On : Dependencies := No_Dependencies;
Properties : Alire.Properties.Vector := Alire.Properties.Vectors.Empty_Vector; Properties : Alire.Properties.Vector := No_Properties;
Requisites : Alire.Requisites.Tree := Alire.Requisites.No_Requisites; Requisites : Alire.Requisites.Tree := No_Requisites;
Available_When : Alire.Requisites.Tree := Alire.Requisites.No_Requisites; Available_When : Alire.Requisites.Tree := No_Requisites;
Native : Boolean := False) return Release; Native : Boolean := False) return Release;
-- Properties are of the Release; currently not used but could support License or other attributes. -- Properties are of the Release; currently not used but could support License or other attributes.
-- Requisites are properties that dependencies have to fulfill, again not used yet. -- Requisites are properties that dependencies have to fulfill, again not used yet.
@@ -43,9 +46,9 @@ package Alire.Index is
Hosting : URL; Hosting : URL;
Commit : Repositories.Git.Commit_ID; Commit : Repositories.Git.Commit_ID;
-- Optional -- Optional
Properties : Alire.Properties.Vector := Alire.Properties.Vectors.Empty_Vector; Properties : Alire.Properties.Vector := No_Properties;
Requisites : Alire.Requisites.Tree := Alire.Requisites.No_Requisites; Requisites : Alire.Requisites.Tree := No_Requisites;
Depends_On : Dependencies := Depends.Nothing) return Release; Depends_On : Dependencies := No_Dependencies) return Release;
-- Shortcuts to give dependencies: -- Shortcuts to give dependencies:
@@ -81,8 +84,7 @@ package Alire.Index is
use all type Requisites.Requisite'Class; use all type Requisites.Requisite'Class;
use all type Requisites.Tree; -- for logical operators use all type Requisites.Tree; -- for logical operators
Default_Properties : constant Properties.Vector := Properties.Vectors.Empty_Vector; Default_Properties : constant Properties.Vector := No_Properties;
No_Requisites : constant Requisites.Tree := Requisites.No_Requisites;
function Verifies (P : Properties.Property'Class) return Properties.Vector; function Verifies (P : Properties.Property'Class) return Properties.Vector;
function "+" (P : Properties.Property'Class) return Properties.Vector renames Verifies; function "+" (P : Properties.Property'Class) return Properties.Vector renames Verifies;
@@ -105,9 +107,9 @@ private
Description : Project_Description; Description : Project_Description;
Hosting : URL; Hosting : URL;
Commit : Repositories.Git.Commit_ID; Commit : Repositories.Git.Commit_ID;
Properties : Alire.Properties.Vector := Alire.Properties.Vectors.Empty_Vector; Properties : Alire.Properties.Vector := No_Properties;
Requisites : Alire.Requisites.Tree := Alire.Requisites.No_Requisites; Requisites : Alire.Requisites.Tree := No_Requisites;
Depends_On : Dependencies := Depends.Nothing) return Release Depends_On : Dependencies := No_Dependencies) return Release
is (Register (Project, is (Register (Project,
Version, Version,
Description, Description,
@@ -118,9 +120,10 @@ private
Requisites => Requisites, Requisites => Requisites,
Native => False)); Native => False));
use Depends;
use Semantic_Versioning; use Semantic_Versioning;
use all type Dependencies;
function At_Least_Within_Major (R : Release) return Dependencies is function At_Least_Within_Major (R : Release) return Dependencies is
(New_Dependency (R.Project, At_Least_Within_Major (R.Version))); (New_Dependency (R.Project, At_Least_Within_Major (R.Version)));
@@ -144,25 +147,25 @@ private
function At_Least_Within_Major (P : Project_Name; V : Version) return Dependencies is function At_Least_Within_Major (P : Project_Name; V : Version) return Dependencies is
(Depends_On (P, At_Least_Within_Major (V))); (New_Dependency (P, At_Least_Within_Major (V)));
function At_Least (P : Project_Name; V : Version) return Dependencies is function At_Least (P : Project_Name; V : Version) return Dependencies is
(Depends_On (P, At_Least (V))); (New_Dependency (P, At_Least (V)));
function At_Most (P : Project_Name; V : Version) return Dependencies is function At_Most (P : Project_Name; V : Version) return Dependencies is
(Depends_On (P, At_Most (V))); (New_Dependency (P, At_Most (V)));
function Less_Than (P : Project_Name; V : Version) return Dependencies is function Less_Than (P : Project_Name; V : Version) return Dependencies is
(Depends_On (P, Less_Than (V))); (New_Dependency (P, Less_Than (V)));
function More_Than (P : Project_Name; V : Version) return Dependencies is function More_Than (P : Project_Name; V : Version) return Dependencies is
(Depends_On (P, More_Than (V))); (New_Dependency (P, More_Than (V)));
function Exactly (P : Project_Name; V : Version) return Dependencies is function Exactly (P : Project_Name; V : Version) return Dependencies is
(Depends_On (P, Exactly (V))); (New_Dependency (P, Exactly (V)));
function Except (P : Project_Name; V : Version) return Dependencies is function Except (P : Project_Name; V : Version) return Dependencies is
(Depends_On (P, Except (V))); (New_Dependency (P, Except (V)));
function Verifies (P : Properties.Property'Class) return Properties.Vector is function Verifies (P : Properties.Property'Class) return Properties.Vector is
+36
View File
@@ -0,0 +1,36 @@
with Semantic_Versioning;
package Alire.Milestones with Preelaborate is
type Milestone (<>) is tagged private;
function "<" (L, R : Milestone) return Boolean;
function New_Milestone (Name : Project_Name;
Version : Semantic_Versioning.Version) return Milestone;
function Project (M : Milestone) return Project_Name;
function Version (M : Milestone) return Semantic_Versioning.Version;
private
type Milestone (Name_Len : Positive) is tagged record
Name : Project_Name (1 .. Name_Len);
Version : Semantic_Versioning.Version;
end record;
use all type Semantic_Versioning.Version;
function "<" (L, R : Milestone) return Boolean is
(L.Name < R.Name or else (L.Name = R.Name and then L.Version < R.Version));
function New_Milestone (Name : Project_Name;
Version : Semantic_Versioning.Version) return Milestone is
(Name'Length, Name, Version);
function Project (M : Milestone) return Project_Name is (M.Name);
function Version (M : Milestone) return Semantic_Versioning.Version is (M.Version);
end Alire.Milestones;
-10
View File
@@ -1,10 +0,0 @@
package Alire.Properties.Versions with Preelaborate is
-- Internally we manage versions as a tree of conditions, so arbitrary logical expressions can be used
package Values is new Properties.values (Semantic_Versioning.Version);
function New_Version (V : Semantic_Versioning.Version) return Property'Class is
(Values.New_Property (V));
end Alire.Properties.Versions;
+16 -10
View File
@@ -1,5 +1,11 @@
with Alire.Dependencies;
with Semantic_Versioning;
package body Alire.Query is package body Alire.Query is
package Semver renames Semantic_Versioning;
------------ ------------
-- Exists -- -- Exists --
------------ ------------
@@ -37,20 +43,20 @@ package body Alire.Query is
-- Resolve -- -- Resolve --
------------- -------------
function Resolve (Unresolved : Dependencies; function Resolve (Unresolved : Index.Dependencies;
Frozen : Instance; Frozen : Instance;
Success : out Boolean) return Instance Success : out Boolean) return Instance
is is
-- FIXME: since this is depth-first, Frozen can be passed in-out and updated on the spot, -- FIXME: since this is depth-first, Frozen can be passed in-out and updated on the spot,
-- thus saving copies. Probably the same applies to Unresolved. -- thus saving copies. Probably the same applies to Unresolved.
Dep : constant Dependency := Unresolved.First_Element; Dep : constant Alire.Dependencies.Dependency := Unresolved.First_Element;
Remain : Dependencies := Unresolved; Remain : Index.Dependencies := Unresolved;
--------------- ---------------
-- Go_Deeper -- -- Go_Deeper --
--------------- ---------------
function Go_Deeper (Unresolved : Dependencies; function Go_Deeper (Unresolved : Index.Dependencies;
Frozen : Instance) return Instance Frozen : Instance) return Instance
is is
begin begin
@@ -68,7 +74,7 @@ package body Alire.Query is
Remain.Delete_First; Remain.Delete_First;
if Frozen.Contains (Dep.Project) then if Frozen.Contains (Dep.Project) then
if Satisfies (Frozen.Element (Dep.Project).Version, Dep.Versions) then if Semver.Satisfies (Frozen.Element (Dep.Project).Version, Dep.Versions) then
-- Dependency already met, simply go down... -- Dependency already met, simply go down...
return Go_Deeper (Remain, Frozen); return Go_Deeper (Remain, Frozen);
else else
@@ -79,10 +85,10 @@ package body Alire.Query is
-- Need to check all versions for the first one... -- Need to check all versions for the first one...
-- FIXME: complexity can be improved not visiting blindly all releases to match by project -- FIXME: complexity can be improved not visiting blindly all releases to match by project
for R of reverse Index.Releases loop for R of reverse Index.Releases loop
if Dep.Project = R.Project and then Satisfies (R.Version, Dep.Versions) then if Dep.Project = R.Project and then Semver.Satisfies (R.Version, Dep.Versions) then
declare declare
New_Frozen : Instance := Frozen; New_Frozen : Instance := Frozen;
New_Remain : Dependencies := Remain; New_Remain : Index.Dependencies := Remain;
Solution : Instance; Solution : Instance;
begin begin
@@ -108,7 +114,7 @@ package body Alire.Query is
-- Resolve -- -- Resolve --
------------- -------------
function Resolve (Deps : Dependencies; function Resolve (Deps : Index.Dependencies;
Success : out Boolean) return Instance is Success : out Boolean) return Instance is
begin begin
Success := False; Success := False;
+2 -2
View File
@@ -10,8 +10,8 @@ package Alire.Query is
function Exists (Project : Project_Name) return Boolean; function Exists (Project : Project_Name) return Boolean;
function Resolve (Deps : Dependencies; function Resolve (Deps : Index.Dependencies;
Success : out Boolean) return Instance; Success : out Boolean) return Instance;
procedure Print_Solution (I : Instance); procedure Print_Solution (I : Instance);
+7 -5
View File
@@ -1,13 +1,13 @@
with Alire.Depends; with Alire.Dependencies.Vectors;
with Alire.Properties; with Alire.Properties;
with Alire.Repositories; with Alire.Repositories;
with Alire.Requisites; with Alire.Requisites;
package Alire.Releases with Semantic_Versioning;
with Preelaborate
is
subtype Dependencies is Depends.Dependencies; package Alire.Releases with Preelaborate is
subtype Dependencies is Alire.Dependencies.Vectors.Vector;
type Release (<>) is tagged private; type Release (<>) is tagged private;
@@ -77,6 +77,8 @@ private
Requisites, Requisites,
Native); Native);
use all type Semantic_Versioning.Version;
function "<" (L, R : Release) return Boolean is function "<" (L, R : Release) return Boolean is
(L.Project < R.Project or else (L.Project < R.Project or else
(L.Project = R.Project and then L.Version < R.Version) or else (L.Project = R.Project and then L.Version < R.Version) or else
-34
View File
@@ -1,34 +0,0 @@
with Alire.Properties.Versions;
package Alire.Requisites.Versions with Preelaborate is
package Semver renames Semantic_Versioning;
function Exactly (V : Semver.Version) return Requisite'Class;
private
package Props renames Alire.Properties.Versions;
package Version_Requisites is new Typed_Requisites (Props.Values.Property'Class);
type Version_Requisite is new Version_Requisites.Requisite with record
Set : Semver.Version_Set;
end record;
------------------
-- Is_Satisfied --
------------------
overriding function Is_Satisfied (R : Version_Requisite;
P : Props.Values.Property'Class) return Boolean is
(Semver.Is_In (V => P.Element, VS => R.Set));
-------------
-- Exactly --
-------------
function Exactly (V : Semver.Version) return Requisite'Class is
(Version_Requisite'(Set => Semver.Exactly (V)));
end Alire.Requisites.Versions;
+2 -63
View File
@@ -1,20 +1,16 @@
private with Ada.Containers.Indefinite_Holders;
with Semantic_Versioning;
with Simple_Logging; with Simple_Logging;
package Alire with Preelaborate is package Alire with Preelaborate is
File_Error : exception; File_Error : exception;
type URL is new String; type URL is new String;
Max_Name_Length : constant := 72; -- Github maximum is 100 and bitbucket 128, but since Description is 72... Max_Name_Length : constant := 72; -- Github maximum is 100 and bitbucket 128, but since Description is 72...
Max_Description_Length : constant := 72; -- Git line recommendation (although it's 50 for subject line) Max_Description_Length : constant := 72; -- Git line recommendation (although it's 50 for subject line)
-- Basics of projects: Name and Description
-- Rest of properties are grouped in the Index
subtype Project_Name is String with Dynamic_Predicate => subtype Project_Name is String with Dynamic_Predicate =>
Project_Name'Length >= 3 and then Project_Name'Length >= 3 and then
@@ -22,30 +18,9 @@ package Alire with Preelaborate is
Project_Name (Project_Name'First) /= '_' and then Project_Name (Project_Name'First) /= '_' and then
(for all C of Project_Name => C in 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_'); (for all C of Project_Name => C in 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_');
subtype Project_Description is String with Dynamic_Predicate => subtype Project_Description is String with Dynamic_Predicate =>
Project_Description'Length <= Max_Description_Length; Project_Description'Length <= Max_Description_Length;
type Dependency (<>) is tagged private;
function Project (Dep : Dependency) return Project_Name;
function Versions (Dep : Dependency) return Semantic_Versioning.Version_Set;
type Milestone (<>) is tagged private;
function "<" (L, R : Milestone) return Boolean;
function New_Milestone (Name : Project_Name;
Version : Semantic_Versioning.Version) return Milestone;
function Project (M : Milestone) return Project_Name;
function Version (M : Milestone) return Semantic_Versioning.Version;
--------------- ---------------
-- LOGGING -- -- LOGGING --
--------------- ---------------
@@ -58,40 +33,4 @@ package Alire with Preelaborate is
procedure Log (S : String; Level : Simple_Logging.Levels := Info) renames Simple_Logging.Log; procedure Log (S : String; Level : Simple_Logging.Levels := Info) renames Simple_Logging.Log;
private
use all type Semantic_Versioning.Version;
package Version_Holders is new Ada.Containers.Indefinite_Holders
(Semantic_Versioning.Version_Set, Semantic_Versioning."=");
type Version_Set_Holder is new Version_Holders.Holder with null record;
type Dependency (Name_Len : Positive) is tagged record
Project : Project_Name (1 .. Name_Len);
Versions_H : Version_Set_holder;
end record;
function Project (Dep : Dependency) return Project_Name is (Dep.Project);
function Versions (Dep : Dependency) return Semantic_Versioning.Version_Set is
(Dep.Versions_H.Element);
type Milestone (Name_Len : Positive) is tagged record
Name : Project_Name (1 .. Name_Len);
Version : Semantic_Versioning.Version;
end record;
function "<" (L, R : Milestone) return Boolean is
(L.Name < R.Name or else (L.Name = R.Name and then L.Version < R.Version));
function New_Milestone (Name : Project_Name;
Version : Semantic_Versioning.Version) return Milestone is
(Name'Length, Name, Version);
function Project (M : Milestone) return Project_Name is (M.Name);
function Version (M : Milestone) return Semantic_Versioning.Version is (M.Version);
end Alire; end Alire;