Skip to content

Commit

Permalink
Use a separate system deployer in unknown systems
Browse files Browse the repository at this point in the history
Instead of defaulting to apt.
  • Loading branch information
mosteo committed Feb 15, 2024
1 parent d680bdc commit dd79711
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
23 changes: 23 additions & 0 deletions src/alire/alire-origins-deployers-system-unknown.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package Alire.Origins.Deployers.System.Unknown is

type Deployer is new Deployers.System.Deployer with null record;

overriding
function Already_Installed (This : Deployer) return Boolean
is (raise Program_Error with "Should be unreachable");

overriding
function Detect (This : Deployer)
return Version_Outcomes.Outcome
is (Version_Outcomes.Outcome_Failure
("unknown distro, cannot detect versions of system packages"));

overriding
function Install (This : Deployer) return Outcome
is (Outcome_Failure ("unknown distro, no system deployer"));

overriding
function Executable_Name (This : Deployer) return String
is ("nonexistent-package-manager-that-alire-musnt-find");

end Alire.Origins.Deployers.System.Unknown;
22 changes: 16 additions & 6 deletions src/alire/alire-origins-deployers-system.adb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ with Alire.Origins.Deployers.System.Homebrew;
with Alire.Origins.Deployers.System.Macports;
with Alire.Origins.Deployers.System.Pacman;
with Alire.Origins.Deployers.System.RPM_Wrappers;
with Alire.Origins.Deployers.System.Unknown;
with Alire.Origins.Deployers.System.Zypper;
with Alire.OS_Lib;
with Alire.Platforms.Current;

with CLIC.User_Input;

Expand Down Expand Up @@ -87,9 +87,12 @@ package body Alire.Origins.Deployers.System is
-- Platform_Deployer --
-----------------------

function Platform_Deployer (From : Origins.Origin) return Deployer'Class is
(case Platforms.Distro_Manager (Platforms.Current.Distribution) is
when Platforms.Apt | Platforms.Packager_Unknown =>
function Platform_Deployer
(From : Origins.Origin;
Distro : Platforms.Distributions := Platforms.Current.Distribution)
return Deployer'Class
is (case Platforms.Distro_Manager (Distro) is
when Platforms.Apt =>
System.Apt.Deployer'(Deployers.Deployer'(Base => From)
with others => <>),
when Platforms.Pacman =>
Expand All @@ -113,7 +116,11 @@ package body Alire.Origins.Deployers.System is
with others => <>),
when Platforms.Macports =>
System.Macports.Deployer'(Deployers.Deployer'(Base => From)
with others => <>));
with others => <>),
when Platforms.Packager_Unknown =>
System.Unknown.Deployer'(Deployers.Deployer'(Base => From)
with others => <>)
);
-- NOTE: add here other native package managers as they get
-- implemented.

Expand All @@ -135,7 +142,10 @@ package body Alire.Origins.Deployers.System is
-- We use a mock system package to be able to obtain a deployer. It
-- doesn't matter if this system package doesn't exist.
begin
return Platform_Deployer (Make).Executable_Name;
return Platform_Deployer
(Make,
Distro => Platforms.Current.Detected_Distribution)
.Executable_Name;
end Executable_Name;

---------------------
Expand Down
8 changes: 7 additions & 1 deletion src/alire/alire-origins-deployers-system.ads
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
with Alire.Outcomes.Definite;
with Alire.Platforms.Current;

with Semantic_Versioning;

Expand Down Expand Up @@ -56,8 +57,13 @@ package Alire.Origins.Deployers.System is
-- Factory --
-------------

function Platform_Deployer (From : Origins.Origin) return Deployer'Class
function Platform_Deployer
(From : Origins.Origin;
Distro : Platforms.Distributions := Platforms.Current.Distribution)
return Deployer'Class
with Pre => From.Is_System;
-- Returns the deployer for a current system. Defaults to current one,
-- unless distro detection is disabled.

function Platform_Deployer (Package_Name : String) return Deployer'Class is
(Platform_Deployer (Origins.New_System (Package_Name)));
Expand Down

0 comments on commit dd79711

Please sign in to comment.