diff --git a/src/alire-hooks.ads b/src/alire-hooks.ads deleted file mode 100644 index 4e77b6e8..00000000 --- a/src/alire-hooks.ads +++ /dev/null @@ -1,11 +0,0 @@ -with Alire.Origins; - -package Alire.Hooks with Preelaborate is - - -- Hackish way to enable Alire to obtain some platform-specific info that only Alr knows how to get - - -- WARNING: this will be null during elaboration! - - Version_Getter : access function (O : Origins.Origin) return String; - -end Alire.Hooks; diff --git a/src/alire-platform.adb b/src/alire-platform.adb new file mode 100644 index 00000000..fb108710 --- /dev/null +++ b/src/alire-platform.adb @@ -0,0 +1,32 @@ +with Ada.Containers.Indefinite_Holders; + +package body Alire.Platform is + + package Holders is new Ada.Containers.Indefinite_Holders (Supported_Platform'Class); + + This : Holders.Holder; + + + type Unsupported_Platform is new Supported_Platform with null record; + + overriding function Package_Version (P : Unsupported_Platform; Origin : Origins.Origin) return String is (""); + + ------------- + -- Current -- + ------------- + + function Current return Supported_Platform'Class is + (if This.Is_Empty + then Unsupported_Platform'(Supported_Platform with null record) + else This.Element); + + ------------------ + -- Set_Platform -- + ------------------ + + procedure Set_Platform (P : Supported_Platform'Class) is + begin + This.Replace_Element (P); + end Set_Platform; + +end Alire.Platform; diff --git a/src/alire-platform.ads b/src/alire-platform.ads new file mode 100644 index 00000000..7c382c38 --- /dev/null +++ b/src/alire-platform.ads @@ -0,0 +1,18 @@ +with Alire.Origins; + +package Alire.Platform with Preelaborate is + + -- This interface encapsulates what a supported platform must provide for use in Alire, and a way + -- to hook it after elaboration + + type Supported_Platform is interface; + + function Package_Version (P : Supported_Platform; Origin : Origins.Origin) return String is abstract; + + procedure Set_Platform (P : Supported_Platform'Class); + + function Current return Supported_Platform'Class + with Pre => Platform'Elaborated; + -- Always valid, because at worst a dummy do-nothign one is returned + +end Alire.Platform; diff --git a/src/alire-releases.adb b/src/alire-releases.adb index 4b843721..ba4705ed 100644 --- a/src/alire-releases.adb +++ b/src/alire-releases.adb @@ -1,6 +1,6 @@ with Alire.Conditional_Values; with Alire.Dependencies.Vectors; -with Alire.Hooks; +with Alire.Platform; with Alire.Platforms; with Alire.Requisites.Booleans; @@ -247,11 +247,10 @@ package body Alire.Releases is ------------- function Version (R : Release) return Semantic_Versioning.Version is - use Hooks; begin - if Hooks.Version_Getter /= null and then R.Origin.Is_Native then + if R.Origin.Is_Native then declare - Native_Version : constant String := Hooks.Version_Getter (R.Origin); + Native_Version : constant String := Platform.Current.Package_Version (R.Origin); begin if Native_Version /= "" then return New_Version (Image (R.Version) & "+" & Native_Version);