Skip to content

Commit 87c9375

Browse files
LucretiamosteomgrojoAldanTanneoSeb-MCaw
authored
Add Gentoo system package manager (#2006)
* Add Gentoo and Portage into the platforms and package managers. * Add a new package to support portage on Gentoo. * Hook in Gentoo/Portage into the Deployers * dev: check templates are up to date (#1995) * dev: check templates are up to date * Touch template * Better feedback * Restore touched template * dev: guidelines for automatic Copilot reviews (#1998) * dev: instructions for copilot reviews * Add info about testing * fix: pass GH token in Docker tests too (#1999) * dev: placeholder for ignoring known future properties (#2000) * Minimal spec for future property * Implementation & Test * Do not leak hidden property * fix: typos in `catalog-format-spec.md` (#2002) * fix: workflow on aarch64 linux, macOS 14 instead of latest (#2003) * attempt fixing workflow on aarch64 linux * dev: force macOS 14 macos-latest runner is now macOS 15 which breaks things, yet to diagnose... * fix: force macOS 14 in `ci-toolchain.yml` * dev: remove custom aarch case from `ci-release.yml` * Revert "dev: remove custom aarch case from `ci-release.yml`" This reverts commit 069997e. --------- Co-authored-by: Alejandro R Mosteo <amosteo@unizar.es> * feat: prevent incidental output breaking structured output (#2005) * Add test * Fix incidental output breaking structured output * Add note to `--format`'s description * Fix typo in test comment Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add documentation for Gentoo. * Simplify the expression. * Fix indexing error. Check to make sure we have a line to check before checking the line. * feat: validation of GH PATs (#1994) * feat: minimal vetting of GH PATs * Old check when forcing * Correct the package manager's name to emerge. * Change the log level to Detail. * Change Info -> Debug. * Add the comment box. * Bump den dependency * Downgrade level of some logs --------- Co-authored-by: Alejandro R Mosteo <amosteo@unizar.es> Co-authored-by: Manuel <mgrojo@gmail.com> Co-authored-by: César Sagaert <aldantanneo@gmail.com> Co-authored-by: Seb M'Caw <mcaw@adacore.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 8062c0d commit 87c9375

File tree

6 files changed

+181
-3
lines changed

6 files changed

+181
-3
lines changed

doc/user-changes.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ stay on top of `alr` new features.
66

77
## Release `3.0`
88

9+
### Gentoo support
10+
11+
Add Gentoo's Portage support via sudo, if the base package contains a section for gentoo, see libsdl2 for example, emerge will be called if the package is not installed.
12+
913
### New `--github` switch for `alr init` command
1014

1115
PR [#1972](https://github.com/alire-project/alire/pull/1972)
@@ -81,9 +85,9 @@ easily. It takes several optional command line flags:
8185

8286
- `--location=<path/to/alr>` to specify where to install the new binary
8387
- `--release=<version>` to download and install a specific version (provided
84-
that Alire builds binaries for this version on your platform)
88+
that Alire builds binaries for this version on your platform)
8589
- `--nightly` to install a pre-release version of Alire.
86-
90+
8791
**Disclaimer**: nightly versions may have incomplete features, unresolved
8892
bugs and may delete features or break compatibility without warning.
8993

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
with Ada.Characters.Latin_1;
2+
with AAA.Strings; use AAA.Strings;
3+
4+
with Alire.Errors;
5+
with Alire.OS_Lib.Subprocess;
6+
-- with Alire.Utils.Regex;
7+
8+
package body Alire.Origins.Deployers.System.Portage is
9+
10+
package L1 renames Ada.Characters.Latin_1;
11+
package Subprocess renames Alire.OS_Lib.Subprocess;
12+
13+
-----------------------
14+
-- Already_Installed --
15+
-----------------------
16+
17+
overriding function Already_Installed (This : Deployer) return Boolean
18+
is
19+
-- The following call is faster than using emerge.
20+
Output : constant AAA.Strings.Vector :=
21+
Subprocess.Checked_Spawn_And_Capture
22+
("eix",
23+
Empty_Vector & "-ce" & This.Base.Package_Name,
24+
-- Check the category (A),
25+
-- whether it is installed (I) and
26+
-- match against the exact string (e).
27+
-- i.e. "app-editors/zed"
28+
Valid_Exit_Codes => (1, 0), -- returns 1 when not found
29+
Err_To_Out => True);
30+
31+
Indicator : constant String := "[I]";
32+
Line : constant String := AAA.Strings.First_Element (Output);
33+
begin
34+
Trace.Detail ("Already_Installed: " & This.Base.Package_Name);
35+
36+
if Line'Length >= Indicator'Length then
37+
return
38+
Line (Line'First .. Line'First + Indicator'Length - 1) = Indicator;
39+
end if;
40+
41+
return False;
42+
end Already_Installed;
43+
44+
-------------------------
45+
-- To_Semantic_Version --
46+
-------------------------
47+
48+
function To_Semantic_Version (Gentoo_Version : String) return String is
49+
Tmp : String := Gentoo_Version;
50+
begin
51+
for C in Tmp'Range loop
52+
-- Format: 0.0.0_release-rc9
53+
if Tmp (C) = L1.Low_Line then
54+
Tmp (C) := L1.Hyphen;
55+
56+
Trace.Debug ("To_Semantic_Version: " & Tmp);
57+
58+
return Tmp;
59+
end if;
60+
end loop;
61+
62+
Trace.Debug ("To_Semantic_Version: " & Tmp);
63+
64+
return Tmp;
65+
end To_Semantic_Version;
66+
67+
------------
68+
-- Detect --
69+
------------
70+
71+
overriding
72+
function Detect (This : Deployer) return Version_Outcomes.Outcome
73+
is
74+
function Split_Version (Gentoo_Package_Version : String) return String is
75+
begin
76+
for Index in Gentoo_Package_Version'Range loop
77+
if Gentoo_Package_Version (Index) = L1.Hyphen then
78+
return Gentoo_Package_Version
79+
(Index + 1 .. Gentoo_Package_Version'Last);
80+
end if;
81+
end loop;
82+
83+
return "";
84+
end Split_Version;
85+
pragma Unreferenced (Split_Version);
86+
87+
PortageQ_Output : constant AAA.Strings.Vector :=
88+
Subprocess.Checked_Spawn_And_Capture
89+
("portageq",
90+
Empty_Vector & "best_visible" & "/" &
91+
This.Base.Package_Name,
92+
Valid_Exit_Codes => (0, 1), -- Returned when not found
93+
Err_To_Out => True);
94+
-- portageq should *always* produce zero or one line result.
95+
96+
Output : constant AAA.Strings.Vector :=
97+
Subprocess.Checked_Spawn_And_Capture
98+
("qatom",
99+
Empty_Vector & "-F%{PVR}" &
100+
First_Element (PortageQ_Output),
101+
Valid_Exit_Codes => (0, 1), -- Returned when not found
102+
Err_To_Out => True);
103+
Gentoo_Version : constant String := First_Element (Output);
104+
105+
-- Regexp : constant String :=
106+
-- "[0-9]+(\.[0-9]+)*[a-z](_[a-z]+[0-9]?)*(-r[0-9]*)*";
107+
-- From the pms.pdf.
108+
begin
109+
if Gentoo_Version /= "" then
110+
Trace.Debug ("Detect: " & This.Base.Package_Name & " - " &
111+
Gentoo_Version & " - " & To_Semantic_Version (Gentoo_Version) &
112+
" => " & Semantic_Versioning.Parse
113+
(To_Semantic_Version (Gentoo_Version),
114+
Relaxed => True).Image);
115+
116+
return
117+
Version_Outcomes.New_Result
118+
(Semantic_Versioning.Parse
119+
(To_Semantic_Version (Gentoo_Version), Relaxed => True));
120+
end if;
121+
122+
Trace.Debug ("System deployer could not detect: " & This.Base.Image);
123+
return Version_Outcomes.Outcome_Failure ("could not be detected",
124+
Report => False);
125+
end Detect;
126+
127+
-------------
128+
-- Install --
129+
-------------
130+
131+
overriding
132+
function Install (This : Deployer) return Outcome is
133+
begin
134+
Trace.Debug ("Install: " & This.Base.Package_Name);
135+
136+
Subprocess.Checked_Spawn
137+
("sudo", Empty_Vector &
138+
"emerge" &
139+
"-av" &
140+
This.Base.Package_Name);
141+
142+
return Outcome_Success;
143+
exception
144+
when E : others =>
145+
return Alire.Errors.Get (E);
146+
end Install;
147+
148+
end Alire.Origins.Deployers.System.Portage;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package Alire.Origins.Deployers.System.Portage is
2+
3+
type Deployer is new Deployers.System.Deployer with null record;
4+
5+
overriding
6+
function Already_Installed (This : Deployer) return Boolean;
7+
8+
overriding
9+
function Detect (This : Deployer)
10+
return Version_Outcomes.Outcome;
11+
12+
overriding
13+
function Install (This : Deployer) return Outcome;
14+
15+
overriding
16+
function Executable_Name (This : Deployer) return String is ("emerge");
17+
18+
end Alire.Origins.Deployers.System.Portage;

src/alire/alire-origins-deployers-system.adb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
with Alire.Origins.Deployers.System.Apt;
2+
with Alire.Origins.Deployers.System.Portage;
23
with Alire.Origins.Deployers.System.Homebrew;
34
with Alire.Origins.Deployers.System.Macports;
45
with Alire.Origins.Deployers.System.Pacman;
@@ -11,6 +12,7 @@ with Alire.Toolchains;
1112
with CLIC.User_Input;
1213

1314
with GNAT.IO;
15+
-- with System;
1416

1517
package body Alire.Origins.Deployers.System is
1618

@@ -118,6 +120,9 @@ package body Alire.Origins.Deployers.System is
118120
when Platforms.Macports =>
119121
System.Macports.Deployer'(Deployers.Deployer'(Base => From)
120122
with others => <>),
123+
when Platforms.Portage =>
124+
System.Portage.Deployer'(Deployers.Deployer'(Base => From)
125+
with others => <>),
121126
when Platforms.Packager_Unknown =>
122127
System.Unknown.Deployer'(Deployers.Deployer'(Base => From)
123128
with others => <>)

src/alire/alire-platforms.ads

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ package Alire.Platforms with Preelaborate is
4444
Suse,
4545
Homebrew,
4646
Macports,
47+
Gentoo,
4748
Distribution_Unknown);
4849

4950
subtype Known_Distributions is
@@ -61,6 +62,7 @@ package Alire.Platforms with Preelaborate is
6162
Zypper,
6263
Homebrew,
6364
Macports,
65+
Portage,
6466
Packager_Unknown);
6567

6668
Distro_Manager : constant array (Distributions) of Package_Managers :=
@@ -71,6 +73,7 @@ package Alire.Platforms with Preelaborate is
7173
Suse => Zypper,
7274
Homebrew => Homebrew,
7375
Macports => Macports,
76+
Gentoo => Portage,
7477
Distribution_Unknown => Packager_Unknown);
7578

7679
type Toolchains is (System,

src/alire/alire-utils-tools.adb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ package body Alire.Utils.Tools is
5959
return "";
6060

6161
when Msys2 | Debian | Ubuntu | Arch | Centos | Fedora | Rhel | Suse
62-
| Homebrew | Macports =>
62+
| Homebrew | Macports | Gentoo =>
6363
return (case Tool is
6464
when Easy_Graph =>
6565
(if Distribution in Centos | Fedora | Rhel | Suse

0 commit comments

Comments
 (0)