Proper Root type
This commit is contained in:
+17
-9
@@ -16,7 +16,8 @@ with Alire.Releases;
|
||||
with Alire.Requisites;
|
||||
with Alire.Requisites.Dependencies;
|
||||
with Alire.Requisites.Platform;
|
||||
with Alire.Root_Release;
|
||||
with Alire.Root;
|
||||
with Alire.Roots;
|
||||
with Alire.Utils;
|
||||
|
||||
with Semantic_Versioning;
|
||||
@@ -42,7 +43,7 @@ package Alire.Index is
|
||||
No_Properties : constant Release_Properties := Conditional.For_Properties.Empty;
|
||||
No_Requisites : constant Requisites.Tree := Requisites.Trees.Empty_Tree;
|
||||
|
||||
subtype Release is Alire.Releases.Release;
|
||||
subtype Release is Alire.Releases.Release;
|
||||
|
||||
function Register (-- Mandatory
|
||||
Project : Names;
|
||||
@@ -256,13 +257,20 @@ package Alire.Index is
|
||||
function Word_Size is new Requisites.Platform.Word_Sizes.Factory;
|
||||
use all type Requisites.Platform.Word_Sizes.Comparable;
|
||||
|
||||
function Set_Root_Release (Project : Alire.Name_String;
|
||||
Version : Semantic_Versioning.Version;
|
||||
Dependencies : Conditional.Dependencies := No_Dependencies)
|
||||
return Release renames Root_Release.Set;
|
||||
-- This function must be called in the working project alire file.
|
||||
-- Otherwise alr does not know what's the current project, and its version and dependencies
|
||||
-- The returned Release is the same; this is just a trick to be able to use it in an spec file.
|
||||
------------
|
||||
-- ROOT --
|
||||
------------
|
||||
-- The root determines the starting point to look for dependencies
|
||||
|
||||
function Set (Project : Projects.Names;
|
||||
Version : Semantic_Versioning.Version)
|
||||
return Roots.Root renames Root.Set;
|
||||
-- All information will be taken from the indexed release
|
||||
|
||||
function Set (Project : Name_String;
|
||||
Dependencies : Conditional.Dependencies)
|
||||
return Roots.Root renames Root.Set;
|
||||
-- An unindexed working copy
|
||||
|
||||
private
|
||||
|
||||
|
||||
@@ -40,6 +40,8 @@ package Alire.Releases with Preelaborate is
|
||||
function Description (R : Release) return Description_String;
|
||||
-- The global project description
|
||||
|
||||
function Depends (R : Release) return Conditional.Dependencies;
|
||||
|
||||
function Depends (R : Release;
|
||||
P : Properties.Vector)
|
||||
return Dependencies.Vector;
|
||||
@@ -176,6 +178,8 @@ private
|
||||
function Notes (R : Release) return Description_String is (R.Notes);
|
||||
function Version (R : Release) return Semantic_Versioning.Version is (R.Version);
|
||||
|
||||
function Depends (R : Release) return Conditional.Dependencies is (R.Dependencies);
|
||||
|
||||
function Depends (R : Release;
|
||||
P : Properties.Vector)
|
||||
return Dependencies.Vector is (R.Dependencies.Evaluate (P));
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
with Alire.Index;
|
||||
|
||||
package body Alire.Root is
|
||||
|
||||
Root : access Roots.Root;
|
||||
-- Root dependency (the working project). If Is_Empty we know we must recompile,
|
||||
-- unless the hash already matches. In this case, we know the project file is
|
||||
-- missing the Set call
|
||||
|
||||
-------------
|
||||
-- Current --
|
||||
-------------
|
||||
|
||||
function Current return Roots.Root is (Root.all);
|
||||
|
||||
------------
|
||||
-- Is_Set --
|
||||
------------
|
||||
|
||||
function Is_Set return Boolean is (Root /= null);
|
||||
|
||||
---------
|
||||
-- Set --
|
||||
---------
|
||||
|
||||
function Set (Project : Projects.Names;
|
||||
Version : Semantic_Versioning.Version)
|
||||
return Roots.Root
|
||||
is
|
||||
begin
|
||||
Root := new Roots.Root'(Roots.New_Root (Index.Find (Projects.Image (Project), Version)));
|
||||
Trace.Debug ("Storing indexed release as root: " & Root.Release.Milestone.Image);
|
||||
return Root.all;
|
||||
end Set;
|
||||
|
||||
---------
|
||||
-- Set --
|
||||
---------
|
||||
|
||||
function Set (Project : Name_String;
|
||||
Dependencies : Conditional.Dependencies)
|
||||
return Roots.Root
|
||||
is
|
||||
begin
|
||||
Trace.Debug ("Storing unindexed project as root:" & Project);
|
||||
Root := new Roots.Root'(Roots.New_Root (Project, Dependencies));
|
||||
return Root.all;
|
||||
end Set;
|
||||
|
||||
end Alire.Root;
|
||||
@@ -0,0 +1,27 @@
|
||||
with Alire.Conditional;
|
||||
with Alire.Projects;
|
||||
with Alire.Roots;
|
||||
|
||||
with Semantic_Versioning;
|
||||
|
||||
package Alire.Root is
|
||||
|
||||
-- When alr self-compiles it inserts a call to this function, so the dependency root is stablished
|
||||
|
||||
-- The two flavors distinguish when it is an already indexed project and a new unindexed one (working copy)
|
||||
|
||||
function Set (Project : Projects.Names;
|
||||
Version : Semantic_Versioning.Version)
|
||||
return Roots.Root;
|
||||
-- All information will be taken from the indexed release
|
||||
|
||||
function Set (Project : Name_String;
|
||||
Dependencies : Conditional.Dependencies)
|
||||
return Roots.Root;
|
||||
-- An unindexed working copy
|
||||
|
||||
function Current return Roots.Root;
|
||||
|
||||
function Is_Set return Boolean;
|
||||
|
||||
end Alire.Root;
|
||||
@@ -1,64 +0,0 @@
|
||||
|
||||
with Ada.Directories;
|
||||
|
||||
with Alire.Containers;
|
||||
with Alire.Index;
|
||||
with Alire.Origins;
|
||||
with Alire.Projects;
|
||||
with Alire.Requisites;
|
||||
|
||||
package body Alire.Root_Release is
|
||||
|
||||
Root : Alire.Containers.Release_H;
|
||||
-- Root dependency (the working project). If Is_Empty we know we must recompile,
|
||||
-- unless the hash already matches. In this case, we know the project file is
|
||||
-- missing the Set call
|
||||
|
||||
-------------
|
||||
-- Current --
|
||||
-------------
|
||||
|
||||
function Current return Releases.Release is (Root.Element);
|
||||
|
||||
------------
|
||||
-- Is_Set --
|
||||
------------
|
||||
|
||||
function Is_Set return Boolean is
|
||||
(not Root.Is_Empty);
|
||||
|
||||
---------
|
||||
-- Set --
|
||||
---------
|
||||
|
||||
function Set (Project : Alire.Name_String;
|
||||
Version : Semantic_Versioning.Version;
|
||||
Dependencies : Conditional.Dependencies := Conditional.For_Dependencies.Empty)
|
||||
return Releases.Release
|
||||
is
|
||||
use Origins;
|
||||
|
||||
Rel : constant Releases.Release :=
|
||||
Alire.Releases.New_Release
|
||||
(Projects.Alire_Reserved,
|
||||
Version => Version,
|
||||
Origin => New_Filesystem (Ada.Directories.Current_Directory),
|
||||
Notes => "Unindexed working copy",
|
||||
Dependencies => Dependencies,
|
||||
Properties => Index.No_Properties,
|
||||
Private_Properties => Index.No_Properties,
|
||||
Available => Requisites.No_Requisites);
|
||||
begin
|
||||
if Index.Exists (Project, Version) then
|
||||
-- This is done to ensure that properties are all available
|
||||
Trace.Debug ("Storing pre-indexed release of root project");
|
||||
Root.Replace_Element (Index.Find (Project, Version));
|
||||
else
|
||||
Trace.Debug ("Storing unindexed release of root project");
|
||||
Root.Replace_Element (Rel);
|
||||
end if;
|
||||
|
||||
return Rel;
|
||||
end Set;
|
||||
|
||||
end Alire.Root_Release;
|
||||
@@ -1,23 +0,0 @@
|
||||
with Alire.Conditional;
|
||||
with Alire.Releases;
|
||||
|
||||
with Semantic_Versioning;
|
||||
|
||||
package Alire.Root_Release is
|
||||
|
||||
-- When alr self-compiles it inserts a call to this function, so the dependency root is stablished
|
||||
|
||||
function Set (Project : Name_String;
|
||||
Version : Semantic_Versioning.Version;
|
||||
Dependencies : Conditional.Dependencies := Conditional.For_Dependencies.Empty)
|
||||
return Releases.Release;
|
||||
-- This function must be called in the working project alire file.
|
||||
-- Otherwise alr does not know what's the current project, and its version and dependencies
|
||||
-- It could be manually parsed from the file, but that's precisely what we want to avoid
|
||||
-- The returned Release is the same; this is just a trick to be able to use it in an spec file.
|
||||
|
||||
function Current return Releases.Release;
|
||||
|
||||
function Is_Set return Boolean;
|
||||
|
||||
end Alire.Root_Release;
|
||||
@@ -0,0 +1,64 @@
|
||||
with Alire.Conditional;
|
||||
with Alire.Containers;
|
||||
with Alire.Releases;
|
||||
|
||||
with Semantic_Versioning;
|
||||
|
||||
package Alire.Roots is
|
||||
|
||||
-- Type used to encapsulate the information about the root release/working copy
|
||||
|
||||
type Root (<>) is tagged private;
|
||||
|
||||
function New_Root (R : Releases.Release) return Root;
|
||||
|
||||
function New_Root (Name : Name_String;
|
||||
Dependencies : Conditional.Dependencies := Conditional.For_Dependencies.Empty)
|
||||
return Root;
|
||||
|
||||
function Dependencies (R : Root) return Conditional.Dependencies;
|
||||
function Is_Released (R : Root) return Boolean;
|
||||
function Name (R : Root) return Name_String;
|
||||
function Release (R : Root) return Releases.Release with Pre => R.Is_Released;
|
||||
function Version (R : Root) return Semantic_Versioning.Version with Pre => R.Is_Released;
|
||||
|
||||
private
|
||||
|
||||
type Root (Name_Len : Natural; Released : Boolean) is tagged record
|
||||
case Released is
|
||||
when False =>
|
||||
Name : String (1 .. Name_Len);
|
||||
Dependencies : Conditional.Dependencies;
|
||||
when True =>
|
||||
Release : Containers.Release_H;
|
||||
end case;
|
||||
end record;
|
||||
|
||||
function New_Root (R : Releases.Release) return Root is
|
||||
(0, True, Containers.Release_Holders.To_Holder (R));
|
||||
|
||||
function New_Root (Name : Name_String;
|
||||
Dependencies : Conditional.Dependencies := Conditional.For_Dependencies.Empty)
|
||||
return Root is
|
||||
(Name'Length, False, Name, Dependencies);
|
||||
|
||||
function Dependencies (R : Root) return Conditional.Dependencies is
|
||||
(if R.Released
|
||||
then R.Release.Constant_Reference.Depends
|
||||
else R.Dependencies);
|
||||
|
||||
function Is_Released (R : Root) return Boolean is (R.Released);
|
||||
|
||||
function Name (R : Root) return Name_String is
|
||||
(if R.Released
|
||||
then R.Release.Constant_Reference.Project
|
||||
else R.Name);
|
||||
|
||||
function Release (R : Root) return Releases.Release is (R.Release.Element);
|
||||
|
||||
function Version (R : Root) return Semantic_Versioning.Version is
|
||||
(if R.Released
|
||||
then R.Release.Constant_Reference.Version
|
||||
else raise Constraint_Error with "Unreleased root");
|
||||
|
||||
end Alire.Roots;
|
||||
Reference in New Issue
Block a user