Moved to new registration framework

This commit is contained in:
Alejandro R. Mosteo
2018-03-11 22:42:30 +01:00
parent 0af8323d1e
commit e637c27bca
38 changed files with 1021 additions and 822 deletions
+24
View File
@@ -1,8 +1,11 @@
with Alire.Conditional_Values;
with Alire.Dependencies.Vectors;
with Alire.Projects;
with Alire.Properties;
with Alire.Requisites;
with Semantic_Versioning;
package Alire.Conditional with Preelaborate is
package For_Dependencies is new Conditional_Values (Dependencies.Vectors.Vector,
@@ -10,9 +13,30 @@ package Alire.Conditional with Preelaborate is
Dependencies.Vectors.Image_One_Line);
subtype Dependencies is For_Dependencies.Conditional_Value;
function New_Dependency (Name : Projects.Names;
Versions : Semantic_Versioning.Version_Set)
return Dependencies;
package For_Properties is new Conditional_Values (Properties.Vector,
Properties."and",
Properties.Image_One_Line);
subtype Properties is For_Properties.Conditional_Value;
function New_Property (Property : Alire.Properties.Property'Class)
return Properties;
private
function New_Dependency (Name : Projects.Names;
Versions : Semantic_Versioning.Version_Set)
return Dependencies is
(For_Dependencies.New_Value
(Alire.Dependencies.Vectors.New_Dependency (Name, Versions)));
function New_Property (Property : Alire.Properties.Property'Class)
return Properties is
(For_Properties.New_Value
(Alire.Properties.To_Vector (Property, 1)));
end Alire.Conditional;
+46 -2
View File
@@ -1,3 +1,4 @@
with Ada.Containers.Ordered_Maps;
with Ada.Directories;
with Ada.Strings.Maps;
@@ -5,6 +6,49 @@ package body Alire.Index is
use all type Version;
package Name_Entry_Maps is new Ada.Containers.Ordered_Maps (Projects.Names,
Catalog_Entry);
Master_Entries : Name_Entry_Maps.Map;
------------------------
-- Catalogued_Project --
------------------------
function Catalogued_Project return Catalog_Entry is
begin
return C : constant Catalog_Entry := (Name, Parent) do
if Master_Entries.Contains (Name) then
Trace.Error ("Duplicate master project registration");
raise Constraint_Error with "Duplicate project master entry";
else
Master_Entries.Insert (Name, C);
end if;
end return;
end Catalogued_Project;
-------------
-- Current --
-------------
function Current (C : Catalog_Entry) return Release is
begin
for R of reverse Catalog loop
if R.Name = C.Name then
return R;
end if;
end loop;
raise Program_Error with "Catalog entry without releases: " & Image (C.Name);
end Current;
---------
-- Get --
---------
function Get (Name : Projects.Names) return Catalog_Entry is
(Master_Entries.Element (Name));
------------
-- Exists --
------------
@@ -55,7 +99,7 @@ package body Alire.Index is
--------------
function Register (-- Mandatory
Project : Names;
Project : Catalog_Entry;
Version : Semantic_Versioning.Version;
Origin : Origins.Origin;
-- we force naming beyond this point with this ugly guard:
@@ -72,7 +116,7 @@ package body Alire.Index is
use all type Alire.Properties.Labeled.Labels;
begin
return Rel : constant Alire.Releases.Release :=
Alire.Releases.New_Release (Project,
Alire.Releases.New_Release (Project.Name,
Version,
Origin,
Notes,
+76 -41
View File
@@ -19,6 +19,7 @@ with Alire.Requisites.Platform;
with Alire.Root;
with Alire.Roots;
with Alire.Utils;
with Alire.Versions;
with Semantic_Versioning;
@@ -29,6 +30,23 @@ package Alire.Index is
---------------
Catalog : Containers.Release_Set;
type Catalog_Entry is new Versions.Comparable with private;
function Name (C : Catalog_Entry) return Projects.Names;
generic
Name : Projects.Names;
-- The following two allow to group several releases in one index file
-- It's a bit of an abuse, but I'm feeling lazy right now
-- The instance should be called subproject_name instead of just project
Parent : Projects.Names := Name;
function Catalogued_Project return Catalog_Entry;
function Callable_String (C : Catalog_Entry) return String;
-- Returns Name.Project, for master projects
-- Returns Parent.Subproject_Name, for subprojects
-----------------
-- Index types --
@@ -46,7 +64,7 @@ package Alire.Index is
subtype Release is Alire.Releases.Release;
function Register (-- Mandatory
Project : Names;
Project : Catalog_Entry;
Version : Semantic_Versioning.Version;
Origin : Origins.Origin;
-- we force naming beyond this point with this ugly guard:
@@ -71,6 +89,12 @@ package Alire.Index is
---------------------
-- BASIC QUERIES --
---------------------
function Current (C : Catalog_Entry) return Release;
-- Get newest release of C project
function Get (Name : Projects.Names) return Catalog_Entry;
-- Master entry for project
function Exists (Project : Name_String) return Boolean;
@@ -110,60 +134,36 @@ package Alire.Index is
function V (Semantic_Version : String) return Semver.Version
renames Semver.Relaxed;
use Versions.Expressions;
function On (Name : Names;
Versions : Semver.Version_Set)
return Conditional.Dependencies renames Releases.On;
-- We provide two easy shortcut forms:
-- One, using another release, from which we'll take name and version
-- The advantage is that strong typing is used
-- Two, using textual name plus version
-- Simpler if there's no exact release matching the versions we want to say
-- Also needed for the generated _alr files which don't know about package names
function Unavailable return Release_Dependencies renames Releases.Unavailable;
function Unavailable return Release_Dependencies;
-- A never available release
function Current (R : Release) return Release_Dependencies is
(On (R.Name, Semver.Within_Major (R.Version)));
-- Within the major of R,
-- it will accept the newest/oldest version according to the resolution policy (by default, newest)
-- These take a release and use its name and version to derive a dependency
function Within_Major is new Releases.From_Release (Semver.Within_Major);
function Within_Minor is new Releases.From_Release (Semver.Within_Minor);
function At_Least is new Releases.From_Release (Semver.At_Least);
function At_Most is new Releases.From_Release (Semver.At_Most);
function Less_Than is new Releases.From_Release (Semver.Less_Than);
function More_Than is new Releases.From_Release (Semver.More_Than);
function Exactly is new Releases.From_Release (Semver.Exactly);
function Except is new Releases.From_Release (Semver.Except);
-- DEPENDENCIES BUILT FROM RELEASES
-- See too Major_Compatible and Minor_Compatible methods of Release
subtype Version is Semantic_Versioning.Version;
subtype Version_Set is Semantic_Versioning.Version_Set;
function Current (P : Names) return Release_Dependencies is (On (P, Semver.Any));
-- 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);
function At_Most is new Releases.From_Names (Semver.At_Most);
function Less_Than is new Releases.From_Names (Semver.Less_Than);
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 Current (C : Catalog_Entry) return Conditional.Dependencies;
function Within_Major (C : Catalog_Entry; V : Version) return Conditional.Dependencies;
function Within_Major (C : Catalog_Entry; V : String) return Conditional.Dependencies;
function Within_Minor (C : Catalog_Entry; V : Version) return Conditional.Dependencies;
function Within_Minor (C : Catalog_Entry; V : String) return Conditional.Dependencies;
function On_Condition (Condition : Requisites.Tree;
When_True : Release_Dependencies;
When_False : Release_Dependencies := No_Dependencies)
return Release_Dependencies
renames Conditional.For_Dependencies.New_Conditional;
-- Excplicitly conditional
-- Explicitly conditional
function When_Available (Preferred : Release_Dependencies;
Otherwise : Release_Dependencies := Releases.Unavailable)
Otherwise : Release_Dependencies := Unavailable)
return Release_Dependencies is
(On_Condition (Requisites.Dependencies.New_Requisite (Preferred),
Preferred,
@@ -274,12 +274,47 @@ package Alire.Index is
return Roots.Root renames Alire.Root.Set;
-- An unindexed working copy
private
private
type Catalog_Entry is new Versions.Comparable with record
Name : Projects.Names;
Parent : Projects.Names;
end record;
overriding
function New_Dependency (L : Catalog_Entry; VS : Semantic_Versioning.Version_Set)
return Conditional.Dependencies is
(Conditional.For_Dependencies.New_Value -- A conditional (without condition) dependency vector
(Dependencies.Vectors.New_Dependency (L.Name, VS)));
function Callable_String (C : Catalog_Entry) return String is
(if C.Parent = C.Name
then Utils.To_Mixed_Case (Projects.Image (C.Name) & ".Project")
else Utils.To_Mixed_Case (Projects.Image (C.Parent) & ".Subproject_" & Image (C.Name)));
function Current (C : Catalog_Entry) return Conditional.Dependencies is
(Conditional.New_Dependency (C.Name, Semver.Any));
function Within_Major (C : Catalog_Entry; V : Version) return Conditional.Dependencies is
(Conditional.New_Dependency (C.Name, Semver.Within_Major (V)));
function Within_Major (C : Catalog_Entry; V : String) return Conditional.Dependencies is
(Conditional.New_Dependency (C.Name, Semver.Within_Major (Index.V (V))));
function Within_Minor (C : Catalog_Entry; V : Version) return Conditional.Dependencies is
(Conditional.New_Dependency (C.Name, Semver.Within_Minor (V)));
function Within_Minor (C : Catalog_Entry; V : String) return Conditional.Dependencies is
(Conditional.New_Dependency (C.Name, Semver.Within_Minor (Index.V (V))));
function Name (C : Catalog_Entry) return Projects.Names is (C.Name);
function GPR_File_Unsafe is new PL.Cond_New_Label (Properties.Labeled.GPR_File);
function GPR_Path_Unsafe is new PL.Cond_New_Label (Properties.Labeled.GPR_Path);
function GPR_File (File : Platform_Independent_Path) return Release_Properties renames GPR_File_Unsafe;
function GPR_Path (Path : Platform_Independent_Path) return Release_Properties renames GPR_Path_Unsafe;
function Unavailable return Conditional.Dependencies is
(Conditional.For_Dependencies.New_Value -- A conditional (without condition) dependency vector
(Dependencies.Vectors.New_Dependency (Projects.Alire_Reserved, Semver.Any)));
end Alire.Index;
+1
View File
@@ -1,4 +1,5 @@
with Alire.Conditional_Values;
with Alire.Dependencies.Vectors;
with Alire.Platforms;
with Alire.Requisites.Booleans;
+19 -33
View File
@@ -1,6 +1,6 @@
with Alire.Conditional;
with Alire.Dependencies;
with Alire.Dependencies.Vectors;
-- with Alire.Dependencies.Vectors;
with Alire.Milestones;
with Alire.Origins;
with Alire.Projects;
@@ -8,6 +8,7 @@ with Alire.Properties;
with Alire.Properties.Labeled;
with Alire.Requisites;
with Alire.Utils;
with Alire.Versions;
with Semantic_Versioning;
@@ -15,7 +16,7 @@ private with Alire.OS_Lib;
package Alire.Releases with Preelaborate is
type Release (<>) is tagged private;
type Release (<>) is new Versions.Versioned with private;
function New_Release (Name : Projects.Names;
Version : Semantic_Versioning.Version;
@@ -98,36 +99,25 @@ package Alire.Releases with Preelaborate is
-- Dependency generation helpers for all semantic versioning functions:
-- These are here to avoid a 'body not seen' Program_Error if they were in Index
function On (Name : Projects.Names;
Versions : Semantic_Versioning.Version_Set)
return Conditional.Dependencies;
generic
with function Condition (V : Semantic_Versioning.Version) return Semantic_Versioning.Version_Set;
function From_Release (R : Release) return Conditional.Dependencies;
generic
with function Condition (V : Semantic_Versioning.Version) return Semantic_Versioning.Version_Set;
function From_Names (P : Projects.Names;
V : Semantic_Versioning.Version) return Conditional.Dependencies;
function Unavailable return Conditional.Dependencies;
-- A never available dependency that is useful in conditional chained dependencies (see Index)
-- function On (Name : Projects.Names;
-- Versions : Semantic_Versioning.Version_Set)
-- return Conditional.Dependencies;
--
-- generic
-- with function Condition (V : Semantic_Versioning.Version) return Semantic_Versioning.Version_Set;
-- function From_Release (R : Release) return Conditional.Dependencies;
private
use all type Projects.Names;
function All_Properties (R : Release) return Conditional.Properties;
function Unavailable return Conditional.Dependencies is
(On (Alire_Reserved, Semantic_Versioning.Any));
function All_Properties (R : Release) return Conditional.Properties;
use Alire.Properties;
function Comment is new Alire.Properties.Labeled.Cond_New_Label (Alire.Properties.Labeled.Comment);
function Describe is new Alire.Properties.Labeled.Cond_New_Label (Alire.Properties.Labeled.Description);
type Release (Descr_Len : Natural) is tagged record
type Release (Descr_Len : Natural) is new Versions.Versioned with record
Name : Projects.Names;
Version : Semantic_Versioning.Version;
Origin : Origins.Origin;
@@ -206,17 +196,13 @@ private
-- Dependency helpers
function On (Name : Projects.Names;
Versions : Semantic_Versioning.Version_Set)
return Conditional.Dependencies is
(Conditional.For_Dependencies.New_Value -- A conditional (without condition) dependency vector
(Dependencies.Vectors.New_Dependency (Name, Versions))); -- A dependency vector
-- function On (Name : Projects.Names;
-- Versions : Semantic_Versioning.Version_Set)
-- return Conditional.Dependencies is
-- (Conditional.For_Dependencies.New_Value -- A conditional (without condition) dependency vector
-- (Dependencies.Vectors.New_Dependency (Name, Versions))); -- A dependency vector
function From_Release (R : Release) return Conditional.Dependencies is
(On (R.Name, Condition (R.Version)));
function From_Names (P : Projects.Names;
V : Semantic_Versioning.Version) return Conditional.Dependencies is
(On (P, Condition (V)));
-- function From_Release (R : Release) return Conditional.Dependencies is
-- (On (R.Name, Condition (R.Version)));
end Alire.Releases;
+1 -1
View File
@@ -34,7 +34,7 @@ package body Alire.Root is
return Root.all;
else
-- Session is outdated or outside
Trace.Debug ("Storing incomplete root for outdated session");
Trace.Warning ("Storing incomplete root for outdated session");
return Set (Projects.Image (Project),
Conditional.For_Dependencies.Empty);
end if;
+43
View File
@@ -0,0 +1,43 @@
with Alire.Conditional;
with Alire.Projects;
with Semantic_Versioning;
with Semantic_Versioning.Expressions;
package Alire.Versions with Preelaborate is
-- Helper package to prepare expressions on version for use in Alire.Index.*
type Versioned is interface;
function Name (V : Versioned) return Projects.Names is abstract;
function Version (V : Versioned) return Semantic_Versioning.Version is abstract;
function Within_Major (V : Versioned'Class) return Conditional.Dependencies;
function Within_Minor (V : Versioned'Class) return Conditional.Dependencies;
type Comparable is interface;
function New_Dependency (L : Comparable; VS : Semantic_Versioning.Version_Set)
return Conditional.Dependencies is abstract;
function New_Dependency_Classwide (L : Comparable'Class; VS : Semantic_Versioning.Version_Set)
return Conditional.Dependencies is (L.New_Dependency (VS));
package Expressions is new Semantic_Versioning.Expressions
(Comparable'Class,
Conditional.Dependencies,
New_Dependency_Classwide);
private
use Semantic_Versioning;
function Within_Major (V : Versioned'Class) return Conditional.Dependencies is
(Conditional.New_Dependency (V.Name, Within_Major (V.Version)));
function Within_Minor (V : Versioned'Class) return Conditional.Dependencies is
(Conditional.New_Dependency (V.Name, Within_Minor (V.Version)));
end Alire.Versions;